diff --git a/build.go b/build.go index bc75e7d53..2bda4d522 100644 --- a/build.go +++ b/build.go @@ -705,7 +705,7 @@ func shouldRebuildAssets(target, srcdir string) bool { } func proto() { - runPrint("go", "generate", "github.com/syncthing/syncthing/lib/...") + runPrint("go", "generate", "github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/stdiscosrv") } func translate() { diff --git a/cmd/stdiscosrv/LICENSE b/cmd/stdiscosrv/LICENSE deleted file mode 100644 index 9dd6db410..000000000 --- a/cmd/stdiscosrv/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (C) 2014-2015 The Discosrv Authors - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -- The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/cmd/stdiscosrv/README.md b/cmd/stdiscosrv/README.md index 7de906c7b..bdc0a5a84 100644 --- a/cmd/stdiscosrv/README.md +++ b/cmd/stdiscosrv/README.md @@ -6,33 +6,4 @@ This is the global discovery server for the `syncthing` project. Usage ----- -The discovery server supports `ql` and `postgres` backends. -Specify the backend via `-db-backend` and the database DSN via `-db-dsn`. - -By default it will use in-memory `ql` backend. If you wish to persist the -information on disk between restarts in `ql`, specify a file DSN: - -```bash -$ stdiscosrv -db-dsn="file:///var/run/stdiscosrv.db" -``` - -For `postgres`, you will need to create a database and a user with permissions -to create tables in it, then start the stdiscosrv as follows: - -```bash -$ export STDISCOSRV_DB_DSN="postgres://user:password@localhost/databasename" -$ stdiscosrv -db-backend="postgres" -``` - -You can pass the DSN as command line option, but the value what you pass in will -be visible in most process managers, potentially exposing the database password -to other users. - -In all cases, the appropriate tables and indexes will be created at first -startup. If it doesn't exit with an error, you're fine. - -See `stdiscosrv -help` for other options. - -##### Third-party attribution - -[cznic/lldb](https://github.com/cznic/lldb), Copyright (C) 2014 The lldb Authors. +https://docs.syncthing.net/users/stdiscosrv.html \ No newline at end of file diff --git a/cmd/stdiscosrv/apisrv.go b/cmd/stdiscosrv/apisrv.go new file mode 100644 index 000000000..3190a04b9 --- /dev/null +++ b/cmd/stdiscosrv/apisrv.go @@ -0,0 +1,394 @@ +// Copyright (C) 2018 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. + +package main + +import ( + "bytes" + "crypto/tls" + "encoding/json" + "encoding/pem" + "fmt" + "log" + "math/rand" + "net" + "net/http" + "net/url" + "strconv" + "sync" + "time" + + "github.com/syncthing/syncthing/lib/protocol" + "golang.org/x/net/context" +) + +// announcement is the format received from and sent to clients +type announcement struct { + Seen time.Time `json:"seen"` + Addresses []string `json:"addresses"` +} + +type apiSrv struct { + addr string + cert tls.Certificate + db database + listener net.Listener + repl replicator // optional + useHTTP bool + + mapsMut sync.Mutex + misses map[string]int32 +} + +type requestID int64 + +func (i requestID) String() string { + return fmt.Sprintf("%016x", int64(i)) +} + +type contextKey int + +const idKey contextKey = iota + +func newAPISrv(addr string, cert tls.Certificate, db database, repl replicator, useHTTP bool) *apiSrv { + return &apiSrv{ + addr: addr, + cert: cert, + db: db, + repl: repl, + useHTTP: useHTTP, + misses: make(map[string]int32), + } +} + +func (s *apiSrv) Serve() { + if s.useHTTP { + listener, err := net.Listen("tcp", s.addr) + if err != nil { + log.Println("Listen:", err) + return + } + s.listener = listener + } else { + tlsCfg := &tls.Config{ + Certificates: []tls.Certificate{s.cert}, + ClientAuth: tls.RequestClientCert, + SessionTicketsDisabled: true, + MinVersion: tls.VersionTLS12, + CipherSuites: []uint16{ + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, + tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, + }, + } + + tlsListener, err := tls.Listen("tcp", s.addr, tlsCfg) + if err != nil { + log.Println("Listen:", err) + return + } + s.listener = tlsListener + } + + http.HandleFunc("/", s.handler) + http.HandleFunc("/ping", handlePing) + + srv := &http.Server{ + ReadTimeout: httpReadTimeout, + WriteTimeout: httpWriteTimeout, + MaxHeaderBytes: httpMaxHeaderBytes, + } + + if err := srv.Serve(s.listener); err != nil { + log.Println("Serve:", err) + } +} + +var topCtx = context.Background() + +func (s *apiSrv) handler(w http.ResponseWriter, req *http.Request) { + t0 := time.Now() + + lw := NewLoggingResponseWriter(w) + + defer func() { + diff := time.Since(t0) + apiRequestsSeconds.WithLabelValues(req.Method).Observe(diff.Seconds()) + apiRequestsTotal.WithLabelValues(req.Method, strconv.Itoa(lw.statusCode)).Inc() + }() + + reqID := requestID(rand.Int63()) + ctx := context.WithValue(topCtx, idKey, reqID) + + if debug { + log.Println(reqID, req.Method, req.URL) + } + + var remoteIP net.IP + if s.useHTTP { + remoteIP = net.ParseIP(req.Header.Get("X-Forwarded-For")) + } else { + addr, err := net.ResolveTCPAddr("tcp", req.RemoteAddr) + if err != nil { + log.Println("remoteAddr:", err) + lw.Header().Set("Retry-After", errorRetryAfterString()) + http.Error(lw, "Internal Server Error", http.StatusInternalServerError) + apiRequestsTotal.WithLabelValues("no_remote_addr").Inc() + return + } + remoteIP = addr.IP + } + + switch req.Method { + case "GET": + s.handleGET(ctx, lw, req) + case "POST": + s.handlePOST(ctx, remoteIP, lw, req) + default: + http.Error(lw, "Method Not Allowed", http.StatusMethodNotAllowed) + } +} + +func (s *apiSrv) handleGET(ctx context.Context, w http.ResponseWriter, req *http.Request) { + reqID := ctx.Value(idKey).(requestID) + + deviceID, err := protocol.DeviceIDFromString(req.URL.Query().Get("device")) + if err != nil { + if debug { + log.Println(reqID, "bad device param") + } + lookupRequestsTotal.WithLabelValues("bad_request").Inc() + w.Header().Set("Retry-After", errorRetryAfterString()) + http.Error(w, "Bad Request", http.StatusBadRequest) + return + } + + key := deviceID.String() + rec, err := s.db.get(key) + if err != nil { + // some sort of internal error + lookupRequestsTotal.WithLabelValues("internal_error").Inc() + w.Header().Set("Retry-After", errorRetryAfterString()) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return + } + + if len(rec.Addresses) == 0 { + lookupRequestsTotal.WithLabelValues("not_found").Inc() + + s.mapsMut.Lock() + misses := s.misses[key] + if misses < rec.Misses { + misses = rec.Misses + 1 + } else { + misses++ + } + s.misses[key] = misses + s.mapsMut.Unlock() + + if misses%notFoundMissesWriteInterval == 0 { + rec.Misses = misses + rec.Addresses = nil + // rec.Seen retained from get + s.db.put(key, rec) + } + + w.Header().Set("Retry-After", notFoundRetryAfterString(int(misses))) + http.Error(w, "Not Found", http.StatusNotFound) + return + } + + lookupRequestsTotal.WithLabelValues("success").Inc() + + bs, _ := json.Marshal(announcement{ + Seen: time.Unix(0, rec.Seen), + Addresses: addressStrs(rec.Addresses), + }) + w.Header().Set("Content-Type", "application/json") + w.Write(bs) +} + +func (s *apiSrv) handlePOST(ctx context.Context, remoteIP net.IP, w http.ResponseWriter, req *http.Request) { + reqID := ctx.Value(idKey).(requestID) + + rawCert := certificateBytes(req) + if rawCert == nil { + if debug { + log.Println(reqID, "no certificates") + } + announceRequestsTotal.WithLabelValues("no_certificate").Inc() + w.Header().Set("Retry-After", errorRetryAfterString()) + http.Error(w, "Forbidden", http.StatusForbidden) + return + } + + var ann announcement + if err := json.NewDecoder(req.Body).Decode(&ann); err != nil { + if debug { + log.Println(reqID, "decode:", err) + } + announceRequestsTotal.WithLabelValues("bad_request").Inc() + w.Header().Set("Retry-After", errorRetryAfterString()) + http.Error(w, "Bad Request", http.StatusBadRequest) + return + } + + deviceID := protocol.NewDeviceID(rawCert) + + addresses := fixupAddresses(remoteIP, ann.Addresses) + if len(addresses) == 0 { + announceRequestsTotal.WithLabelValues("bad_request").Inc() + w.Header().Set("Retry-After", errorRetryAfterString()) + http.Error(w, "Bad Request", http.StatusBadRequest) + return + } + + if err := s.handleAnnounce(remoteIP, deviceID, addresses); err != nil { + announceRequestsTotal.WithLabelValues("internal_error").Inc() + w.Header().Set("Retry-After", errorRetryAfterString()) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return + } + + announceRequestsTotal.WithLabelValues("success").Inc() + + w.Header().Set("Reannounce-After", reannounceAfterString()) + w.WriteHeader(http.StatusNoContent) +} + +func (s *apiSrv) Stop() { + s.listener.Close() +} + +func (s *apiSrv) handleAnnounce(remote net.IP, deviceID protocol.DeviceID, addresses []string) error { + key := deviceID.String() + now := time.Now() + expire := now.Add(addressExpiryTime).UnixNano() + + dbAddrs := make([]DatabaseAddress, len(addresses)) + for i := range addresses { + dbAddrs[i].Address = addresses[i] + dbAddrs[i].Expires = expire + } + + seen := now.UnixNano() + if s.repl != nil { + s.repl.send(key, dbAddrs, seen) + } + return s.db.merge(key, dbAddrs, seen) +} + +func handlePing(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(204) +} + +func certificateBytes(req *http.Request) []byte { + if req.TLS != nil && len(req.TLS.PeerCertificates) > 0 { + return req.TLS.PeerCertificates[0].Raw + } + + if hdr := req.Header.Get("X-SSL-Cert"); hdr != "" { + bs := []byte(hdr) + // The certificate is in PEM format but with spaces for newlines. We + // need to reinstate the newlines for the PEM decoder. But we need to + // leave the spaces in the BEGIN and END lines - the first and last + // space - alone. + firstSpace := bytes.Index(bs, []byte(" ")) + lastSpace := bytes.LastIndex(bs, []byte(" ")) + for i := firstSpace + 1; i < lastSpace; i++ { + if bs[i] == ' ' { + bs[i] = '\n' + } + } + block, _ := pem.Decode(bs) + if block == nil { + // Decoding failed + return nil + } + return block.Bytes + } + + return nil +} + +// fixupAddresses checks the list of addresses, removing invalid ones and +// replacing unspecified IPs with the given remote IP. +func fixupAddresses(remote net.IP, addresses []string) []string { + fixed := make([]string, 0, len(addresses)) + for _, annAddr := range addresses { + uri, err := url.Parse(annAddr) + if err != nil { + continue + } + + host, port, err := net.SplitHostPort(uri.Host) + if err != nil { + continue + } + + ip := net.ParseIP(host) + if host == "" || ip.IsUnspecified() { + // Do not use IPv6 remote address if requested scheme is tcp4 + if uri.Scheme == "tcp4" && remote.To4() == nil { + continue + } + + // Do not use IPv4 remote address if requested scheme is tcp6 + if uri.Scheme == "tcp6" && remote.To4() != nil { + continue + } + + host = remote.String() + } + + uri.Host = net.JoinHostPort(host, port) + fixed = append(fixed, uri.String()) + } + + return fixed +} + +type loggingResponseWriter struct { + http.ResponseWriter + statusCode int +} + +func NewLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter { + return &loggingResponseWriter{w, http.StatusOK} +} + +func (lrw *loggingResponseWriter) WriteHeader(code int) { + lrw.statusCode = code + lrw.ResponseWriter.WriteHeader(code) +} + +func addressStrs(dbAddrs []DatabaseAddress) []string { + res := make([]string, len(dbAddrs)) + for i, a := range dbAddrs { + res[i] = a.Address + } + return res +} + +func errorRetryAfterString() string { + return strconv.Itoa(errorRetryAfterSeconds + rand.Intn(errorRetryFuzzSeconds)) +} + +func notFoundRetryAfterString(misses int) string { + retryAfterS := notFoundRetryMinSeconds + notFoundRetryIncSeconds*misses + if retryAfterS > notFoundRetryMaxSeconds { + retryAfterS = notFoundRetryMaxSeconds + } + retryAfterS += rand.Intn(notFoundRetryFuzzSeconds) + return strconv.Itoa(retryAfterS) +} + +func reannounceAfterString() string { + return strconv.Itoa(reannounceAfterSeconds + rand.Intn(reannounzeFuzzSeconds)) +} diff --git a/cmd/stdiscosrv/clean.go b/cmd/stdiscosrv/clean.go deleted file mode 100644 index 962f773f4..000000000 --- a/cmd/stdiscosrv/clean.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2014-2015 Jakob Borg and Contributors (see the CONTRIBUTORS file). - -package main - -import ( - "database/sql" - "log" - "time" -) - -type cleansrv struct { - intv time.Duration - db *sql.DB - prep map[string]*sql.Stmt -} - -func (s *cleansrv) Serve() { - for { - time.Sleep(next(s.intv)) - - err := s.cleanOldEntries() - if err != nil { - log.Println("Clean:", err) - } - } -} - -func (s *cleansrv) Stop() { - panic("stop unimplemented") -} - -func (s *cleansrv) cleanOldEntries() (err error) { - var tx *sql.Tx - tx, err = s.db.Begin() - if err != nil { - return err - } - - defer func() { - if err == nil { - err = tx.Commit() - } else { - tx.Rollback() - } - }() - - res, err := tx.Stmt(s.prep["cleanAddress"]).Exec() - if err != nil { - return err - } - if rows, _ := res.RowsAffected(); rows > 0 { - log.Printf("Clean: %d old addresses", rows) - } - - res, err = tx.Stmt(s.prep["cleanDevice"]).Exec() - if err != nil { - return err - } - if rows, _ := res.RowsAffected(); rows > 0 { - log.Printf("Clean: %d old devices", rows) - } - - var devs, addrs int - row := tx.Stmt(s.prep["countDevice"]).QueryRow() - if err = row.Scan(&devs); err != nil { - return err - } - row = tx.Stmt(s.prep["countAddress"]).QueryRow() - if err = row.Scan(&addrs); err != nil { - return err - } - - log.Printf("Database: %d devices, %d addresses", devs, addrs) - return nil -} diff --git a/cmd/stdiscosrv/database.go b/cmd/stdiscosrv/database.go new file mode 100644 index 000000000..9b7eec4fa --- /dev/null +++ b/cmd/stdiscosrv/database.go @@ -0,0 +1,336 @@ +// Copyright (C) 2018 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. + +//go:generate go run ../../script/protofmt.go database.proto +//go:generate protoc -I ../../../../../ -I ../../vendor/ -I ../../vendor/github.com/gogo/protobuf/protobuf -I . --gogofast_out=. database.proto + +package main + +import ( + "sort" + "time" + + "github.com/syndtr/goleveldb/leveldb" + "github.com/syndtr/goleveldb/leveldb/util" +) + +type clock interface { + Now() time.Time +} + +type defaultClock struct{} + +func (defaultClock) Now() time.Time { + return time.Now() +} + +type database interface { + put(key string, rec DatabaseRecord) error + merge(key string, addrs []DatabaseAddress, seen int64) error + get(key string) (DatabaseRecord, error) +} + +type levelDBStore struct { + db *leveldb.DB + inbox chan func() + stop chan struct{} + clock clock + marshalBuf []byte +} + +func newLevelDBStore(dir string) (*levelDBStore, error) { + db, err := leveldb.OpenFile(dir, levelDBOptions) + if err != nil { + return nil, err + } + return &levelDBStore{ + db: db, + inbox: make(chan func(), 16), + stop: make(chan struct{}), + clock: defaultClock{}, + }, nil +} + +func (s *levelDBStore) put(key string, rec DatabaseRecord) error { + t0 := time.Now() + defer func() { + databaseOperationSeconds.WithLabelValues(dbOpPut).Observe(time.Since(t0).Seconds()) + }() + + rc := make(chan error) + + s.inbox <- func() { + size := rec.Size() + if len(s.marshalBuf) < size { + s.marshalBuf = make([]byte, size) + } + n, _ := rec.MarshalTo(s.marshalBuf) + rc <- s.db.Put([]byte(key), s.marshalBuf[:n], nil) + } + + err := <-rc + if err != nil { + databaseOperations.WithLabelValues(dbOpPut, dbResError).Inc() + } else { + databaseOperations.WithLabelValues(dbOpPut, dbResSuccess).Inc() + } + + return err +} + +func (s *levelDBStore) merge(key string, addrs []DatabaseAddress, seen int64) error { + t0 := time.Now() + defer func() { + databaseOperationSeconds.WithLabelValues(dbOpMerge).Observe(time.Since(t0).Seconds()) + }() + + rc := make(chan error) + newRec := DatabaseRecord{ + Addresses: addrs, + Seen: seen, + } + + s.inbox <- func() { + // grab the existing record + oldRec, err := s.get(key) + if err != nil { + // "not found" is not an error from get, so this is serious + // stuff only + rc <- err + return + } + newRec = merge(newRec, oldRec) + + // We replicate s.put() functionality here ourselves instead of + // calling it because we want to serialize our get above together + // with the put in the same function. + size := newRec.Size() + if len(s.marshalBuf) < size { + s.marshalBuf = make([]byte, size) + } + n, _ := newRec.MarshalTo(s.marshalBuf) + rc <- s.db.Put([]byte(key), s.marshalBuf[:n], nil) + } + + err := <-rc + if err != nil { + databaseOperations.WithLabelValues(dbOpMerge, dbResError).Inc() + } else { + databaseOperations.WithLabelValues(dbOpMerge, dbResSuccess).Inc() + } + + return err +} + +func (s *levelDBStore) get(key string) (DatabaseRecord, error) { + t0 := time.Now() + defer func() { + databaseOperationSeconds.WithLabelValues(dbOpGet).Observe(time.Since(t0).Seconds()) + }() + + keyBs := []byte(key) + val, err := s.db.Get(keyBs, nil) + if err == leveldb.ErrNotFound { + databaseOperations.WithLabelValues(dbOpGet, dbResNotFound).Inc() + return DatabaseRecord{}, nil + } + if err != nil { + databaseOperations.WithLabelValues(dbOpGet, dbResError).Inc() + return DatabaseRecord{}, err + } + + var rec DatabaseRecord + + if err := rec.Unmarshal(val); err != nil { + databaseOperations.WithLabelValues(dbOpGet, dbResUnmarshalError).Inc() + return DatabaseRecord{}, nil + } + + rec.Addresses = expire(rec.Addresses, s.clock.Now().UnixNano()) + databaseOperations.WithLabelValues(dbOpGet, dbResSuccess).Inc() + return rec, nil +} + +func (s *levelDBStore) Serve() { + t := time.NewTimer(0) + defer t.Stop() + defer s.db.Close() + + // Start the statistics serve routine. It will exit with us when + // statisticsTrigger is closed. + statisticsTrigger := make(chan struct{}) + defer close(statisticsTrigger) + statisticsDone := make(chan struct{}) + go s.statisticsServe(statisticsTrigger, statisticsDone) + + for { + select { + case fn := <-s.inbox: + // Run function in serialized order. + fn() + + case <-t.C: + // Trigger the statistics routine to do its thing in the + // background. + statisticsTrigger <- struct{}{} + + case <-statisticsDone: + // The statistics routine is done with one iteratation, schedule + // the next. + t.Reset(databaseStatisticsInterval) + + case <-s.stop: + // We're done. + return + } + } +} + +func (s *levelDBStore) statisticsServe(trigger <-chan struct{}, done chan<- struct{}) { + for range trigger { + t0 := time.Now() + nowNanos := t0.UnixNano() + cutoff24h := t0.Add(-24 * time.Hour).UnixNano() + cutoff1w := t0.Add(-7 * 24 * time.Hour).UnixNano() + current, last24h, last1w, inactive, errors := 0, 0, 0, 0, 0 + + iter := s.db.NewIterator(&util.Range{}, nil) + for iter.Next() { + // Attempt to unmarshal the record and count the + // failure if there's something wrong with it. + var rec DatabaseRecord + if err := rec.Unmarshal(iter.Value()); err != nil { + errors++ + continue + } + + // If there are addresses that have not expired it's a current + // record, otherwise account it based on when it was last seen + // (last 24 hours or last week) or finally as inactice. + switch { + case len(expire(rec.Addresses, nowNanos)) > 0: + current++ + case rec.Seen > cutoff24h: + last24h++ + case rec.Seen > cutoff1w: + last1w++ + default: + inactive++ + } + } + + iter.Release() + + databaseKeys.WithLabelValues("current").Set(float64(current)) + databaseKeys.WithLabelValues("last24h").Set(float64(last24h)) + databaseKeys.WithLabelValues("last1w").Set(float64(last1w)) + databaseKeys.WithLabelValues("inactive").Set(float64(inactive)) + databaseKeys.WithLabelValues("error").Set(float64(errors)) + databaseStatisticsSeconds.Set(time.Since(t0).Seconds()) + + // Signal that we are done and can be scheduled again. + done <- struct{}{} + } +} + +func (s *levelDBStore) Stop() { + close(s.stop) +} + +// merge returns the merged result of the two database records a and b. The +// result is the union of the two address sets, with the newer expiry time +// chosen for any duplicates. +func merge(a, b DatabaseRecord) DatabaseRecord { + // Both lists must be sorted for this to work. + sort.Slice(a.Addresses, func(i, j int) bool { + return a.Addresses[i].Address < a.Addresses[j].Address + }) + sort.Slice(b.Addresses, func(i, j int) bool { + return b.Addresses[i].Address < b.Addresses[j].Address + }) + + res := DatabaseRecord{ + Addresses: make([]DatabaseAddress, 0, len(a.Addresses)+len(b.Addresses)), + Seen: a.Seen, + } + if b.Seen > a.Seen { + res.Seen = b.Seen + } + + aIdx := 0 + bIdx := 0 + aAddrs := a.Addresses + bAddrs := b.Addresses +loop: + for { + switch { + case aIdx == len(aAddrs) && bIdx == len(bAddrs): + // both lists are exhausted, we are done + break loop + + case aIdx == len(aAddrs): + // a is exhausted, pick from b and continue + res.Addresses = append(res.Addresses, bAddrs[bIdx]) + bIdx++ + continue + + case bIdx == len(bAddrs): + // b is exhausted, pick from a and continue + res.Addresses = append(res.Addresses, aAddrs[aIdx]) + aIdx++ + continue + } + + // We have values left on both sides. + aVal := aAddrs[aIdx] + bVal := bAddrs[bIdx] + + switch { + case aVal.Address == bVal.Address: + // update for same address, pick newer + if aVal.Expires > bVal.Expires { + res.Addresses = append(res.Addresses, aVal) + } else { + res.Addresses = append(res.Addresses, bVal) + } + aIdx++ + bIdx++ + + case aVal.Address < bVal.Address: + // a is smallest, pick it and continue + res.Addresses = append(res.Addresses, aVal) + aIdx++ + + default: + // b is smallest, pick it and continue + res.Addresses = append(res.Addresses, bVal) + bIdx++ + } + } + return res +} + +// expire returns the list of addresses after removing expired entries. +// Expiration happen in place, so the slice given as the parameter is +// destroyed. Internal order is not preserved. +func expire(addrs []DatabaseAddress, now int64) []DatabaseAddress { + i := 0 + for i < len(addrs) { + if addrs[i].Expires < now { + // This item is expired. Replace it with the last in the list + // (noop if we are at the last item). + addrs[i] = addrs[len(addrs)-1] + // Wipe the last item of the list to release references to + // strings and stuff. + addrs[len(addrs)-1] = DatabaseAddress{} + // Shorten the slice. + addrs = addrs[:len(addrs)-1] + continue + } + i++ + } + return addrs +} diff --git a/cmd/stdiscosrv/database.pb.go b/cmd/stdiscosrv/database.pb.go new file mode 100644 index 000000000..eaa4b75cb --- /dev/null +++ b/cmd/stdiscosrv/database.pb.go @@ -0,0 +1,743 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: database.proto + +/* + Package main is a generated protocol buffer package. + + It is generated from these files: + database.proto + + It has these top-level messages: + DatabaseRecord + ReplicationRecord + DatabaseAddress +*/ +package main + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +import io "io" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type DatabaseRecord struct { + Addresses []DatabaseAddress `protobuf:"bytes,1,rep,name=addresses" json:"addresses"` + Misses int32 `protobuf:"varint,2,opt,name=misses,proto3" json:"misses,omitempty"` + Seen int64 `protobuf:"varint,3,opt,name=seen,proto3" json:"seen,omitempty"` +} + +func (m *DatabaseRecord) Reset() { *m = DatabaseRecord{} } +func (m *DatabaseRecord) String() string { return proto.CompactTextString(m) } +func (*DatabaseRecord) ProtoMessage() {} +func (*DatabaseRecord) Descriptor() ([]byte, []int) { return fileDescriptorDatabase, []int{0} } + +type ReplicationRecord struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Addresses []DatabaseAddress `protobuf:"bytes,2,rep,name=addresses" json:"addresses"` + Seen int64 `protobuf:"varint,3,opt,name=seen,proto3" json:"seen,omitempty"` +} + +func (m *ReplicationRecord) Reset() { *m = ReplicationRecord{} } +func (m *ReplicationRecord) String() string { return proto.CompactTextString(m) } +func (*ReplicationRecord) ProtoMessage() {} +func (*ReplicationRecord) Descriptor() ([]byte, []int) { return fileDescriptorDatabase, []int{1} } + +type DatabaseAddress struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Expires int64 `protobuf:"varint,2,opt,name=expires,proto3" json:"expires,omitempty"` +} + +func (m *DatabaseAddress) Reset() { *m = DatabaseAddress{} } +func (m *DatabaseAddress) String() string { return proto.CompactTextString(m) } +func (*DatabaseAddress) ProtoMessage() {} +func (*DatabaseAddress) Descriptor() ([]byte, []int) { return fileDescriptorDatabase, []int{2} } + +func init() { + proto.RegisterType((*DatabaseRecord)(nil), "main.DatabaseRecord") + proto.RegisterType((*ReplicationRecord)(nil), "main.ReplicationRecord") + proto.RegisterType((*DatabaseAddress)(nil), "main.DatabaseAddress") +} +func (m *DatabaseRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DatabaseRecord) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Addresses) > 0 { + for _, msg := range m.Addresses { + dAtA[i] = 0xa + i++ + i = encodeVarintDatabase(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + if m.Misses != 0 { + dAtA[i] = 0x10 + i++ + i = encodeVarintDatabase(dAtA, i, uint64(m.Misses)) + } + if m.Seen != 0 { + dAtA[i] = 0x18 + i++ + i = encodeVarintDatabase(dAtA, i, uint64(m.Seen)) + } + return i, nil +} + +func (m *ReplicationRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ReplicationRecord) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Key) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintDatabase(dAtA, i, uint64(len(m.Key))) + i += copy(dAtA[i:], m.Key) + } + if len(m.Addresses) > 0 { + for _, msg := range m.Addresses { + dAtA[i] = 0x12 + i++ + i = encodeVarintDatabase(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + if m.Seen != 0 { + dAtA[i] = 0x18 + i++ + i = encodeVarintDatabase(dAtA, i, uint64(m.Seen)) + } + return i, nil +} + +func (m *DatabaseAddress) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DatabaseAddress) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Address) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintDatabase(dAtA, i, uint64(len(m.Address))) + i += copy(dAtA[i:], m.Address) + } + if m.Expires != 0 { + dAtA[i] = 0x10 + i++ + i = encodeVarintDatabase(dAtA, i, uint64(m.Expires)) + } + return i, nil +} + +func encodeFixed64Database(dAtA []byte, offset int, v uint64) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + dAtA[offset+4] = uint8(v >> 32) + dAtA[offset+5] = uint8(v >> 40) + dAtA[offset+6] = uint8(v >> 48) + dAtA[offset+7] = uint8(v >> 56) + return offset + 8 +} +func encodeFixed32Database(dAtA []byte, offset int, v uint32) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + return offset + 4 +} +func encodeVarintDatabase(dAtA []byte, offset int, v uint64) int { + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return offset + 1 +} +func (m *DatabaseRecord) Size() (n int) { + var l int + _ = l + if len(m.Addresses) > 0 { + for _, e := range m.Addresses { + l = e.Size() + n += 1 + l + sovDatabase(uint64(l)) + } + } + if m.Misses != 0 { + n += 1 + sovDatabase(uint64(m.Misses)) + } + if m.Seen != 0 { + n += 1 + sovDatabase(uint64(m.Seen)) + } + return n +} + +func (m *ReplicationRecord) Size() (n int) { + var l int + _ = l + l = len(m.Key) + if l > 0 { + n += 1 + l + sovDatabase(uint64(l)) + } + if len(m.Addresses) > 0 { + for _, e := range m.Addresses { + l = e.Size() + n += 1 + l + sovDatabase(uint64(l)) + } + } + if m.Seen != 0 { + n += 1 + sovDatabase(uint64(m.Seen)) + } + return n +} + +func (m *DatabaseAddress) Size() (n int) { + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovDatabase(uint64(l)) + } + if m.Expires != 0 { + n += 1 + sovDatabase(uint64(m.Expires)) + } + return n +} + +func sovDatabase(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozDatabase(x uint64) (n int) { + return sovDatabase(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *DatabaseRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DatabaseRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DatabaseRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDatabase + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, DatabaseAddress{}) + if err := m.Addresses[len(m.Addresses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Misses", wireType) + } + m.Misses = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Misses |= (int32(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Seen", wireType) + } + m.Seen = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Seen |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipDatabase(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthDatabase + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ReplicationRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ReplicationRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ReplicationRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDatabase + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Key = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDatabase + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, DatabaseAddress{}) + if err := m.Addresses[len(m.Addresses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Seen", wireType) + } + m.Seen = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Seen |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipDatabase(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthDatabase + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DatabaseAddress) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DatabaseAddress: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DatabaseAddress: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDatabase + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Expires", wireType) + } + m.Expires = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDatabase + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Expires |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipDatabase(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthDatabase + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDatabase(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDatabase + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDatabase + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + return iNdEx, nil + case 1: + iNdEx += 8 + return iNdEx, nil + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDatabase + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + iNdEx += length + if length < 0 { + return 0, ErrInvalidLengthDatabase + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDatabase + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + innerWire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + innerWireType := int(innerWire & 0x7) + if innerWireType == 4 { + break + } + next, err := skipDatabase(dAtA[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + } + return iNdEx, nil + case 4: + return iNdEx, nil + case 5: + iNdEx += 4 + return iNdEx, nil + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + } + panic("unreachable") +} + +var ( + ErrInvalidLengthDatabase = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDatabase = fmt.Errorf("proto: integer overflow") +) + +func init() { proto.RegisterFile("database.proto", fileDescriptorDatabase) } + +var fileDescriptorDatabase = []byte{ + // 254 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0x49, 0x2c, 0x49, + 0x4c, 0x4a, 0x2c, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, + 0x93, 0xd2, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f, + 0xcf, 0xd7, 0x07, 0x4b, 0x26, 0x95, 0xa6, 0x81, 0x79, 0x60, 0x0e, 0x98, 0x05, 0xd1, 0xa4, 0x54, + 0xce, 0xc5, 0xe7, 0x02, 0x35, 0x26, 0x28, 0x35, 0x39, 0xbf, 0x28, 0x45, 0xc8, 0x92, 0x8b, 0x33, + 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x38, 0xb5, 0x58, 0x82, 0x51, 0x81, 0x59, 0x83, 0xdb, 0x48, + 0x54, 0x0f, 0x64, 0xb4, 0x1e, 0x4c, 0xa1, 0x23, 0x44, 0xda, 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, + 0x20, 0x84, 0x6a, 0x21, 0x31, 0x2e, 0xb6, 0xdc, 0x4c, 0xb0, 0x3e, 0x26, 0x05, 0x46, 0x0d, 0xd6, + 0x20, 0x28, 0x4f, 0x48, 0x88, 0x8b, 0xa5, 0x38, 0x35, 0x35, 0x4f, 0x82, 0x59, 0x81, 0x51, 0x83, + 0x39, 0x08, 0xcc, 0x56, 0x2a, 0xe1, 0x12, 0x0c, 0x4a, 0x2d, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, + 0xcc, 0xcf, 0x83, 0xda, 0x2d, 0xc0, 0xc5, 0x9c, 0x9d, 0x5a, 0x29, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, + 0x19, 0x04, 0x62, 0xa2, 0xba, 0x86, 0x89, 0x24, 0xd7, 0x60, 0xb3, 0xd5, 0x95, 0x8b, 0x1f, 0x4d, + 0x9f, 0x90, 0x04, 0x17, 0x3b, 0x54, 0x0f, 0xd4, 0x5e, 0x18, 0x17, 0x24, 0x93, 0x5a, 0x51, 0x90, + 0x59, 0x04, 0xf5, 0x0f, 0x73, 0x10, 0x8c, 0xeb, 0x24, 0x70, 0xe2, 0xa1, 0x1c, 0xc3, 0x89, 0x47, + 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x98, 0xc4, 0x06, 0x0e, 0x4e, 0x63, + 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9e, 0x45, 0x60, 0x7e, 0x95, 0x01, 0x00, 0x00, +} diff --git a/cmd/stdiscosrv/database.proto b/cmd/stdiscosrv/database.proto new file mode 100644 index 000000000..ff0c6dabb --- /dev/null +++ b/cmd/stdiscosrv/database.proto @@ -0,0 +1,30 @@ +// Copyright (C) 2018 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. + +syntax = "proto3"; + +package main; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_getters_all) = false; + +message DatabaseRecord { + repeated DatabaseAddress addresses = 1 [(gogoproto.nullable) = false]; + int32 misses = 2; // Number of lookups without hits + int64 seen = 3; // Unix nanos, last device announce +} + +message ReplicationRecord { + string key = 1; + repeated DatabaseAddress addresses = 2 [(gogoproto.nullable) = false]; + int64 seen = 3; // Unix nanos, last device announce +} + +message DatabaseAddress { + string address = 1; + int64 expires = 2; // Unix nanos +} diff --git a/cmd/stdiscosrv/database_test.go b/cmd/stdiscosrv/database_test.go new file mode 100644 index 000000000..1cfd28519 --- /dev/null +++ b/cmd/stdiscosrv/database_test.go @@ -0,0 +1,211 @@ +// Copyright (C) 2018 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. + +package main + +import ( + "fmt" + "os" + "testing" + "time" +) + +func TestDatabaseGetSet(t *testing.T) { + os.RemoveAll("_database") + defer os.RemoveAll("_database") + db, err := newLevelDBStore("_database") + if err != nil { + t.Fatal(err) + } + go db.Serve() + defer db.Stop() + + // Check missing record + + rec, err := db.get("abcd") + if err != nil { + t.Error("not found should not be an error") + } + if len(rec.Addresses) != 0 { + t.Error("addresses should be empty") + } + if rec.Misses != 0 { + t.Error("missing should be zero") + } + + // Set up a clock + + now := time.Now() + tc := &testClock{now} + db.clock = tc + + // Put a record + + rec.Addresses = []DatabaseAddress{ + {Address: "tcp://1.2.3.4:5", Expires: tc.Now().Add(time.Minute).UnixNano()}, + } + if err := db.put("abcd", rec); err != nil { + t.Fatal(err) + } + + // Verify it + + rec, err = db.get("abcd") + if err != nil { + t.Fatal(err) + } + if len(rec.Addresses) != 1 { + t.Log(rec.Addresses) + t.Fatal("should have one address") + } + if rec.Addresses[0].Address != "tcp://1.2.3.4:5" { + t.Log(rec.Addresses) + t.Error("incorrect address") + } + + // Wind the clock one half expiry, and merge in a new address + + tc.wind(30 * time.Second) + + addrs := []DatabaseAddress{ + {Address: "tcp://6.7.8.9:0", Expires: tc.Now().Add(time.Minute).UnixNano()}, + } + if err := db.merge("abcd", addrs, tc.Now().UnixNano()); err != nil { + t.Fatal(err) + } + + // Verify it + + rec, err = db.get("abcd") + if err != nil { + t.Fatal(err) + } + if len(rec.Addresses) != 2 { + t.Log(rec.Addresses) + t.Fatal("should have two addresses") + } + if rec.Addresses[0].Address != "tcp://1.2.3.4:5" { + t.Log(rec.Addresses) + t.Error("incorrect address[0]") + } + if rec.Addresses[1].Address != "tcp://6.7.8.9:0" { + t.Log(rec.Addresses) + t.Error("incorrect address[1]") + } + + // Pass the first expiry time + + tc.wind(45 * time.Second) + + // Verify it + + rec, err = db.get("abcd") + if err != nil { + t.Fatal(err) + } + if len(rec.Addresses) != 1 { + t.Log(rec.Addresses) + t.Fatal("should have one address") + } + if rec.Addresses[0].Address != "tcp://6.7.8.9:0" { + t.Log(rec.Addresses) + t.Error("incorrect address") + } + + // Put a record with misses + + rec = DatabaseRecord{Misses: 42} + if err := db.put("efgh", rec); err != nil { + t.Fatal(err) + } + + // Verify it + + rec, err = db.get("efgh") + if err != nil { + t.Fatal(err) + } + if len(rec.Addresses) != 0 { + t.Log(rec.Addresses) + t.Fatal("should have no addresses") + } + if rec.Misses != 42 { + t.Log(rec.Misses) + t.Error("incorrect misses") + } + + // Set an address + + addrs = []DatabaseAddress{ + {Address: "tcp://6.7.8.9:0", Expires: tc.Now().Add(time.Minute).UnixNano()}, + } + if err := db.merge("efgh", addrs, tc.Now().UnixNano()); err != nil { + t.Fatal(err) + } + + // Verify it + + rec, err = db.get("efgh") + if err != nil { + t.Fatal(err) + } + if len(rec.Addresses) != 1 { + t.Log(rec.Addresses) + t.Fatal("should have one addres") + } + if rec.Misses != 0 { + t.Log(rec.Misses) + t.Error("should have no misses") + } +} + +func TestFilter(t *testing.T) { + // all cases are expired with t=10 + cases := []struct { + a []DatabaseAddress + b []DatabaseAddress + }{ + { + a: nil, + b: nil, + }, + { + a: []DatabaseAddress{{Address: "a", Expires: 9}, {Address: "b", Expires: 9}, {Address: "c", Expires: 9}}, + b: []DatabaseAddress{}, + }, + { + a: []DatabaseAddress{{Address: "a", Expires: 10}}, + b: []DatabaseAddress{{Address: "a", Expires: 10}}, + }, + { + a: []DatabaseAddress{{Address: "a", Expires: 10}, {Address: "b", Expires: 10}, {Address: "c", Expires: 10}}, + b: []DatabaseAddress{{Address: "a", Expires: 10}, {Address: "b", Expires: 10}, {Address: "c", Expires: 10}}, + }, + { + a: []DatabaseAddress{{Address: "a", Expires: 5}, {Address: "b", Expires: 15}, {Address: "c", Expires: 5}, {Address: "d", Expires: 15}, {Address: "e", Expires: 5}}, + b: []DatabaseAddress{{Address: "d", Expires: 15}, {Address: "b", Expires: 15}}, // gets reordered + }, + } + + for _, tc := range cases { + res := expire(tc.a, 10) + if fmt.Sprint(res) != fmt.Sprint(tc.b) { + t.Errorf("Incorrect result %v, expected %v", res, tc.b) + } + } +} + +type testClock struct { + now time.Time +} + +func (t *testClock) wind(d time.Duration) { + t.now = t.now.Add(d) +} + +func (t *testClock) Now() time.Time { + return t.now +} diff --git a/cmd/stdiscosrv/db.go b/cmd/stdiscosrv/db.go deleted file mode 100644 index 34162d588..000000000 --- a/cmd/stdiscosrv/db.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2014-2015 Jakob Borg and Contributors (see the CONTRIBUTORS file). - -package main - -import ( - "database/sql" - "fmt" -) - -type setupFunc func(db *sql.DB) error -type compileFunc func(db *sql.DB) (map[string]*sql.Stmt, error) - -var ( - setupFuncs = make(map[string]setupFunc) - compileFuncs = make(map[string]compileFunc) -) - -func register(name string, setup setupFunc, compile compileFunc) { - setupFuncs[name] = setup - compileFuncs[name] = compile -} - -func setup(backend string, db *sql.DB) (map[string]*sql.Stmt, error) { - setup, ok := setupFuncs[backend] - if !ok { - return nil, fmt.Errorf("Unsupported backend") - } - if err := setup(db); err != nil { - return nil, err - } - return compileFuncs[backend](db) -} diff --git a/cmd/stdiscosrv/main.go b/cmd/stdiscosrv/main.go index bbbf7c996..b74fcee5e 100644 --- a/cmd/stdiscosrv/main.go +++ b/cmd/stdiscosrv/main.go @@ -1,29 +1,70 @@ -// Copyright (C) 2014-2015 Jakob Borg and Contributors (see the CONTRIBUTORS file). +// Copyright (C) 2018 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. package main import ( "crypto/tls" - "database/sql" "flag" "fmt" "log" + "net" + "net/http" "os" "runtime" "strconv" + "strings" "time" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/tlsutil" + "github.com/syndtr/goleveldb/leveldb/opt" "github.com/thejerf/suture" ) const ( - minNegCache = 60 // seconds - maxNegCache = 3600 // seconds - maxDeviceAge = 7 * 86400 // one week, in seconds + addressExpiryTime = 2 * time.Hour + databaseStatisticsInterval = 5 * time.Minute + + // Reannounce-After is set to reannounceAfterSeconds + + // random(reannounzeFuzzSeconds), similar for Retry-After + reannounceAfterSeconds = 3300 + reannounzeFuzzSeconds = 300 + errorRetryAfterSeconds = 1500 + errorRetryFuzzSeconds = 300 + + // Retry for not found is minSeconds + failures * incSeconds + + // random(fuzz), where failures is the number of consecutive lookups + // with no answer, up to maxSeconds. The fuzz is applied after capping + // to maxSeconds. + notFoundRetryMinSeconds = 60 + notFoundRetryMaxSeconds = 3540 + notFoundRetryIncSeconds = 10 + notFoundRetryFuzzSeconds = 60 + + // How often (in requests) we serialize the missed counter to database. + notFoundMissesWriteInterval = 10 + + httpReadTimeout = 5 * time.Second + httpWriteTimeout = 5 * time.Second + httpMaxHeaderBytes = 1 << 10 + + // Size of the replication outbox channel + replicationOutboxSize = 10000 ) +// These options make the database a little more optimized for writes, at +// the expense of some memory usage and risk of losing writes in a (system) +// crash. +var levelDBOptions = &opt.Options{ + NoSync: true, + WriteBuffer: 32 << 20, // default 4<<20 +} + var ( Version string BuildStamp string @@ -43,17 +84,7 @@ func init() { } var ( - lruSize = 10240 - limitAvg = 5 - limitBurst = 20 - globalStats stats - statsFile string - backend = "ql" - dsn = getEnvDefault("STDISCOSRV_DB_DSN", "memory://stdiscosrv") - certFile = "cert.pem" - keyFile = "key.pem" - debug = false - useHTTP = false + debug = false ) func main() { @@ -63,84 +94,112 @@ func main() { ) var listen string + var dir string + var metricsListen string + var replicationListen string + var replicationPeers string + var certFile string + var keyFile string + var useHTTP bool log.SetOutput(os.Stdout) log.SetFlags(0) + flag.StringVar(&certFile, "cert", "./cert.pem", "Certificate file") + flag.StringVar(&dir, "db-dir", "./discovery.db", "Database directory") + flag.BoolVar(&debug, "debug", false, "Print debug output") + flag.BoolVar(&useHTTP, "http", false, "Listen on HTTP (behind an HTTPS proxy)") flag.StringVar(&listen, "listen", ":8443", "Listen address") - flag.IntVar(&lruSize, "limit-cache", lruSize, "Limiter cache entries") - flag.IntVar(&limitAvg, "limit-avg", limitAvg, "Allowed average package rate, per 10 s") - flag.IntVar(&limitBurst, "limit-burst", limitBurst, "Allowed burst size, packets") - flag.StringVar(&statsFile, "stats-file", statsFile, "File to write periodic operation stats to") - flag.StringVar(&backend, "db-backend", backend, "Database backend to use") - flag.StringVar(&dsn, "db-dsn", dsn, "Database DSN") - flag.StringVar(&certFile, "cert", certFile, "Certificate file") - flag.StringVar(&keyFile, "key", keyFile, "Key file") - flag.BoolVar(&debug, "debug", debug, "Debug") - flag.BoolVar(&useHTTP, "http", useHTTP, "Listen on HTTP (behind an HTTPS proxy)") + flag.StringVar(&keyFile, "key", "./key.pem", "Key file") + flag.StringVar(&metricsListen, "metrics-listen", "", "Metrics listen address") + flag.StringVar(&replicationPeers, "replicate", "", "Replication peers, id@address, comma separated") + flag.StringVar(&replicationListen, "replication-listen", ":19200", "Replication listen address") flag.Parse() log.Println(LongVersion) - var cert tls.Certificate - var err error - if !useHTTP { - cert, err = tls.LoadX509KeyPair(certFile, keyFile) + cert, err := tls.LoadX509KeyPair(certFile, keyFile) + if err != nil { + log.Println("Failed to load keypair. Generating one, this might take a while...") + cert, err = tlsutil.NewCertificate(certFile, keyFile, "stdiscosrv", 0) if err != nil { - log.Println("Failed to load keypair. Generating one, this might take a while...") - cert, err = tlsutil.NewCertificate(certFile, keyFile, "stdiscosrv", 3072) - if err != nil { - log.Fatalln("Failed to generate X509 key pair:", err) - } + log.Fatalln("Failed to generate X509 key pair:", err) } - - devID := protocol.NewDeviceID(cert.Certificate[0]) - log.Println("Server device ID is", devID) } - db, err := sql.Open(backend, dsn) - if err != nil { - log.Fatalln("sql.Open:", err) - } - prep, err := setup(backend, db) - if err != nil { - log.Fatalln("Setup:", err) + devID := protocol.NewDeviceID(cert.Certificate[0]) + log.Println("Server device ID is", devID) + + // Parse the replication specs, if any. + var allowedReplicationPeers []protocol.DeviceID + var replicationDestinations []string + parts := strings.Split(replicationPeers, ",") + for _, part := range parts { + fields := strings.Split(part, "@") + + switch len(fields) { + case 2: + // This is an id@address specification. Grab the address for the + // destination list. Try to resolve it once to catch obvious + // syntax errors here rather than having the sender service fail + // repeatedly later. + _, err := net.ResolveTCPAddr("tcp", fields[1]) + if err != nil { + log.Fatalln("Resolving address:", err) + } + replicationDestinations = append(replicationDestinations, fields[1]) + fallthrough // N.B. + + case 1: + // The first part is always a device ID. + id, err := protocol.DeviceIDFromString(fields[0]) + if err != nil { + log.Fatalln("Parsing device ID:", err) + } + allowedReplicationPeers = append(allowedReplicationPeers, id) + + default: + log.Fatalln("Unrecognized replication spec:", part) + } } + // Root of the service tree. main := suture.NewSimple("main") - main.Add(&querysrv{ - addr: listen, - cert: cert, - db: db, - prep: prep, - }) + // Start the database. + db, err := newLevelDBStore(dir) + if err != nil { + log.Fatalln("Open database:", err) + } + main.Add(db) - main.Add(&cleansrv{ - intv: cleanIntv, - db: db, - prep: prep, - }) + // Start any replication senders. + var repl replicationMultiplexer + for _, dst := range replicationDestinations { + rs := newReplicationSender(dst, cert, allowedReplicationPeers) + main.Add(rs) + repl = append(repl, rs) + } - main.Add(&statssrv{ - intv: statsIntv, - file: statsFile, - db: db, - }) + // If we have replication configured, start the replication listener. + if len(allowedReplicationPeers) > 0 { + rl := newReplicationListener(replicationListen, cert, allowedReplicationPeers, db) + main.Add(rl) + } - globalStats.Reset() + // Start the main API server. + qs := newAPISrv(listen, cert, db, repl, useHTTP) + main.Add(qs) + + // If we have a metrics port configured, start a metrics handler. + if metricsListen != "" { + go func() { + mux := http.NewServeMux() + mux.Handle("/metrics", promhttp.Handler()) + log.Fatal(http.ListenAndServe(metricsListen, mux)) + }() + } + + // Engage! main.Serve() } - -func getEnvDefault(key, def string) string { - if val := os.Getenv(key); val != "" { - return val - } - return def -} - -func next(intv time.Duration) time.Duration { - t0 := time.Now() - t1 := t0.Add(intv).Truncate(intv) - return t1.Sub(t0) -} diff --git a/cmd/stdiscosrv/psql.go b/cmd/stdiscosrv/psql.go deleted file mode 100644 index cb69df9c6..000000000 --- a/cmd/stdiscosrv/psql.go +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2014-2015 Jakob Borg and Contributors (see the CONTRIBUTORS file). - -package main - -import ( - "database/sql" - "fmt" - - _ "github.com/lib/pq" -) - -func init() { - register("postgres", postgresSetup, postgresCompile) -} - -func postgresSetup(db *sql.DB) error { - var err error - - db.SetMaxIdleConns(4) - db.SetMaxOpenConns(8) - - _, err = db.Exec(`CREATE TABLE IF NOT EXISTS Devices ( - DeviceID CHAR(63) NOT NULL PRIMARY KEY, - Seen TIMESTAMP NOT NULL - )`) - if err != nil { - return err - } - - var tmp string - row := db.QueryRow(`SELECT 'DevicesDeviceIDIndex'::regclass`) - if err = row.Scan(&tmp); err != nil { - _, err = db.Exec(`CREATE INDEX DevicesDeviceIDIndex ON Devices (DeviceID)`) - } - if err != nil { - return err - } - - row = db.QueryRow(`SELECT 'DevicesSeenIndex'::regclass`) - if err = row.Scan(&tmp); err != nil { - _, err = db.Exec(`CREATE INDEX DevicesSeenIndex ON Devices (Seen)`) - } - if err != nil { - return err - } - - _, err = db.Exec(`CREATE TABLE IF NOT EXISTS Addresses ( - DeviceID CHAR(63) NOT NULL, - Seen TIMESTAMP NOT NULL, - Address VARCHAR(2048) NOT NULL - )`) - if err != nil { - return err - } - - row = db.QueryRow(`SELECT 'AddressesDeviceIDSeenIndex'::regclass`) - if err = row.Scan(&tmp); err != nil { - _, err = db.Exec(`CREATE INDEX AddressesDeviceIDSeenIndex ON Addresses (DeviceID, Seen)`) - } - if err != nil { - return err - } - - row = db.QueryRow(`SELECT 'AddressesDeviceIDAddressIndex'::regclass`) - if err = row.Scan(&tmp); err != nil { - _, err = db.Exec(`CREATE INDEX AddressesDeviceIDAddressIndex ON Addresses (DeviceID, Address)`) - } - if err != nil { - return err - } - - return nil -} - -func postgresCompile(db *sql.DB) (map[string]*sql.Stmt, error) { - stmts := map[string]string{ - "cleanAddress": "DELETE FROM Addresses WHERE Seen < now() - '2 hour'::INTERVAL", - "cleanDevice": fmt.Sprintf("DELETE FROM Devices WHERE Seen < now() - '%d hour'::INTERVAL", maxDeviceAge/3600), - "countAddress": "SELECT count(*) FROM Addresses", - "countDevice": "SELECT count(*) FROM Devices", - "insertAddress": "INSERT INTO Addresses (DeviceID, Seen, Address) VALUES ($1, now(), $2)", - "insertDevice": "INSERT INTO Devices (DeviceID, Seen) VALUES ($1, now())", - "selectAddress": "SELECT Address FROM Addresses WHERE DeviceID=$1 AND Seen > now() - '1 hour'::INTERVAL ORDER BY random() LIMIT 16", - "selectDevice": "SELECT Seen FROM Devices WHERE DeviceID=$1", - "updateAddress": "UPDATE Addresses SET Seen=now() WHERE DeviceID=$1 AND Address=$2", - "updateDevice": "UPDATE Devices SET Seen=now() WHERE DeviceID=$1", - } - - res := make(map[string]*sql.Stmt, len(stmts)) - for key, stmt := range stmts { - prep, err := db.Prepare(stmt) - if err != nil { - return nil, err - } - res[key] = prep - } - return res, nil -} diff --git a/cmd/stdiscosrv/ql.go b/cmd/stdiscosrv/ql.go deleted file mode 100644 index 971ee6f27..000000000 --- a/cmd/stdiscosrv/ql.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2015 Audrius Butkevicius and Contributors (see the CONTRIBUTORS file). - -package main - -import ( - "database/sql" - "fmt" - "log" - - "github.com/cznic/ql" -) - -func init() { - ql.RegisterDriver() - register("ql", qlSetup, qlCompile) -} - -func qlSetup(db *sql.DB) (err error) { - tx, err := db.Begin() - if err != nil { - return - } - - defer func() { - if err == nil { - err = tx.Commit() - } else { - tx.Rollback() - } - }() - - _, err = tx.Exec(`CREATE TABLE IF NOT EXISTS Devices ( - DeviceID STRING NOT NULL, - Seen TIME NOT NULL - )`) - if err != nil { - return - } - - if _, err = tx.Exec(`CREATE INDEX IF NOT EXISTS DevicesDeviceIDIndex ON Devices (DeviceID)`); err != nil { - return - } - - _, err = tx.Exec(`CREATE TABLE IF NOT EXISTS Addresses ( - DeviceID STRING NOT NULL, - Seen TIME NOT NULL, - Address STRING NOT NULL, - )`) - if err != nil { - return - } - - _, err = tx.Exec(`CREATE INDEX IF NOT EXISTS AddressesDeviceIDAddressIndex ON Addresses (DeviceID, Address)`) - return -} - -func qlCompile(db *sql.DB) (map[string]*sql.Stmt, error) { - stmts := map[string]string{ - "cleanAddress": `DELETE FROM Addresses WHERE Seen < now() - duration("2h")`, - "cleanDevice": fmt.Sprintf(`DELETE FROM Devices WHERE Seen < now() - duration("%dh")`, maxDeviceAge/3600), - "countAddress": "SELECT count(*) FROM Addresses", - "countDevice": "SELECT count(*) FROM Devices", - "insertAddress": "INSERT INTO Addresses (DeviceID, Seen, Address) VALUES ($1, now(), $2)", - "insertDevice": "INSERT INTO Devices (DeviceID, Seen) VALUES ($1, now())", - "selectAddress": `SELECT Address from Addresses WHERE DeviceID==$1 AND Seen > now() - duration("1h") LIMIT 16`, - "selectDevice": "SELECT Seen FROM Devices WHERE DeviceID==$1", - "updateAddress": "UPDATE Addresses Seen=now() WHERE DeviceID==$1 AND Address==$2", - "updateDevice": "UPDATE Devices Seen=now() WHERE DeviceID==$1", - } - - res := make(map[string]*sql.Stmt, len(stmts)) - for key, stmt := range stmts { - prep, err := db.Prepare(stmt) - if err != nil { - log.Println("Failed to compile", stmt) - return nil, err - } - res[key] = prep - } - return res, nil -} diff --git a/cmd/stdiscosrv/querysrv.go b/cmd/stdiscosrv/querysrv.go deleted file mode 100644 index 61c321177..000000000 --- a/cmd/stdiscosrv/querysrv.go +++ /dev/null @@ -1,492 +0,0 @@ -// Copyright (C) 2014-2015 Jakob Borg and Contributors (see the CONTRIBUTORS file). - -package main - -import ( - "bytes" - "crypto/tls" - "database/sql" - "encoding/json" - "encoding/pem" - "fmt" - "log" - "math/rand" - "net" - "net/http" - "net/url" - "strconv" - "sync" - "time" - - "github.com/golang/groupcache/lru" - "github.com/syncthing/syncthing/lib/protocol" - "golang.org/x/net/context" - "golang.org/x/time/rate" -) - -type querysrv struct { - addr string - db *sql.DB - prep map[string]*sql.Stmt - limiter *safeCache - cert tls.Certificate - listener net.Listener -} - -type announcement struct { - Seen time.Time `json:"seen"` - Addresses []string `json:"addresses"` -} - -type safeCache struct { - *lru.Cache - mut sync.Mutex -} - -func (s *safeCache) Get(key string) (val interface{}, ok bool) { - s.mut.Lock() - val, ok = s.Cache.Get(key) - s.mut.Unlock() - return -} - -func (s *safeCache) Add(key string, val interface{}) { - s.mut.Lock() - s.Cache.Add(key, val) - s.mut.Unlock() -} - -type requestID int64 - -func (i requestID) String() string { - return fmt.Sprintf("%016x", int64(i)) -} - -type contextKey int - -const idKey contextKey = iota - -func negCacheFor(lastSeen time.Time) int { - since := time.Since(lastSeen).Seconds() - if since >= maxDeviceAge { - return maxNegCache - } - if since < 0 { - // That's weird - return minNegCache - } - - // Return a value linearly scaled from minNegCache (at zero seconds ago) - // to maxNegCache (at maxDeviceAge seconds ago). - r := since / maxDeviceAge - return int(minNegCache + r*(maxNegCache-minNegCache)) -} - -func (s *querysrv) Serve() { - s.limiter = &safeCache{ - Cache: lru.New(lruSize), - } - - if useHTTP { - listener, err := net.Listen("tcp", s.addr) - if err != nil { - log.Println("Listen:", err) - return - } - s.listener = listener - } else { - tlsCfg := &tls.Config{ - Certificates: []tls.Certificate{s.cert}, - ClientAuth: tls.RequestClientCert, - SessionTicketsDisabled: true, - MinVersion: tls.VersionTLS12, - CipherSuites: []uint16{ - tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, - tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, - tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, - tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, - tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, - }, - } - - tlsListener, err := tls.Listen("tcp", s.addr, tlsCfg) - if err != nil { - log.Println("Listen:", err) - return - } - s.listener = tlsListener - } - - http.HandleFunc("/v2/", s.handler) - http.HandleFunc("/ping", handlePing) - - srv := &http.Server{ - ReadTimeout: 5 * time.Second, - WriteTimeout: 5 * time.Second, - MaxHeaderBytes: 1 << 10, - } - - if err := srv.Serve(s.listener); err != nil { - log.Println("Serve:", err) - } -} - -var topCtx = context.Background() - -func (s *querysrv) handler(w http.ResponseWriter, req *http.Request) { - reqID := requestID(rand.Int63()) - ctx := context.WithValue(topCtx, idKey, reqID) - - if debug { - log.Println(reqID, req.Method, req.URL) - } - - t0 := time.Now() - defer func() { - diff := time.Since(t0) - var comment string - if diff > time.Second { - comment = "(very slow request)" - } else if diff > 100*time.Millisecond { - comment = "(slow request)" - } - if comment != "" || debug { - log.Println(reqID, req.Method, req.URL, "completed in", diff, comment) - } - }() - - var remoteIP net.IP - if useHTTP { - remoteIP = net.ParseIP(req.Header.Get("X-Forwarded-For")) - } else { - addr, err := net.ResolveTCPAddr("tcp", req.RemoteAddr) - if err != nil { - log.Println("remoteAddr:", err) - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - return - } - remoteIP = addr.IP - } - - if s.limit(remoteIP) { - if debug { - log.Println(remoteIP, "is limited") - } - w.Header().Set("Retry-After", "60") - http.Error(w, "Too Many Requests", 429) - return - } - - switch req.Method { - case "GET": - s.handleGET(ctx, w, req) - case "POST": - s.handlePOST(ctx, remoteIP, w, req) - default: - globalStats.Error() - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - } -} - -func (s *querysrv) handleGET(ctx context.Context, w http.ResponseWriter, req *http.Request) { - reqID := ctx.Value(idKey).(requestID) - - deviceID, err := protocol.DeviceIDFromString(req.URL.Query().Get("device")) - if err != nil { - if debug { - log.Println(reqID, "bad device param") - } - globalStats.Error() - http.Error(w, "Bad Request", http.StatusBadRequest) - return - } - - var ann announcement - - ann.Seen, err = s.getDeviceSeen(deviceID) - negCache := strconv.Itoa(negCacheFor(ann.Seen)) - w.Header().Set("Retry-After", negCache) - w.Header().Set("Cache-Control", "public, max-age="+negCache) - - if err != nil { - // The device is not in the database. - globalStats.Query() - http.Error(w, "Not Found", http.StatusNotFound) - return - } - - t0 := time.Now() - ann.Addresses, err = s.getAddresses(ctx, deviceID) - if err != nil { - log.Println(reqID, "getAddresses:", err) - globalStats.Error() - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - return - } - if debug { - log.Println(reqID, "getAddresses in", time.Since(t0)) - } - - globalStats.Query() - - if len(ann.Addresses) == 0 { - http.Error(w, "Not Found", http.StatusNotFound) - return - } - - globalStats.Answer() - - w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(ann) -} - -func (s *querysrv) handlePOST(ctx context.Context, remoteIP net.IP, w http.ResponseWriter, req *http.Request) { - reqID := ctx.Value(idKey).(requestID) - - rawCert := certificateBytes(req) - if rawCert == nil { - if debug { - log.Println(reqID, "no certificates") - } - globalStats.Error() - http.Error(w, "Forbidden", http.StatusForbidden) - return - } - - var ann announcement - if err := json.NewDecoder(req.Body).Decode(&ann); err != nil { - if debug { - log.Println(reqID, "decode:", err) - } - globalStats.Error() - http.Error(w, "Bad Request", http.StatusBadRequest) - return - } - - deviceID := protocol.NewDeviceID(rawCert) - - // handleAnnounce returns *two* errors. The first indicates a problem with - // something the client posted to us. We should return a 400 Bad Request - // and not worry about it. The second indicates that the request was fine, - // but something internal messed up. We should log it and respond with a - // more apologetic 500 Internal Server Error. - userErr, internalErr := s.handleAnnounce(ctx, remoteIP, deviceID, ann.Addresses) - if userErr != nil { - if debug { - log.Println(reqID, "handleAnnounce:", userErr) - } - globalStats.Error() - http.Error(w, "Bad Request", http.StatusBadRequest) - return - } - if internalErr != nil { - log.Println(reqID, "handleAnnounce:", internalErr) - globalStats.Error() - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - return - } - - globalStats.Announce() - - // TODO: Slowly increase this for stable clients - w.Header().Set("Reannounce-After", "1800") - - // We could return the lookup result here, but it's kind of unnecessarily - // expensive to go query the database again so we let the client decide to - // do a lookup if they really care. - w.WriteHeader(http.StatusNoContent) -} - -func (s *querysrv) Stop() { - s.listener.Close() -} - -func (s *querysrv) handleAnnounce(ctx context.Context, remote net.IP, deviceID protocol.DeviceID, addresses []string) (userErr, internalErr error) { - reqID := ctx.Value(idKey).(requestID) - - tx, err := s.db.Begin() - if err != nil { - internalErr = err - return - } - - defer func() { - // Since we return from a bunch of different places, we handle - // rollback in the defer. - if internalErr != nil || userErr != nil { - tx.Rollback() - } - }() - - for _, annAddr := range addresses { - uri, err := url.Parse(annAddr) - if err != nil { - userErr = err - return - } - - host, port, err := net.SplitHostPort(uri.Host) - if err != nil { - userErr = err - return - } - - ip := net.ParseIP(host) - if host == "" || ip.IsUnspecified() { - // Do not use IPv6 remote address if requested scheme is tcp4 - if uri.Scheme == "tcp4" && remote.To4() == nil { - continue - } - - // Do not use IPv4 remote address if requested scheme is tcp6 - if uri.Scheme == "tcp6" && remote.To4() != nil { - continue - } - - host = remote.String() - } - - uri.Host = net.JoinHostPort(host, port) - - if err := s.updateAddress(ctx, tx, deviceID, uri.String()); err != nil { - internalErr = err - return - } - } - - if err := s.updateDevice(ctx, tx, deviceID); err != nil { - internalErr = err - return - } - - t0 := time.Now() - internalErr = tx.Commit() - if debug { - log.Println(reqID, "commit in", time.Since(t0)) - } - return -} - -func (s *querysrv) limit(remote net.IP) bool { - key := remote.String() - - bkt, ok := s.limiter.Get(key) - if ok { - bkt := bkt.(*rate.Limiter) - if !bkt.Allow() { - // Rate limit exceeded; ignore packet - return true - } - } else { - // limitAvg is in packets per ten seconds. - s.limiter.Add(key, rate.NewLimiter(rate.Limit(limitAvg)/10, limitBurst)) - } - - return false -} - -func (s *querysrv) updateDevice(ctx context.Context, tx *sql.Tx, device protocol.DeviceID) error { - reqID := ctx.Value(idKey).(requestID) - t0 := time.Now() - res, err := tx.Stmt(s.prep["updateDevice"]).Exec(device.String()) - if err != nil { - return err - } - if debug { - log.Println(reqID, "updateDevice in", time.Since(t0)) - } - - if rows, _ := res.RowsAffected(); rows == 0 { - t0 = time.Now() - _, err := tx.Stmt(s.prep["insertDevice"]).Exec(device.String()) - if err != nil { - return err - } - if debug { - log.Println(reqID, "insertDevice in", time.Since(t0)) - } - } - - return nil -} - -func (s *querysrv) updateAddress(ctx context.Context, tx *sql.Tx, device protocol.DeviceID, uri string) error { - res, err := tx.Stmt(s.prep["updateAddress"]).Exec(device.String(), uri) - if err != nil { - return err - } - - if rows, _ := res.RowsAffected(); rows == 0 { - _, err := tx.Stmt(s.prep["insertAddress"]).Exec(device.String(), uri) - if err != nil { - return err - } - } - - return nil -} - -func (s *querysrv) getAddresses(ctx context.Context, device protocol.DeviceID) ([]string, error) { - rows, err := s.prep["selectAddress"].Query(device.String()) - if err != nil { - return nil, err - } - defer rows.Close() - - var res []string - for rows.Next() { - var addr string - - err := rows.Scan(&addr) - if err != nil { - log.Println("Scan:", err) - continue - } - res = append(res, addr) - } - - return res, nil -} - -func (s *querysrv) getDeviceSeen(device protocol.DeviceID) (time.Time, error) { - row := s.prep["selectDevice"].QueryRow(device.String()) - var seen time.Time - if err := row.Scan(&seen); err != nil { - return time.Time{}, err - } - return seen.In(time.UTC), nil -} - -func handlePing(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(204) -} - -func certificateBytes(req *http.Request) []byte { - if req.TLS != nil && len(req.TLS.PeerCertificates) > 0 { - return req.TLS.PeerCertificates[0].Raw - } - - if hdr := req.Header.Get("X-SSL-Cert"); hdr != "" { - bs := []byte(hdr) - // The certificate is in PEM format but with spaces for newlines. We - // need to reinstate the newlines for the PEM decoder. But we need to - // leave the spaces in the BEGIN and END lines - the first and last - // space - alone. - firstSpace := bytes.Index(bs, []byte(" ")) - lastSpace := bytes.LastIndex(bs, []byte(" ")) - for i := firstSpace + 1; i < lastSpace; i++ { - if bs[i] == ' ' { - bs[i] = '\n' - } - } - block, _ := pem.Decode(bs) - if block == nil { - // Decoding failed - return nil - } - return block.Bytes - } - - return nil -} diff --git a/cmd/stdiscosrv/replication.go b/cmd/stdiscosrv/replication.go new file mode 100644 index 000000000..5d8f804ab --- /dev/null +++ b/cmd/stdiscosrv/replication.go @@ -0,0 +1,304 @@ +// Copyright (C) 2018 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. + +package main + +import ( + "crypto/tls" + "encoding/binary" + "fmt" + io "io" + "log" + "net" + "time" + + "github.com/syncthing/syncthing/lib/protocol" +) + +type replicator interface { + send(key string, addrs []DatabaseAddress, seen int64) +} + +// a replicationSender tries to connect to the remote address and provide +// them with a feed of replication updates. +type replicationSender struct { + dst string + cert tls.Certificate // our certificate + allowedIDs []protocol.DeviceID + outbox chan ReplicationRecord + stop chan struct{} +} + +func newReplicationSender(dst string, cert tls.Certificate, allowedIDs []protocol.DeviceID) *replicationSender { + return &replicationSender{ + dst: dst, + cert: cert, + allowedIDs: allowedIDs, + outbox: make(chan ReplicationRecord, replicationOutboxSize), + stop: make(chan struct{}), + } +} + +func (s *replicationSender) Serve() { + // Sleep a little at startup. Peers often restart at the same time, and + // this avoid the service failing and entering backoff state + // unnecessarily, while also reducing the reconnect rate to something + // reasonable by default. + time.Sleep(2 * time.Second) + + tlsCfg := &tls.Config{ + Certificates: []tls.Certificate{s.cert}, + MinVersion: tls.VersionTLS12, + InsecureSkipVerify: true, + } + + // Dial the TLS connection. + conn, err := tls.Dial("tcp", s.dst, tlsCfg) + if err != nil { + log.Println("Replication connect:", err) + return + } + defer func() { + conn.SetWriteDeadline(time.Now().Add(time.Second)) + conn.Close() + }() + + // Get the other side device ID. + remoteID, err := deviceID(conn) + if err != nil { + log.Println("Replication connect:", err) + return + } + + // Verify it's in the set of allowed device IDs. + if !deviceIDIn(remoteID, s.allowedIDs) { + log.Println("Replication connect: unexpected device ID:", remoteID) + return + } + + // Send records. + buf := make([]byte, 1024) + for { + select { + case rec := <-s.outbox: + // Buffer must hold record plus four bytes for size + size := rec.Size() + if len(buf) < size+4 { + buf = make([]byte, size+4) + } + + // Record comes after the four bytes size + n, err := rec.MarshalTo(buf[4:]) + if err != nil { + // odd to get an error here, but we haven't sent anything + // yet so it's not fatal + replicationSendsTotal.WithLabelValues("error").Inc() + log.Println("Replication marshal:", err) + continue + } + binary.BigEndian.PutUint32(buf, uint32(n)) + + // Send + conn.SetWriteDeadline(time.Now().Add(5 * time.Second)) + if _, err := conn.Write(buf[:4+n]); err != nil { + replicationSendsTotal.WithLabelValues("error").Inc() + log.Println("Replication write:", err) + return + } + replicationSendsTotal.WithLabelValues("success").Inc() + + case <-s.stop: + return + } + } +} + +func (s *replicationSender) Stop() { + close(s.stop) +} + +func (s *replicationSender) String() string { + return fmt.Sprintf("replicationSender(%q)", s.dst) +} + +func (s *replicationSender) send(key string, ps []DatabaseAddress, seen int64) { + item := ReplicationRecord{ + Key: key, + Addresses: ps, + } + + // The send should never block. The inbox is suitably buffered for at + // least a few seconds of stalls, which shouldn't happen in practice. + select { + case s.outbox <- item: + default: + replicationSendsTotal.WithLabelValues("drop").Inc() + } +} + +// a replicationMultiplexer sends to multiple replicators +type replicationMultiplexer []replicator + +func (m replicationMultiplexer) send(key string, ps []DatabaseAddress, seen int64) { + for _, s := range m { + // each send is nonblocking + s.send(key, ps, seen) + } +} + +// replicationListener acceptes incoming connections and reads replication +// items from them. Incoming items are applied to the KV store. +type replicationListener struct { + addr string + cert tls.Certificate + allowedIDs []protocol.DeviceID + db database + stop chan struct{} +} + +func newReplicationListener(addr string, cert tls.Certificate, allowedIDs []protocol.DeviceID, db database) *replicationListener { + return &replicationListener{ + addr: addr, + cert: cert, + allowedIDs: allowedIDs, + db: db, + stop: make(chan struct{}), + } +} + +func (l *replicationListener) Serve() { + tlsCfg := &tls.Config{ + Certificates: []tls.Certificate{l.cert}, + ClientAuth: tls.RequestClientCert, + MinVersion: tls.VersionTLS12, + InsecureSkipVerify: true, + } + + lst, err := tls.Listen("tcp", l.addr, tlsCfg) + if err != nil { + log.Println("Replication listen:", err) + return + } + defer lst.Close() + + for { + select { + case <-l.stop: + return + default: + } + + // Accept a connection + conn, err := lst.Accept() + if err != nil { + log.Println("Replication accept:", err) + return + } + + // Figure out the other side device ID + remoteID, err := deviceID(conn.(*tls.Conn)) + if err != nil { + log.Println("Replication accept:", err) + conn.SetWriteDeadline(time.Now().Add(time.Second)) + conn.Close() + continue + } + + // Verify it is in the set of allowed device IDs + if !deviceIDIn(remoteID, l.allowedIDs) { + log.Println("Replication accept: unexpected device ID:", remoteID) + conn.SetWriteDeadline(time.Now().Add(time.Second)) + conn.Close() + continue + } + + go l.handle(conn) + } +} + +func (l *replicationListener) Stop() { + close(l.stop) +} + +func (l *replicationListener) String() string { + return fmt.Sprintf("replicationListener(%q)", l.addr) +} + +func (l *replicationListener) handle(conn net.Conn) { + defer func() { + conn.SetWriteDeadline(time.Now().Add(time.Second)) + conn.Close() + }() + + buf := make([]byte, 1024) + + for { + select { + case <-l.stop: + return + default: + } + + conn.SetReadDeadline(time.Now().Add(time.Minute)) + + // First four bytes are the size + if _, err := io.ReadFull(conn, buf[:4]); err != nil { + log.Println("Replication read size:", err) + replicationRecvsTotal.WithLabelValues("error").Inc() + return + } + + // Read the rest of the record + size := int(binary.BigEndian.Uint32(buf[:4])) + if len(buf) < size { + buf = make([]byte, size) + } + if _, err := io.ReadFull(conn, buf[:size]); err != nil { + log.Println("Replication read record:", err) + replicationRecvsTotal.WithLabelValues("error").Inc() + return + } + + // Unmarshal + var rec ReplicationRecord + if err := rec.Unmarshal(buf[:size]); err != nil { + log.Println("Replication unmarshal:", err) + replicationRecvsTotal.WithLabelValues("error").Inc() + continue + } + + // Store + l.db.merge(rec.Key, rec.Addresses, rec.Seen) + replicationRecvsTotal.WithLabelValues("success").Inc() + } +} + +func deviceID(conn *tls.Conn) (protocol.DeviceID, error) { + // Handshake may not be complete on the server side yet, which we need + // to get the client certificate. + if !conn.ConnectionState().HandshakeComplete { + if err := conn.Handshake(); err != nil { + return protocol.DeviceID{}, err + } + } + + // We expect exactly one certificate. + certs := conn.ConnectionState().PeerCertificates + if len(certs) != 1 { + return protocol.DeviceID{}, fmt.Errorf("unexpected number of certificates (%d != 1)", len(certs)) + } + + return protocol.NewDeviceID(certs[0].Raw), nil +} + +func deviceIDIn(id protocol.DeviceID, ids []protocol.DeviceID) bool { + for _, candidate := range ids { + if id == candidate { + return true + } + } + return false +} diff --git a/cmd/stdiscosrv/stats.go b/cmd/stdiscosrv/stats.go index cdc8c3012..609b420df 100644 --- a/cmd/stdiscosrv/stats.go +++ b/cmd/stdiscosrv/stats.go @@ -1,141 +1,108 @@ -// Copyright (C) 2014-2015 Jakob Borg and Contributors (see the CONTRIBUTORS file). +// Copyright (C) 2018 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. package main import ( - "bytes" - "database/sql" - "fmt" - "io/ioutil" - "log" - "os" - "sync/atomic" - "time" + "github.com/prometheus/client_golang/prometheus" ) -type stats struct { - // Incremented atomically - announces int64 - queries int64 - answers int64 - errors int64 -} - -func (s *stats) Announce() { - atomic.AddInt64(&s.announces, 1) -} - -func (s *stats) Query() { - atomic.AddInt64(&s.queries, 1) -} - -func (s *stats) Answer() { - atomic.AddInt64(&s.answers, 1) -} - -func (s *stats) Error() { - atomic.AddInt64(&s.errors, 1) -} - -// Reset returns a copy of the current stats and resets the counters to -// zero. -func (s *stats) Reset() stats { - // Create a copy of the stats using atomic reads - copy := stats{ - announces: atomic.LoadInt64(&s.announces), - queries: atomic.LoadInt64(&s.queries), - answers: atomic.LoadInt64(&s.answers), - errors: atomic.LoadInt64(&s.errors), - } - - // Reset the stats by subtracting the values that we copied - atomic.AddInt64(&s.announces, -copy.announces) - atomic.AddInt64(&s.queries, -copy.queries) - atomic.AddInt64(&s.answers, -copy.answers) - atomic.AddInt64(&s.errors, -copy.errors) - - return copy -} - -type statssrv struct { - intv time.Duration - file string - db *sql.DB -} - -func (s *statssrv) Serve() { - lastReset := time.Now() - for { - time.Sleep(next(s.intv)) - - stats := globalStats.Reset() - d := time.Since(lastReset).Seconds() - lastReset = time.Now() - - log.Printf("Stats: %.02f announces/s, %.02f queries/s, %.02f answers/s, %.02f errors/s", - float64(stats.announces)/d, float64(stats.queries)/d, float64(stats.answers)/d, float64(stats.errors)/d) - - if s.file != "" { - s.writeToFile(stats, d) - } - } -} - -func (s *statssrv) Stop() { - panic("stop unimplemented") -} - -func (s *statssrv) writeToFile(stats stats, secs float64) { - newLine := []byte("\n") - - var addrs int - row := s.db.QueryRow("SELECT COUNT(*) FROM Addresses") - if err := row.Scan(&addrs); err != nil { - log.Println("stats query:", err) - return - } - - fd, err := os.OpenFile(s.file, os.O_RDWR|os.O_CREATE, 0666) - if err != nil { - log.Println("stats file:", err) - return - } - defer func() { - err = fd.Close() - if err != nil { - log.Println("stats file:", err) - } - }() - - bs, err := ioutil.ReadAll(fd) - if err != nil { - log.Println("stats file:", err) - return - } - lines := bytes.Split(bytes.TrimSpace(bs), newLine) - if len(lines) > 12 { - lines = lines[len(lines)-12:] - } - - latest := fmt.Sprintf("%v: %6d addresses, %8.02f announces/s, %8.02f queries/s, %8.02f answers/s, %8.02f errors/s\n", - time.Now().UTC().Format(time.RFC3339), addrs, - float64(stats.announces)/secs, float64(stats.queries)/secs, float64(stats.answers)/secs, float64(stats.errors)/secs) - lines = append(lines, []byte(latest)) - - _, err = fd.Seek(0, 0) - if err != nil { - log.Println("stats file:", err) - return - } - err = fd.Truncate(0) - if err != nil { - log.Println("stats file:", err) - return - } - - _, err = fd.Write(bytes.Join(lines, newLine)) - if err != nil { - log.Println("stats file:", err) - return - } +var ( + apiRequestsTotal = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "api_requests_total", + Help: "Number of API requests.", + }, []string{"type", "result"}) + apiRequestsSeconds = prometheus.NewSummaryVec( + prometheus.SummaryOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "api_requests_seconds", + Help: "Latency of API requests.", + Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, + }, []string{"type"}) + + lookupRequestsTotal = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "lookup_requests_total", + Help: "Number of lookup requests.", + }, []string{"result"}) + announceRequestsTotal = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "announcement_requests_total", + Help: "Number of announcement requests.", + }, []string{"result"}) + + replicationSendsTotal = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "replication_sends_total", + Help: "Number of replication sends.", + }, []string{"result"}) + replicationRecvsTotal = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "replication_recvs_total", + Help: "Number of replication receives.", + }, []string{"result"}) + + databaseKeys = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "database_keys", + Help: "Number of database keys at last count.", + }, []string{"category"}) + databaseStatisticsSeconds = prometheus.NewGauge( + prometheus.GaugeOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "database_statistics_seconds", + Help: "Time spent running the statistics routine.", + }) + + databaseOperations = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "database_operations_total", + Help: "Number of database operations.", + }, []string{"operation", "result"}) + databaseOperationSeconds = prometheus.NewSummaryVec( + prometheus.SummaryOpts{ + Namespace: "syncthing", + Subsystem: "discovery", + Name: "database_operation_seconds", + Help: "Latency of database operations.", + Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, + }, []string{"operation"}) +) + +const ( + dbOpGet = "get" + dbOpPut = "put" + dbOpMerge = "merge" + dbResSuccess = "success" + dbResNotFound = "not_found" + dbResError = "error" + dbResUnmarshalError = "unmarsh_err" +) + +func init() { + prometheus.MustRegister(apiRequestsTotal, apiRequestsSeconds, + lookupRequestsTotal, announceRequestsTotal, + replicationSendsTotal, replicationRecvsTotal, + databaseKeys, databaseStatisticsSeconds, + databaseOperations, databaseOperationSeconds) } diff --git a/vendor/github.com/BurntSushi/toml/COPYING b/vendor/github.com/BurntSushi/toml/COPYING new file mode 100644 index 000000000..01b574320 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/COPYING @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013 TOML authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/main.go b/vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/main.go new file mode 100644 index 000000000..14e755700 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/main.go @@ -0,0 +1,90 @@ +// Command toml-test-decoder satisfies the toml-test interface for testing +// TOML decoders. Namely, it accepts TOML on stdin and outputs JSON on stdout. +package main + +import ( + "encoding/json" + "flag" + "fmt" + "log" + "os" + "path" + "time" + + "github.com/BurntSushi/toml" +) + +func init() { + log.SetFlags(0) + + flag.Usage = usage + flag.Parse() +} + +func usage() { + log.Printf("Usage: %s < toml-file\n", path.Base(os.Args[0])) + flag.PrintDefaults() + + os.Exit(1) +} + +func main() { + if flag.NArg() != 0 { + flag.Usage() + } + + var tmp interface{} + if _, err := toml.DecodeReader(os.Stdin, &tmp); err != nil { + log.Fatalf("Error decoding TOML: %s", err) + } + + typedTmp := translate(tmp) + if err := json.NewEncoder(os.Stdout).Encode(typedTmp); err != nil { + log.Fatalf("Error encoding JSON: %s", err) + } +} + +func translate(tomlData interface{}) interface{} { + switch orig := tomlData.(type) { + case map[string]interface{}: + typed := make(map[string]interface{}, len(orig)) + for k, v := range orig { + typed[k] = translate(v) + } + return typed + case []map[string]interface{}: + typed := make([]map[string]interface{}, len(orig)) + for i, v := range orig { + typed[i] = translate(v).(map[string]interface{}) + } + return typed + case []interface{}: + typed := make([]interface{}, len(orig)) + for i, v := range orig { + typed[i] = translate(v) + } + + // We don't really need to tag arrays, but let's be future proof. + // (If TOML ever supports tuples, we'll need this.) + return tag("array", typed) + case time.Time: + return tag("datetime", orig.Format("2006-01-02T15:04:05Z")) + case bool: + return tag("bool", fmt.Sprintf("%v", orig)) + case int64: + return tag("integer", fmt.Sprintf("%d", orig)) + case float64: + return tag("float", fmt.Sprintf("%v", orig)) + case string: + return tag("string", orig) + } + + panic(fmt.Sprintf("Unknown type: %T", tomlData)) +} + +func tag(typeName string, data interface{}) map[string]interface{} { + return map[string]interface{}{ + "type": typeName, + "value": data, + } +} diff --git a/vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/main.go b/vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/main.go new file mode 100644 index 000000000..092cc6844 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/main.go @@ -0,0 +1,131 @@ +// Command toml-test-encoder satisfies the toml-test interface for testing +// TOML encoders. Namely, it accepts JSON on stdin and outputs TOML on stdout. +package main + +import ( + "encoding/json" + "flag" + "log" + "os" + "path" + "strconv" + "time" + + "github.com/BurntSushi/toml" +) + +func init() { + log.SetFlags(0) + + flag.Usage = usage + flag.Parse() +} + +func usage() { + log.Printf("Usage: %s < json-file\n", path.Base(os.Args[0])) + flag.PrintDefaults() + + os.Exit(1) +} + +func main() { + if flag.NArg() != 0 { + flag.Usage() + } + + var tmp interface{} + if err := json.NewDecoder(os.Stdin).Decode(&tmp); err != nil { + log.Fatalf("Error decoding JSON: %s", err) + } + + tomlData := translate(tmp) + if err := toml.NewEncoder(os.Stdout).Encode(tomlData); err != nil { + log.Fatalf("Error encoding TOML: %s", err) + } +} + +func translate(typedJson interface{}) interface{} { + switch v := typedJson.(type) { + case map[string]interface{}: + if len(v) == 2 && in("type", v) && in("value", v) { + return untag(v) + } + m := make(map[string]interface{}, len(v)) + for k, v2 := range v { + m[k] = translate(v2) + } + return m + case []interface{}: + tabArray := make([]map[string]interface{}, len(v)) + for i := range v { + if m, ok := translate(v[i]).(map[string]interface{}); ok { + tabArray[i] = m + } else { + log.Fatalf("JSON arrays may only contain objects. This " + + "corresponds to only tables being allowed in " + + "TOML table arrays.") + } + } + return tabArray + } + log.Fatalf("Unrecognized JSON format '%T'.", typedJson) + panic("unreachable") +} + +func untag(typed map[string]interface{}) interface{} { + t := typed["type"].(string) + v := typed["value"] + switch t { + case "string": + return v.(string) + case "integer": + v := v.(string) + n, err := strconv.Atoi(v) + if err != nil { + log.Fatalf("Could not parse '%s' as integer: %s", v, err) + } + return n + case "float": + v := v.(string) + f, err := strconv.ParseFloat(v, 64) + if err != nil { + log.Fatalf("Could not parse '%s' as float64: %s", v, err) + } + return f + case "datetime": + v := v.(string) + t, err := time.Parse("2006-01-02T15:04:05Z", v) + if err != nil { + log.Fatalf("Could not parse '%s' as a datetime: %s", v, err) + } + return t + case "bool": + v := v.(string) + switch v { + case "true": + return true + case "false": + return false + } + log.Fatalf("Could not parse '%s' as a boolean.", v) + case "array": + v := v.([]interface{}) + array := make([]interface{}, len(v)) + for i := range v { + if m, ok := v[i].(map[string]interface{}); ok { + array[i] = untag(m) + } else { + log.Fatalf("Arrays may only contain other arrays or "+ + "primitive values, but found a '%T'.", m) + } + } + return array + } + log.Fatalf("Unrecognized tag type '%s'.", t) + panic("unreachable") +} + +func in(key string, m map[string]interface{}) bool { + _, ok := m[key] + return ok +} diff --git a/vendor/github.com/BurntSushi/toml/cmd/tomlv/main.go b/vendor/github.com/BurntSushi/toml/cmd/tomlv/main.go new file mode 100644 index 000000000..c7d689a7e --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/cmd/tomlv/main.go @@ -0,0 +1,61 @@ +// Command tomlv validates TOML documents and prints each key's type. +package main + +import ( + "flag" + "fmt" + "log" + "os" + "path" + "strings" + "text/tabwriter" + + "github.com/BurntSushi/toml" +) + +var ( + flagTypes = false +) + +func init() { + log.SetFlags(0) + + flag.BoolVar(&flagTypes, "types", flagTypes, + "When set, the types of every defined key will be shown.") + + flag.Usage = usage + flag.Parse() +} + +func usage() { + log.Printf("Usage: %s toml-file [ toml-file ... ]\n", + path.Base(os.Args[0])) + flag.PrintDefaults() + + os.Exit(1) +} + +func main() { + if flag.NArg() < 1 { + flag.Usage() + } + for _, f := range flag.Args() { + var tmp interface{} + md, err := toml.DecodeFile(f, &tmp) + if err != nil { + log.Fatalf("Error in '%s': %s", f, err) + } + if flagTypes { + printTypes(md) + } + } +} + +func printTypes(md toml.MetaData) { + tabw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) + for _, key := range md.Keys() { + fmt.Fprintf(tabw, "%s%s\t%s\n", + strings.Repeat(" ", len(key)-1), key, md.Type(key...)) + } + tabw.Flush() +} diff --git a/vendor/github.com/BurntSushi/toml/decode.go b/vendor/github.com/BurntSushi/toml/decode.go new file mode 100644 index 000000000..b0fd51d5b --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/decode.go @@ -0,0 +1,509 @@ +package toml + +import ( + "fmt" + "io" + "io/ioutil" + "math" + "reflect" + "strings" + "time" +) + +func e(format string, args ...interface{}) error { + return fmt.Errorf("toml: "+format, args...) +} + +// Unmarshaler is the interface implemented by objects that can unmarshal a +// TOML description of themselves. +type Unmarshaler interface { + UnmarshalTOML(interface{}) error +} + +// Unmarshal decodes the contents of `p` in TOML format into a pointer `v`. +func Unmarshal(p []byte, v interface{}) error { + _, err := Decode(string(p), v) + return err +} + +// Primitive is a TOML value that hasn't been decoded into a Go value. +// When using the various `Decode*` functions, the type `Primitive` may +// be given to any value, and its decoding will be delayed. +// +// A `Primitive` value can be decoded using the `PrimitiveDecode` function. +// +// The underlying representation of a `Primitive` value is subject to change. +// Do not rely on it. +// +// N.B. Primitive values are still parsed, so using them will only avoid +// the overhead of reflection. They can be useful when you don't know the +// exact type of TOML data until run time. +type Primitive struct { + undecoded interface{} + context Key +} + +// DEPRECATED! +// +// Use MetaData.PrimitiveDecode instead. +func PrimitiveDecode(primValue Primitive, v interface{}) error { + md := MetaData{decoded: make(map[string]bool)} + return md.unify(primValue.undecoded, rvalue(v)) +} + +// PrimitiveDecode is just like the other `Decode*` functions, except it +// decodes a TOML value that has already been parsed. Valid primitive values +// can *only* be obtained from values filled by the decoder functions, +// including this method. (i.e., `v` may contain more `Primitive` +// values.) +// +// Meta data for primitive values is included in the meta data returned by +// the `Decode*` functions with one exception: keys returned by the Undecoded +// method will only reflect keys that were decoded. Namely, any keys hidden +// behind a Primitive will be considered undecoded. Executing this method will +// update the undecoded keys in the meta data. (See the example.) +func (md *MetaData) PrimitiveDecode(primValue Primitive, v interface{}) error { + md.context = primValue.context + defer func() { md.context = nil }() + return md.unify(primValue.undecoded, rvalue(v)) +} + +// Decode will decode the contents of `data` in TOML format into a pointer +// `v`. +// +// TOML hashes correspond to Go structs or maps. (Dealer's choice. They can be +// used interchangeably.) +// +// TOML arrays of tables correspond to either a slice of structs or a slice +// of maps. +// +// TOML datetimes correspond to Go `time.Time` values. +// +// All other TOML types (float, string, int, bool and array) correspond +// to the obvious Go types. +// +// An exception to the above rules is if a type implements the +// encoding.TextUnmarshaler interface. In this case, any primitive TOML value +// (floats, strings, integers, booleans and datetimes) will be converted to +// a byte string and given to the value's UnmarshalText method. See the +// Unmarshaler example for a demonstration with time duration strings. +// +// Key mapping +// +// TOML keys can map to either keys in a Go map or field names in a Go +// struct. The special `toml` struct tag may be used to map TOML keys to +// struct fields that don't match the key name exactly. (See the example.) +// A case insensitive match to struct names will be tried if an exact match +// can't be found. +// +// The mapping between TOML values and Go values is loose. That is, there +// may exist TOML values that cannot be placed into your representation, and +// there may be parts of your representation that do not correspond to +// TOML values. This loose mapping can be made stricter by using the IsDefined +// and/or Undecoded methods on the MetaData returned. +// +// This decoder will not handle cyclic types. If a cyclic type is passed, +// `Decode` will not terminate. +func Decode(data string, v interface{}) (MetaData, error) { + rv := reflect.ValueOf(v) + if rv.Kind() != reflect.Ptr { + return MetaData{}, e("Decode of non-pointer %s", reflect.TypeOf(v)) + } + if rv.IsNil() { + return MetaData{}, e("Decode of nil %s", reflect.TypeOf(v)) + } + p, err := parse(data) + if err != nil { + return MetaData{}, err + } + md := MetaData{ + p.mapping, p.types, p.ordered, + make(map[string]bool, len(p.ordered)), nil, + } + return md, md.unify(p.mapping, indirect(rv)) +} + +// DecodeFile is just like Decode, except it will automatically read the +// contents of the file at `fpath` and decode it for you. +func DecodeFile(fpath string, v interface{}) (MetaData, error) { + bs, err := ioutil.ReadFile(fpath) + if err != nil { + return MetaData{}, err + } + return Decode(string(bs), v) +} + +// DecodeReader is just like Decode, except it will consume all bytes +// from the reader and decode it for you. +func DecodeReader(r io.Reader, v interface{}) (MetaData, error) { + bs, err := ioutil.ReadAll(r) + if err != nil { + return MetaData{}, err + } + return Decode(string(bs), v) +} + +// unify performs a sort of type unification based on the structure of `rv`, +// which is the client representation. +// +// Any type mismatch produces an error. Finding a type that we don't know +// how to handle produces an unsupported type error. +func (md *MetaData) unify(data interface{}, rv reflect.Value) error { + + // Special case. Look for a `Primitive` value. + if rv.Type() == reflect.TypeOf((*Primitive)(nil)).Elem() { + // Save the undecoded data and the key context into the primitive + // value. + context := make(Key, len(md.context)) + copy(context, md.context) + rv.Set(reflect.ValueOf(Primitive{ + undecoded: data, + context: context, + })) + return nil + } + + // Special case. Unmarshaler Interface support. + if rv.CanAddr() { + if v, ok := rv.Addr().Interface().(Unmarshaler); ok { + return v.UnmarshalTOML(data) + } + } + + // Special case. Handle time.Time values specifically. + // TODO: Remove this code when we decide to drop support for Go 1.1. + // This isn't necessary in Go 1.2 because time.Time satisfies the encoding + // interfaces. + if rv.Type().AssignableTo(rvalue(time.Time{}).Type()) { + return md.unifyDatetime(data, rv) + } + + // Special case. Look for a value satisfying the TextUnmarshaler interface. + if v, ok := rv.Interface().(TextUnmarshaler); ok { + return md.unifyText(data, v) + } + // BUG(burntsushi) + // The behavior here is incorrect whenever a Go type satisfies the + // encoding.TextUnmarshaler interface but also corresponds to a TOML + // hash or array. In particular, the unmarshaler should only be applied + // to primitive TOML values. But at this point, it will be applied to + // all kinds of values and produce an incorrect error whenever those values + // are hashes or arrays (including arrays of tables). + + k := rv.Kind() + + // laziness + if k >= reflect.Int && k <= reflect.Uint64 { + return md.unifyInt(data, rv) + } + switch k { + case reflect.Ptr: + elem := reflect.New(rv.Type().Elem()) + err := md.unify(data, reflect.Indirect(elem)) + if err != nil { + return err + } + rv.Set(elem) + return nil + case reflect.Struct: + return md.unifyStruct(data, rv) + case reflect.Map: + return md.unifyMap(data, rv) + case reflect.Array: + return md.unifyArray(data, rv) + case reflect.Slice: + return md.unifySlice(data, rv) + case reflect.String: + return md.unifyString(data, rv) + case reflect.Bool: + return md.unifyBool(data, rv) + case reflect.Interface: + // we only support empty interfaces. + if rv.NumMethod() > 0 { + return e("unsupported type %s", rv.Type()) + } + return md.unifyAnything(data, rv) + case reflect.Float32: + fallthrough + case reflect.Float64: + return md.unifyFloat64(data, rv) + } + return e("unsupported type %s", rv.Kind()) +} + +func (md *MetaData) unifyStruct(mapping interface{}, rv reflect.Value) error { + tmap, ok := mapping.(map[string]interface{}) + if !ok { + if mapping == nil { + return nil + } + return e("type mismatch for %s: expected table but found %T", + rv.Type().String(), mapping) + } + + for key, datum := range tmap { + var f *field + fields := cachedTypeFields(rv.Type()) + for i := range fields { + ff := &fields[i] + if ff.name == key { + f = ff + break + } + if f == nil && strings.EqualFold(ff.name, key) { + f = ff + } + } + if f != nil { + subv := rv + for _, i := range f.index { + subv = indirect(subv.Field(i)) + } + if isUnifiable(subv) { + md.decoded[md.context.add(key).String()] = true + md.context = append(md.context, key) + if err := md.unify(datum, subv); err != nil { + return err + } + md.context = md.context[0 : len(md.context)-1] + } else if f.name != "" { + // Bad user! No soup for you! + return e("cannot write unexported field %s.%s", + rv.Type().String(), f.name) + } + } + } + return nil +} + +func (md *MetaData) unifyMap(mapping interface{}, rv reflect.Value) error { + tmap, ok := mapping.(map[string]interface{}) + if !ok { + if tmap == nil { + return nil + } + return badtype("map", mapping) + } + if rv.IsNil() { + rv.Set(reflect.MakeMap(rv.Type())) + } + for k, v := range tmap { + md.decoded[md.context.add(k).String()] = true + md.context = append(md.context, k) + + rvkey := indirect(reflect.New(rv.Type().Key())) + rvval := reflect.Indirect(reflect.New(rv.Type().Elem())) + if err := md.unify(v, rvval); err != nil { + return err + } + md.context = md.context[0 : len(md.context)-1] + + rvkey.SetString(k) + rv.SetMapIndex(rvkey, rvval) + } + return nil +} + +func (md *MetaData) unifyArray(data interface{}, rv reflect.Value) error { + datav := reflect.ValueOf(data) + if datav.Kind() != reflect.Slice { + if !datav.IsValid() { + return nil + } + return badtype("slice", data) + } + sliceLen := datav.Len() + if sliceLen != rv.Len() { + return e("expected array length %d; got TOML array of length %d", + rv.Len(), sliceLen) + } + return md.unifySliceArray(datav, rv) +} + +func (md *MetaData) unifySlice(data interface{}, rv reflect.Value) error { + datav := reflect.ValueOf(data) + if datav.Kind() != reflect.Slice { + if !datav.IsValid() { + return nil + } + return badtype("slice", data) + } + n := datav.Len() + if rv.IsNil() || rv.Cap() < n { + rv.Set(reflect.MakeSlice(rv.Type(), n, n)) + } + rv.SetLen(n) + return md.unifySliceArray(datav, rv) +} + +func (md *MetaData) unifySliceArray(data, rv reflect.Value) error { + sliceLen := data.Len() + for i := 0; i < sliceLen; i++ { + v := data.Index(i).Interface() + sliceval := indirect(rv.Index(i)) + if err := md.unify(v, sliceval); err != nil { + return err + } + } + return nil +} + +func (md *MetaData) unifyDatetime(data interface{}, rv reflect.Value) error { + if _, ok := data.(time.Time); ok { + rv.Set(reflect.ValueOf(data)) + return nil + } + return badtype("time.Time", data) +} + +func (md *MetaData) unifyString(data interface{}, rv reflect.Value) error { + if s, ok := data.(string); ok { + rv.SetString(s) + return nil + } + return badtype("string", data) +} + +func (md *MetaData) unifyFloat64(data interface{}, rv reflect.Value) error { + if num, ok := data.(float64); ok { + switch rv.Kind() { + case reflect.Float32: + fallthrough + case reflect.Float64: + rv.SetFloat(num) + default: + panic("bug") + } + return nil + } + return badtype("float", data) +} + +func (md *MetaData) unifyInt(data interface{}, rv reflect.Value) error { + if num, ok := data.(int64); ok { + if rv.Kind() >= reflect.Int && rv.Kind() <= reflect.Int64 { + switch rv.Kind() { + case reflect.Int, reflect.Int64: + // No bounds checking necessary. + case reflect.Int8: + if num < math.MinInt8 || num > math.MaxInt8 { + return e("value %d is out of range for int8", num) + } + case reflect.Int16: + if num < math.MinInt16 || num > math.MaxInt16 { + return e("value %d is out of range for int16", num) + } + case reflect.Int32: + if num < math.MinInt32 || num > math.MaxInt32 { + return e("value %d is out of range for int32", num) + } + } + rv.SetInt(num) + } else if rv.Kind() >= reflect.Uint && rv.Kind() <= reflect.Uint64 { + unum := uint64(num) + switch rv.Kind() { + case reflect.Uint, reflect.Uint64: + // No bounds checking necessary. + case reflect.Uint8: + if num < 0 || unum > math.MaxUint8 { + return e("value %d is out of range for uint8", num) + } + case reflect.Uint16: + if num < 0 || unum > math.MaxUint16 { + return e("value %d is out of range for uint16", num) + } + case reflect.Uint32: + if num < 0 || unum > math.MaxUint32 { + return e("value %d is out of range for uint32", num) + } + } + rv.SetUint(unum) + } else { + panic("unreachable") + } + return nil + } + return badtype("integer", data) +} + +func (md *MetaData) unifyBool(data interface{}, rv reflect.Value) error { + if b, ok := data.(bool); ok { + rv.SetBool(b) + return nil + } + return badtype("boolean", data) +} + +func (md *MetaData) unifyAnything(data interface{}, rv reflect.Value) error { + rv.Set(reflect.ValueOf(data)) + return nil +} + +func (md *MetaData) unifyText(data interface{}, v TextUnmarshaler) error { + var s string + switch sdata := data.(type) { + case TextMarshaler: + text, err := sdata.MarshalText() + if err != nil { + return err + } + s = string(text) + case fmt.Stringer: + s = sdata.String() + case string: + s = sdata + case bool: + s = fmt.Sprintf("%v", sdata) + case int64: + s = fmt.Sprintf("%d", sdata) + case float64: + s = fmt.Sprintf("%f", sdata) + default: + return badtype("primitive (string-like)", data) + } + if err := v.UnmarshalText([]byte(s)); err != nil { + return err + } + return nil +} + +// rvalue returns a reflect.Value of `v`. All pointers are resolved. +func rvalue(v interface{}) reflect.Value { + return indirect(reflect.ValueOf(v)) +} + +// indirect returns the value pointed to by a pointer. +// Pointers are followed until the value is not a pointer. +// New values are allocated for each nil pointer. +// +// An exception to this rule is if the value satisfies an interface of +// interest to us (like encoding.TextUnmarshaler). +func indirect(v reflect.Value) reflect.Value { + if v.Kind() != reflect.Ptr { + if v.CanSet() { + pv := v.Addr() + if _, ok := pv.Interface().(TextUnmarshaler); ok { + return pv + } + } + return v + } + if v.IsNil() { + v.Set(reflect.New(v.Type().Elem())) + } + return indirect(reflect.Indirect(v)) +} + +func isUnifiable(rv reflect.Value) bool { + if rv.CanSet() { + return true + } + if _, ok := rv.Interface().(TextUnmarshaler); ok { + return true + } + return false +} + +func badtype(expected string, data interface{}) error { + return e("cannot load TOML value of type %T into a Go %s", data, expected) +} diff --git a/vendor/github.com/BurntSushi/toml/decode_meta.go b/vendor/github.com/BurntSushi/toml/decode_meta.go new file mode 100644 index 000000000..b9914a679 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/decode_meta.go @@ -0,0 +1,121 @@ +package toml + +import "strings" + +// MetaData allows access to meta information about TOML data that may not +// be inferrable via reflection. In particular, whether a key has been defined +// and the TOML type of a key. +type MetaData struct { + mapping map[string]interface{} + types map[string]tomlType + keys []Key + decoded map[string]bool + context Key // Used only during decoding. +} + +// IsDefined returns true if the key given exists in the TOML data. The key +// should be specified hierarchially. e.g., +// +// // access the TOML key 'a.b.c' +// IsDefined("a", "b", "c") +// +// IsDefined will return false if an empty key given. Keys are case sensitive. +func (md *MetaData) IsDefined(key ...string) bool { + if len(key) == 0 { + return false + } + + var hash map[string]interface{} + var ok bool + var hashOrVal interface{} = md.mapping + for _, k := range key { + if hash, ok = hashOrVal.(map[string]interface{}); !ok { + return false + } + if hashOrVal, ok = hash[k]; !ok { + return false + } + } + return true +} + +// Type returns a string representation of the type of the key specified. +// +// Type will return the empty string if given an empty key or a key that +// does not exist. Keys are case sensitive. +func (md *MetaData) Type(key ...string) string { + fullkey := strings.Join(key, ".") + if typ, ok := md.types[fullkey]; ok { + return typ.typeString() + } + return "" +} + +// Key is the type of any TOML key, including key groups. Use (MetaData).Keys +// to get values of this type. +type Key []string + +func (k Key) String() string { + return strings.Join(k, ".") +} + +func (k Key) maybeQuotedAll() string { + var ss []string + for i := range k { + ss = append(ss, k.maybeQuoted(i)) + } + return strings.Join(ss, ".") +} + +func (k Key) maybeQuoted(i int) string { + quote := false + for _, c := range k[i] { + if !isBareKeyChar(c) { + quote = true + break + } + } + if quote { + return "\"" + strings.Replace(k[i], "\"", "\\\"", -1) + "\"" + } + return k[i] +} + +func (k Key) add(piece string) Key { + newKey := make(Key, len(k)+1) + copy(newKey, k) + newKey[len(k)] = piece + return newKey +} + +// Keys returns a slice of every key in the TOML data, including key groups. +// Each key is itself a slice, where the first element is the top of the +// hierarchy and the last is the most specific. +// +// The list will have the same order as the keys appeared in the TOML data. +// +// All keys returned are non-empty. +func (md *MetaData) Keys() []Key { + return md.keys +} + +// Undecoded returns all keys that have not been decoded in the order in which +// they appear in the original TOML document. +// +// This includes keys that haven't been decoded because of a Primitive value. +// Once the Primitive value is decoded, the keys will be considered decoded. +// +// Also note that decoding into an empty interface will result in no decoding, +// and so no keys will be considered decoded. +// +// In this sense, the Undecoded keys correspond to keys in the TOML document +// that do not have a concrete type in your representation. +func (md *MetaData) Undecoded() []Key { + undecoded := make([]Key, 0, len(md.keys)) + for _, key := range md.keys { + if !md.decoded[key.String()] { + undecoded = append(undecoded, key) + } + } + return undecoded +} diff --git a/vendor/github.com/BurntSushi/toml/doc.go b/vendor/github.com/BurntSushi/toml/doc.go new file mode 100644 index 000000000..b371f396e --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/doc.go @@ -0,0 +1,27 @@ +/* +Package toml provides facilities for decoding and encoding TOML configuration +files via reflection. There is also support for delaying decoding with +the Primitive type, and querying the set of keys in a TOML document with the +MetaData type. + +The specification implemented: https://github.com/toml-lang/toml + +The sub-command github.com/BurntSushi/toml/cmd/tomlv can be used to verify +whether a file is a valid TOML document. It can also be used to print the +type of each key in a TOML document. + +Testing + +There are two important types of tests used for this package. The first is +contained inside '*_test.go' files and uses the standard Go unit testing +framework. These tests are primarily devoted to holistically testing the +decoder and encoder. + +The second type of testing is used to verify the implementation's adherence +to the TOML specification. These tests have been factored into their own +project: https://github.com/BurntSushi/toml-test + +The reason the tests are in a separate project is so that they can be used by +any implementation of TOML. Namely, it is language agnostic. +*/ +package toml diff --git a/vendor/github.com/BurntSushi/toml/encode.go b/vendor/github.com/BurntSushi/toml/encode.go new file mode 100644 index 000000000..d905c21a2 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/encode.go @@ -0,0 +1,568 @@ +package toml + +import ( + "bufio" + "errors" + "fmt" + "io" + "reflect" + "sort" + "strconv" + "strings" + "time" +) + +type tomlEncodeError struct{ error } + +var ( + errArrayMixedElementTypes = errors.New( + "toml: cannot encode array with mixed element types") + errArrayNilElement = errors.New( + "toml: cannot encode array with nil element") + errNonString = errors.New( + "toml: cannot encode a map with non-string key type") + errAnonNonStruct = errors.New( + "toml: cannot encode an anonymous field that is not a struct") + errArrayNoTable = errors.New( + "toml: TOML array element cannot contain a table") + errNoKey = errors.New( + "toml: top-level values must be Go maps or structs") + errAnything = errors.New("") // used in testing +) + +var quotedReplacer = strings.NewReplacer( + "\t", "\\t", + "\n", "\\n", + "\r", "\\r", + "\"", "\\\"", + "\\", "\\\\", +) + +// Encoder controls the encoding of Go values to a TOML document to some +// io.Writer. +// +// The indentation level can be controlled with the Indent field. +type Encoder struct { + // A single indentation level. By default it is two spaces. + Indent string + + // hasWritten is whether we have written any output to w yet. + hasWritten bool + w *bufio.Writer +} + +// NewEncoder returns a TOML encoder that encodes Go values to the io.Writer +// given. By default, a single indentation level is 2 spaces. +func NewEncoder(w io.Writer) *Encoder { + return &Encoder{ + w: bufio.NewWriter(w), + Indent: " ", + } +} + +// Encode writes a TOML representation of the Go value to the underlying +// io.Writer. If the value given cannot be encoded to a valid TOML document, +// then an error is returned. +// +// The mapping between Go values and TOML values should be precisely the same +// as for the Decode* functions. Similarly, the TextMarshaler interface is +// supported by encoding the resulting bytes as strings. (If you want to write +// arbitrary binary data then you will need to use something like base64 since +// TOML does not have any binary types.) +// +// When encoding TOML hashes (i.e., Go maps or structs), keys without any +// sub-hashes are encoded first. +// +// If a Go map is encoded, then its keys are sorted alphabetically for +// deterministic output. More control over this behavior may be provided if +// there is demand for it. +// +// Encoding Go values without a corresponding TOML representation---like map +// types with non-string keys---will cause an error to be returned. Similarly +// for mixed arrays/slices, arrays/slices with nil elements, embedded +// non-struct types and nested slices containing maps or structs. +// (e.g., [][]map[string]string is not allowed but []map[string]string is OK +// and so is []map[string][]string.) +func (enc *Encoder) Encode(v interface{}) error { + rv := eindirect(reflect.ValueOf(v)) + if err := enc.safeEncode(Key([]string{}), rv); err != nil { + return err + } + return enc.w.Flush() +} + +func (enc *Encoder) safeEncode(key Key, rv reflect.Value) (err error) { + defer func() { + if r := recover(); r != nil { + if terr, ok := r.(tomlEncodeError); ok { + err = terr.error + return + } + panic(r) + } + }() + enc.encode(key, rv) + return nil +} + +func (enc *Encoder) encode(key Key, rv reflect.Value) { + // Special case. Time needs to be in ISO8601 format. + // Special case. If we can marshal the type to text, then we used that. + // Basically, this prevents the encoder for handling these types as + // generic structs (or whatever the underlying type of a TextMarshaler is). + switch rv.Interface().(type) { + case time.Time, TextMarshaler: + enc.keyEqElement(key, rv) + return + } + + k := rv.Kind() + switch k { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, + reflect.Int64, + reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, + reflect.Uint64, + reflect.Float32, reflect.Float64, reflect.String, reflect.Bool: + enc.keyEqElement(key, rv) + case reflect.Array, reflect.Slice: + if typeEqual(tomlArrayHash, tomlTypeOfGo(rv)) { + enc.eArrayOfTables(key, rv) + } else { + enc.keyEqElement(key, rv) + } + case reflect.Interface: + if rv.IsNil() { + return + } + enc.encode(key, rv.Elem()) + case reflect.Map: + if rv.IsNil() { + return + } + enc.eTable(key, rv) + case reflect.Ptr: + if rv.IsNil() { + return + } + enc.encode(key, rv.Elem()) + case reflect.Struct: + enc.eTable(key, rv) + default: + panic(e("unsupported type for key '%s': %s", key, k)) + } +} + +// eElement encodes any value that can be an array element (primitives and +// arrays). +func (enc *Encoder) eElement(rv reflect.Value) { + switch v := rv.Interface().(type) { + case time.Time: + // Special case time.Time as a primitive. Has to come before + // TextMarshaler below because time.Time implements + // encoding.TextMarshaler, but we need to always use UTC. + enc.wf(v.UTC().Format("2006-01-02T15:04:05Z")) + return + case TextMarshaler: + // Special case. Use text marshaler if it's available for this value. + if s, err := v.MarshalText(); err != nil { + encPanic(err) + } else { + enc.writeQuoted(string(s)) + } + return + } + switch rv.Kind() { + case reflect.Bool: + enc.wf(strconv.FormatBool(rv.Bool())) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, + reflect.Int64: + enc.wf(strconv.FormatInt(rv.Int(), 10)) + case reflect.Uint, reflect.Uint8, reflect.Uint16, + reflect.Uint32, reflect.Uint64: + enc.wf(strconv.FormatUint(rv.Uint(), 10)) + case reflect.Float32: + enc.wf(floatAddDecimal(strconv.FormatFloat(rv.Float(), 'f', -1, 32))) + case reflect.Float64: + enc.wf(floatAddDecimal(strconv.FormatFloat(rv.Float(), 'f', -1, 64))) + case reflect.Array, reflect.Slice: + enc.eArrayOrSliceElement(rv) + case reflect.Interface: + enc.eElement(rv.Elem()) + case reflect.String: + enc.writeQuoted(rv.String()) + default: + panic(e("unexpected primitive type: %s", rv.Kind())) + } +} + +// By the TOML spec, all floats must have a decimal with at least one +// number on either side. +func floatAddDecimal(fstr string) string { + if !strings.Contains(fstr, ".") { + return fstr + ".0" + } + return fstr +} + +func (enc *Encoder) writeQuoted(s string) { + enc.wf("\"%s\"", quotedReplacer.Replace(s)) +} + +func (enc *Encoder) eArrayOrSliceElement(rv reflect.Value) { + length := rv.Len() + enc.wf("[") + for i := 0; i < length; i++ { + elem := rv.Index(i) + enc.eElement(elem) + if i != length-1 { + enc.wf(", ") + } + } + enc.wf("]") +} + +func (enc *Encoder) eArrayOfTables(key Key, rv reflect.Value) { + if len(key) == 0 { + encPanic(errNoKey) + } + for i := 0; i < rv.Len(); i++ { + trv := rv.Index(i) + if isNil(trv) { + continue + } + panicIfInvalidKey(key) + enc.newline() + enc.wf("%s[[%s]]", enc.indentStr(key), key.maybeQuotedAll()) + enc.newline() + enc.eMapOrStruct(key, trv) + } +} + +func (enc *Encoder) eTable(key Key, rv reflect.Value) { + panicIfInvalidKey(key) + if len(key) == 1 { + // Output an extra newline between top-level tables. + // (The newline isn't written if nothing else has been written though.) + enc.newline() + } + if len(key) > 0 { + enc.wf("%s[%s]", enc.indentStr(key), key.maybeQuotedAll()) + enc.newline() + } + enc.eMapOrStruct(key, rv) +} + +func (enc *Encoder) eMapOrStruct(key Key, rv reflect.Value) { + switch rv := eindirect(rv); rv.Kind() { + case reflect.Map: + enc.eMap(key, rv) + case reflect.Struct: + enc.eStruct(key, rv) + default: + panic("eTable: unhandled reflect.Value Kind: " + rv.Kind().String()) + } +} + +func (enc *Encoder) eMap(key Key, rv reflect.Value) { + rt := rv.Type() + if rt.Key().Kind() != reflect.String { + encPanic(errNonString) + } + + // Sort keys so that we have deterministic output. And write keys directly + // underneath this key first, before writing sub-structs or sub-maps. + var mapKeysDirect, mapKeysSub []string + for _, mapKey := range rv.MapKeys() { + k := mapKey.String() + if typeIsHash(tomlTypeOfGo(rv.MapIndex(mapKey))) { + mapKeysSub = append(mapKeysSub, k) + } else { + mapKeysDirect = append(mapKeysDirect, k) + } + } + + var writeMapKeys = func(mapKeys []string) { + sort.Strings(mapKeys) + for _, mapKey := range mapKeys { + mrv := rv.MapIndex(reflect.ValueOf(mapKey)) + if isNil(mrv) { + // Don't write anything for nil fields. + continue + } + enc.encode(key.add(mapKey), mrv) + } + } + writeMapKeys(mapKeysDirect) + writeMapKeys(mapKeysSub) +} + +func (enc *Encoder) eStruct(key Key, rv reflect.Value) { + // Write keys for fields directly under this key first, because if we write + // a field that creates a new table, then all keys under it will be in that + // table (not the one we're writing here). + rt := rv.Type() + var fieldsDirect, fieldsSub [][]int + var addFields func(rt reflect.Type, rv reflect.Value, start []int) + addFields = func(rt reflect.Type, rv reflect.Value, start []int) { + for i := 0; i < rt.NumField(); i++ { + f := rt.Field(i) + // skip unexported fields + if f.PkgPath != "" && !f.Anonymous { + continue + } + frv := rv.Field(i) + if f.Anonymous { + t := f.Type + switch t.Kind() { + case reflect.Struct: + // Treat anonymous struct fields with + // tag names as though they are not + // anonymous, like encoding/json does. + if getOptions(f.Tag).name == "" { + addFields(t, frv, f.Index) + continue + } + case reflect.Ptr: + if t.Elem().Kind() == reflect.Struct && + getOptions(f.Tag).name == "" { + if !frv.IsNil() { + addFields(t.Elem(), frv.Elem(), f.Index) + } + continue + } + // Fall through to the normal field encoding logic below + // for non-struct anonymous fields. + } + } + + if typeIsHash(tomlTypeOfGo(frv)) { + fieldsSub = append(fieldsSub, append(start, f.Index...)) + } else { + fieldsDirect = append(fieldsDirect, append(start, f.Index...)) + } + } + } + addFields(rt, rv, nil) + + var writeFields = func(fields [][]int) { + for _, fieldIndex := range fields { + sft := rt.FieldByIndex(fieldIndex) + sf := rv.FieldByIndex(fieldIndex) + if isNil(sf) { + // Don't write anything for nil fields. + continue + } + + opts := getOptions(sft.Tag) + if opts.skip { + continue + } + keyName := sft.Name + if opts.name != "" { + keyName = opts.name + } + if opts.omitempty && isEmpty(sf) { + continue + } + if opts.omitzero && isZero(sf) { + continue + } + + enc.encode(key.add(keyName), sf) + } + } + writeFields(fieldsDirect) + writeFields(fieldsSub) +} + +// tomlTypeName returns the TOML type name of the Go value's type. It is +// used to determine whether the types of array elements are mixed (which is +// forbidden). If the Go value is nil, then it is illegal for it to be an array +// element, and valueIsNil is returned as true. + +// Returns the TOML type of a Go value. The type may be `nil`, which means +// no concrete TOML type could be found. +func tomlTypeOfGo(rv reflect.Value) tomlType { + if isNil(rv) || !rv.IsValid() { + return nil + } + switch rv.Kind() { + case reflect.Bool: + return tomlBool + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, + reflect.Int64, + reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, + reflect.Uint64: + return tomlInteger + case reflect.Float32, reflect.Float64: + return tomlFloat + case reflect.Array, reflect.Slice: + if typeEqual(tomlHash, tomlArrayType(rv)) { + return tomlArrayHash + } + return tomlArray + case reflect.Ptr, reflect.Interface: + return tomlTypeOfGo(rv.Elem()) + case reflect.String: + return tomlString + case reflect.Map: + return tomlHash + case reflect.Struct: + switch rv.Interface().(type) { + case time.Time: + return tomlDatetime + case TextMarshaler: + return tomlString + default: + return tomlHash + } + default: + panic("unexpected reflect.Kind: " + rv.Kind().String()) + } +} + +// tomlArrayType returns the element type of a TOML array. The type returned +// may be nil if it cannot be determined (e.g., a nil slice or a zero length +// slize). This function may also panic if it finds a type that cannot be +// expressed in TOML (such as nil elements, heterogeneous arrays or directly +// nested arrays of tables). +func tomlArrayType(rv reflect.Value) tomlType { + if isNil(rv) || !rv.IsValid() || rv.Len() == 0 { + return nil + } + firstType := tomlTypeOfGo(rv.Index(0)) + if firstType == nil { + encPanic(errArrayNilElement) + } + + rvlen := rv.Len() + for i := 1; i < rvlen; i++ { + elem := rv.Index(i) + switch elemType := tomlTypeOfGo(elem); { + case elemType == nil: + encPanic(errArrayNilElement) + case !typeEqual(firstType, elemType): + encPanic(errArrayMixedElementTypes) + } + } + // If we have a nested array, then we must make sure that the nested + // array contains ONLY primitives. + // This checks arbitrarily nested arrays. + if typeEqual(firstType, tomlArray) || typeEqual(firstType, tomlArrayHash) { + nest := tomlArrayType(eindirect(rv.Index(0))) + if typeEqual(nest, tomlHash) || typeEqual(nest, tomlArrayHash) { + encPanic(errArrayNoTable) + } + } + return firstType +} + +type tagOptions struct { + skip bool // "-" + name string + omitempty bool + omitzero bool +} + +func getOptions(tag reflect.StructTag) tagOptions { + t := tag.Get("toml") + if t == "-" { + return tagOptions{skip: true} + } + var opts tagOptions + parts := strings.Split(t, ",") + opts.name = parts[0] + for _, s := range parts[1:] { + switch s { + case "omitempty": + opts.omitempty = true + case "omitzero": + opts.omitzero = true + } + } + return opts +} + +func isZero(rv reflect.Value) bool { + switch rv.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return rv.Int() == 0 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return rv.Uint() == 0 + case reflect.Float32, reflect.Float64: + return rv.Float() == 0.0 + } + return false +} + +func isEmpty(rv reflect.Value) bool { + switch rv.Kind() { + case reflect.Array, reflect.Slice, reflect.Map, reflect.String: + return rv.Len() == 0 + case reflect.Bool: + return !rv.Bool() + } + return false +} + +func (enc *Encoder) newline() { + if enc.hasWritten { + enc.wf("\n") + } +} + +func (enc *Encoder) keyEqElement(key Key, val reflect.Value) { + if len(key) == 0 { + encPanic(errNoKey) + } + panicIfInvalidKey(key) + enc.wf("%s%s = ", enc.indentStr(key), key.maybeQuoted(len(key)-1)) + enc.eElement(val) + enc.newline() +} + +func (enc *Encoder) wf(format string, v ...interface{}) { + if _, err := fmt.Fprintf(enc.w, format, v...); err != nil { + encPanic(err) + } + enc.hasWritten = true +} + +func (enc *Encoder) indentStr(key Key) string { + return strings.Repeat(enc.Indent, len(key)-1) +} + +func encPanic(err error) { + panic(tomlEncodeError{err}) +} + +func eindirect(v reflect.Value) reflect.Value { + switch v.Kind() { + case reflect.Ptr, reflect.Interface: + return eindirect(v.Elem()) + default: + return v + } +} + +func isNil(rv reflect.Value) bool { + switch rv.Kind() { + case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: + return rv.IsNil() + default: + return false + } +} + +func panicIfInvalidKey(key Key) { + for _, k := range key { + if len(k) == 0 { + encPanic(e("Key '%s' is not a valid table name. Key names "+ + "cannot be empty.", key.maybeQuotedAll())) + } + } +} + +func isValidKeyName(s string) bool { + return len(s) != 0 +} diff --git a/vendor/github.com/BurntSushi/toml/encoding_types.go b/vendor/github.com/BurntSushi/toml/encoding_types.go new file mode 100644 index 000000000..d36e1dd60 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/encoding_types.go @@ -0,0 +1,19 @@ +// +build go1.2 + +package toml + +// In order to support Go 1.1, we define our own TextMarshaler and +// TextUnmarshaler types. For Go 1.2+, we just alias them with the +// standard library interfaces. + +import ( + "encoding" +) + +// TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here +// so that Go 1.1 can be supported. +type TextMarshaler encoding.TextMarshaler + +// TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined +// here so that Go 1.1 can be supported. +type TextUnmarshaler encoding.TextUnmarshaler diff --git a/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go b/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go new file mode 100644 index 000000000..e8d503d04 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go @@ -0,0 +1,18 @@ +// +build !go1.2 + +package toml + +// These interfaces were introduced in Go 1.2, so we add them manually when +// compiling for Go 1.1. + +// TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here +// so that Go 1.1 can be supported. +type TextMarshaler interface { + MarshalText() (text []byte, err error) +} + +// TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined +// here so that Go 1.1 can be supported. +type TextUnmarshaler interface { + UnmarshalText(text []byte) error +} diff --git a/vendor/github.com/BurntSushi/toml/lex.go b/vendor/github.com/BurntSushi/toml/lex.go new file mode 100644 index 000000000..e0a742a88 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/lex.go @@ -0,0 +1,953 @@ +package toml + +import ( + "fmt" + "strings" + "unicode" + "unicode/utf8" +) + +type itemType int + +const ( + itemError itemType = iota + itemNIL // used in the parser to indicate no type + itemEOF + itemText + itemString + itemRawString + itemMultilineString + itemRawMultilineString + itemBool + itemInteger + itemFloat + itemDatetime + itemArray // the start of an array + itemArrayEnd + itemTableStart + itemTableEnd + itemArrayTableStart + itemArrayTableEnd + itemKeyStart + itemCommentStart + itemInlineTableStart + itemInlineTableEnd +) + +const ( + eof = 0 + comma = ',' + tableStart = '[' + tableEnd = ']' + arrayTableStart = '[' + arrayTableEnd = ']' + tableSep = '.' + keySep = '=' + arrayStart = '[' + arrayEnd = ']' + commentStart = '#' + stringStart = '"' + stringEnd = '"' + rawStringStart = '\'' + rawStringEnd = '\'' + inlineTableStart = '{' + inlineTableEnd = '}' +) + +type stateFn func(lx *lexer) stateFn + +type lexer struct { + input string + start int + pos int + line int + state stateFn + items chan item + + // Allow for backing up up to three runes. + // This is necessary because TOML contains 3-rune tokens (""" and '''). + prevWidths [3]int + nprev int // how many of prevWidths are in use + // If we emit an eof, we can still back up, but it is not OK to call + // next again. + atEOF bool + + // A stack of state functions used to maintain context. + // The idea is to reuse parts of the state machine in various places. + // For example, values can appear at the top level or within arbitrarily + // nested arrays. The last state on the stack is used after a value has + // been lexed. Similarly for comments. + stack []stateFn +} + +type item struct { + typ itemType + val string + line int +} + +func (lx *lexer) nextItem() item { + for { + select { + case item := <-lx.items: + return item + default: + lx.state = lx.state(lx) + } + } +} + +func lex(input string) *lexer { + lx := &lexer{ + input: input, + state: lexTop, + line: 1, + items: make(chan item, 10), + stack: make([]stateFn, 0, 10), + } + return lx +} + +func (lx *lexer) push(state stateFn) { + lx.stack = append(lx.stack, state) +} + +func (lx *lexer) pop() stateFn { + if len(lx.stack) == 0 { + return lx.errorf("BUG in lexer: no states to pop") + } + last := lx.stack[len(lx.stack)-1] + lx.stack = lx.stack[0 : len(lx.stack)-1] + return last +} + +func (lx *lexer) current() string { + return lx.input[lx.start:lx.pos] +} + +func (lx *lexer) emit(typ itemType) { + lx.items <- item{typ, lx.current(), lx.line} + lx.start = lx.pos +} + +func (lx *lexer) emitTrim(typ itemType) { + lx.items <- item{typ, strings.TrimSpace(lx.current()), lx.line} + lx.start = lx.pos +} + +func (lx *lexer) next() (r rune) { + if lx.atEOF { + panic("next called after EOF") + } + if lx.pos >= len(lx.input) { + lx.atEOF = true + return eof + } + + if lx.input[lx.pos] == '\n' { + lx.line++ + } + lx.prevWidths[2] = lx.prevWidths[1] + lx.prevWidths[1] = lx.prevWidths[0] + if lx.nprev < 3 { + lx.nprev++ + } + r, w := utf8.DecodeRuneInString(lx.input[lx.pos:]) + lx.prevWidths[0] = w + lx.pos += w + return r +} + +// ignore skips over the pending input before this point. +func (lx *lexer) ignore() { + lx.start = lx.pos +} + +// backup steps back one rune. Can be called only twice between calls to next. +func (lx *lexer) backup() { + if lx.atEOF { + lx.atEOF = false + return + } + if lx.nprev < 1 { + panic("backed up too far") + } + w := lx.prevWidths[0] + lx.prevWidths[0] = lx.prevWidths[1] + lx.prevWidths[1] = lx.prevWidths[2] + lx.nprev-- + lx.pos -= w + if lx.pos < len(lx.input) && lx.input[lx.pos] == '\n' { + lx.line-- + } +} + +// accept consumes the next rune if it's equal to `valid`. +func (lx *lexer) accept(valid rune) bool { + if lx.next() == valid { + return true + } + lx.backup() + return false +} + +// peek returns but does not consume the next rune in the input. +func (lx *lexer) peek() rune { + r := lx.next() + lx.backup() + return r +} + +// skip ignores all input that matches the given predicate. +func (lx *lexer) skip(pred func(rune) bool) { + for { + r := lx.next() + if pred(r) { + continue + } + lx.backup() + lx.ignore() + return + } +} + +// errorf stops all lexing by emitting an error and returning `nil`. +// Note that any value that is a character is escaped if it's a special +// character (newlines, tabs, etc.). +func (lx *lexer) errorf(format string, values ...interface{}) stateFn { + lx.items <- item{ + itemError, + fmt.Sprintf(format, values...), + lx.line, + } + return nil +} + +// lexTop consumes elements at the top level of TOML data. +func lexTop(lx *lexer) stateFn { + r := lx.next() + if isWhitespace(r) || isNL(r) { + return lexSkip(lx, lexTop) + } + switch r { + case commentStart: + lx.push(lexTop) + return lexCommentStart + case tableStart: + return lexTableStart + case eof: + if lx.pos > lx.start { + return lx.errorf("unexpected EOF") + } + lx.emit(itemEOF) + return nil + } + + // At this point, the only valid item can be a key, so we back up + // and let the key lexer do the rest. + lx.backup() + lx.push(lexTopEnd) + return lexKeyStart +} + +// lexTopEnd is entered whenever a top-level item has been consumed. (A value +// or a table.) It must see only whitespace, and will turn back to lexTop +// upon a newline. If it sees EOF, it will quit the lexer successfully. +func lexTopEnd(lx *lexer) stateFn { + r := lx.next() + switch { + case r == commentStart: + // a comment will read to a newline for us. + lx.push(lexTop) + return lexCommentStart + case isWhitespace(r): + return lexTopEnd + case isNL(r): + lx.ignore() + return lexTop + case r == eof: + lx.emit(itemEOF) + return nil + } + return lx.errorf("expected a top-level item to end with a newline, "+ + "comment, or EOF, but got %q instead", r) +} + +// lexTable lexes the beginning of a table. Namely, it makes sure that +// it starts with a character other than '.' and ']'. +// It assumes that '[' has already been consumed. +// It also handles the case that this is an item in an array of tables. +// e.g., '[[name]]'. +func lexTableStart(lx *lexer) stateFn { + if lx.peek() == arrayTableStart { + lx.next() + lx.emit(itemArrayTableStart) + lx.push(lexArrayTableEnd) + } else { + lx.emit(itemTableStart) + lx.push(lexTableEnd) + } + return lexTableNameStart +} + +func lexTableEnd(lx *lexer) stateFn { + lx.emit(itemTableEnd) + return lexTopEnd +} + +func lexArrayTableEnd(lx *lexer) stateFn { + if r := lx.next(); r != arrayTableEnd { + return lx.errorf("expected end of table array name delimiter %q, "+ + "but got %q instead", arrayTableEnd, r) + } + lx.emit(itemArrayTableEnd) + return lexTopEnd +} + +func lexTableNameStart(lx *lexer) stateFn { + lx.skip(isWhitespace) + switch r := lx.peek(); { + case r == tableEnd || r == eof: + return lx.errorf("unexpected end of table name " + + "(table names cannot be empty)") + case r == tableSep: + return lx.errorf("unexpected table separator " + + "(table names cannot be empty)") + case r == stringStart || r == rawStringStart: + lx.ignore() + lx.push(lexTableNameEnd) + return lexValue // reuse string lexing + default: + return lexBareTableName + } +} + +// lexBareTableName lexes the name of a table. It assumes that at least one +// valid character for the table has already been read. +func lexBareTableName(lx *lexer) stateFn { + r := lx.next() + if isBareKeyChar(r) { + return lexBareTableName + } + lx.backup() + lx.emit(itemText) + return lexTableNameEnd +} + +// lexTableNameEnd reads the end of a piece of a table name, optionally +// consuming whitespace. +func lexTableNameEnd(lx *lexer) stateFn { + lx.skip(isWhitespace) + switch r := lx.next(); { + case isWhitespace(r): + return lexTableNameEnd + case r == tableSep: + lx.ignore() + return lexTableNameStart + case r == tableEnd: + return lx.pop() + default: + return lx.errorf("expected '.' or ']' to end table name, "+ + "but got %q instead", r) + } +} + +// lexKeyStart consumes a key name up until the first non-whitespace character. +// lexKeyStart will ignore whitespace. +func lexKeyStart(lx *lexer) stateFn { + r := lx.peek() + switch { + case r == keySep: + return lx.errorf("unexpected key separator %q", keySep) + case isWhitespace(r) || isNL(r): + lx.next() + return lexSkip(lx, lexKeyStart) + case r == stringStart || r == rawStringStart: + lx.ignore() + lx.emit(itemKeyStart) + lx.push(lexKeyEnd) + return lexValue // reuse string lexing + default: + lx.ignore() + lx.emit(itemKeyStart) + return lexBareKey + } +} + +// lexBareKey consumes the text of a bare key. Assumes that the first character +// (which is not whitespace) has not yet been consumed. +func lexBareKey(lx *lexer) stateFn { + switch r := lx.next(); { + case isBareKeyChar(r): + return lexBareKey + case isWhitespace(r): + lx.backup() + lx.emit(itemText) + return lexKeyEnd + case r == keySep: + lx.backup() + lx.emit(itemText) + return lexKeyEnd + default: + return lx.errorf("bare keys cannot contain %q", r) + } +} + +// lexKeyEnd consumes the end of a key and trims whitespace (up to the key +// separator). +func lexKeyEnd(lx *lexer) stateFn { + switch r := lx.next(); { + case r == keySep: + return lexSkip(lx, lexValue) + case isWhitespace(r): + return lexSkip(lx, lexKeyEnd) + default: + return lx.errorf("expected key separator %q, but got %q instead", + keySep, r) + } +} + +// lexValue starts the consumption of a value anywhere a value is expected. +// lexValue will ignore whitespace. +// After a value is lexed, the last state on the next is popped and returned. +func lexValue(lx *lexer) stateFn { + // We allow whitespace to precede a value, but NOT newlines. + // In array syntax, the array states are responsible for ignoring newlines. + r := lx.next() + switch { + case isWhitespace(r): + return lexSkip(lx, lexValue) + case isDigit(r): + lx.backup() // avoid an extra state and use the same as above + return lexNumberOrDateStart + } + switch r { + case arrayStart: + lx.ignore() + lx.emit(itemArray) + return lexArrayValue + case inlineTableStart: + lx.ignore() + lx.emit(itemInlineTableStart) + return lexInlineTableValue + case stringStart: + if lx.accept(stringStart) { + if lx.accept(stringStart) { + lx.ignore() // Ignore """ + return lexMultilineString + } + lx.backup() + } + lx.ignore() // ignore the '"' + return lexString + case rawStringStart: + if lx.accept(rawStringStart) { + if lx.accept(rawStringStart) { + lx.ignore() // Ignore """ + return lexMultilineRawString + } + lx.backup() + } + lx.ignore() // ignore the "'" + return lexRawString + case '+', '-': + return lexNumberStart + case '.': // special error case, be kind to users + return lx.errorf("floats must start with a digit, not '.'") + } + if unicode.IsLetter(r) { + // Be permissive here; lexBool will give a nice error if the + // user wrote something like + // x = foo + // (i.e. not 'true' or 'false' but is something else word-like.) + lx.backup() + return lexBool + } + return lx.errorf("expected value but found %q instead", r) +} + +// lexArrayValue consumes one value in an array. It assumes that '[' or ',' +// have already been consumed. All whitespace and newlines are ignored. +func lexArrayValue(lx *lexer) stateFn { + r := lx.next() + switch { + case isWhitespace(r) || isNL(r): + return lexSkip(lx, lexArrayValue) + case r == commentStart: + lx.push(lexArrayValue) + return lexCommentStart + case r == comma: + return lx.errorf("unexpected comma") + case r == arrayEnd: + // NOTE(caleb): The spec isn't clear about whether you can have + // a trailing comma or not, so we'll allow it. + return lexArrayEnd + } + + lx.backup() + lx.push(lexArrayValueEnd) + return lexValue +} + +// lexArrayValueEnd consumes everything between the end of an array value and +// the next value (or the end of the array): it ignores whitespace and newlines +// and expects either a ',' or a ']'. +func lexArrayValueEnd(lx *lexer) stateFn { + r := lx.next() + switch { + case isWhitespace(r) || isNL(r): + return lexSkip(lx, lexArrayValueEnd) + case r == commentStart: + lx.push(lexArrayValueEnd) + return lexCommentStart + case r == comma: + lx.ignore() + return lexArrayValue // move on to the next value + case r == arrayEnd: + return lexArrayEnd + } + return lx.errorf( + "expected a comma or array terminator %q, but got %q instead", + arrayEnd, r, + ) +} + +// lexArrayEnd finishes the lexing of an array. +// It assumes that a ']' has just been consumed. +func lexArrayEnd(lx *lexer) stateFn { + lx.ignore() + lx.emit(itemArrayEnd) + return lx.pop() +} + +// lexInlineTableValue consumes one key/value pair in an inline table. +// It assumes that '{' or ',' have already been consumed. Whitespace is ignored. +func lexInlineTableValue(lx *lexer) stateFn { + r := lx.next() + switch { + case isWhitespace(r): + return lexSkip(lx, lexInlineTableValue) + case isNL(r): + return lx.errorf("newlines not allowed within inline tables") + case r == commentStart: + lx.push(lexInlineTableValue) + return lexCommentStart + case r == comma: + return lx.errorf("unexpected comma") + case r == inlineTableEnd: + return lexInlineTableEnd + } + lx.backup() + lx.push(lexInlineTableValueEnd) + return lexKeyStart +} + +// lexInlineTableValueEnd consumes everything between the end of an inline table +// key/value pair and the next pair (or the end of the table): +// it ignores whitespace and expects either a ',' or a '}'. +func lexInlineTableValueEnd(lx *lexer) stateFn { + r := lx.next() + switch { + case isWhitespace(r): + return lexSkip(lx, lexInlineTableValueEnd) + case isNL(r): + return lx.errorf("newlines not allowed within inline tables") + case r == commentStart: + lx.push(lexInlineTableValueEnd) + return lexCommentStart + case r == comma: + lx.ignore() + return lexInlineTableValue + case r == inlineTableEnd: + return lexInlineTableEnd + } + return lx.errorf("expected a comma or an inline table terminator %q, "+ + "but got %q instead", inlineTableEnd, r) +} + +// lexInlineTableEnd finishes the lexing of an inline table. +// It assumes that a '}' has just been consumed. +func lexInlineTableEnd(lx *lexer) stateFn { + lx.ignore() + lx.emit(itemInlineTableEnd) + return lx.pop() +} + +// lexString consumes the inner contents of a string. It assumes that the +// beginning '"' has already been consumed and ignored. +func lexString(lx *lexer) stateFn { + r := lx.next() + switch { + case r == eof: + return lx.errorf("unexpected EOF") + case isNL(r): + return lx.errorf("strings cannot contain newlines") + case r == '\\': + lx.push(lexString) + return lexStringEscape + case r == stringEnd: + lx.backup() + lx.emit(itemString) + lx.next() + lx.ignore() + return lx.pop() + } + return lexString +} + +// lexMultilineString consumes the inner contents of a string. It assumes that +// the beginning '"""' has already been consumed and ignored. +func lexMultilineString(lx *lexer) stateFn { + switch lx.next() { + case eof: + return lx.errorf("unexpected EOF") + case '\\': + return lexMultilineStringEscape + case stringEnd: + if lx.accept(stringEnd) { + if lx.accept(stringEnd) { + lx.backup() + lx.backup() + lx.backup() + lx.emit(itemMultilineString) + lx.next() + lx.next() + lx.next() + lx.ignore() + return lx.pop() + } + lx.backup() + } + } + return lexMultilineString +} + +// lexRawString consumes a raw string. Nothing can be escaped in such a string. +// It assumes that the beginning "'" has already been consumed and ignored. +func lexRawString(lx *lexer) stateFn { + r := lx.next() + switch { + case r == eof: + return lx.errorf("unexpected EOF") + case isNL(r): + return lx.errorf("strings cannot contain newlines") + case r == rawStringEnd: + lx.backup() + lx.emit(itemRawString) + lx.next() + lx.ignore() + return lx.pop() + } + return lexRawString +} + +// lexMultilineRawString consumes a raw string. Nothing can be escaped in such +// a string. It assumes that the beginning "'''" has already been consumed and +// ignored. +func lexMultilineRawString(lx *lexer) stateFn { + switch lx.next() { + case eof: + return lx.errorf("unexpected EOF") + case rawStringEnd: + if lx.accept(rawStringEnd) { + if lx.accept(rawStringEnd) { + lx.backup() + lx.backup() + lx.backup() + lx.emit(itemRawMultilineString) + lx.next() + lx.next() + lx.next() + lx.ignore() + return lx.pop() + } + lx.backup() + } + } + return lexMultilineRawString +} + +// lexMultilineStringEscape consumes an escaped character. It assumes that the +// preceding '\\' has already been consumed. +func lexMultilineStringEscape(lx *lexer) stateFn { + // Handle the special case first: + if isNL(lx.next()) { + return lexMultilineString + } + lx.backup() + lx.push(lexMultilineString) + return lexStringEscape(lx) +} + +func lexStringEscape(lx *lexer) stateFn { + r := lx.next() + switch r { + case 'b': + fallthrough + case 't': + fallthrough + case 'n': + fallthrough + case 'f': + fallthrough + case 'r': + fallthrough + case '"': + fallthrough + case '\\': + return lx.pop() + case 'u': + return lexShortUnicodeEscape + case 'U': + return lexLongUnicodeEscape + } + return lx.errorf("invalid escape character %q; only the following "+ + "escape characters are allowed: "+ + `\b, \t, \n, \f, \r, \", \\, \uXXXX, and \UXXXXXXXX`, r) +} + +func lexShortUnicodeEscape(lx *lexer) stateFn { + var r rune + for i := 0; i < 4; i++ { + r = lx.next() + if !isHexadecimal(r) { + return lx.errorf(`expected four hexadecimal digits after '\u', `+ + "but got %q instead", lx.current()) + } + } + return lx.pop() +} + +func lexLongUnicodeEscape(lx *lexer) stateFn { + var r rune + for i := 0; i < 8; i++ { + r = lx.next() + if !isHexadecimal(r) { + return lx.errorf(`expected eight hexadecimal digits after '\U', `+ + "but got %q instead", lx.current()) + } + } + return lx.pop() +} + +// lexNumberOrDateStart consumes either an integer, a float, or datetime. +func lexNumberOrDateStart(lx *lexer) stateFn { + r := lx.next() + if isDigit(r) { + return lexNumberOrDate + } + switch r { + case '_': + return lexNumber + case 'e', 'E': + return lexFloat + case '.': + return lx.errorf("floats must start with a digit, not '.'") + } + return lx.errorf("expected a digit but got %q", r) +} + +// lexNumberOrDate consumes either an integer, float or datetime. +func lexNumberOrDate(lx *lexer) stateFn { + r := lx.next() + if isDigit(r) { + return lexNumberOrDate + } + switch r { + case '-': + return lexDatetime + case '_': + return lexNumber + case '.', 'e', 'E': + return lexFloat + } + + lx.backup() + lx.emit(itemInteger) + return lx.pop() +} + +// lexDatetime consumes a Datetime, to a first approximation. +// The parser validates that it matches one of the accepted formats. +func lexDatetime(lx *lexer) stateFn { + r := lx.next() + if isDigit(r) { + return lexDatetime + } + switch r { + case '-', 'T', ':', '.', 'Z', '+': + return lexDatetime + } + + lx.backup() + lx.emit(itemDatetime) + return lx.pop() +} + +// lexNumberStart consumes either an integer or a float. It assumes that a sign +// has already been read, but that *no* digits have been consumed. +// lexNumberStart will move to the appropriate integer or float states. +func lexNumberStart(lx *lexer) stateFn { + // We MUST see a digit. Even floats have to start with a digit. + r := lx.next() + if !isDigit(r) { + if r == '.' { + return lx.errorf("floats must start with a digit, not '.'") + } + return lx.errorf("expected a digit but got %q", r) + } + return lexNumber +} + +// lexNumber consumes an integer or a float after seeing the first digit. +func lexNumber(lx *lexer) stateFn { + r := lx.next() + if isDigit(r) { + return lexNumber + } + switch r { + case '_': + return lexNumber + case '.', 'e', 'E': + return lexFloat + } + + lx.backup() + lx.emit(itemInteger) + return lx.pop() +} + +// lexFloat consumes the elements of a float. It allows any sequence of +// float-like characters, so floats emitted by the lexer are only a first +// approximation and must be validated by the parser. +func lexFloat(lx *lexer) stateFn { + r := lx.next() + if isDigit(r) { + return lexFloat + } + switch r { + case '_', '.', '-', '+', 'e', 'E': + return lexFloat + } + + lx.backup() + lx.emit(itemFloat) + return lx.pop() +} + +// lexBool consumes a bool string: 'true' or 'false. +func lexBool(lx *lexer) stateFn { + var rs []rune + for { + r := lx.next() + if !unicode.IsLetter(r) { + lx.backup() + break + } + rs = append(rs, r) + } + s := string(rs) + switch s { + case "true", "false": + lx.emit(itemBool) + return lx.pop() + } + return lx.errorf("expected value but found %q instead", s) +} + +// lexCommentStart begins the lexing of a comment. It will emit +// itemCommentStart and consume no characters, passing control to lexComment. +func lexCommentStart(lx *lexer) stateFn { + lx.ignore() + lx.emit(itemCommentStart) + return lexComment +} + +// lexComment lexes an entire comment. It assumes that '#' has been consumed. +// It will consume *up to* the first newline character, and pass control +// back to the last state on the stack. +func lexComment(lx *lexer) stateFn { + r := lx.peek() + if isNL(r) || r == eof { + lx.emit(itemText) + return lx.pop() + } + lx.next() + return lexComment +} + +// lexSkip ignores all slurped input and moves on to the next state. +func lexSkip(lx *lexer, nextState stateFn) stateFn { + return func(lx *lexer) stateFn { + lx.ignore() + return nextState + } +} + +// isWhitespace returns true if `r` is a whitespace character according +// to the spec. +func isWhitespace(r rune) bool { + return r == '\t' || r == ' ' +} + +func isNL(r rune) bool { + return r == '\n' || r == '\r' +} + +func isDigit(r rune) bool { + return r >= '0' && r <= '9' +} + +func isHexadecimal(r rune) bool { + return (r >= '0' && r <= '9') || + (r >= 'a' && r <= 'f') || + (r >= 'A' && r <= 'F') +} + +func isBareKeyChar(r rune) bool { + return (r >= 'A' && r <= 'Z') || + (r >= 'a' && r <= 'z') || + (r >= '0' && r <= '9') || + r == '_' || + r == '-' +} + +func (itype itemType) String() string { + switch itype { + case itemError: + return "Error" + case itemNIL: + return "NIL" + case itemEOF: + return "EOF" + case itemText: + return "Text" + case itemString, itemRawString, itemMultilineString, itemRawMultilineString: + return "String" + case itemBool: + return "Bool" + case itemInteger: + return "Integer" + case itemFloat: + return "Float" + case itemDatetime: + return "DateTime" + case itemTableStart: + return "TableStart" + case itemTableEnd: + return "TableEnd" + case itemKeyStart: + return "KeyStart" + case itemArray: + return "Array" + case itemArrayEnd: + return "ArrayEnd" + case itemCommentStart: + return "CommentStart" + } + panic(fmt.Sprintf("BUG: Unknown type '%d'.", int(itype))) +} + +func (item item) String() string { + return fmt.Sprintf("(%s, %s)", item.typ.String(), item.val) +} diff --git a/vendor/github.com/BurntSushi/toml/parse.go b/vendor/github.com/BurntSushi/toml/parse.go new file mode 100644 index 000000000..50869ef92 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/parse.go @@ -0,0 +1,592 @@ +package toml + +import ( + "fmt" + "strconv" + "strings" + "time" + "unicode" + "unicode/utf8" +) + +type parser struct { + mapping map[string]interface{} + types map[string]tomlType + lx *lexer + + // A list of keys in the order that they appear in the TOML data. + ordered []Key + + // the full key for the current hash in scope + context Key + + // the base key name for everything except hashes + currentKey string + + // rough approximation of line number + approxLine int + + // A map of 'key.group.names' to whether they were created implicitly. + implicits map[string]bool +} + +type parseError string + +func (pe parseError) Error() string { + return string(pe) +} + +func parse(data string) (p *parser, err error) { + defer func() { + if r := recover(); r != nil { + var ok bool + if err, ok = r.(parseError); ok { + return + } + panic(r) + } + }() + + p = &parser{ + mapping: make(map[string]interface{}), + types: make(map[string]tomlType), + lx: lex(data), + ordered: make([]Key, 0), + implicits: make(map[string]bool), + } + for { + item := p.next() + if item.typ == itemEOF { + break + } + p.topLevel(item) + } + + return p, nil +} + +func (p *parser) panicf(format string, v ...interface{}) { + msg := fmt.Sprintf("Near line %d (last key parsed '%s'): %s", + p.approxLine, p.current(), fmt.Sprintf(format, v...)) + panic(parseError(msg)) +} + +func (p *parser) next() item { + it := p.lx.nextItem() + if it.typ == itemError { + p.panicf("%s", it.val) + } + return it +} + +func (p *parser) bug(format string, v ...interface{}) { + panic(fmt.Sprintf("BUG: "+format+"\n\n", v...)) +} + +func (p *parser) expect(typ itemType) item { + it := p.next() + p.assertEqual(typ, it.typ) + return it +} + +func (p *parser) assertEqual(expected, got itemType) { + if expected != got { + p.bug("Expected '%s' but got '%s'.", expected, got) + } +} + +func (p *parser) topLevel(item item) { + switch item.typ { + case itemCommentStart: + p.approxLine = item.line + p.expect(itemText) + case itemTableStart: + kg := p.next() + p.approxLine = kg.line + + var key Key + for ; kg.typ != itemTableEnd && kg.typ != itemEOF; kg = p.next() { + key = append(key, p.keyString(kg)) + } + p.assertEqual(itemTableEnd, kg.typ) + + p.establishContext(key, false) + p.setType("", tomlHash) + p.ordered = append(p.ordered, key) + case itemArrayTableStart: + kg := p.next() + p.approxLine = kg.line + + var key Key + for ; kg.typ != itemArrayTableEnd && kg.typ != itemEOF; kg = p.next() { + key = append(key, p.keyString(kg)) + } + p.assertEqual(itemArrayTableEnd, kg.typ) + + p.establishContext(key, true) + p.setType("", tomlArrayHash) + p.ordered = append(p.ordered, key) + case itemKeyStart: + kname := p.next() + p.approxLine = kname.line + p.currentKey = p.keyString(kname) + + val, typ := p.value(p.next()) + p.setValue(p.currentKey, val) + p.setType(p.currentKey, typ) + p.ordered = append(p.ordered, p.context.add(p.currentKey)) + p.currentKey = "" + default: + p.bug("Unexpected type at top level: %s", item.typ) + } +} + +// Gets a string for a key (or part of a key in a table name). +func (p *parser) keyString(it item) string { + switch it.typ { + case itemText: + return it.val + case itemString, itemMultilineString, + itemRawString, itemRawMultilineString: + s, _ := p.value(it) + return s.(string) + default: + p.bug("Unexpected key type: %s", it.typ) + panic("unreachable") + } +} + +// value translates an expected value from the lexer into a Go value wrapped +// as an empty interface. +func (p *parser) value(it item) (interface{}, tomlType) { + switch it.typ { + case itemString: + return p.replaceEscapes(it.val), p.typeOfPrimitive(it) + case itemMultilineString: + trimmed := stripFirstNewline(stripEscapedWhitespace(it.val)) + return p.replaceEscapes(trimmed), p.typeOfPrimitive(it) + case itemRawString: + return it.val, p.typeOfPrimitive(it) + case itemRawMultilineString: + return stripFirstNewline(it.val), p.typeOfPrimitive(it) + case itemBool: + switch it.val { + case "true": + return true, p.typeOfPrimitive(it) + case "false": + return false, p.typeOfPrimitive(it) + } + p.bug("Expected boolean value, but got '%s'.", it.val) + case itemInteger: + if !numUnderscoresOK(it.val) { + p.panicf("Invalid integer %q: underscores must be surrounded by digits", + it.val) + } + val := strings.Replace(it.val, "_", "", -1) + num, err := strconv.ParseInt(val, 10, 64) + if err != nil { + // Distinguish integer values. Normally, it'd be a bug if the lexer + // provides an invalid integer, but it's possible that the number is + // out of range of valid values (which the lexer cannot determine). + // So mark the former as a bug but the latter as a legitimate user + // error. + if e, ok := err.(*strconv.NumError); ok && + e.Err == strconv.ErrRange { + + p.panicf("Integer '%s' is out of the range of 64-bit "+ + "signed integers.", it.val) + } else { + p.bug("Expected integer value, but got '%s'.", it.val) + } + } + return num, p.typeOfPrimitive(it) + case itemFloat: + parts := strings.FieldsFunc(it.val, func(r rune) bool { + switch r { + case '.', 'e', 'E': + return true + } + return false + }) + for _, part := range parts { + if !numUnderscoresOK(part) { + p.panicf("Invalid float %q: underscores must be "+ + "surrounded by digits", it.val) + } + } + if !numPeriodsOK(it.val) { + // As a special case, numbers like '123.' or '1.e2', + // which are valid as far as Go/strconv are concerned, + // must be rejected because TOML says that a fractional + // part consists of '.' followed by 1+ digits. + p.panicf("Invalid float %q: '.' must be followed "+ + "by one or more digits", it.val) + } + val := strings.Replace(it.val, "_", "", -1) + num, err := strconv.ParseFloat(val, 64) + if err != nil { + if e, ok := err.(*strconv.NumError); ok && + e.Err == strconv.ErrRange { + + p.panicf("Float '%s' is out of the range of 64-bit "+ + "IEEE-754 floating-point numbers.", it.val) + } else { + p.panicf("Invalid float value: %q", it.val) + } + } + return num, p.typeOfPrimitive(it) + case itemDatetime: + var t time.Time + var ok bool + var err error + for _, format := range []string{ + "2006-01-02T15:04:05Z07:00", + "2006-01-02T15:04:05", + "2006-01-02", + } { + t, err = time.ParseInLocation(format, it.val, time.Local) + if err == nil { + ok = true + break + } + } + if !ok { + p.panicf("Invalid TOML Datetime: %q.", it.val) + } + return t, p.typeOfPrimitive(it) + case itemArray: + array := make([]interface{}, 0) + types := make([]tomlType, 0) + + for it = p.next(); it.typ != itemArrayEnd; it = p.next() { + if it.typ == itemCommentStart { + p.expect(itemText) + continue + } + + val, typ := p.value(it) + array = append(array, val) + types = append(types, typ) + } + return array, p.typeOfArray(types) + case itemInlineTableStart: + var ( + hash = make(map[string]interface{}) + outerContext = p.context + outerKey = p.currentKey + ) + + p.context = append(p.context, p.currentKey) + p.currentKey = "" + for it := p.next(); it.typ != itemInlineTableEnd; it = p.next() { + if it.typ != itemKeyStart { + p.bug("Expected key start but instead found %q, around line %d", + it.val, p.approxLine) + } + if it.typ == itemCommentStart { + p.expect(itemText) + continue + } + + // retrieve key + k := p.next() + p.approxLine = k.line + kname := p.keyString(k) + + // retrieve value + p.currentKey = kname + val, typ := p.value(p.next()) + // make sure we keep metadata up to date + p.setType(kname, typ) + p.ordered = append(p.ordered, p.context.add(p.currentKey)) + hash[kname] = val + } + p.context = outerContext + p.currentKey = outerKey + return hash, tomlHash + } + p.bug("Unexpected value type: %s", it.typ) + panic("unreachable") +} + +// numUnderscoresOK checks whether each underscore in s is surrounded by +// characters that are not underscores. +func numUnderscoresOK(s string) bool { + accept := false + for _, r := range s { + if r == '_' { + if !accept { + return false + } + accept = false + continue + } + accept = true + } + return accept +} + +// numPeriodsOK checks whether every period in s is followed by a digit. +func numPeriodsOK(s string) bool { + period := false + for _, r := range s { + if period && !isDigit(r) { + return false + } + period = r == '.' + } + return !period +} + +// establishContext sets the current context of the parser, +// where the context is either a hash or an array of hashes. Which one is +// set depends on the value of the `array` parameter. +// +// Establishing the context also makes sure that the key isn't a duplicate, and +// will create implicit hashes automatically. +func (p *parser) establishContext(key Key, array bool) { + var ok bool + + // Always start at the top level and drill down for our context. + hashContext := p.mapping + keyContext := make(Key, 0) + + // We only need implicit hashes for key[0:-1] + for _, k := range key[0 : len(key)-1] { + _, ok = hashContext[k] + keyContext = append(keyContext, k) + + // No key? Make an implicit hash and move on. + if !ok { + p.addImplicit(keyContext) + hashContext[k] = make(map[string]interface{}) + } + + // If the hash context is actually an array of tables, then set + // the hash context to the last element in that array. + // + // Otherwise, it better be a table, since this MUST be a key group (by + // virtue of it not being the last element in a key). + switch t := hashContext[k].(type) { + case []map[string]interface{}: + hashContext = t[len(t)-1] + case map[string]interface{}: + hashContext = t + default: + p.panicf("Key '%s' was already created as a hash.", keyContext) + } + } + + p.context = keyContext + if array { + // If this is the first element for this array, then allocate a new + // list of tables for it. + k := key[len(key)-1] + if _, ok := hashContext[k]; !ok { + hashContext[k] = make([]map[string]interface{}, 0, 5) + } + + // Add a new table. But make sure the key hasn't already been used + // for something else. + if hash, ok := hashContext[k].([]map[string]interface{}); ok { + hashContext[k] = append(hash, make(map[string]interface{})) + } else { + p.panicf("Key '%s' was already created and cannot be used as "+ + "an array.", keyContext) + } + } else { + p.setValue(key[len(key)-1], make(map[string]interface{})) + } + p.context = append(p.context, key[len(key)-1]) +} + +// setValue sets the given key to the given value in the current context. +// It will make sure that the key hasn't already been defined, account for +// implicit key groups. +func (p *parser) setValue(key string, value interface{}) { + var tmpHash interface{} + var ok bool + + hash := p.mapping + keyContext := make(Key, 0) + for _, k := range p.context { + keyContext = append(keyContext, k) + if tmpHash, ok = hash[k]; !ok { + p.bug("Context for key '%s' has not been established.", keyContext) + } + switch t := tmpHash.(type) { + case []map[string]interface{}: + // The context is a table of hashes. Pick the most recent table + // defined as the current hash. + hash = t[len(t)-1] + case map[string]interface{}: + hash = t + default: + p.bug("Expected hash to have type 'map[string]interface{}', but "+ + "it has '%T' instead.", tmpHash) + } + } + keyContext = append(keyContext, key) + + if _, ok := hash[key]; ok { + // Typically, if the given key has already been set, then we have + // to raise an error since duplicate keys are disallowed. However, + // it's possible that a key was previously defined implicitly. In this + // case, it is allowed to be redefined concretely. (See the + // `tests/valid/implicit-and-explicit-after.toml` test in `toml-test`.) + // + // But we have to make sure to stop marking it as an implicit. (So that + // another redefinition provokes an error.) + // + // Note that since it has already been defined (as a hash), we don't + // want to overwrite it. So our business is done. + if p.isImplicit(keyContext) { + p.removeImplicit(keyContext) + return + } + + // Otherwise, we have a concrete key trying to override a previous + // key, which is *always* wrong. + p.panicf("Key '%s' has already been defined.", keyContext) + } + hash[key] = value +} + +// setType sets the type of a particular value at a given key. +// It should be called immediately AFTER setValue. +// +// Note that if `key` is empty, then the type given will be applied to the +// current context (which is either a table or an array of tables). +func (p *parser) setType(key string, typ tomlType) { + keyContext := make(Key, 0, len(p.context)+1) + for _, k := range p.context { + keyContext = append(keyContext, k) + } + if len(key) > 0 { // allow type setting for hashes + keyContext = append(keyContext, key) + } + p.types[keyContext.String()] = typ +} + +// addImplicit sets the given Key as having been created implicitly. +func (p *parser) addImplicit(key Key) { + p.implicits[key.String()] = true +} + +// removeImplicit stops tagging the given key as having been implicitly +// created. +func (p *parser) removeImplicit(key Key) { + p.implicits[key.String()] = false +} + +// isImplicit returns true if the key group pointed to by the key was created +// implicitly. +func (p *parser) isImplicit(key Key) bool { + return p.implicits[key.String()] +} + +// current returns the full key name of the current context. +func (p *parser) current() string { + if len(p.currentKey) == 0 { + return p.context.String() + } + if len(p.context) == 0 { + return p.currentKey + } + return fmt.Sprintf("%s.%s", p.context, p.currentKey) +} + +func stripFirstNewline(s string) string { + if len(s) == 0 || s[0] != '\n' { + return s + } + return s[1:] +} + +func stripEscapedWhitespace(s string) string { + esc := strings.Split(s, "\\\n") + if len(esc) > 1 { + for i := 1; i < len(esc); i++ { + esc[i] = strings.TrimLeftFunc(esc[i], unicode.IsSpace) + } + } + return strings.Join(esc, "") +} + +func (p *parser) replaceEscapes(str string) string { + var replaced []rune + s := []byte(str) + r := 0 + for r < len(s) { + if s[r] != '\\' { + c, size := utf8.DecodeRune(s[r:]) + r += size + replaced = append(replaced, c) + continue + } + r += 1 + if r >= len(s) { + p.bug("Escape sequence at end of string.") + return "" + } + switch s[r] { + default: + p.bug("Expected valid escape code after \\, but got %q.", s[r]) + return "" + case 'b': + replaced = append(replaced, rune(0x0008)) + r += 1 + case 't': + replaced = append(replaced, rune(0x0009)) + r += 1 + case 'n': + replaced = append(replaced, rune(0x000A)) + r += 1 + case 'f': + replaced = append(replaced, rune(0x000C)) + r += 1 + case 'r': + replaced = append(replaced, rune(0x000D)) + r += 1 + case '"': + replaced = append(replaced, rune(0x0022)) + r += 1 + case '\\': + replaced = append(replaced, rune(0x005C)) + r += 1 + case 'u': + // At this point, we know we have a Unicode escape of the form + // `uXXXX` at [r, r+5). (Because the lexer guarantees this + // for us.) + escaped := p.asciiEscapeToUnicode(s[r+1 : r+5]) + replaced = append(replaced, escaped) + r += 5 + case 'U': + // At this point, we know we have a Unicode escape of the form + // `uXXXX` at [r, r+9). (Because the lexer guarantees this + // for us.) + escaped := p.asciiEscapeToUnicode(s[r+1 : r+9]) + replaced = append(replaced, escaped) + r += 9 + } + } + return string(replaced) +} + +func (p *parser) asciiEscapeToUnicode(bs []byte) rune { + s := string(bs) + hex, err := strconv.ParseUint(strings.ToLower(s), 16, 32) + if err != nil { + p.bug("Could not parse '%s' as a hexadecimal number, but the "+ + "lexer claims it's OK: %s", s, err) + } + if !utf8.ValidRune(rune(hex)) { + p.panicf("Escaped character '\\u%s' is not valid UTF-8.", s) + } + return rune(hex) +} + +func isStringType(ty itemType) bool { + return ty == itemString || ty == itemMultilineString || + ty == itemRawString || ty == itemRawMultilineString +} diff --git a/vendor/github.com/BurntSushi/toml/type_check.go b/vendor/github.com/BurntSushi/toml/type_check.go new file mode 100644 index 000000000..c73f8afc1 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/type_check.go @@ -0,0 +1,91 @@ +package toml + +// tomlType represents any Go type that corresponds to a TOML type. +// While the first draft of the TOML spec has a simplistic type system that +// probably doesn't need this level of sophistication, we seem to be militating +// toward adding real composite types. +type tomlType interface { + typeString() string +} + +// typeEqual accepts any two types and returns true if they are equal. +func typeEqual(t1, t2 tomlType) bool { + if t1 == nil || t2 == nil { + return false + } + return t1.typeString() == t2.typeString() +} + +func typeIsHash(t tomlType) bool { + return typeEqual(t, tomlHash) || typeEqual(t, tomlArrayHash) +} + +type tomlBaseType string + +func (btype tomlBaseType) typeString() string { + return string(btype) +} + +func (btype tomlBaseType) String() string { + return btype.typeString() +} + +var ( + tomlInteger tomlBaseType = "Integer" + tomlFloat tomlBaseType = "Float" + tomlDatetime tomlBaseType = "Datetime" + tomlString tomlBaseType = "String" + tomlBool tomlBaseType = "Bool" + tomlArray tomlBaseType = "Array" + tomlHash tomlBaseType = "Hash" + tomlArrayHash tomlBaseType = "ArrayHash" +) + +// typeOfPrimitive returns a tomlType of any primitive value in TOML. +// Primitive values are: Integer, Float, Datetime, String and Bool. +// +// Passing a lexer item other than the following will cause a BUG message +// to occur: itemString, itemBool, itemInteger, itemFloat, itemDatetime. +func (p *parser) typeOfPrimitive(lexItem item) tomlType { + switch lexItem.typ { + case itemInteger: + return tomlInteger + case itemFloat: + return tomlFloat + case itemDatetime: + return tomlDatetime + case itemString: + return tomlString + case itemMultilineString: + return tomlString + case itemRawString: + return tomlString + case itemRawMultilineString: + return tomlString + case itemBool: + return tomlBool + } + p.bug("Cannot infer primitive type of lex item '%s'.", lexItem) + panic("unreachable") +} + +// typeOfArray returns a tomlType for an array given a list of types of its +// values. +// +// In the current spec, if an array is homogeneous, then its type is always +// "Array". If the array is not homogeneous, an error is generated. +func (p *parser) typeOfArray(types []tomlType) tomlType { + // Empty arrays are cool. + if len(types) == 0 { + return tomlArray + } + + theType := types[0] + for _, t := range types[1:] { + if !typeEqual(theType, t) { + p.panicf("Array contains values of type '%s' and '%s', but "+ + "arrays must be homogeneous.", theType, t) + } + } + return tomlArray +} diff --git a/vendor/github.com/BurntSushi/toml/type_fields.go b/vendor/github.com/BurntSushi/toml/type_fields.go new file mode 100644 index 000000000..608997c22 --- /dev/null +++ b/vendor/github.com/BurntSushi/toml/type_fields.go @@ -0,0 +1,242 @@ +package toml + +// Struct field handling is adapted from code in encoding/json: +// +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the Go distribution. + +import ( + "reflect" + "sort" + "sync" +) + +// A field represents a single field found in a struct. +type field struct { + name string // the name of the field (`toml` tag included) + tag bool // whether field has a `toml` tag + index []int // represents the depth of an anonymous field + typ reflect.Type // the type of the field +} + +// byName sorts field by name, breaking ties with depth, +// then breaking ties with "name came from toml tag", then +// breaking ties with index sequence. +type byName []field + +func (x byName) Len() int { return len(x) } + +func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] } + +func (x byName) Less(i, j int) bool { + if x[i].name != x[j].name { + return x[i].name < x[j].name + } + if len(x[i].index) != len(x[j].index) { + return len(x[i].index) < len(x[j].index) + } + if x[i].tag != x[j].tag { + return x[i].tag + } + return byIndex(x).Less(i, j) +} + +// byIndex sorts field by index sequence. +type byIndex []field + +func (x byIndex) Len() int { return len(x) } + +func (x byIndex) Swap(i, j int) { x[i], x[j] = x[j], x[i] } + +func (x byIndex) Less(i, j int) bool { + for k, xik := range x[i].index { + if k >= len(x[j].index) { + return false + } + if xik != x[j].index[k] { + return xik < x[j].index[k] + } + } + return len(x[i].index) < len(x[j].index) +} + +// typeFields returns a list of fields that TOML should recognize for the given +// type. The algorithm is breadth-first search over the set of structs to +// include - the top struct and then any reachable anonymous structs. +func typeFields(t reflect.Type) []field { + // Anonymous fields to explore at the current level and the next. + current := []field{} + next := []field{{typ: t}} + + // Count of queued names for current level and the next. + count := map[reflect.Type]int{} + nextCount := map[reflect.Type]int{} + + // Types already visited at an earlier level. + visited := map[reflect.Type]bool{} + + // Fields found. + var fields []field + + for len(next) > 0 { + current, next = next, current[:0] + count, nextCount = nextCount, map[reflect.Type]int{} + + for _, f := range current { + if visited[f.typ] { + continue + } + visited[f.typ] = true + + // Scan f.typ for fields to include. + for i := 0; i < f.typ.NumField(); i++ { + sf := f.typ.Field(i) + if sf.PkgPath != "" && !sf.Anonymous { // unexported + continue + } + opts := getOptions(sf.Tag) + if opts.skip { + continue + } + index := make([]int, len(f.index)+1) + copy(index, f.index) + index[len(f.index)] = i + + ft := sf.Type + if ft.Name() == "" && ft.Kind() == reflect.Ptr { + // Follow pointer. + ft = ft.Elem() + } + + // Record found field and index sequence. + if opts.name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct { + tagged := opts.name != "" + name := opts.name + if name == "" { + name = sf.Name + } + fields = append(fields, field{name, tagged, index, ft}) + if count[f.typ] > 1 { + // If there were multiple instances, add a second, + // so that the annihilation code will see a duplicate. + // It only cares about the distinction between 1 or 2, + // so don't bother generating any more copies. + fields = append(fields, fields[len(fields)-1]) + } + continue + } + + // Record new anonymous struct to explore in next round. + nextCount[ft]++ + if nextCount[ft] == 1 { + f := field{name: ft.Name(), index: index, typ: ft} + next = append(next, f) + } + } + } + } + + sort.Sort(byName(fields)) + + // Delete all fields that are hidden by the Go rules for embedded fields, + // except that fields with TOML tags are promoted. + + // The fields are sorted in primary order of name, secondary order + // of field index length. Loop over names; for each name, delete + // hidden fields by choosing the one dominant field that survives. + out := fields[:0] + for advance, i := 0, 0; i < len(fields); i += advance { + // One iteration per name. + // Find the sequence of fields with the name of this first field. + fi := fields[i] + name := fi.name + for advance = 1; i+advance < len(fields); advance++ { + fj := fields[i+advance] + if fj.name != name { + break + } + } + if advance == 1 { // Only one field with this name + out = append(out, fi) + continue + } + dominant, ok := dominantField(fields[i : i+advance]) + if ok { + out = append(out, dominant) + } + } + + fields = out + sort.Sort(byIndex(fields)) + + return fields +} + +// dominantField looks through the fields, all of which are known to +// have the same name, to find the single field that dominates the +// others using Go's embedding rules, modified by the presence of +// TOML tags. If there are multiple top-level fields, the boolean +// will be false: This condition is an error in Go and we skip all +// the fields. +func dominantField(fields []field) (field, bool) { + // The fields are sorted in increasing index-length order. The winner + // must therefore be one with the shortest index length. Drop all + // longer entries, which is easy: just truncate the slice. + length := len(fields[0].index) + tagged := -1 // Index of first tagged field. + for i, f := range fields { + if len(f.index) > length { + fields = fields[:i] + break + } + if f.tag { + if tagged >= 0 { + // Multiple tagged fields at the same level: conflict. + // Return no field. + return field{}, false + } + tagged = i + } + } + if tagged >= 0 { + return fields[tagged], true + } + // All remaining fields have the same length. If there's more than one, + // we have a conflict (two fields named "X" at the same level) and we + // return no field. + if len(fields) > 1 { + return field{}, false + } + return fields[0], true +} + +var fieldCache struct { + sync.RWMutex + m map[reflect.Type][]field +} + +// cachedTypeFields is like typeFields but uses a cache to avoid repeated work. +func cachedTypeFields(t reflect.Type) []field { + fieldCache.RLock() + f := fieldCache.m[t] + fieldCache.RUnlock() + if f != nil { + return f + } + + // Compute fields without lock. + // Might duplicate effort but won't hold other computations back. + f = typeFields(t) + if f == nil { + f = []field{} + } + + fieldCache.Lock() + if fieldCache.m == nil { + fieldCache.m = map[reflect.Type][]field{} + } + fieldCache.m[t] = f + fieldCache.Unlock() + return f +} diff --git a/vendor/github.com/lib/pq/LICENSE.md b/vendor/github.com/a8m/mark/LICENSE similarity index 91% rename from vendor/github.com/lib/pq/LICENSE.md rename to vendor/github.com/a8m/mark/LICENSE index 5773904a3..e84e96027 100644 --- a/vendor/github.com/lib/pq/LICENSE.md +++ b/vendor/github.com/a8m/mark/LICENSE @@ -1,8 +1,9 @@ -Copyright (c) 2011-2013, 'pq' Contributors -Portions Copyright (C) 2011 Blake Mizerany +The MIT License + +Copyright (c) 2015 Ariel Mashraki Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/vendor/github.com/a8m/mark/cmd/mark/main.go b/vendor/github.com/a8m/mark/cmd/mark/main.go new file mode 100644 index 000000000..2fd1a7661 --- /dev/null +++ b/vendor/github.com/a8m/mark/cmd/mark/main.go @@ -0,0 +1,94 @@ +// mark command line tool. available at https://github.com/a8m/mark +package main + +import ( + "bufio" + "flag" + "fmt" + "io" + "os" + + "github.com/a8m/mark" +) + +var ( + input = flag.String("i", "", "") + output = flag.String("o", "", "") + smarty = flag.Bool("smartypants", false, "") + fractions = flag.Bool("fractions", false, "") +) + +var usage = `Usage: mark [options...] + +Options: + -i Specify file input, otherwise use last argument as input file. + If no input file is specified, read from stdin. + -o Specify file output. If none is specified, write to stdout. + + -smartypants Use "smart" typograhic punctuation for things like + quotes and dashes. + -fractions Traslate fraction like to suitable HTML elements +` + +func main() { + flag.Usage = func() { + fmt.Fprint(os.Stderr, fmt.Sprintf(usage)) + } + flag.Parse() + // read + var reader *bufio.Reader + if *input != "" { + file, err := os.Open(*input) + if err != nil { + usageAndExit(fmt.Sprintf("Error to open file input: %s.", *input)) + } + defer file.Close() + reader = bufio.NewReader(file) + } else { + stat, err := os.Stdin.Stat() + if err != nil || (stat.Mode()&os.ModeCharDevice) != 0 { + usageAndExit("") + } + reader = bufio.NewReader(os.Stdin) + } + // collect data + var data string + for { + line, err := reader.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + usageAndExit("failed to reading input.") + } + data += line + } + // write + var ( + err error + file = os.Stdout + ) + if *output != "" { + if file, err = os.Create(*output); err != nil { + usageAndExit("error to create the wanted output file.") + } + } + // mark rendering + opts := mark.DefaultOptions() + opts.Smartypants = *smarty + opts.Fractions = *fractions + m := mark.New(data, opts) + if _, err := file.WriteString(m.Render()); err != nil { + usageAndExit(fmt.Sprintf("error writing output to: %s.", file.Name())) + } +} + +func usageAndExit(msg string) { + if msg != "" { + fmt.Fprintf(os.Stderr, msg) + fmt.Fprintf(os.Stderr, "\n\n") + } + flag.Usage() + fmt.Fprintf(os.Stderr, "\n") + os.Exit(1) +} diff --git a/vendor/github.com/a8m/mark/grammar.go b/vendor/github.com/a8m/mark/grammar.go new file mode 100644 index 000000000..7e741731e --- /dev/null +++ b/vendor/github.com/a8m/mark/grammar.go @@ -0,0 +1,92 @@ +package mark + +import ( + "fmt" + "regexp" +) + +// Block Grammar +var ( + reHr = regexp.MustCompile(`^(?:(?:\* *){3,}|(?:_ *){3,}|(?:- *){3,}) *(?:\n+|$)`) + reHeading = regexp.MustCompile(`^ *(#{1,6})(?: +#*| +([^\n]*?)|)(?: +#*|) *(?:\n|$)`) + reLHeading = regexp.MustCompile(`^([^\n]+?) *\n {0,3}(=|-){1,} *(?:\n+|$)`) + reBlockQuote = regexp.MustCompile(`^ *>[^\n]*(\n[^\n]+)*\n*`) + reDefLink = regexp.MustCompile(`(?s)^ *\[([^\]]+)\]: *\n? *]+)>?(?: *\n? *["'(](.+?)['")])? *(?:\n+|$)`) + reSpaceGen = func(i int) *regexp.Regexp { + return regexp.MustCompile(fmt.Sprintf(`(?m)^ {1,%d}`, i)) + } +) + +var reList = struct { + item, marker, loose *regexp.Regexp + scanLine, scanNewLine func(src string) string +}{ + regexp.MustCompile(`^( *)(?:[*+-]|\d{1,9}\.) (.*)(?:\n|)`), + regexp.MustCompile(`^ *([*+-]|\d+\.) +`), + regexp.MustCompile(`(?m)\n\n(.*)`), + regexp.MustCompile(`^(.*)(?:\n|)`).FindString, + regexp.MustCompile(`^\n{1,}`).FindString, +} + +var reCodeBlock = struct { + *regexp.Regexp + trim func(src, repl string) string +}{ + regexp.MustCompile(`^( {4}[^\n]+(?: *\n)*)+`), + regexp.MustCompile("(?m)^( {0,4})").ReplaceAllLiteralString, +} + +var reGfmCode = struct { + *regexp.Regexp + endGen func(end string, i int) *regexp.Regexp +}{ + regexp.MustCompile("^( {0,3})([`~]{3,}) *(\\S*)?(?:.*)"), + func(end string, i int) *regexp.Regexp { + return regexp.MustCompile(fmt.Sprintf(`(?s)(.*?)(?:((?m)^ {0,3}%s{%d,} *$)|$)`, end, i)) + }, +} + +var reTable = struct { + item, itemLp *regexp.Regexp + split func(s string, n int) []string + trim func(src, repl string) string +}{ + regexp.MustCompile(`^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*`), + regexp.MustCompile(`(^ *\|.+)\n( *\| *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*`), + regexp.MustCompile(` *\| *`).Split, + regexp.MustCompile(`^ *\| *| *\| *$`).ReplaceAllString, +} + +var reHTML = struct { + CDATA_OPEN, CDATA_CLOSE string + item, comment, tag, span *regexp.Regexp + endTagGen func(tag string) *regexp.Regexp +}{ + `![CDATA[`, + "?\\]\\]", + regexp.MustCompile(`^<(\w+|!\[CDATA\[)(?:"[^"]*"|'[^']*'|[^'">])*?>`), + regexp.MustCompile(`(?sm)`), + regexp.MustCompile(`^|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>`), + // TODO: Add all span-tags and move to config. + regexp.MustCompile(`^(a|em|strong|small|s|q|data|time|code|sub|sup|i|b|u|span|br|del|img)$`), + func(tag string) *regexp.Regexp { + return regexp.MustCompile(fmt.Sprintf(`(?s)(.+?)<\/%s> *`, tag)) + }, +} + +// Inline Grammar +var ( + reBr = regexp.MustCompile(`^(?: {2,}|\\)\n`) + reLinkText = `(?:\[[^\]]*\]|[^\[\]]|\])*` + reLinkHref = `\s*?(?:\s+['"\(](.*?)['"\)])?\s*` + reGfmLink = regexp.MustCompile(`^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])`) + reLink = regexp.MustCompile(fmt.Sprintf(`(?s)^!?\[(%s)\]\(%s\)`, reLinkText, reLinkHref)) + reAutoLink = regexp.MustCompile(`^<([^ >]+(@|:\/)[^ >]+)>`) + reRefLink = regexp.MustCompile(`^!?\[((?:\[[^\]]*\]|[^\[\]]|\])*)\](?:\s*\[([^\]]*)\])?`) + reImage = regexp.MustCompile(fmt.Sprintf(`(?s)^!?\[(%s)\]\(%s\)`, reLinkText, reLinkHref)) + reCode = regexp.MustCompile("(?s)^`{1,2}\\s*(.*?[^`])\\s*`{1,2}") + reStrike = regexp.MustCompile(`(?s)^~{2}(.+?)~{2}`) + reEmphasise = `(?s)^_{%[1]d}(\S.*?_*)_{%[1]d}|^\*{%[1]d}(\S.*?\**)\*{%[1]d}` + reItalic = regexp.MustCompile(fmt.Sprintf(reEmphasise, 1)) + reStrong = regexp.MustCompile(fmt.Sprintf(reEmphasise, 2)) +) diff --git a/vendor/github.com/a8m/mark/lexer.go b/vendor/github.com/a8m/mark/lexer.go new file mode 100644 index 000000000..33867931c --- /dev/null +++ b/vendor/github.com/a8m/mark/lexer.go @@ -0,0 +1,568 @@ +package mark + +import ( + "regexp" + "strings" + "unicode/utf8" +) + +// type position +type Pos int + +// itemType identifies the type of lex items. +type itemType int + +// Item represent a token or text string returned from the scanner +type item struct { + typ itemType // The type of this item. + pos Pos // The starting position, in bytes, of this item in the input string. + val string // The value of this item. +} + +const eof = -1 // Zero value so closed channel delivers EOF + +const ( + itemError itemType = iota // Error occurred; value is text of error + itemEOF + itemNewLine + itemHTML + itemHeading + itemLHeading + itemBlockQuote + itemList + itemListItem + itemLooseItem + itemCodeBlock + itemGfmCodeBlock + itemHr + itemTable + itemLpTable + itemTableRow + itemTableCell + itemStrong + itemItalic + itemStrike + itemCode + itemLink + itemDefLink + itemRefLink + itemAutoLink + itemGfmLink + itemImage + itemRefImage + itemText + itemBr + itemPipe + itemIndent +) + +// stateFn represents the state of the scanner as a function that returns the next state. +type stateFn func(*lexer) stateFn + +// Lexer interface, used to composed it inside the parser +type Lexer interface { + nextItem() item +} + +// lexer holds the state of the scanner. +type lexer struct { + input string // the string being scanned + state stateFn // the next lexing function to enter + pos Pos // current position in the input + start Pos // start position of this item + width Pos // width of last rune read from input + lastPos Pos // position of most recent item returned by nextItem + items chan item // channel of scanned items +} + +// lex creates a new lexer for the input string. +func lex(input string) *lexer { + l := &lexer{ + input: input, + items: make(chan item), + } + go l.run() + return l +} + +// lexInline create a new lexer for one phase lexing(inline blocks). +func lexInline(input string) *lexer { + l := &lexer{ + input: input, + items: make(chan item), + } + go l.lexInline() + return l +} + +// run runs the state machine for the lexer. +func (l *lexer) run() { + for l.state = lexAny; l.state != nil; { + l.state = l.state(l) + } + close(l.items) +} + +// next return the next rune in the input +func (l *lexer) next() rune { + if int(l.pos) >= len(l.input) { + l.width = 0 + return eof + } + r, w := utf8.DecodeRuneInString(l.input[l.pos:]) + l.width = Pos(w) + l.pos += l.width + return r +} + +// lexAny scanner is kind of forwarder, it get the current char in the text +// and forward it to the appropriate scanner based on some conditions. +func lexAny(l *lexer) stateFn { + switch r := l.peek(); r { + case '*', '-', '_': + return lexHr + case '+', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': + return lexList + case '<': + return lexHTML + case '>': + return lexBlockQuote + case '[': + return lexDefLink + case '#': + return lexHeading + case '`', '~': + return lexGfmCode + case ' ': + if reCodeBlock.MatchString(l.input[l.pos:]) { + return lexCode + } else if reGfmCode.MatchString(l.input[l.pos:]) { + return lexGfmCode + } + // Keep moving forward until we get all the indentation size + for ; r == l.peek(); r = l.next() { + } + l.emit(itemIndent) + return lexAny + case '|': + if m := reTable.itemLp.MatchString(l.input[l.pos:]); m { + l.emit(itemLpTable) + return lexTable + } + fallthrough + default: + if m := reTable.item.MatchString(l.input[l.pos:]); m { + l.emit(itemTable) + return lexTable + } + return lexText + } +} + +// lexHeading test if the current text position is an heading item. +// is so, it will emit an item and return back to lenAny function +// else, lex it as a simple text value +func lexHeading(l *lexer) stateFn { + if m := reHeading.FindString(l.input[l.pos:]); m != "" { + l.pos += Pos(len(m)) + l.emit(itemHeading) + return lexAny + } + return lexText +} + +// lexHr test if the current text position is an horizontal rules item. +// is so, it will emit an horizontal rule item and return back to lenAny function +// else, forward it to lexList function +func lexHr(l *lexer) stateFn { + if match := reHr.FindString(l.input[l.pos:]); match != "" { + l.pos += Pos(len(match)) + l.emit(itemHr) + return lexAny + } + return lexList +} + +// lexGfmCode test if the current text position is start of GFM code-block item. +// if so, it will generate regexp based on the fence type[`~] and it length. +// it scan until the end, and then emit the code-block item and return back to the +// lenAny forwarder. +// else, lex it as a simple inline text. +func lexGfmCode(l *lexer) stateFn { + if match := reGfmCode.FindStringSubmatch(l.input[l.pos:]); len(match) != 0 { + l.pos += Pos(len(match[0])) + fence := match[2] + // Generate Regexp based on fence type[`~] and length + reGfmEnd := reGfmCode.endGen(fence[0:1], len(fence)) + infoContainer := reGfmEnd.FindStringSubmatch(l.input[l.pos:]) + l.pos += Pos(len(infoContainer[0])) + infoString := infoContainer[1] + // Remove leading and trailing spaces + if indent := len(match[1]); indent > 0 { + reSpace := reSpaceGen(indent) + infoString = reSpace.ReplaceAllString(infoString, "") + } + l.emit(itemGfmCodeBlock, match[0]+infoString) + return lexAny + } + return lexText +} + +// lexCode scans code block. +func lexCode(l *lexer) stateFn { + match := reCodeBlock.FindString(l.input[l.pos:]) + l.pos += Pos(len(match)) + l.emit(itemCodeBlock) + return lexAny +} + +// lexText scans until end-of-line(\n) +func lexText(l *lexer) stateFn { + // Drain text before emitting + emit := func(item itemType, pos Pos) { + if l.pos > l.start { + l.emit(itemText) + } + l.pos += pos + l.emit(item) + } +Loop: + for { + switch r := l.peek(); r { + case eof: + emit(itemEOF, Pos(0)) + break Loop + case '\n': + // CM 4.4: An indented code block cannot interrupt a paragraph. + if l.pos > l.start && strings.HasPrefix(l.input[l.pos+1:], " ") { + l.next() + continue + } + emit(itemNewLine, l.width) + break Loop + default: + // Test for Setext-style headers + if m := reLHeading.FindString(l.input[l.pos:]); m != "" { + emit(itemLHeading, Pos(len(m))) + break Loop + } + l.next() + } + } + return lexAny +} + +// backup steps back one rune. Can only be called once per call of next. +func (l *lexer) backup() { + l.pos -= l.width +} + +// peek returns but does not consume the next rune in the input. +func (l *lexer) peek() rune { + r := l.next() + l.backup() + return r +} + +// emit passes an item back to the client. +func (l *lexer) emit(t itemType, s ...string) { + if len(s) == 0 { + s = append(s, l.input[l.start:l.pos]) + } + l.items <- item{t, l.start, s[0]} + l.start = l.pos +} + +// lexItem return the next item token, called by the parser. +func (l *lexer) nextItem() item { + item := <-l.items + l.lastPos = l.pos + return item +} + +// One phase lexing(inline reason) +func (l *lexer) lexInline() { + escape := regexp.MustCompile("^\\\\([\\`*{}\\[\\]()#+\\-.!_>~|])") + // Drain text before emitting + emit := func(item itemType, pos int) { + if l.pos > l.start { + l.emit(itemText) + } + l.pos += Pos(pos) + l.emit(item) + } +Loop: + for { + switch r := l.peek(); r { + case eof: + if l.pos > l.start { + l.emit(itemText) + } + break Loop + // backslash escaping + case '\\': + if m := escape.FindStringSubmatch(l.input[l.pos:]); len(m) != 0 { + if l.pos > l.start { + l.emit(itemText) + } + l.pos += Pos(len(m[0])) + l.emit(itemText, m[1]) + break + } + fallthrough + case ' ': + if m := reBr.FindString(l.input[l.pos:]); m != "" { + // pos - length of new-line + emit(itemBr, len(m)) + break + } + l.next() + case '_', '*', '~', '`': + input := l.input[l.pos:] + // Strong + if m := reStrong.FindString(input); m != "" { + emit(itemStrong, len(m)) + break + } + // Italic + if m := reItalic.FindString(input); m != "" { + emit(itemItalic, len(m)) + break + } + // Strike + if m := reStrike.FindString(input); m != "" { + emit(itemStrike, len(m)) + break + } + // InlineCode + if m := reCode.FindString(input); m != "" { + emit(itemCode, len(m)) + break + } + l.next() + // itemLink, itemImage, itemRefLink, itemRefImage + case '[', '!': + input := l.input[l.pos:] + if m := reLink.FindString(input); m != "" { + pos := len(m) + if r == '[' { + emit(itemLink, pos) + } else { + emit(itemImage, pos) + } + break + } + if m := reRefLink.FindString(input); m != "" { + pos := len(m) + if r == '[' { + emit(itemRefLink, pos) + } else { + emit(itemRefImage, pos) + } + break + } + l.next() + // itemAutoLink, htmlBlock + case '<': + if m := reAutoLink.FindString(l.input[l.pos:]); m != "" { + emit(itemAutoLink, len(m)) + break + } + if match, res := l.matchHTML(l.input[l.pos:]); match { + emit(itemHTML, len(res)) + break + } + l.next() + default: + if m := reGfmLink.FindString(l.input[l.pos:]); m != "" { + emit(itemGfmLink, len(m)) + break + } + l.next() + } + } + close(l.items) +} + +// lexHTML. +func lexHTML(l *lexer) stateFn { + if match, res := l.matchHTML(l.input[l.pos:]); match { + l.pos += Pos(len(res)) + l.emit(itemHTML) + return lexAny + } + return lexText +} + +// Test if the given input is match the HTML pattern(blocks only) +func (l *lexer) matchHTML(input string) (bool, string) { + if m := reHTML.comment.FindString(input); m != "" { + return true, m + } + if m := reHTML.item.FindStringSubmatch(input); len(m) != 0 { + el, name := m[0], m[1] + // if name is a span... is a text + if reHTML.span.MatchString(name) { + return false, "" + } + // if it's a self-closed html element, but not a itemAutoLink + if strings.HasSuffix(el, "/>") && !reAutoLink.MatchString(el) { + return true, el + } + if name == reHTML.CDATA_OPEN { + name = reHTML.CDATA_CLOSE + } + reEndTag := reHTML.endTagGen(name) + if m := reEndTag.FindString(input); m != "" { + return true, m + } + } + return false, "" +} + +// lexDefLink scans link definition +func lexDefLink(l *lexer) stateFn { + if m := reDefLink.FindString(l.input[l.pos:]); m != "" { + l.pos += Pos(len(m)) + l.emit(itemDefLink) + return lexAny + } + return lexText +} + +// lexList scans ordered and unordered lists. +func lexList(l *lexer) stateFn { + match, items := l.matchList(l.input[l.pos:]) + if !match { + return lexText + } + var space int + var typ itemType + for i, item := range items { + // Emit itemList on the first loop + if i == 0 { + l.emit(itemList, reList.marker.FindStringSubmatch(item)[1]) + } + // Initialize each loop + typ = itemListItem + space = len(item) + l.pos += Pos(space) + item = reList.marker.ReplaceAllString(item, "") + // Indented + if strings.Contains(item, "\n ") { + space -= len(item) + reSpace := reSpaceGen(space) + item = reSpace.ReplaceAllString(item, "") + } + // If current is loose + for _, l := range reList.loose.FindAllString(item, -1) { + if len(strings.TrimSpace(l)) > 0 || i != len(items)-1 { + typ = itemLooseItem + break + } + } + // or previous + if typ != itemLooseItem && i > 0 && strings.HasSuffix(items[i-1], "\n\n") { + typ = itemLooseItem + } + l.emit(typ, strings.TrimSpace(item)) + } + return lexAny +} + +func (l *lexer) matchList(input string) (bool, []string) { + var res []string + reItem := reList.item + if !reItem.MatchString(input) { + return false, res + } + // First item + m := reItem.FindStringSubmatch(input) + item, depth := m[0], len(m[1]) + input = input[len(item):] + // Loop over the input + for len(input) > 0 { + // Count new-lines('\n') + if m := reList.scanNewLine(input); m != "" { + item += m + input = input[len(m):] + if len(m) >= 2 || !reItem.MatchString(input) && !strings.HasPrefix(input, " ") { + break + } + } + // DefLink or hr + if reDefLink.MatchString(input) || reHr.MatchString(input) { + break + } + // It's list in the same depth + if m := reItem.FindStringSubmatch(input); len(m) > 0 && len(m[1]) == depth { + if item != "" { + res = append(res, item) + } + item = m[0] + input = input[len(item):] + } else { + m := reList.scanLine(input) + item += m + input = input[len(m):] + } + } + // Drain res + if item != "" { + res = append(res, item) + } + return true, res +} + +// Test if the given input match blockquote +func (l *lexer) matchBlockQuote(input string) (bool, string) { + match := reBlockQuote.FindString(input) + if match == "" { + return false, match + } + lines := strings.Split(match, "\n") + for i, line := range lines { + // if line is a link-definition or horizontal role, we cut the match until this point + if reDefLink.MatchString(line) || reHr.MatchString(line) { + match = strings.Join(lines[0:i], "\n") + break + } + } + return true, match +} + +// lexBlockQuote +func lexBlockQuote(l *lexer) stateFn { + if match, res := l.matchBlockQuote(l.input[l.pos:]); match { + l.pos += Pos(len(res)) + l.emit(itemBlockQuote) + return lexAny + } + return lexText +} + +// lexTable +func lexTable(l *lexer) stateFn { + re := reTable.item + if l.peek() == '|' { + re = reTable.itemLp + } + table := re.FindStringSubmatch(l.input[l.pos:]) + l.pos += Pos(len(table[0])) + l.start = l.pos + // Ignore the first match, and flat all rows(by splitting \n) + rows := append(table[1:3], strings.Split(table[3], "\n")...) + for _, row := range rows { + if row == "" { + continue + } + l.emit(itemTableRow) + rawCells := reTable.trim(row, "") + cells := reTable.split(rawCells, -1) + // Emit cells in the current row + for _, cell := range cells { + l.emit(itemTableCell, cell) + } + } + return lexAny +} diff --git a/vendor/github.com/a8m/mark/mark.go b/vendor/github.com/a8m/mark/mark.go new file mode 100644 index 000000000..f8a2cee8a --- /dev/null +++ b/vendor/github.com/a8m/mark/mark.go @@ -0,0 +1,60 @@ +package mark + +import "strings" + +// Mark +type Mark struct { + *parse + Input string +} + +// Mark options used to configure your Mark object +// set `Smartypants` and `Fractions` to true to enable +// smartypants and smartfractions rendering. +type Options struct { + Gfm bool + Tables bool + Smartypants bool + Fractions bool +} + +// DefaultOptions return an options struct with default configuration +// it's means that only Gfm, and Tables set to true. +func DefaultOptions() *Options { + return &Options{ + Gfm: true, + Tables: true, + } +} + +// New return a new Mark +func New(input string, opts *Options) *Mark { + // Preprocessing + input = strings.Replace(input, "\t", " ", -1) + if opts == nil { + opts = DefaultOptions() + } + return &Mark{ + Input: input, + parse: newParse(input, opts), + } +} + +// parse and render input +func (m *Mark) Render() string { + m.parse.parse() + m.render() + return m.output +} + +// AddRenderFn let you pass NodeType, and RenderFn function +// and override the default Node rendering +func (m *Mark) AddRenderFn(typ NodeType, fn RenderFn) { + m.renderFn[typ] = fn +} + +// Staic render function +func Render(input string) string { + m := New(input, nil) + return m.Render() +} diff --git a/vendor/github.com/a8m/mark/node.go b/vendor/github.com/a8m/mark/node.go new file mode 100644 index 000000000..9801af049 --- /dev/null +++ b/vendor/github.com/a8m/mark/node.go @@ -0,0 +1,614 @@ +package mark + +import ( + "fmt" + "regexp" + "strconv" + "strings" +) + +// A Node is an element in the parse tree. +type Node interface { + Type() NodeType + Render() string +} + +// NodeType identifies the type of a parse tree node. +type NodeType int + +// Type returns itself and provides an easy default implementation +// for embedding in a Node. Embedded in all non-trivial Nodes. +func (t NodeType) Type() NodeType { + return t +} + +// Render function, used for overriding default rendering. +type RenderFn func(Node) string + +const ( + NodeText NodeType = iota // A plain text + NodeParagraph // A Paragraph + NodeEmphasis // An emphasis(strong, em, ...) + NodeHeading // A heading (h1, h2, ...) + NodeBr // A link break + NodeHr // A horizontal rule + NodeImage // An image + NodeRefImage // A image reference + NodeList // A list of ListItems + NodeListItem // A list item node + NodeLink // A link(href) + NodeRefLink // A link reference + NodeDefLink // A link definition + NodeTable // A table of NodeRows + NodeRow // A row of NodeCells + NodeCell // A table-cell(td) + NodeCode // A code block(wrapped with pre) + NodeBlockQuote // A blockquote + NodeHTML // An inline HTML + NodeCheckbox // A checkbox +) + +// ParagraphNode hold simple paragraph node contains text +// that may be emphasis. +type ParagraphNode struct { + NodeType + Pos + Nodes []Node +} + +// Render returns the html representation of ParagraphNode +func (n *ParagraphNode) Render() (s string) { + for _, node := range n.Nodes { + s += node.Render() + } + return wrap("p", s) +} + +func (p *parse) newParagraph(pos Pos) *ParagraphNode { + return &ParagraphNode{NodeType: NodeParagraph, Pos: pos} +} + +// TextNode holds plain text. +type TextNode struct { + NodeType + Pos + Text string +} + +// Render returns the string representation of TexNode +func (n *TextNode) Render() string { + return n.Text +} + +func (p *parse) newText(pos Pos, text string) *TextNode { + return &TextNode{NodeType: NodeText, Pos: pos, Text: p.text(text)} +} + +// HTMLNode holds the raw html source. +type HTMLNode struct { + NodeType + Pos + Src string +} + +// Render returns the src of the HTMLNode +func (n *HTMLNode) Render() string { + return n.Src +} + +func (p *parse) newHTML(pos Pos, src string) *HTMLNode { + return &HTMLNode{NodeType: NodeHTML, Pos: pos, Src: src} +} + +// HrNode represents horizontal rule +type HrNode struct { + NodeType + Pos +} + +// Render returns the html representation of hr. +func (n *HrNode) Render() string { + return "
" +} + +func (p *parse) newHr(pos Pos) *HrNode { + return &HrNode{NodeType: NodeHr, Pos: pos} +} + +// BrNode represents a link-break element. +type BrNode struct { + NodeType + Pos +} + +// Render returns the html representation of line-break. +func (n *BrNode) Render() string { + return "
" +} + +func (p *parse) newBr(pos Pos) *BrNode { + return &BrNode{NodeType: NodeBr, Pos: pos} +} + +// EmphasisNode holds plain-text wrapped with style. +// (strong, em, del, code) +type EmphasisNode struct { + NodeType + Pos + Style itemType + Nodes []Node +} + +// Tag return the tagName based on the Style field. +func (n *EmphasisNode) Tag() (s string) { + switch n.Style { + case itemStrong: + s = "strong" + case itemItalic: + s = "em" + case itemStrike: + s = "del" + case itemCode: + s = "code" + } + return +} + +// Return the html representation of emphasis text. +func (n *EmphasisNode) Render() string { + var s string + for _, node := range n.Nodes { + s += node.Render() + } + return wrap(n.Tag(), s) +} + +func (p *parse) newEmphasis(pos Pos, style itemType) *EmphasisNode { + return &EmphasisNode{NodeType: NodeEmphasis, Pos: pos, Style: style} +} + +// HeadingNode holds heaing element with specific level(1-6). +type HeadingNode struct { + NodeType + Pos + Level int + Text string + Nodes []Node +} + +// Render returns the html representation based on heading level. +func (n *HeadingNode) Render() (s string) { + for _, node := range n.Nodes { + s += node.Render() + } + re := regexp.MustCompile(`[^\w]+`) + id := re.ReplaceAllString(n.Text, "-") + // ToLowerCase + id = strings.ToLower(id) + return fmt.Sprintf("<%[1]s id=\"%s\">%s", "h"+strconv.Itoa(n.Level), id, s) +} + +func (p *parse) newHeading(pos Pos, level int, text string) *HeadingNode { + return &HeadingNode{NodeType: NodeHeading, Pos: pos, Level: level, Text: p.text(text)} +} + +// Code holds CodeBlock node with specific lang field. +type CodeNode struct { + NodeType + Pos + Lang, Text string +} + +// Return the html representation of codeBlock +func (n *CodeNode) Render() string { + var attr string + if n.Lang != "" { + attr = fmt.Sprintf(" class=\"lang-%s\"", n.Lang) + } + code := fmt.Sprintf("<%[1]s%s>%s", "code", attr, n.Text) + return wrap("pre", code) +} + +func (p *parse) newCode(pos Pos, lang, text string) *CodeNode { + // DRY: see `escape()` below + text = strings.NewReplacer("<", "<", ">", ">", "\"", """, "&", "&").Replace(text) + return &CodeNode{NodeType: NodeCode, Pos: pos, Lang: lang, Text: text} +} + +// Link holds a tag with optional title +type LinkNode struct { + NodeType + Pos + Title, Href string + Nodes []Node +} + +// Return the html representation of link node +func (n *LinkNode) Render() (s string) { + for _, node := range n.Nodes { + s += node.Render() + } + attrs := fmt.Sprintf("href=\"%s\"", n.Href) + if n.Title != "" { + attrs += fmt.Sprintf(" title=\"%s\"", n.Title) + } + return fmt.Sprintf("%s", attrs, s) +} + +func (p *parse) newLink(pos Pos, title, href string, nodes ...Node) *LinkNode { + return &LinkNode{NodeType: NodeLink, Pos: pos, Title: p.text(title), Href: p.text(href), Nodes: nodes} +} + +// RefLink holds link with refrence to link definition +type RefNode struct { + NodeType + Pos + tr *parse + Text, Ref, Raw string + Nodes []Node +} + +// rendering based type +func (n *RefNode) Render() string { + var node Node + ref := strings.ToLower(n.Ref) + if l, ok := n.tr.links[ref]; ok { + if n.Type() == NodeRefLink { + node = n.tr.newLink(n.Pos, l.Title, l.Href, n.Nodes...) + } else { + node = n.tr.newImage(n.Pos, l.Title, l.Href, n.Text) + } + } else { + node = n.tr.newText(n.Pos, n.Raw) + } + return node.Render() +} + +// newRefLink create new RefLink that suitable for link +func (p *parse) newRefLink(typ itemType, pos Pos, raw, ref string, text []Node) *RefNode { + return &RefNode{NodeType: NodeRefLink, Pos: pos, tr: p.root(), Raw: raw, Ref: ref, Nodes: text} +} + +// newRefImage create new RefLink that suitable for image +func (p *parse) newRefImage(typ itemType, pos Pos, raw, ref, text string) *RefNode { + return &RefNode{NodeType: NodeRefImage, Pos: pos, tr: p.root(), Raw: raw, Ref: ref, Text: text} +} + +// DefLinkNode refresent single reference to link-definition +type DefLinkNode struct { + NodeType + Pos + Name, Href, Title string +} + +// Deflink have no representation(Transparent node) +func (n *DefLinkNode) Render() string { + return "" +} + +func (p *parse) newDefLink(pos Pos, name, href, title string) *DefLinkNode { + return &DefLinkNode{NodeType: NodeLink, Pos: pos, Name: name, Href: href, Title: title} +} + +// ImageNode represents an image element with optional alt and title attributes. +type ImageNode struct { + NodeType + Pos + Title, Src, Alt string +} + +// Render returns the html representation on image node +func (n *ImageNode) Render() string { + attrs := fmt.Sprintf("src=\"%s\" alt=\"%s\"", n.Src, n.Alt) + if n.Title != "" { + attrs += fmt.Sprintf(" title=\"%s\"", n.Title) + } + return fmt.Sprintf("", attrs) +} + +func (p *parse) newImage(pos Pos, title, src, alt string) *ImageNode { + return &ImageNode{NodeType: NodeImage, Pos: pos, Title: p.text(title), Src: p.text(src), Alt: p.text(alt)} +} + +// ListNode holds list items nodes in ordered or unordered states. +type ListNode struct { + NodeType + Pos + Ordered bool + Items []*ListItemNode +} + +func (n *ListNode) append(item *ListItemNode) { + n.Items = append(n.Items, item) +} + +// Render returns the html representation of orderd(ol) or unordered(ul) list. +func (n *ListNode) Render() (s string) { + tag := "ul" + if n.Ordered { + tag = "ol" + } + for _, item := range n.Items { + s += "\n" + item.Render() + } + s += "\n" + return wrap(tag, s) +} + +func (p *parse) newList(pos Pos, ordered bool) *ListNode { + return &ListNode{NodeType: NodeList, Pos: pos, Ordered: ordered} +} + +// ListItem represents single item in ListNode that may contains nested nodes. +type ListItemNode struct { + NodeType + Pos + Nodes []Node +} + +func (l *ListItemNode) append(n Node) { + l.Nodes = append(l.Nodes, n) +} + +// Render returns the html representation of list-item +func (l *ListItemNode) Render() (s string) { + for _, node := range l.Nodes { + s += node.Render() + } + return wrap("li", s) +} + +func (p *parse) newListItem(pos Pos) *ListItemNode { + return &ListItemNode{NodeType: NodeListItem, Pos: pos} +} + +// TableNode represents table element contains head and body +type TableNode struct { + NodeType + Pos + Rows []*RowNode +} + +func (n *TableNode) append(row *RowNode) { + n.Rows = append(n.Rows, row) +} + +// Render returns the html representation of a table +func (n *TableNode) Render() string { + var s string + for i, row := range n.Rows { + s += "\n" + switch i { + case 0: + s += wrap("thead", "\n"+row.Render()+"\n") + case 1: + s += "\n" + fallthrough + default: + s += row.Render() + } + } + s += "\n\n" + return wrap("table", s) +} + +func (p *parse) newTable(pos Pos) *TableNode { + return &TableNode{NodeType: NodeTable, Pos: pos} +} + +// RowNode represnt tr that holds list of cell-nodes +type RowNode struct { + NodeType + Pos + Cells []*CellNode +} + +func (r *RowNode) append(cell *CellNode) { + r.Cells = append(r.Cells, cell) +} + +// Render returns the html representation of table-row +func (r *RowNode) Render() string { + var s string + for _, cell := range r.Cells { + s += "\n" + cell.Render() + } + s += "\n" + return wrap("tr", s) +} + +func (p *parse) newRow(pos Pos) *RowNode { + return &RowNode{NodeType: NodeRow, Pos: pos} +} + +// AlignType identifies the aligment-type of specfic cell. +type AlignType int + +// Align returns itself and provides an easy default implementation +// for embedding in a Node. +func (t AlignType) Align() AlignType { + return t +} + +// Alignment +const ( + None AlignType = iota + Right + Left + Center +) + +// Cell types +const ( + Header = iota + Data +) + +// CellNode represents table-data/cell that holds simple text(may be emphasis) +// Note: the text in elements are bold and centered by default. +type CellNode struct { + NodeType + Pos + AlignType + Kind int + Nodes []Node +} + +// Render returns the html reprenestation of table-cell +func (c *CellNode) Render() string { + var s string + tag := "td" + if c.Kind == Header { + tag = "th" + } + for _, node := range c.Nodes { + s += node.Render() + } + return fmt.Sprintf("<%[1]s%s>%s", tag, c.Style(), s) +} + +// Style return the cell-style based on alignment field +func (c *CellNode) Style() string { + s := " style=\"text-align:" + switch c.Align() { + case Right: + s += "right\"" + case Left: + s += "left\"" + case Center: + s += "center\"" + default: + s = "" + } + return s +} + +func (p *parse) newCell(pos Pos, kind int, align AlignType) *CellNode { + return &CellNode{NodeType: NodeCell, Pos: pos, Kind: kind, AlignType: align} +} + +// BlockQuote represents block-quote tag. +type BlockQuoteNode struct { + NodeType + Pos + Nodes []Node +} + +// Render returns the html representation of BlockQuote +func (n *BlockQuoteNode) Render() string { + var s string + for _, node := range n.Nodes { + s += node.Render() + } + return wrap("blockquote", s) +} + +func (p *parse) newBlockQuote(pos Pos) *BlockQuoteNode { + return &BlockQuoteNode{NodeType: NodeBlockQuote, Pos: pos} +} + +// CheckboxNode represents checked and unchecked checkbox tag. +// Used in task lists. +type CheckboxNode struct { + NodeType + Pos + Checked bool +} + +// Render returns the html representation of checked and unchecked CheckBox. +func (n *CheckboxNode) Render() string { + s := "" +} + +func (p *parse) newCheckbox(pos Pos, checked bool) *CheckboxNode { + return &CheckboxNode{NodeType: NodeCheckbox, Pos: pos, Checked: checked} +} + +// Wrap text with specific tag. +func wrap(tag, body string) string { + return fmt.Sprintf("<%[1]s>%s", tag, body) +} + +// Group all text configuration in one place(escaping, smartypants, etc..) +func (p *parse) text(input string) string { + opts := p.root().options + if opts.Smartypants { + input = smartypants(input) + } + if opts.Fractions { + input = smartyfractions(input) + } + return escape(input) +} + +// Helper escaper +func escape(str string) (cpy string) { + emp := regexp.MustCompile(`&\w+;`) + for i := 0; i < len(str); i++ { + switch s := str[i]; s { + case '>': + cpy += ">" + case '"': + cpy += """ + case '\'': + cpy += "'" + case '<': + if res := reHTML.tag.FindString(str[i:]); res != "" { + cpy += res + i += len(res) - 1 + } else { + cpy += "<" + } + case '&': + if res := emp.FindString(str[i:]); res != "" { + cpy += res + i += len(res) - 1 + } else { + cpy += "&" + } + default: + cpy += str[i : i+1] + } + } + return +} + +// Smartypants transformation helper, translate from marked.js +func smartypants(text string) string { + // em-dashes, en-dashes, ellipses + re := strings.NewReplacer("---", "\u2014", "--", "\u2013", "...", "\u2026") + text = re.Replace(text) + // opening singles + text = regexp.MustCompile("(^|[-\u2014/(\\[{\"\\s])'").ReplaceAllString(text, "$1\u2018") + // closing singles & apostrophes + text = strings.Replace(text, "'", "\u2019", -1) + // opening doubles + text = regexp.MustCompile("(^|[-\u2014/(\\[{\u2018\\s])\"").ReplaceAllString(text, "$1\u201c") + // closing doubles + text = strings.Replace(text, "\"", "\u201d", -1) + return text +} + +// Smartyfractions transformation helper. +func smartyfractions(text string) string { + re := regexp.MustCompile(`(\d+)(/\d+)(/\d+|)`) + return re.ReplaceAllStringFunc(text, func(str string) string { + var match []string + // If it's date like + if match = re.FindStringSubmatch(str); match[3] != "" { + return str + } + switch n := match[1] + match[2]; n { + case "1/2", "1/3", "2/3", "1/4", "3/4", "1/5", "2/5", "3/5", "4/5", + "1/6", "5/6", "1/7", "1/8", "3/8", "5/8", "7/8": + return fmt.Sprintf("&frac%s;", strings.Replace(n, "/", "", 1)) + default: + return fmt.Sprintf("%s%s", + match[1], strings.Replace(match[2], "/", "", 1)) + } + }) +} diff --git a/vendor/github.com/a8m/mark/parser.go b/vendor/github.com/a8m/mark/parser.go new file mode 100644 index 000000000..3dbe73246 --- /dev/null +++ b/vendor/github.com/a8m/mark/parser.go @@ -0,0 +1,436 @@ +package mark + +import ( + "regexp" + "strings" + "unicode" + "unicode/utf8" +) + +// parse holds the state of the parser. +type parse struct { + Nodes []Node + lex Lexer + options *Options + tr *parse + output string + peekCount int + token [3]item // three-token lookahead for parser + links map[string]*DefLinkNode // Deflink parsing, used RefLinks + renderFn map[NodeType]RenderFn // Custom overridden fns +} + +// Return new parser +func newParse(input string, opts *Options) *parse { + return &parse{ + lex: lex(input), + options: opts, + links: make(map[string]*DefLinkNode), + renderFn: make(map[NodeType]RenderFn), + } +} + +// parse convert the raw text to Nodeparse. +func (p *parse) parse() { +Loop: + for { + var n Node + switch t := p.peek(); t.typ { + case itemEOF, itemError: + break Loop + case itemNewLine: + p.next() + case itemHr: + n = p.newHr(p.next().pos) + case itemHTML: + t = p.next() + n = p.newHTML(t.pos, t.val) + case itemDefLink: + n = p.parseDefLink() + case itemHeading, itemLHeading: + n = p.parseHeading() + case itemCodeBlock, itemGfmCodeBlock: + n = p.parseCodeBlock() + case itemList: + n = p.parseList() + case itemTable, itemLpTable: + n = p.parseTable() + case itemBlockQuote: + n = p.parseBlockQuote() + case itemIndent: + space := p.next() + // If it isn't followed by itemText + if p.peek().typ != itemText { + continue + } + p.backup2(space) + fallthrough + // itemText + default: + tmp := p.newParagraph(t.pos) + tmp.Nodes = p.parseText(p.next().val + p.scanLines()) + n = tmp + } + if n != nil { + p.append(n) + } + } +} + +// Root getter +func (p *parse) root() *parse { + if p.tr == nil { + return p + } + return p.tr.root() +} + +// Render parse nodes to the wanted output +func (p *parse) render() { + var output string + for i, node := range p.Nodes { + // If there's a custom render function, use it instead. + if fn, ok := p.renderFn[node.Type()]; ok { + output = fn(node) + } else { + output = node.Render() + } + p.output += output + if output != "" && i != len(p.Nodes)-1 { + p.output += "\n" + } + } +} + +// append new node to nodes-list +func (p *parse) append(n Node) { + p.Nodes = append(p.Nodes, n) +} + +// next returns the next token +func (p *parse) next() item { + if p.peekCount > 0 { + p.peekCount-- + } else { + p.token[0] = p.lex.nextItem() + } + return p.token[p.peekCount] +} + +// peek returns but does not consume the next token. +func (p *parse) peek() item { + if p.peekCount > 0 { + return p.token[p.peekCount-1] + } + p.peekCount = 1 + p.token[0] = p.lex.nextItem() + return p.token[0] +} + +// backup backs the input stream tp one token +func (p *parse) backup() { + p.peekCount++ +} + +// backup2 backs the input stream up two tokens. +// The zeroth token is already there. +func (p *parse) backup2(t1 item) { + p.token[1] = t1 + p.peekCount = 2 +} + +// parseText +func (p *parse) parseText(input string) (nodes []Node) { + // Trim whitespaces that not a line-break + input = regexp.MustCompile(`(?m)^ +| +(\n|$)`).ReplaceAllStringFunc(input, func(s string) string { + if reBr.MatchString(s) { + return s + } + return strings.Replace(s, " ", "", -1) + }) + l := lexInline(input) + for token := range l.items { + var node Node + switch token.typ { + case itemBr: + node = p.newBr(token.pos) + case itemStrong, itemItalic, itemStrike, itemCode: + node = p.parseEmphasis(token.typ, token.pos, token.val) + case itemLink, itemAutoLink, itemGfmLink: + var title, href string + var text []Node + if token.typ == itemLink { + match := reLink.FindStringSubmatch(token.val) + text = p.parseText(match[1]) + href, title = match[2], match[3] + } else { + var match []string + if token.typ == itemGfmLink { + match = reGfmLink.FindStringSubmatch(token.val) + } else { + match = reAutoLink.FindStringSubmatch(token.val) + } + href = match[1] + text = append(text, p.newText(token.pos, match[1])) + } + node = p.newLink(token.pos, title, href, text...) + case itemImage: + match := reImage.FindStringSubmatch(token.val) + node = p.newImage(token.pos, match[3], match[2], match[1]) + case itemRefLink, itemRefImage: + match := reRefLink.FindStringSubmatch(token.val) + text, ref := match[1], match[2] + if ref == "" { + ref = text + } + if token.typ == itemRefLink { + node = p.newRefLink(token.typ, token.pos, token.val, ref, p.parseText(text)) + } else { + node = p.newRefImage(token.typ, token.pos, token.val, ref, text) + } + case itemHTML: + node = p.newHTML(token.pos, token.val) + default: + node = p.newText(token.pos, token.val) + } + nodes = append(nodes, node) + } + return nodes +} + +// parse inline emphasis +func (p *parse) parseEmphasis(typ itemType, pos Pos, val string) *EmphasisNode { + var re *regexp.Regexp + switch typ { + case itemStrike: + re = reStrike + case itemStrong: + re = reStrong + case itemCode: + re = reCode + case itemItalic: + re = reItalic + } + node := p.newEmphasis(pos, typ) + match := re.FindStringSubmatch(val) + text := match[len(match)-1] + if text == "" { + text = match[1] + } + node.Nodes = p.parseText(text) + return node +} + +// parse heading block +func (p *parse) parseHeading() (node *HeadingNode) { + token := p.next() + level := 1 + var text string + if token.typ == itemHeading { + match := reHeading.FindStringSubmatch(token.val) + level, text = len(match[1]), match[2] + } else { + match := reLHeading.FindStringSubmatch(token.val) + // using equal signs for first-level, and dashes for second-level. + text = match[1] + if match[2] == "-" { + level = 2 + } + } + node = p.newHeading(token.pos, level, text) + node.Nodes = p.parseText(text) + return +} + +func (p *parse) parseDefLink() *DefLinkNode { + token := p.next() + match := reDefLink.FindStringSubmatch(token.val) + name := strings.ToLower(match[1]) + // name(lowercase), href, title + n := p.newDefLink(token.pos, name, match[2], match[3]) + // store in links + links := p.root().links + if _, ok := links[name]; !ok { + links[name] = n + } + return n +} + +// parse codeBlock +func (p *parse) parseCodeBlock() *CodeNode { + var lang, text string + token := p.next() + if token.typ == itemGfmCodeBlock { + codeStart := reGfmCode.FindStringSubmatch(token.val) + lang = codeStart[3] + text = token.val[len(codeStart[0]):] + } else { + text = reCodeBlock.trim(token.val, "") + } + return p.newCode(token.pos, lang, text) +} + +func (p *parse) parseBlockQuote() (n *BlockQuoteNode) { + token := p.next() + // replacer + re := regexp.MustCompile(`(?m)^ *> ?`) + raw := re.ReplaceAllString(token.val, "") + // TODO(a8m): doesn't work right now with defLink(inside the blockQuote) + tr := &parse{lex: lex(raw), tr: p} + tr.parse() + n = p.newBlockQuote(token.pos) + n.Nodes = tr.Nodes + return +} + +// parse list +func (p *parse) parseList() *ListNode { + token := p.next() + list := p.newList(token.pos, isDigit(token.val)) +Loop: + for { + switch token = p.peek(); token.typ { + case itemLooseItem, itemListItem: + list.append(p.parseListItem()) + default: + break Loop + } + } + return list +} + +// parse listItem +func (p *parse) parseListItem() *ListItemNode { + token := p.next() + item := p.newListItem(token.pos) + token.val = strings.TrimSpace(token.val) + if p.isTaskItem(token.val) { + item.Nodes = p.parseTaskItem(token) + return item + } + tr := &parse{lex: lex(token.val), tr: p} + tr.parse() + for _, node := range tr.Nodes { + // wrap with paragraph only when it's a loose item + if n, ok := node.(*ParagraphNode); ok && token.typ == itemListItem { + item.Nodes = append(item.Nodes, n.Nodes...) + } else { + item.append(node) + } + } + return item +} + +// parseTaskItem parses list item as a task item. +func (p *parse) parseTaskItem(token item) []Node { + checkbox := p.newCheckbox(token.pos, token.val[1] == 'x') + token.val = strings.TrimSpace(token.val[3:]) + return append([]Node{checkbox}, p.parseText(token.val)...) +} + +// isTaskItem tests if the given string is list task item. +func (p *parse) isTaskItem(s string) bool { + if len(s) < 5 || s[0] != '[' || (s[1] != 'x' && s[1] != ' ') || s[2] != ']' { + return false + } + return "" != strings.TrimSpace(s[3:]) +} + +// parse table +func (p *parse) parseTable() *TableNode { + table := p.newTable(p.next().pos) + // Align [ None, Left, Right, ... ] + // Header [ Cells: [ ... ] ] + // Data: [ Rows: [ Cells: [ ... ] ] ] + rows := struct { + Align []AlignType + Header []item + Cells [][]item + }{} +Loop: + for i := 0; ; { + switch token := p.next(); token.typ { + case itemTableRow: + i++ + if i > 2 { + rows.Cells = append(rows.Cells, []item{}) + } + case itemTableCell: + // Header + if i == 1 { + rows.Header = append(rows.Header, token) + // Alignment + } else if i == 2 { + rows.Align = append(rows.Align, parseAlign(token.val)) + // Data + } else { + pos := i - 3 + rows.Cells[pos] = append(rows.Cells[pos], token) + } + default: + p.backup() + break Loop + } + } + // Tranform to nodes + table.append(p.parseCells(Header, rows.Header, rows.Align)) + // Table body + for _, row := range rows.Cells { + table.append(p.parseCells(Data, row, rows.Align)) + } + return table +} + +// parse cells and return new row +func (p *parse) parseCells(kind int, items []item, align []AlignType) *RowNode { + var row *RowNode + for i, item := range items { + if i == 0 { + row = p.newRow(item.pos) + } + cell := p.newCell(item.pos, kind, align[i]) + cell.Nodes = p.parseText(item.val) + row.append(cell) + } + return row +} + +// Used to consume lines(itemText) for a continues paragraphs +func (p *parse) scanLines() (s string) { + for { + tkn := p.next() + if tkn.typ == itemText || tkn.typ == itemIndent { + s += tkn.val + } else if tkn.typ == itemNewLine { + if t := p.peek().typ; t != itemText && t != itemIndent { + p.backup2(tkn) + break + } + s += tkn.val + } else { + p.backup() + break + } + } + return +} + +// get align-string and return the align type of it +func parseAlign(s string) (typ AlignType) { + sfx, pfx := strings.HasSuffix(s, ":"), strings.HasPrefix(s, ":") + switch { + case sfx && pfx: + typ = Center + case sfx: + typ = Right + case pfx: + typ = Left + } + return +} + +// test if given string is digit +func isDigit(s string) bool { + r, _ := utf8.DecodeRuneInString(s) + return unicode.IsDigit(r) +} diff --git a/vendor/github.com/beorn7/perks/quantile/LICENSE b/vendor/github.com/beorn7/perks/quantile/LICENSE new file mode 100644 index 000000000..339177be6 --- /dev/null +++ b/vendor/github.com/beorn7/perks/quantile/LICENSE @@ -0,0 +1,20 @@ +Copyright (C) 2013 Blake Mizerany + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/beorn7/perks/quantile/stream.go b/vendor/github.com/beorn7/perks/quantile/stream.go new file mode 100644 index 000000000..f4cabd669 --- /dev/null +++ b/vendor/github.com/beorn7/perks/quantile/stream.go @@ -0,0 +1,292 @@ +// Package quantile computes approximate quantiles over an unbounded data +// stream within low memory and CPU bounds. +// +// A small amount of accuracy is traded to achieve the above properties. +// +// Multiple streams can be merged before calling Query to generate a single set +// of results. This is meaningful when the streams represent the same type of +// data. See Merge and Samples. +// +// For more detailed information about the algorithm used, see: +// +// Effective Computation of Biased Quantiles over Data Streams +// +// http://www.cs.rutgers.edu/~muthu/bquant.pdf +package quantile + +import ( + "math" + "sort" +) + +// Sample holds an observed value and meta information for compression. JSON +// tags have been added for convenience. +type Sample struct { + Value float64 `json:",string"` + Width float64 `json:",string"` + Delta float64 `json:",string"` +} + +// Samples represents a slice of samples. It implements sort.Interface. +type Samples []Sample + +func (a Samples) Len() int { return len(a) } +func (a Samples) Less(i, j int) bool { return a[i].Value < a[j].Value } +func (a Samples) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + +type invariant func(s *stream, r float64) float64 + +// NewLowBiased returns an initialized Stream for low-biased quantiles +// (e.g. 0.01, 0.1, 0.5) where the needed quantiles are not known a priori, but +// error guarantees can still be given even for the lower ranks of the data +// distribution. +// +// The provided epsilon is a relative error, i.e. the true quantile of a value +// returned by a query is guaranteed to be within (1±Epsilon)*Quantile. +// +// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error +// properties. +func NewLowBiased(epsilon float64) *Stream { + ƒ := func(s *stream, r float64) float64 { + return 2 * epsilon * r + } + return newStream(ƒ) +} + +// NewHighBiased returns an initialized Stream for high-biased quantiles +// (e.g. 0.01, 0.1, 0.5) where the needed quantiles are not known a priori, but +// error guarantees can still be given even for the higher ranks of the data +// distribution. +// +// The provided epsilon is a relative error, i.e. the true quantile of a value +// returned by a query is guaranteed to be within 1-(1±Epsilon)*(1-Quantile). +// +// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error +// properties. +func NewHighBiased(epsilon float64) *Stream { + ƒ := func(s *stream, r float64) float64 { + return 2 * epsilon * (s.n - r) + } + return newStream(ƒ) +} + +// NewTargeted returns an initialized Stream concerned with a particular set of +// quantile values that are supplied a priori. Knowing these a priori reduces +// space and computation time. The targets map maps the desired quantiles to +// their absolute errors, i.e. the true quantile of a value returned by a query +// is guaranteed to be within (Quantile±Epsilon). +// +// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties. +func NewTargeted(targets map[float64]float64) *Stream { + ƒ := func(s *stream, r float64) float64 { + var m = math.MaxFloat64 + var f float64 + for quantile, epsilon := range targets { + if quantile*s.n <= r { + f = (2 * epsilon * r) / quantile + } else { + f = (2 * epsilon * (s.n - r)) / (1 - quantile) + } + if f < m { + m = f + } + } + return m + } + return newStream(ƒ) +} + +// Stream computes quantiles for a stream of float64s. It is not thread-safe by +// design. Take care when using across multiple goroutines. +type Stream struct { + *stream + b Samples + sorted bool +} + +func newStream(ƒ invariant) *Stream { + x := &stream{ƒ: ƒ} + return &Stream{x, make(Samples, 0, 500), true} +} + +// Insert inserts v into the stream. +func (s *Stream) Insert(v float64) { + s.insert(Sample{Value: v, Width: 1}) +} + +func (s *Stream) insert(sample Sample) { + s.b = append(s.b, sample) + s.sorted = false + if len(s.b) == cap(s.b) { + s.flush() + } +} + +// Query returns the computed qth percentiles value. If s was created with +// NewTargeted, and q is not in the set of quantiles provided a priori, Query +// will return an unspecified result. +func (s *Stream) Query(q float64) float64 { + if !s.flushed() { + // Fast path when there hasn't been enough data for a flush; + // this also yields better accuracy for small sets of data. + l := len(s.b) + if l == 0 { + return 0 + } + i := int(math.Ceil(float64(l) * q)) + if i > 0 { + i -= 1 + } + s.maybeSort() + return s.b[i].Value + } + s.flush() + return s.stream.query(q) +} + +// Merge merges samples into the underlying streams samples. This is handy when +// merging multiple streams from separate threads, database shards, etc. +// +// ATTENTION: This method is broken and does not yield correct results. The +// underlying algorithm is not capable of merging streams correctly. +func (s *Stream) Merge(samples Samples) { + sort.Sort(samples) + s.stream.merge(samples) +} + +// Reset reinitializes and clears the list reusing the samples buffer memory. +func (s *Stream) Reset() { + s.stream.reset() + s.b = s.b[:0] +} + +// Samples returns stream samples held by s. +func (s *Stream) Samples() Samples { + if !s.flushed() { + return s.b + } + s.flush() + return s.stream.samples() +} + +// Count returns the total number of samples observed in the stream +// since initialization. +func (s *Stream) Count() int { + return len(s.b) + s.stream.count() +} + +func (s *Stream) flush() { + s.maybeSort() + s.stream.merge(s.b) + s.b = s.b[:0] +} + +func (s *Stream) maybeSort() { + if !s.sorted { + s.sorted = true + sort.Sort(s.b) + } +} + +func (s *Stream) flushed() bool { + return len(s.stream.l) > 0 +} + +type stream struct { + n float64 + l []Sample + ƒ invariant +} + +func (s *stream) reset() { + s.l = s.l[:0] + s.n = 0 +} + +func (s *stream) insert(v float64) { + s.merge(Samples{{v, 1, 0}}) +} + +func (s *stream) merge(samples Samples) { + // TODO(beorn7): This tries to merge not only individual samples, but + // whole summaries. The paper doesn't mention merging summaries at + // all. Unittests show that the merging is inaccurate. Find out how to + // do merges properly. + var r float64 + i := 0 + for _, sample := range samples { + for ; i < len(s.l); i++ { + c := s.l[i] + if c.Value > sample.Value { + // Insert at position i. + s.l = append(s.l, Sample{}) + copy(s.l[i+1:], s.l[i:]) + s.l[i] = Sample{ + sample.Value, + sample.Width, + math.Max(sample.Delta, math.Floor(s.ƒ(s, r))-1), + // TODO(beorn7): How to calculate delta correctly? + } + i++ + goto inserted + } + r += c.Width + } + s.l = append(s.l, Sample{sample.Value, sample.Width, 0}) + i++ + inserted: + s.n += sample.Width + r += sample.Width + } + s.compress() +} + +func (s *stream) count() int { + return int(s.n) +} + +func (s *stream) query(q float64) float64 { + t := math.Ceil(q * s.n) + t += math.Ceil(s.ƒ(s, t) / 2) + p := s.l[0] + var r float64 + for _, c := range s.l[1:] { + r += p.Width + if r+c.Width+c.Delta > t { + return p.Value + } + p = c + } + return p.Value +} + +func (s *stream) compress() { + if len(s.l) < 2 { + return + } + x := s.l[len(s.l)-1] + xi := len(s.l) - 1 + r := s.n - 1 - x.Width + + for i := len(s.l) - 2; i >= 0; i-- { + c := s.l[i] + if c.Width+x.Width+x.Delta <= s.ƒ(s, r) { + x.Width += c.Width + s.l[xi] = x + // Remove element at i. + copy(s.l[i:], s.l[i+1:]) + s.l = s.l[:len(s.l)-1] + xi -= 1 + } else { + x = c + xi = i + } + r -= c.Width + } +} + +func (s *stream) samples() Samples { + samples := make(Samples, len(s.l)) + copy(samples, s.l) + return samples +} diff --git a/vendor/github.com/cheggaaa/pb/LICENSE b/vendor/github.com/cheggaaa/pb/LICENSE new file mode 100644 index 000000000..511970333 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/LICENSE @@ -0,0 +1,12 @@ +Copyright (c) 2012-2015, Sergey Cherepanov +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/vendor/github.com/cheggaaa/pb/format.go b/vendor/github.com/cheggaaa/pb/format.go new file mode 100644 index 000000000..0723561c2 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/format.go @@ -0,0 +1,118 @@ +package pb + +import ( + "fmt" + "time" +) + +type Units int + +const ( + // U_NO are default units, they represent a simple value and are not formatted at all. + U_NO Units = iota + // U_BYTES units are formatted in a human readable way (B, KiB, MiB, ...) + U_BYTES + // U_BYTES_DEC units are like U_BYTES, but base 10 (B, KB, MB, ...) + U_BYTES_DEC + // U_DURATION units are formatted in a human readable way (3h14m15s) + U_DURATION +) + +const ( + KiB = 1024 + MiB = 1048576 + GiB = 1073741824 + TiB = 1099511627776 + + KB = 1e3 + MB = 1e6 + GB = 1e9 + TB = 1e12 +) + +func Format(i int64) *formatter { + return &formatter{n: i} +} + +type formatter struct { + n int64 + unit Units + width int + perSec bool +} + +func (f *formatter) To(unit Units) *formatter { + f.unit = unit + return f +} + +func (f *formatter) Width(width int) *formatter { + f.width = width + return f +} + +func (f *formatter) PerSec() *formatter { + f.perSec = true + return f +} + +func (f *formatter) String() (out string) { + switch f.unit { + case U_BYTES: + out = formatBytes(f.n) + case U_BYTES_DEC: + out = formatBytesDec(f.n) + case U_DURATION: + out = formatDuration(f.n) + default: + out = fmt.Sprintf(fmt.Sprintf("%%%dd", f.width), f.n) + } + if f.perSec { + out += "/s" + } + return +} + +// Convert bytes to human readable string. Like 2 MiB, 64.2 KiB, 52 B +func formatBytes(i int64) (result string) { + switch { + case i >= TiB: + result = fmt.Sprintf("%.02f TiB", float64(i)/TiB) + case i >= GiB: + result = fmt.Sprintf("%.02f GiB", float64(i)/GiB) + case i >= MiB: + result = fmt.Sprintf("%.02f MiB", float64(i)/MiB) + case i >= KiB: + result = fmt.Sprintf("%.02f KiB", float64(i)/KiB) + default: + result = fmt.Sprintf("%d B", i) + } + return +} + +// Convert bytes to base-10 human readable string. Like 2 MB, 64.2 KB, 52 B +func formatBytesDec(i int64) (result string) { + switch { + case i >= TB: + result = fmt.Sprintf("%.02f TB", float64(i)/TB) + case i >= GB: + result = fmt.Sprintf("%.02f GB", float64(i)/GB) + case i >= MB: + result = fmt.Sprintf("%.02f MB", float64(i)/MB) + case i >= KB: + result = fmt.Sprintf("%.02f KB", float64(i)/KB) + default: + result = fmt.Sprintf("%d B", i) + } + return +} + +func formatDuration(n int64) (result string) { + d := time.Duration(n) + if d > time.Hour*24 { + result = fmt.Sprintf("%dd", d/24/time.Hour) + d -= (d / time.Hour / 24) * (time.Hour * 24) + } + result = fmt.Sprintf("%s%v", result, d) + return +} diff --git a/vendor/github.com/cheggaaa/pb/pb.go b/vendor/github.com/cheggaaa/pb/pb.go new file mode 100644 index 000000000..19eb4d1a9 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/pb.go @@ -0,0 +1,469 @@ +// Simple console progress bars +package pb + +import ( + "fmt" + "io" + "math" + "strings" + "sync" + "sync/atomic" + "time" + "unicode/utf8" +) + +// Current version +const Version = "1.0.19" + +const ( + // Default refresh rate - 200ms + DEFAULT_REFRESH_RATE = time.Millisecond * 200 + FORMAT = "[=>-]" +) + +// DEPRECATED +// variables for backward compatibility, from now do not work +// use pb.Format and pb.SetRefreshRate +var ( + DefaultRefreshRate = DEFAULT_REFRESH_RATE + BarStart, BarEnd, Empty, Current, CurrentN string +) + +// Create new progress bar object +func New(total int) *ProgressBar { + return New64(int64(total)) +} + +// Create new progress bar object using int64 as total +func New64(total int64) *ProgressBar { + pb := &ProgressBar{ + Total: total, + RefreshRate: DEFAULT_REFRESH_RATE, + ShowPercent: true, + ShowCounters: true, + ShowBar: true, + ShowTimeLeft: true, + ShowFinalTime: true, + Units: U_NO, + ManualUpdate: false, + finish: make(chan struct{}), + } + return pb.Format(FORMAT) +} + +// Create new object and start +func StartNew(total int) *ProgressBar { + return New(total).Start() +} + +// Callback for custom output +// For example: +// bar.Callback = func(s string) { +// mySuperPrint(s) +// } +// +type Callback func(out string) + +type ProgressBar struct { + current int64 // current must be first member of struct (https://code.google.com/p/go/issues/detail?id=5278) + previous int64 + + Total int64 + RefreshRate time.Duration + ShowPercent, ShowCounters bool + ShowSpeed, ShowTimeLeft, ShowBar bool + ShowFinalTime bool + Output io.Writer + Callback Callback + NotPrint bool + Units Units + Width int + ForceWidth bool + ManualUpdate bool + AutoStat bool + + // Default width for the time box. + UnitsWidth int + TimeBoxWidth int + + finishOnce sync.Once //Guards isFinish + finish chan struct{} + isFinish bool + + startTime time.Time + startValue int64 + + changeTime time.Time + + prefix, postfix string + + mu sync.Mutex + lastPrint string + + BarStart string + BarEnd string + Empty string + Current string + CurrentN string + + AlwaysUpdate bool +} + +// Start print +func (pb *ProgressBar) Start() *ProgressBar { + pb.startTime = time.Now() + pb.startValue = atomic.LoadInt64(&pb.current) + if pb.Total == 0 { + pb.ShowTimeLeft = false + pb.ShowPercent = false + pb.AutoStat = false + } + if !pb.ManualUpdate { + pb.Update() // Initial printing of the bar before running the bar refresher. + go pb.refresher() + } + return pb +} + +// Increment current value +func (pb *ProgressBar) Increment() int { + return pb.Add(1) +} + +// Get current value +func (pb *ProgressBar) Get() int64 { + c := atomic.LoadInt64(&pb.current) + return c +} + +// Set current value +func (pb *ProgressBar) Set(current int) *ProgressBar { + return pb.Set64(int64(current)) +} + +// Set64 sets the current value as int64 +func (pb *ProgressBar) Set64(current int64) *ProgressBar { + atomic.StoreInt64(&pb.current, current) + return pb +} + +// Add to current value +func (pb *ProgressBar) Add(add int) int { + return int(pb.Add64(int64(add))) +} + +func (pb *ProgressBar) Add64(add int64) int64 { + return atomic.AddInt64(&pb.current, add) +} + +// Set prefix string +func (pb *ProgressBar) Prefix(prefix string) *ProgressBar { + pb.prefix = prefix + return pb +} + +// Set postfix string +func (pb *ProgressBar) Postfix(postfix string) *ProgressBar { + pb.postfix = postfix + return pb +} + +// Set custom format for bar +// Example: bar.Format("[=>_]") +// Example: bar.Format("[\x00=\x00>\x00-\x00]") // \x00 is the delimiter +func (pb *ProgressBar) Format(format string) *ProgressBar { + var formatEntries []string + if utf8.RuneCountInString(format) == 5 { + formatEntries = strings.Split(format, "") + } else { + formatEntries = strings.Split(format, "\x00") + } + if len(formatEntries) == 5 { + pb.BarStart = formatEntries[0] + pb.BarEnd = formatEntries[4] + pb.Empty = formatEntries[3] + pb.Current = formatEntries[1] + pb.CurrentN = formatEntries[2] + } + return pb +} + +// Set bar refresh rate +func (pb *ProgressBar) SetRefreshRate(rate time.Duration) *ProgressBar { + pb.RefreshRate = rate + return pb +} + +// Set units +// bar.SetUnits(U_NO) - by default +// bar.SetUnits(U_BYTES) - for Mb, Kb, etc +func (pb *ProgressBar) SetUnits(units Units) *ProgressBar { + pb.Units = units + return pb +} + +// Set max width, if width is bigger than terminal width, will be ignored +func (pb *ProgressBar) SetMaxWidth(width int) *ProgressBar { + pb.Width = width + pb.ForceWidth = false + return pb +} + +// Set bar width +func (pb *ProgressBar) SetWidth(width int) *ProgressBar { + pb.Width = width + pb.ForceWidth = true + return pb +} + +// End print +func (pb *ProgressBar) Finish() { + //Protect multiple calls + pb.finishOnce.Do(func() { + close(pb.finish) + pb.write(atomic.LoadInt64(&pb.current)) + pb.mu.Lock() + defer pb.mu.Unlock() + switch { + case pb.Output != nil: + fmt.Fprintln(pb.Output) + case !pb.NotPrint: + fmt.Println() + } + pb.isFinish = true + }) +} + +// IsFinished return boolean +func (pb *ProgressBar) IsFinished() bool { + pb.mu.Lock() + defer pb.mu.Unlock() + return pb.isFinish +} + +// End print and write string 'str' +func (pb *ProgressBar) FinishPrint(str string) { + pb.Finish() + if pb.Output != nil { + fmt.Fprintln(pb.Output, str) + } else { + fmt.Println(str) + } +} + +// implement io.Writer +func (pb *ProgressBar) Write(p []byte) (n int, err error) { + n = len(p) + pb.Add(n) + return +} + +// implement io.Reader +func (pb *ProgressBar) Read(p []byte) (n int, err error) { + n = len(p) + pb.Add(n) + return +} + +// Create new proxy reader over bar +// Takes io.Reader or io.ReadCloser +func (pb *ProgressBar) NewProxyReader(r io.Reader) *Reader { + return &Reader{r, pb} +} + +func (pb *ProgressBar) write(current int64) { + width := pb.GetWidth() + + var percentBox, countersBox, timeLeftBox, speedBox, barBox, end, out string + + // percents + if pb.ShowPercent { + var percent float64 + if pb.Total > 0 { + percent = float64(current) / (float64(pb.Total) / float64(100)) + } else { + percent = float64(current) / float64(100) + } + percentBox = fmt.Sprintf(" %6.02f%%", percent) + } + + // counters + if pb.ShowCounters { + current := Format(current).To(pb.Units).Width(pb.UnitsWidth) + if pb.Total > 0 { + total := Format(pb.Total).To(pb.Units).Width(pb.UnitsWidth) + countersBox = fmt.Sprintf(" %s / %s ", current, total) + } else { + countersBox = fmt.Sprintf(" %s / ? ", current) + } + } + + // time left + pb.mu.Lock() + currentFromStart := current - pb.startValue + fromStart := time.Now().Sub(pb.startTime) + lastChangeTime := pb.changeTime + fromChange := lastChangeTime.Sub(pb.startTime) + pb.mu.Unlock() + select { + case <-pb.finish: + if pb.ShowFinalTime { + var left time.Duration + left = (fromStart / time.Second) * time.Second + timeLeftBox = fmt.Sprintf(" %s", left.String()) + } + default: + if pb.ShowTimeLeft && currentFromStart > 0 { + perEntry := fromChange / time.Duration(currentFromStart) + var left time.Duration + if pb.Total > 0 { + left = time.Duration(pb.Total-currentFromStart) * perEntry + left -= time.Since(lastChangeTime) + left = (left / time.Second) * time.Second + } else { + left = time.Duration(currentFromStart) * perEntry + left = (left / time.Second) * time.Second + } + if left > 0 { + timeLeft := Format(int64(left)).To(U_DURATION).String() + timeLeftBox = fmt.Sprintf(" %s", timeLeft) + } + } + } + + if len(timeLeftBox) < pb.TimeBoxWidth { + timeLeftBox = fmt.Sprintf("%s%s", strings.Repeat(" ", pb.TimeBoxWidth-len(timeLeftBox)), timeLeftBox) + } + + // speed + if pb.ShowSpeed && currentFromStart > 0 { + fromStart := time.Now().Sub(pb.startTime) + speed := float64(currentFromStart) / (float64(fromStart) / float64(time.Second)) + speedBox = " " + Format(int64(speed)).To(pb.Units).Width(pb.UnitsWidth).PerSec().String() + } + + barWidth := escapeAwareRuneCountInString(countersBox + pb.BarStart + pb.BarEnd + percentBox + timeLeftBox + speedBox + pb.prefix + pb.postfix) + // bar + if pb.ShowBar { + size := width - barWidth + if size > 0 { + if pb.Total > 0 { + curSize := int(math.Ceil((float64(current) / float64(pb.Total)) * float64(size))) + emptySize := size - curSize + barBox = pb.BarStart + if emptySize < 0 { + emptySize = 0 + } + if curSize > size { + curSize = size + } + + cursorLen := escapeAwareRuneCountInString(pb.Current) + if emptySize <= 0 { + barBox += strings.Repeat(pb.Current, curSize/cursorLen) + } else if curSize > 0 { + cursorEndLen := escapeAwareRuneCountInString(pb.CurrentN) + cursorRepetitions := (curSize - cursorEndLen) / cursorLen + barBox += strings.Repeat(pb.Current, cursorRepetitions) + barBox += pb.CurrentN + } + + emptyLen := escapeAwareRuneCountInString(pb.Empty) + barBox += strings.Repeat(pb.Empty, emptySize/emptyLen) + barBox += pb.BarEnd + } else { + pos := size - int(current)%int(size) + barBox = pb.BarStart + if pos-1 > 0 { + barBox += strings.Repeat(pb.Empty, pos-1) + } + barBox += pb.Current + if size-pos-1 > 0 { + barBox += strings.Repeat(pb.Empty, size-pos-1) + } + barBox += pb.BarEnd + } + } + } + + // check len + out = pb.prefix + countersBox + barBox + percentBox + speedBox + timeLeftBox + pb.postfix + if cl := escapeAwareRuneCountInString(out); cl < width { + end = strings.Repeat(" ", width-cl) + } + + // and print! + pb.mu.Lock() + pb.lastPrint = out + end + isFinish := pb.isFinish + pb.mu.Unlock() + switch { + case isFinish: + return + case pb.Output != nil: + fmt.Fprint(pb.Output, "\r"+out+end) + case pb.Callback != nil: + pb.Callback(out + end) + case !pb.NotPrint: + fmt.Print("\r" + out + end) + } +} + +// GetTerminalWidth - returns terminal width for all platforms. +func GetTerminalWidth() (int, error) { + return terminalWidth() +} + +func (pb *ProgressBar) GetWidth() int { + if pb.ForceWidth { + return pb.Width + } + + width := pb.Width + termWidth, _ := terminalWidth() + if width == 0 || termWidth <= width { + width = termWidth + } + + return width +} + +// Write the current state of the progressbar +func (pb *ProgressBar) Update() { + c := atomic.LoadInt64(&pb.current) + p := atomic.LoadInt64(&pb.previous) + if p != c { + pb.mu.Lock() + pb.changeTime = time.Now() + pb.mu.Unlock() + atomic.StoreInt64(&pb.previous, c) + } + pb.write(c) + if pb.AutoStat { + if c == 0 { + pb.startTime = time.Now() + pb.startValue = 0 + } else if c >= pb.Total && pb.isFinish != true { + pb.Finish() + } + } +} + +// String return the last bar print +func (pb *ProgressBar) String() string { + pb.mu.Lock() + defer pb.mu.Unlock() + return pb.lastPrint +} + +// Internal loop for refreshing the progressbar +func (pb *ProgressBar) refresher() { + for { + select { + case <-pb.finish: + return + case <-time.After(pb.RefreshRate): + pb.Update() + } + } +} diff --git a/vendor/github.com/cheggaaa/pb/pb_appengine.go b/vendor/github.com/cheggaaa/pb/pb_appengine.go new file mode 100644 index 000000000..d85dbc3b2 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/pb_appengine.go @@ -0,0 +1,11 @@ +// +build appengine + +package pb + +import "errors" + +// terminalWidth returns width of the terminal, which is not supported +// and should always failed on appengine classic which is a sandboxed PaaS. +func terminalWidth() (int, error) { + return 0, errors.New("Not supported") +} diff --git a/vendor/github.com/cheggaaa/pb/pb_win.go b/vendor/github.com/cheggaaa/pb/pb_win.go new file mode 100644 index 000000000..72f682835 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/pb_win.go @@ -0,0 +1,141 @@ +// +build windows + +package pb + +import ( + "errors" + "fmt" + "os" + "sync" + "syscall" + "unsafe" +) + +var tty = os.Stdin + +var ( + kernel32 = syscall.NewLazyDLL("kernel32.dll") + + // GetConsoleScreenBufferInfo retrieves information about the + // specified console screen buffer. + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx + procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") + + // GetConsoleMode retrieves the current input mode of a console's + // input buffer or the current output mode of a console screen buffer. + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx + getConsoleMode = kernel32.NewProc("GetConsoleMode") + + // SetConsoleMode sets the input mode of a console's input buffer + // or the output mode of a console screen buffer. + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx + setConsoleMode = kernel32.NewProc("SetConsoleMode") + + // SetConsoleCursorPosition sets the cursor position in the + // specified console screen buffer. + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms686025(v=vs.85).aspx + setConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition") +) + +type ( + // Defines the coordinates of the upper left and lower right corners + // of a rectangle. + // See + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms686311(v=vs.85).aspx + smallRect struct { + Left, Top, Right, Bottom int16 + } + + // Defines the coordinates of a character cell in a console screen + // buffer. The origin of the coordinate system (0,0) is at the top, left cell + // of the buffer. + // See + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682119(v=vs.85).aspx + coordinates struct { + X, Y int16 + } + + word int16 + + // Contains information about a console screen buffer. + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682093(v=vs.85).aspx + consoleScreenBufferInfo struct { + dwSize coordinates + dwCursorPosition coordinates + wAttributes word + srWindow smallRect + dwMaximumWindowSize coordinates + } +) + +// terminalWidth returns width of the terminal. +func terminalWidth() (width int, err error) { + var info consoleScreenBufferInfo + _, _, e := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&info)), 0) + if e != 0 { + return 0, error(e) + } + return int(info.dwSize.X) - 1, nil +} + +func getCursorPos() (pos coordinates, err error) { + var info consoleScreenBufferInfo + _, _, e := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&info)), 0) + if e != 0 { + return info.dwCursorPosition, error(e) + } + return info.dwCursorPosition, nil +} + +func setCursorPos(pos coordinates) error { + _, _, e := syscall.Syscall(setConsoleCursorPosition.Addr(), 2, uintptr(syscall.Stdout), uintptr(uint32(uint16(pos.Y))<<16|uint32(uint16(pos.X))), 0) + if e != 0 { + return error(e) + } + return nil +} + +var ErrPoolWasStarted = errors.New("Bar pool was started") + +var echoLocked bool +var echoLockMutex sync.Mutex + +var oldState word + +func lockEcho() (quit chan int, err error) { + echoLockMutex.Lock() + defer echoLockMutex.Unlock() + if echoLocked { + err = ErrPoolWasStarted + return + } + echoLocked = true + + if _, _, e := syscall.Syscall(getConsoleMode.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&oldState)), 0); e != 0 { + err = fmt.Errorf("Can't get terminal settings: %v", e) + return + } + + newState := oldState + const ENABLE_ECHO_INPUT = 0x0004 + const ENABLE_LINE_INPUT = 0x0002 + newState = newState & (^(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT)) + if _, _, e := syscall.Syscall(setConsoleMode.Addr(), 2, uintptr(syscall.Stdout), uintptr(newState), 0); e != 0 { + err = fmt.Errorf("Can't set terminal settings: %v", e) + return + } + return +} + +func unlockEcho() (err error) { + echoLockMutex.Lock() + defer echoLockMutex.Unlock() + if !echoLocked { + return + } + echoLocked = false + if _, _, e := syscall.Syscall(setConsoleMode.Addr(), 2, uintptr(syscall.Stdout), uintptr(oldState), 0); e != 0 { + err = fmt.Errorf("Can't set terminal settings") + } + return +} diff --git a/vendor/github.com/cheggaaa/pb/pb_x.go b/vendor/github.com/cheggaaa/pb/pb_x.go new file mode 100644 index 000000000..bbbe7c2d6 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/pb_x.go @@ -0,0 +1,108 @@ +// +build linux darwin freebsd netbsd openbsd solaris dragonfly +// +build !appengine + +package pb + +import ( + "errors" + "fmt" + "os" + "os/signal" + "sync" + "syscall" + + "golang.org/x/sys/unix" +) + +var ErrPoolWasStarted = errors.New("Bar pool was started") + +var ( + echoLockMutex sync.Mutex + origTermStatePtr *unix.Termios + tty *os.File +) + +func init() { + echoLockMutex.Lock() + defer echoLockMutex.Unlock() + + var err error + tty, err = os.Open("/dev/tty") + if err != nil { + tty = os.Stdin + } +} + +// terminalWidth returns width of the terminal. +func terminalWidth() (int, error) { + echoLockMutex.Lock() + defer echoLockMutex.Unlock() + + fd := int(tty.Fd()) + + ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ) + if err != nil { + return 0, err + } + + return int(ws.Col), nil +} + +func lockEcho() (quit chan int, err error) { + echoLockMutex.Lock() + defer echoLockMutex.Unlock() + if origTermStatePtr != nil { + return quit, ErrPoolWasStarted + } + + fd := int(tty.Fd()) + + oldTermStatePtr, err := unix.IoctlGetTermios(fd, ioctlReadTermios) + if err != nil { + return nil, fmt.Errorf("Can't get terminal settings: %v", err) + } + + oldTermios := *oldTermStatePtr + newTermios := oldTermios + newTermios.Lflag &^= syscall.ECHO + newTermios.Lflag |= syscall.ICANON | syscall.ISIG + newTermios.Iflag |= syscall.ICRNL + if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, &newTermios); err != nil { + return nil, fmt.Errorf("Can't set terminal settings: %v", err) + } + + quit = make(chan int, 1) + go catchTerminate(quit) + return +} + +func unlockEcho() error { + echoLockMutex.Lock() + defer echoLockMutex.Unlock() + if origTermStatePtr == nil { + return nil + } + + fd := int(tty.Fd()) + + if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, origTermStatePtr); err != nil { + return fmt.Errorf("Can't set terminal settings: %v", err) + } + + origTermStatePtr = nil + + return nil +} + +// listen exit signals and restore terminal state +func catchTerminate(quit chan int) { + sig := make(chan os.Signal, 1) + signal.Notify(sig, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL) + defer signal.Stop(sig) + select { + case <-quit: + unlockEcho() + case <-sig: + unlockEcho() + } +} diff --git a/vendor/github.com/cheggaaa/pb/pool.go b/vendor/github.com/cheggaaa/pb/pool.go new file mode 100644 index 000000000..bc1a13886 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/pool.go @@ -0,0 +1,82 @@ +// +build linux darwin freebsd netbsd openbsd solaris dragonfly windows + +package pb + +import ( + "io" + "sync" + "time" +) + +// Create and start new pool with given bars +// You need call pool.Stop() after work +func StartPool(pbs ...*ProgressBar) (pool *Pool, err error) { + pool = new(Pool) + if err = pool.start(); err != nil { + return + } + pool.Add(pbs...) + return +} + +type Pool struct { + Output io.Writer + RefreshRate time.Duration + bars []*ProgressBar + lastBarsCount int + quit chan int + m sync.Mutex + finishOnce sync.Once +} + +// Add progress bars. +func (p *Pool) Add(pbs ...*ProgressBar) { + p.m.Lock() + defer p.m.Unlock() + for _, bar := range pbs { + bar.ManualUpdate = true + bar.NotPrint = true + bar.Start() + p.bars = append(p.bars, bar) + } +} + +func (p *Pool) start() (err error) { + p.RefreshRate = DefaultRefreshRate + quit, err := lockEcho() + if err != nil { + return + } + p.quit = make(chan int) + go p.writer(quit) + return +} + +func (p *Pool) writer(finish chan int) { + var first = true + for { + select { + case <-time.After(p.RefreshRate): + if p.print(first) { + p.print(false) + finish <- 1 + return + } + first = false + case <-p.quit: + finish <- 1 + return + } + } +} + +// Restore terminal state and close pool +func (p *Pool) Stop() error { + // Wait until one final refresh has passed. + time.Sleep(p.RefreshRate) + + p.finishOnce.Do(func() { + close(p.quit) + }) + return unlockEcho() +} diff --git a/vendor/github.com/cheggaaa/pb/pool_win.go b/vendor/github.com/cheggaaa/pb/pool_win.go new file mode 100644 index 000000000..63598d378 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/pool_win.go @@ -0,0 +1,45 @@ +// +build windows + +package pb + +import ( + "fmt" + "log" +) + +func (p *Pool) print(first bool) bool { + p.m.Lock() + defer p.m.Unlock() + var out string + if !first { + coords, err := getCursorPos() + if err != nil { + log.Panic(err) + } + coords.Y -= int16(p.lastBarsCount) + if coords.Y < 0 { + coords.Y = 0 + } + coords.X = 0 + + err = setCursorPos(coords) + if err != nil { + log.Panic(err) + } + } + isFinished := true + for _, bar := range p.bars { + if !bar.IsFinished() { + isFinished = false + } + bar.Update() + out += fmt.Sprintf("\r%s\n", bar.String()) + } + if p.Output != nil { + fmt.Fprint(p.Output, out) + } else { + fmt.Print(out) + } + p.lastBarsCount = len(p.bars) + return isFinished +} diff --git a/vendor/github.com/cheggaaa/pb/pool_x.go b/vendor/github.com/cheggaaa/pb/pool_x.go new file mode 100644 index 000000000..a8ae14d2f --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/pool_x.go @@ -0,0 +1,29 @@ +// +build linux darwin freebsd netbsd openbsd solaris dragonfly + +package pb + +import "fmt" + +func (p *Pool) print(first bool) bool { + p.m.Lock() + defer p.m.Unlock() + var out string + if !first { + out = fmt.Sprintf("\033[%dA", p.lastBarsCount) + } + isFinished := true + for _, bar := range p.bars { + if !bar.IsFinished() { + isFinished = false + } + bar.Update() + out += fmt.Sprintf("\r%s\n", bar.String()) + } + if p.Output != nil { + fmt.Fprint(p.Output, out) + } else { + fmt.Print(out) + } + p.lastBarsCount = len(p.bars) + return isFinished +} diff --git a/vendor/github.com/cheggaaa/pb/reader.go b/vendor/github.com/cheggaaa/pb/reader.go new file mode 100644 index 000000000..9f3148b54 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/reader.go @@ -0,0 +1,25 @@ +package pb + +import ( + "io" +) + +// It's proxy reader, implement io.Reader +type Reader struct { + io.Reader + bar *ProgressBar +} + +func (r *Reader) Read(p []byte) (n int, err error) { + n, err = r.Reader.Read(p) + r.bar.Add(n) + return +} + +// Close the reader when it implements io.Closer +func (r *Reader) Close() (err error) { + if closer, ok := r.Reader.(io.Closer); ok { + return closer.Close() + } + return +} diff --git a/vendor/github.com/cheggaaa/pb/runecount.go b/vendor/github.com/cheggaaa/pb/runecount.go new file mode 100644 index 000000000..c617c55ec --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/runecount.go @@ -0,0 +1,17 @@ +package pb + +import ( + "github.com/mattn/go-runewidth" + "regexp" +) + +// Finds the control character sequences (like colors) +var ctrlFinder = regexp.MustCompile("\x1b\x5b[0-9]+\x6d") + +func escapeAwareRuneCountInString(s string) int { + n := runewidth.StringWidth(s) + for _, sm := range ctrlFinder.FindAllString(s, -1) { + n -= runewidth.StringWidth(sm) + } + return n +} diff --git a/vendor/github.com/cheggaaa/pb/termios_bsd.go b/vendor/github.com/cheggaaa/pb/termios_bsd.go new file mode 100644 index 000000000..517ea8ed7 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/termios_bsd.go @@ -0,0 +1,9 @@ +// +build darwin freebsd netbsd openbsd dragonfly +// +build !appengine + +package pb + +import "syscall" + +const ioctlReadTermios = syscall.TIOCGETA +const ioctlWriteTermios = syscall.TIOCSETA diff --git a/vendor/github.com/cheggaaa/pb/termios_sysv.go b/vendor/github.com/cheggaaa/pb/termios_sysv.go new file mode 100644 index 000000000..b10f61859 --- /dev/null +++ b/vendor/github.com/cheggaaa/pb/termios_sysv.go @@ -0,0 +1,13 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build linux solaris +// +build !appengine + +package pb + +import "golang.org/x/sys/unix" + +const ioctlReadTermios = unix.TCGETS +const ioctlWriteTermios = unix.TCSETS diff --git a/vendor/github.com/cznic/b/btree.go b/vendor/github.com/cznic/b/btree.go deleted file mode 100644 index b7bd7739f..000000000 --- a/vendor/github.com/cznic/b/btree.go +++ /dev/null @@ -1,909 +0,0 @@ -// Copyright 2014 The b Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package b - -import ( - "fmt" - "io" - "sync" -) - -const ( - kx = 32 //TODO benchmark tune this number if using custom key/value type(s). - kd = 32 //TODO benchmark tune this number if using custom key/value type(s). -) - -func init() { - if kd < 1 { - panic(fmt.Errorf("kd %d: out of range", kd)) - } - - if kx < 2 { - panic(fmt.Errorf("kx %d: out of range", kx)) - } -} - -var ( - btDPool = sync.Pool{New: func() interface{} { return &d{} }} - btEPool = btEpool{sync.Pool{New: func() interface{} { return &Enumerator{} }}} - btTPool = btTpool{sync.Pool{New: func() interface{} { return &Tree{} }}} - btXPool = sync.Pool{New: func() interface{} { return &x{} }} -) - -type btTpool struct{ sync.Pool } - -func (p *btTpool) get(cmp Cmp) *Tree { - x := p.Get().(*Tree) - x.cmp = cmp - return x -} - -type btEpool struct{ sync.Pool } - -func (p *btEpool) get(err error, hit bool, i int, k interface{} /*K*/, q *d, t *Tree, ver int64) *Enumerator { - x := p.Get().(*Enumerator) - x.err, x.hit, x.i, x.k, x.q, x.t, x.ver = err, hit, i, k, q, t, ver - return x -} - -type ( - // Cmp compares a and b. Return value is: - // - // < 0 if a < b - // 0 if a == b - // > 0 if a > b - // - Cmp func(a, b interface{} /*K*/) int - - d struct { // data page - c int - d [2*kd + 1]de - n *d - p *d - } - - de struct { // d element - k interface{} /*K*/ - v interface{} /*V*/ - } - - // Enumerator captures the state of enumerating a tree. It is returned - // from the Seek* methods. The enumerator is aware of any mutations - // made to the tree in the process of enumerating it and automatically - // resumes the enumeration at the proper key, if possible. - // - // However, once an Enumerator returns io.EOF to signal "no more - // items", it does no more attempt to "resync" on tree mutation(s). In - // other words, io.EOF from an Enumerator is "sticky" (idempotent). - Enumerator struct { - err error - hit bool - i int - k interface{} /*K*/ - q *d - t *Tree - ver int64 - } - - // Tree is a B+tree. - Tree struct { - c int - cmp Cmp - first *d - last *d - r interface{} - ver int64 - } - - xe struct { // x element - ch interface{} - k interface{} /*K*/ - } - - x struct { // index page - c int - x [2*kx + 2]xe - } -) - -var ( // R/O zero values - zd d - zde de - ze Enumerator - zk interface{} /*K*/ - zt Tree - zx x - zxe xe -) - -func clr(q interface{}) { - switch x := q.(type) { - case *x: - for i := 0; i <= x.c; i++ { // Ch0 Sep0 ... Chn-1 Sepn-1 Chn - clr(x.x[i].ch) - } - *x = zx - btXPool.Put(x) - case *d: - *x = zd - btDPool.Put(x) - } -} - -// -------------------------------------------------------------------------- x - -func newX(ch0 interface{}) *x { - r := btXPool.Get().(*x) - r.x[0].ch = ch0 - return r -} - -func (q *x) extract(i int) { - q.c-- - if i < q.c { - copy(q.x[i:], q.x[i+1:q.c+1]) - q.x[q.c].ch = q.x[q.c+1].ch - q.x[q.c].k = zk // GC - q.x[q.c+1] = zxe // GC - } -} - -func (q *x) insert(i int, k interface{} /*K*/, ch interface{}) *x { - c := q.c - if i < c { - q.x[c+1].ch = q.x[c].ch - copy(q.x[i+2:], q.x[i+1:c]) - q.x[i+1].k = q.x[i].k - } - c++ - q.c = c - q.x[i].k = k - q.x[i+1].ch = ch - return q -} - -func (q *x) siblings(i int) (l, r *d) { - if i >= 0 { - if i > 0 { - l = q.x[i-1].ch.(*d) - } - if i < q.c { - r = q.x[i+1].ch.(*d) - } - } - return -} - -// -------------------------------------------------------------------------- d - -func (l *d) mvL(r *d, c int) { - copy(l.d[l.c:], r.d[:c]) - copy(r.d[:], r.d[c:r.c]) - l.c += c - r.c -= c -} - -func (l *d) mvR(r *d, c int) { - copy(r.d[c:], r.d[:r.c]) - copy(r.d[:c], l.d[l.c-c:]) - r.c += c - l.c -= c -} - -// ----------------------------------------------------------------------- Tree - -// TreeNew returns a newly created, empty Tree. The compare function is used -// for key collation. -func TreeNew(cmp Cmp) *Tree { - return btTPool.get(cmp) -} - -// Clear removes all K/V pairs from the tree. -func (t *Tree) Clear() { - if t.r == nil { - return - } - - clr(t.r) - t.c, t.first, t.last, t.r = 0, nil, nil, nil - t.ver++ -} - -// Close performs Clear and recycles t to a pool for possible later reuse. No -// references to t should exist or such references must not be used afterwards. -func (t *Tree) Close() { - t.Clear() - *t = zt - btTPool.Put(t) -} - -func (t *Tree) cat(p *x, q, r *d, pi int) { - t.ver++ - q.mvL(r, r.c) - if r.n != nil { - r.n.p = q - } else { - t.last = q - } - q.n = r.n - *r = zd - btDPool.Put(r) - if p.c > 1 { - p.extract(pi) - p.x[pi].ch = q - return - } - - switch x := t.r.(type) { - case *x: - *x = zx - btXPool.Put(x) - case *d: - *x = zd - btDPool.Put(x) - } - t.r = q -} - -func (t *Tree) catX(p, q, r *x, pi int) { - t.ver++ - q.x[q.c].k = p.x[pi].k - copy(q.x[q.c+1:], r.x[:r.c]) - q.c += r.c + 1 - q.x[q.c].ch = r.x[r.c].ch - *r = zx - btXPool.Put(r) - if p.c > 1 { - p.c-- - pc := p.c - if pi < pc { - p.x[pi].k = p.x[pi+1].k - copy(p.x[pi+1:], p.x[pi+2:pc+1]) - p.x[pc].ch = p.x[pc+1].ch - p.x[pc].k = zk // GC - p.x[pc+1].ch = nil // GC - } - return - } - - switch x := t.r.(type) { - case *x: - *x = zx - btXPool.Put(x) - case *d: - *x = zd - btDPool.Put(x) - } - t.r = q -} - -// Delete removes the k's KV pair, if it exists, in which case Delete returns -// true. -func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { - pi := -1 - var p *x - q := t.r - if q == nil { - return false - } - - for { - var i int - i, ok = t.find(q, k) - if ok { - switch x := q.(type) { - case *x: - if x.c < kx && q != t.r { - x, i = t.underflowX(p, x, pi, i) - } - pi = i + 1 - p = x - q = x.x[pi].ch - continue - case *d: - t.extract(x, i) - if x.c >= kd { - return true - } - - if q != t.r { - t.underflow(p, x, pi) - } else if t.c == 0 { - t.Clear() - } - return true - } - } - - switch x := q.(type) { - case *x: - if x.c < kx && q != t.r { - x, i = t.underflowX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - case *d: - return false - } - } -} - -func (t *Tree) extract(q *d, i int) { // (r interface{} /*V*/) { - t.ver++ - //r = q.d[i].v // prepared for Extract - q.c-- - if i < q.c { - copy(q.d[i:], q.d[i+1:q.c+1]) - } - q.d[q.c] = zde // GC - t.c-- - return -} - -func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) { - var mk interface{} /*K*/ - l := 0 - switch x := q.(type) { - case *x: - h := x.c - 1 - for l <= h { - m := (l + h) >> 1 - mk = x.x[m].k - switch cmp := t.cmp(k, mk); { - case cmp > 0: - l = m + 1 - case cmp == 0: - return m, true - default: - h = m - 1 - } - } - case *d: - h := x.c - 1 - for l <= h { - m := (l + h) >> 1 - mk = x.d[m].k - switch cmp := t.cmp(k, mk); { - case cmp > 0: - l = m + 1 - case cmp == 0: - return m, true - default: - h = m - 1 - } - } - } - return l, false -} - -// First returns the first item of the tree in the key collating order, or -// (zero-value, zero-value) if the tree is empty. -func (t *Tree) First() (k interface{} /*K*/, v interface{} /*V*/) { - if q := t.first; q != nil { - q := &q.d[0] - k, v = q.k, q.v - } - return -} - -// Get returns the value associated with k and true if it exists. Otherwise Get -// returns (zero-value, false). -func (t *Tree) Get(k interface{} /*K*/) (v interface{} /*V*/, ok bool) { - q := t.r - if q == nil { - return - } - - for { - var i int - if i, ok = t.find(q, k); ok { - switch x := q.(type) { - case *x: - q = x.x[i+1].ch - continue - case *d: - return x.d[i].v, true - } - } - switch x := q.(type) { - case *x: - q = x.x[i].ch - default: - return - } - } -} - -func (t *Tree) insert(q *d, i int, k interface{} /*K*/, v interface{} /*V*/) *d { - t.ver++ - c := q.c - if i < c { - copy(q.d[i+1:], q.d[i:c]) - } - c++ - q.c = c - q.d[i].k, q.d[i].v = k, v - t.c++ - return q -} - -// Last returns the last item of the tree in the key collating order, or -// (zero-value, zero-value) if the tree is empty. -func (t *Tree) Last() (k interface{} /*K*/, v interface{} /*V*/) { - if q := t.last; q != nil { - q := &q.d[q.c-1] - k, v = q.k, q.v - } - return -} - -// Len returns the number of items in the tree. -func (t *Tree) Len() int { - return t.c -} - -func (t *Tree) overflow(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} /*V*/) { - t.ver++ - l, r := p.siblings(pi) - - if l != nil && l.c < 2*kd && i != 0 { - l.mvL(q, 1) - t.insert(q, i-1, k, v) - p.x[pi-1].k = q.d[0].k - return - } - - if r != nil && r.c < 2*kd { - if i < 2*kd { - q.mvR(r, 1) - t.insert(q, i, k, v) - p.x[pi].k = r.d[0].k - return - } - - t.insert(r, 0, k, v) - p.x[pi].k = k - return - } - - t.split(p, q, pi, i, k, v) -} - -// Seek returns an Enumerator positioned on an item such that k >= item's key. -// ok reports if k == item.key The Enumerator's position is possibly after the -// last item in the tree. -func (t *Tree) Seek(k interface{} /*K*/) (e *Enumerator, ok bool) { - q := t.r - if q == nil { - e = btEPool.get(nil, false, 0, k, nil, t, t.ver) - return - } - - for { - var i int - if i, ok = t.find(q, k); ok { - switch x := q.(type) { - case *x: - q = x.x[i+1].ch - continue - case *d: - return btEPool.get(nil, ok, i, k, x, t, t.ver), true - } - } - - switch x := q.(type) { - case *x: - q = x.x[i].ch - case *d: - return btEPool.get(nil, ok, i, k, x, t, t.ver), false - } - } -} - -// SeekFirst returns an enumerator positioned on the first KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returned and e will be nil. -func (t *Tree) SeekFirst() (e *Enumerator, err error) { - q := t.first - if q == nil { - return nil, io.EOF - } - - return btEPool.get(nil, true, 0, q.d[0].k, q, t, t.ver), nil -} - -// SeekLast returns an enumerator positioned on the last KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returned and e will be nil. -func (t *Tree) SeekLast() (e *Enumerator, err error) { - q := t.last - if q == nil { - return nil, io.EOF - } - - return btEPool.get(nil, true, q.c-1, q.d[q.c-1].k, q, t, t.ver), nil -} - -// Set sets the value associated with k. -func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { - //dbg("--- PRE Set(%v, %v)\n%s", k, v, t.dump()) - //defer func() { - // dbg("--- POST\n%s\n====\n", t.dump()) - //}() - - pi := -1 - var p *x - q := t.r - if q == nil { - z := t.insert(btDPool.Get().(*d), 0, k, v) - t.r, t.first, t.last = z, z, z - return - } - - for { - i, ok := t.find(q, k) - if ok { - switch x := q.(type) { - case *x: - i++ - if x.c > 2*kx { - x, i = t.splitX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - continue - case *d: - x.d[i].v = v - } - return - } - - switch x := q.(type) { - case *x: - if x.c > 2*kx { - x, i = t.splitX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - case *d: - switch { - case x.c < 2*kd: - t.insert(x, i, k, v) - default: - t.overflow(p, x, pi, i, k, v) - } - return - } - } -} - -// Put combines Get and Set in a more efficient way where the tree is walked -// only once. The upd(ater) receives (old-value, true) if a KV pair for k -// exists or (zero-value, false) otherwise. It can then return a (new-value, -// true) to create or overwrite the existing value in the KV pair, or -// (whatever, false) if it decides not to create or not to update the value of -// the KV pair. -// -// tree.Set(k, v) call conceptually equals calling -// -// tree.Put(k, func(interface{} /*K*/, bool){ return v, true }) -// -// modulo the differing return values. -func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists bool) (newV interface{} /*V*/, write bool)) (oldV interface{} /*V*/, written bool) { - pi := -1 - var p *x - q := t.r - var newV interface{} /*V*/ - if q == nil { - // new KV pair in empty tree - newV, written = upd(newV, false) - if !written { - return - } - - z := t.insert(btDPool.Get().(*d), 0, k, newV) - t.r, t.first, t.last = z, z, z - return - } - - for { - i, ok := t.find(q, k) - if ok { - switch x := q.(type) { - case *x: - i++ - if x.c > 2*kx { - x, i = t.splitX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - continue - case *d: - oldV = x.d[i].v - newV, written = upd(oldV, true) - if !written { - return - } - - x.d[i].v = newV - } - return - } - - switch x := q.(type) { - case *x: - if x.c > 2*kx { - x, i = t.splitX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - case *d: // new KV pair - newV, written = upd(newV, false) - if !written { - return - } - - switch { - case x.c < 2*kd: - t.insert(x, i, k, newV) - default: - t.overflow(p, x, pi, i, k, newV) - } - return - } - } -} - -func (t *Tree) split(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} /*V*/) { - t.ver++ - r := btDPool.Get().(*d) - if q.n != nil { - r.n = q.n - r.n.p = r - } else { - t.last = r - } - q.n = r - r.p = q - - copy(r.d[:], q.d[kd:2*kd]) - for i := range q.d[kd:] { - q.d[kd+i] = zde - } - q.c = kd - r.c = kd - var done bool - if i > kd { - done = true - t.insert(r, i-kd, k, v) - } - if pi >= 0 { - p.insert(pi, r.d[0].k, r) - } else { - t.r = newX(q).insert(0, r.d[0].k, r) - } - if done { - return - } - - t.insert(q, i, k, v) -} - -func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, int) { - t.ver++ - r := btXPool.Get().(*x) - copy(r.x[:], q.x[kx+1:]) - q.c = kx - r.c = kx - if pi >= 0 { - p.insert(pi, q.x[kx].k, r) - } else { - t.r = newX(q).insert(0, q.x[kx].k, r) - } - - q.x[kx].k = zk - for i := range q.x[kx+1:] { - q.x[kx+i+1] = zxe - } - if i > kx { - q = r - i -= kx + 1 - } - - return q, i -} - -func (t *Tree) underflow(p *x, q *d, pi int) { - t.ver++ - l, r := p.siblings(pi) - - if l != nil && l.c+q.c >= 2*kd { - l.mvR(q, 1) - p.x[pi-1].k = q.d[0].k - return - } - - if r != nil && q.c+r.c >= 2*kd { - q.mvL(r, 1) - p.x[pi].k = r.d[0].k - r.d[r.c] = zde // GC - return - } - - if l != nil { - t.cat(p, l, q, pi-1) - return - } - - t.cat(p, q, r, pi) -} - -func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) { - t.ver++ - var l, r *x - - if pi >= 0 { - if pi > 0 { - l = p.x[pi-1].ch.(*x) - } - if pi < p.c { - r = p.x[pi+1].ch.(*x) - } - } - - if l != nil && l.c > kx { - q.x[q.c+1].ch = q.x[q.c].ch - copy(q.x[1:], q.x[:q.c]) - q.x[0].ch = l.x[l.c].ch - q.x[0].k = p.x[pi-1].k - q.c++ - i++ - l.c-- - p.x[pi-1].k = l.x[l.c].k - return q, i - } - - if r != nil && r.c > kx { - q.x[q.c].k = p.x[pi].k - q.c++ - q.x[q.c].ch = r.x[0].ch - p.x[pi].k = r.x[0].k - copy(r.x[:], r.x[1:r.c]) - r.c-- - rc := r.c - r.x[rc].ch = r.x[rc+1].ch - r.x[rc].k = zk - r.x[rc+1].ch = nil - return q, i - } - - if l != nil { - i += l.c + 1 - t.catX(p, l, q, pi-1) - q = l - return q, i - } - - t.catX(p, q, r, pi) - return q, i -} - -// ----------------------------------------------------------------- Enumerator - -// Close recycles e to a pool for possible later reuse. No references to e -// should exist or such references must not be used afterwards. -func (e *Enumerator) Close() { - *e = ze - btEPool.Put(e) -} - -// Next returns the currently enumerated item, if it exists and moves to the -// next item in the key collation order. If there is no item to return, err == -// io.EOF is returned. -func (e *Enumerator) Next() (k interface{} /*K*/, v interface{} /*V*/, err error) { - if err = e.err; err != nil { - return - } - - if e.ver != e.t.ver { - f, _ := e.t.Seek(e.k) - *e = *f - f.Close() - } - if e.q == nil { - e.err, err = io.EOF, io.EOF - return - } - - if e.i >= e.q.c { - if err = e.next(); err != nil { - return - } - } - - i := e.q.d[e.i] - k, v = i.k, i.v - e.k, e.hit = k, true - e.next() - return -} - -func (e *Enumerator) next() error { - if e.q == nil { - e.err = io.EOF - return io.EOF - } - - switch { - case e.i < e.q.c-1: - e.i++ - default: - if e.q, e.i = e.q.n, 0; e.q == nil { - e.err = io.EOF - } - } - return e.err -} - -// Prev returns the currently enumerated item, if it exists and moves to the -// previous item in the key collation order. If there is no item to return, err -// == io.EOF is returned. -func (e *Enumerator) Prev() (k interface{} /*K*/, v interface{} /*V*/, err error) { - if err = e.err; err != nil { - return - } - - if e.ver != e.t.ver { - f, _ := e.t.Seek(e.k) - *e = *f - f.Close() - } - if e.q == nil { - e.err, err = io.EOF, io.EOF - return - } - - if !e.hit { - // move to previous because Seek overshoots if there's no hit - if err = e.prev(); err != nil { - return - } - } - - if e.i >= e.q.c { - if err = e.prev(); err != nil { - return - } - } - - i := e.q.d[e.i] - k, v = i.k, i.v - e.k, e.hit = k, true - e.prev() - return -} - -func (e *Enumerator) prev() error { - if e.q == nil { - e.err = io.EOF - return io.EOF - } - - switch { - case e.i > 0: - e.i-- - default: - if e.q = e.q.p; e.q == nil { - e.err = io.EOF - break - } - - e.i = e.q.c - 1 - } - return e.err -} diff --git a/vendor/github.com/cznic/b/doc.go b/vendor/github.com/cznic/b/doc.go deleted file mode 100644 index 5cba93c29..000000000 --- a/vendor/github.com/cznic/b/doc.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2014 The b Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package b implements the B+tree flavor of a BTree. -// -// Changelog -// -// 2016-07-16: Update benchmark results to newer Go version. Add a note on -// concurrency. -// -// 2014-06-26: Lower GC presure by recycling things. -// -// 2014-04-18: Added new method Put. -// -// Concurrency considerations -// -// Tree.{Clear,Delete,Put,Set} mutate the tree. One can use eg. a -// sync.Mutex.Lock/Unlock (or sync.RWMutex.Lock/Unlock) to wrap those calls if -// they are to be invoked concurrently. -// -// Tree.{First,Get,Last,Len,Seek,SeekFirst,SekLast} read but do not mutate the -// tree. One can use eg. a sync.RWMutex.RLock/RUnlock to wrap those calls if -// they are to be invoked concurrently with any of the tree mutating methods. -// -// Enumerator.{Next,Prev} mutate the enumerator and read but not mutate the -// tree. One can use eg. a sync.RWMutex.RLock/RUnlock to wrap those calls if -// they are to be invoked concurrently with any of the tree mutating methods. A -// separate mutex for the enumerator, or the whole tree in a simplified -// variant, is necessary if the enumerator's Next/Prev methods per se are to -// be invoked concurrently. -// -// Generic types -// -// Keys and their associated values are interface{} typed, similar to all of -// the containers in the standard library. -// -// Semiautomatic production of a type specific variant of this package is -// supported via -// -// $ make generic -// -// This command will write to stdout a version of the btree.go file where every -// key type occurrence is replaced by the word 'KEY' and every value type -// occurrence is replaced by the word 'VALUE'. Then you have to replace these -// tokens with your desired type(s), using any technique you're comfortable -// with. -// -// This is how, for example, 'example/int.go' was created: -// -// $ mkdir example -// $ make generic | sed -e 's/KEY/int/g' -e 's/VALUE/int/g' > example/int.go -// -// No other changes to int.go are necessary, it compiles just fine. -// -// Running the benchmarks for 1000 keys on a machine with Intel i5-4670 CPU @ -// 3.4GHz, Go 1.7rc1. -// -// $ go test -bench 1e3 example/all_test.go example/int.go -// BenchmarkSetSeq1e3-4 20000 78265 ns/op -// BenchmarkGetSeq1e3-4 20000 67980 ns/op -// BenchmarkSetRnd1e3-4 10000 172720 ns/op -// BenchmarkGetRnd1e3-4 20000 89539 ns/op -// BenchmarkDelSeq1e3-4 20000 87863 ns/op -// BenchmarkDelRnd1e3-4 10000 130891 ns/op -// BenchmarkSeekSeq1e3-4 10000 100118 ns/op -// BenchmarkSeekRnd1e3-4 10000 121684 ns/op -// BenchmarkNext1e3-4 200000 6330 ns/op -// BenchmarkPrev1e3-4 200000 9066 ns/op -// PASS -// ok command-line-arguments 42.531s -// $ -package b diff --git a/vendor/github.com/cznic/b/example/int.go b/vendor/github.com/cznic/b/example/int.go deleted file mode 100644 index 37aa9897b..000000000 --- a/vendor/github.com/cznic/b/example/int.go +++ /dev/null @@ -1,910 +0,0 @@ -// Copyright 2014 The b Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package b - -import ( - "fmt" - "io" - "sync" -) - -const ( - kx = 32 //TODO benchmark tune this number if using custom key/value type(s). - kd = 32 //TODO benchmark tune this number if using custom key/value type(s). -) - -func init() { - if kd < 1 { - panic(fmt.Errorf("kd %d: out of range", kd)) - } - - if kx < 2 { - panic(fmt.Errorf("kx %d: out of range", kx)) - } -} - -var ( - btDPool = sync.Pool{New: func() interface{} { return &d{} }} - btEPool = btEpool{sync.Pool{New: func() interface{} { return &Enumerator{} }}} - btTPool = btTpool{sync.Pool{New: func() interface{} { return &Tree{} }}} - btXPool = sync.Pool{New: func() interface{} { return &x{} }} -) - -type btTpool struct{ sync.Pool } - -func (p *btTpool) get(cmp Cmp) *Tree { - x := p.Get().(*Tree) - x.cmp = cmp - return x -} - -type btEpool struct{ sync.Pool } - -func (p *btEpool) get(err error, hit bool, i int, k int, q *d, t *Tree, ver int64) *Enumerator { - x := p.Get().(*Enumerator) - x.err, x.hit, x.i, x.k, x.q, x.t, x.ver = err, hit, i, k, q, t, ver - return x -} - -type ( - // Cmp compares a and b. Return value is: - // - // < 0 if a < b - // 0 if a == b - // > 0 if a > b - // - Cmp func(a, b int) int - - d struct { // data page - c int - d [2*kd + 1]de - n *d - p *d - } - - de struct { // d element - k int - v int - } - - // Enumerator captures the state of enumerating a tree. It is returned - // from the Seek* methods. The enumerator is aware of any mutations - // made to the tree in the process of enumerating it and automatically - // resumes the enumeration at the proper key, if possible. - // - // However, once an Enumerator returns io.EOF to signal "no more - // items", it does no more attempt to "resync" on tree mutation(s). In - // other words, io.EOF from an Enumerator is "sticky" (idempotent). - Enumerator struct { - err error - hit bool - i int - k int - q *d - t *Tree - ver int64 - } - - // Tree is a B+tree. - Tree struct { - c int - cmp Cmp - first *d - last *d - r interface{} - ver int64 - } - - xe struct { // x element - ch interface{} - k int - } - - x struct { // index page - c int - x [2*kx + 2]xe - } -) - -var ( // R/O zero values - zd d - zde de - ze Enumerator - zk int - zt Tree - zx x - zxe xe -) - -func clr(q interface{}) { - switch x := q.(type) { - case *x: - for i := 0; i <= x.c; i++ { // Ch0 Sep0 ... Chn-1 Sepn-1 Chn - clr(x.x[i].ch) - } - *x = zx - btXPool.Put(x) - case *d: - *x = zd - btDPool.Put(x) - } -} - -// -------------------------------------------------------------------------- x - -func newX(ch0 interface{}) *x { - r := btXPool.Get().(*x) - r.x[0].ch = ch0 - return r -} - -func (q *x) extract(i int) { - q.c-- - if i < q.c { - copy(q.x[i:], q.x[i+1:q.c+1]) - q.x[q.c].ch = q.x[q.c+1].ch - q.x[q.c].k = zk // GC - q.x[q.c+1] = zxe // GC - } -} - -func (q *x) insert(i int, k int, ch interface{}) *x { - c := q.c - if i < c { - q.x[c+1].ch = q.x[c].ch - copy(q.x[i+2:], q.x[i+1:c]) - q.x[i+1].k = q.x[i].k - } - c++ - q.c = c - q.x[i].k = k - q.x[i+1].ch = ch - return q -} - -func (q *x) siblings(i int) (l, r *d) { - if i >= 0 { - if i > 0 { - l = q.x[i-1].ch.(*d) - } - if i < q.c { - r = q.x[i+1].ch.(*d) - } - } - return -} - -// -------------------------------------------------------------------------- d - -func (l *d) mvL(r *d, c int) { - copy(l.d[l.c:], r.d[:c]) - copy(r.d[:], r.d[c:r.c]) - l.c += c - r.c -= c -} - -func (l *d) mvR(r *d, c int) { - copy(r.d[c:], r.d[:r.c]) - copy(r.d[:c], l.d[l.c-c:]) - r.c += c - l.c -= c -} - -// ----------------------------------------------------------------------- Tree - -// TreeNew returns a newly created, empty Tree. The compare function is used -// for key collation. -func TreeNew(cmp Cmp) *Tree { - return btTPool.get(cmp) -} - -// Clear removes all K/V pairs from the tree. -func (t *Tree) Clear() { - if t.r == nil { - return - } - - clr(t.r) - t.c, t.first, t.last, t.r = 0, nil, nil, nil - t.ver++ -} - -// Close performs Clear and recycles t to a pool for possible later reuse. No -// references to t should exist or such references must not be used afterwards. -func (t *Tree) Close() { - t.Clear() - *t = zt - btTPool.Put(t) -} - -func (t *Tree) cat(p *x, q, r *d, pi int) { - t.ver++ - q.mvL(r, r.c) - if r.n != nil { - r.n.p = q - } else { - t.last = q - } - q.n = r.n - *r = zd - btDPool.Put(r) - if p.c > 1 { - p.extract(pi) - p.x[pi].ch = q - return - } - - switch x := t.r.(type) { - case *x: - *x = zx - btXPool.Put(x) - case *d: - *x = zd - btDPool.Put(x) - } - t.r = q -} - -func (t *Tree) catX(p, q, r *x, pi int) { - t.ver++ - q.x[q.c].k = p.x[pi].k - copy(q.x[q.c+1:], r.x[:r.c]) - q.c += r.c + 1 - q.x[q.c].ch = r.x[r.c].ch - *r = zx - btXPool.Put(r) - if p.c > 1 { - p.c-- - pc := p.c - if pi < pc { - p.x[pi].k = p.x[pi+1].k - copy(p.x[pi+1:], p.x[pi+2:pc+1]) - p.x[pc].ch = p.x[pc+1].ch - p.x[pc].k = zk // GC - p.x[pc+1].ch = nil // GC - } - return - } - - switch x := t.r.(type) { - case *x: - *x = zx - btXPool.Put(x) - case *d: - *x = zd - btDPool.Put(x) - } - t.r = q -} - -// Delete removes the k's KV pair, if it exists, in which case Delete returns -// true. -func (t *Tree) Delete(k int) (ok bool) { - pi := -1 - var p *x - q := t.r - if q == nil { - return false - } - - for { - var i int - i, ok = t.find(q, k) - if ok { - switch x := q.(type) { - case *x: - if x.c < kx && q != t.r { - x, i = t.underflowX(p, x, pi, i) - } - pi = i + 1 - p = x - q = x.x[pi].ch - ok = false - continue - case *d: - t.extract(x, i) - if x.c >= kd { - return true - } - - if q != t.r { - t.underflow(p, x, pi) - } else if t.c == 0 { - t.Clear() - } - return true - } - } - - switch x := q.(type) { - case *x: - if x.c < kx && q != t.r { - x, i = t.underflowX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - case *d: - return false - } - } -} - -func (t *Tree) extract(q *d, i int) { // (r int) { - t.ver++ - //r = q.d[i].v // prepared for Extract - q.c-- - if i < q.c { - copy(q.d[i:], q.d[i+1:q.c+1]) - } - q.d[q.c] = zde // GC - t.c-- - return -} - -func (t *Tree) find(q interface{}, k int) (i int, ok bool) { - var mk int - l := 0 - switch x := q.(type) { - case *x: - h := x.c - 1 - for l <= h { - m := (l + h) >> 1 - mk = x.x[m].k - switch cmp := t.cmp(k, mk); { - case cmp > 0: - l = m + 1 - case cmp == 0: - return m, true - default: - h = m - 1 - } - } - case *d: - h := x.c - 1 - for l <= h { - m := (l + h) >> 1 - mk = x.d[m].k - switch cmp := t.cmp(k, mk); { - case cmp > 0: - l = m + 1 - case cmp == 0: - return m, true - default: - h = m - 1 - } - } - } - return l, false -} - -// First returns the first item of the tree in the key collating order, or -// (zero-value, zero-value) if the tree is empty. -func (t *Tree) First() (k int, v int) { - if q := t.first; q != nil { - q := &q.d[0] - k, v = q.k, q.v - } - return -} - -// Get returns the value associated with k and true if it exists. Otherwise Get -// returns (zero-value, false). -func (t *Tree) Get(k int) (v int, ok bool) { - q := t.r - if q == nil { - return - } - - for { - var i int - if i, ok = t.find(q, k); ok { - switch x := q.(type) { - case *x: - q = x.x[i+1].ch - continue - case *d: - return x.d[i].v, true - } - } - switch x := q.(type) { - case *x: - q = x.x[i].ch - default: - return - } - } -} - -func (t *Tree) insert(q *d, i int, k int, v int) *d { - t.ver++ - c := q.c - if i < c { - copy(q.d[i+1:], q.d[i:c]) - } - c++ - q.c = c - q.d[i].k, q.d[i].v = k, v - t.c++ - return q -} - -// Last returns the last item of the tree in the key collating order, or -// (zero-value, zero-value) if the tree is empty. -func (t *Tree) Last() (k int, v int) { - if q := t.last; q != nil { - q := &q.d[q.c-1] - k, v = q.k, q.v - } - return -} - -// Len returns the number of items in the tree. -func (t *Tree) Len() int { - return t.c -} - -func (t *Tree) overflow(p *x, q *d, pi, i int, k int, v int) { - t.ver++ - l, r := p.siblings(pi) - - if l != nil && l.c < 2*kd && i != 0 { - l.mvL(q, 1) - t.insert(q, i-1, k, v) - p.x[pi-1].k = q.d[0].k - return - } - - if r != nil && r.c < 2*kd { - if i < 2*kd { - q.mvR(r, 1) - t.insert(q, i, k, v) - p.x[pi].k = r.d[0].k - return - } - - t.insert(r, 0, k, v) - p.x[pi].k = k - return - } - - t.split(p, q, pi, i, k, v) -} - -// Seek returns an Enumerator positioned on an item such that k >= item's key. -// ok reports if k == item.key The Enumerator's position is possibly after the -// last item in the tree. -func (t *Tree) Seek(k int) (e *Enumerator, ok bool) { - q := t.r - if q == nil { - e = btEPool.get(nil, false, 0, k, nil, t, t.ver) - return - } - - for { - var i int - if i, ok = t.find(q, k); ok { - switch x := q.(type) { - case *x: - q = x.x[i+1].ch - continue - case *d: - return btEPool.get(nil, ok, i, k, x, t, t.ver), true - } - } - - switch x := q.(type) { - case *x: - q = x.x[i].ch - case *d: - return btEPool.get(nil, ok, i, k, x, t, t.ver), false - } - } -} - -// SeekFirst returns an enumerator positioned on the first KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returned and e will be nil. -func (t *Tree) SeekFirst() (e *Enumerator, err error) { - q := t.first - if q == nil { - return nil, io.EOF - } - - return btEPool.get(nil, true, 0, q.d[0].k, q, t, t.ver), nil -} - -// SeekLast returns an enumerator positioned on the last KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returned and e will be nil. -func (t *Tree) SeekLast() (e *Enumerator, err error) { - q := t.last - if q == nil { - return nil, io.EOF - } - - return btEPool.get(nil, true, q.c-1, q.d[q.c-1].k, q, t, t.ver), nil -} - -// Set sets the value associated with k. -func (t *Tree) Set(k int, v int) { - //dbg("--- PRE Set(%v, %v)\n%s", k, v, t.dump()) - //defer func() { - // dbg("--- POST\n%s\n====\n", t.dump()) - //}() - - pi := -1 - var p *x - q := t.r - if q == nil { - z := t.insert(btDPool.Get().(*d), 0, k, v) - t.r, t.first, t.last = z, z, z - return - } - - for { - i, ok := t.find(q, k) - if ok { - switch x := q.(type) { - case *x: - i++ - if x.c > 2*kx { - x, i = t.splitX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - continue - case *d: - x.d[i].v = v - } - return - } - - switch x := q.(type) { - case *x: - if x.c > 2*kx { - x, i = t.splitX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - case *d: - switch { - case x.c < 2*kd: - t.insert(x, i, k, v) - default: - t.overflow(p, x, pi, i, k, v) - } - return - } - } -} - -// Put combines Get and Set in a more efficient way where the tree is walked -// only once. The upd(ater) receives (old-value, true) if a KV pair for k -// exists or (zero-value, false) otherwise. It can then return a (new-value, -// true) to create or overwrite the existing value in the KV pair, or -// (whatever, false) if it decides not to create or not to update the value of -// the KV pair. -// -// tree.Set(k, v) call conceptually equals calling -// -// tree.Put(k, func(int, bool){ return v, true }) -// -// modulo the differing return values. -func (t *Tree) Put(k int, upd func(oldV int, exists bool) (newV int, write bool)) (oldV int, written bool) { - pi := -1 - var p *x - q := t.r - var newV int - if q == nil { - // new KV pair in empty tree - newV, written = upd(newV, false) - if !written { - return - } - - z := t.insert(btDPool.Get().(*d), 0, k, newV) - t.r, t.first, t.last = z, z, z - return - } - - for { - i, ok := t.find(q, k) - if ok { - switch x := q.(type) { - case *x: - i++ - if x.c > 2*kx { - x, i = t.splitX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - continue - case *d: - oldV = x.d[i].v - newV, written = upd(oldV, true) - if !written { - return - } - - x.d[i].v = newV - } - return - } - - switch x := q.(type) { - case *x: - if x.c > 2*kx { - x, i = t.splitX(p, x, pi, i) - } - pi = i - p = x - q = x.x[i].ch - case *d: // new KV pair - newV, written = upd(newV, false) - if !written { - return - } - - switch { - case x.c < 2*kd: - t.insert(x, i, k, newV) - default: - t.overflow(p, x, pi, i, k, newV) - } - return - } - } -} - -func (t *Tree) split(p *x, q *d, pi, i int, k int, v int) { - t.ver++ - r := btDPool.Get().(*d) - if q.n != nil { - r.n = q.n - r.n.p = r - } else { - t.last = r - } - q.n = r - r.p = q - - copy(r.d[:], q.d[kd:2*kd]) - for i := range q.d[kd:] { - q.d[kd+i] = zde - } - q.c = kd - r.c = kd - var done bool - if i > kd { - done = true - t.insert(r, i-kd, k, v) - } - if pi >= 0 { - p.insert(pi, r.d[0].k, r) - } else { - t.r = newX(q).insert(0, r.d[0].k, r) - } - if done { - return - } - - t.insert(q, i, k, v) -} - -func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, int) { - t.ver++ - r := btXPool.Get().(*x) - copy(r.x[:], q.x[kx+1:]) - q.c = kx - r.c = kx - if pi >= 0 { - p.insert(pi, q.x[kx].k, r) - } else { - t.r = newX(q).insert(0, q.x[kx].k, r) - } - - q.x[kx].k = zk - for i := range q.x[kx+1:] { - q.x[kx+i+1] = zxe - } - if i > kx { - q = r - i -= kx + 1 - } - - return q, i -} - -func (t *Tree) underflow(p *x, q *d, pi int) { - t.ver++ - l, r := p.siblings(pi) - - if l != nil && l.c+q.c >= 2*kd { - l.mvR(q, 1) - p.x[pi-1].k = q.d[0].k - return - } - - if r != nil && q.c+r.c >= 2*kd { - q.mvL(r, 1) - p.x[pi].k = r.d[0].k - r.d[r.c] = zde // GC - return - } - - if l != nil { - t.cat(p, l, q, pi-1) - return - } - - t.cat(p, q, r, pi) -} - -func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) { - t.ver++ - var l, r *x - - if pi >= 0 { - if pi > 0 { - l = p.x[pi-1].ch.(*x) - } - if pi < p.c { - r = p.x[pi+1].ch.(*x) - } - } - - if l != nil && l.c > kx { - q.x[q.c+1].ch = q.x[q.c].ch - copy(q.x[1:], q.x[:q.c]) - q.x[0].ch = l.x[l.c].ch - q.x[0].k = p.x[pi-1].k - q.c++ - i++ - l.c-- - p.x[pi-1].k = l.x[l.c].k - return q, i - } - - if r != nil && r.c > kx { - q.x[q.c].k = p.x[pi].k - q.c++ - q.x[q.c].ch = r.x[0].ch - p.x[pi].k = r.x[0].k - copy(r.x[:], r.x[1:r.c]) - r.c-- - rc := r.c - r.x[rc].ch = r.x[rc+1].ch - r.x[rc].k = zk - r.x[rc+1].ch = nil - return q, i - } - - if l != nil { - i += l.c + 1 - t.catX(p, l, q, pi-1) - q = l - return q, i - } - - t.catX(p, q, r, pi) - return q, i -} - -// ----------------------------------------------------------------- Enumerator - -// Close recycles e to a pool for possible later reuse. No references to e -// should exist or such references must not be used afterwards. -func (e *Enumerator) Close() { - *e = ze - btEPool.Put(e) -} - -// Next returns the currently enumerated item, if it exists and moves to the -// next item in the key collation order. If there is no item to return, err == -// io.EOF is returned. -func (e *Enumerator) Next() (k int, v int, err error) { - if err = e.err; err != nil { - return - } - - if e.ver != e.t.ver { - f, _ := e.t.Seek(e.k) - *e = *f - f.Close() - } - if e.q == nil { - e.err, err = io.EOF, io.EOF - return - } - - if e.i >= e.q.c { - if err = e.next(); err != nil { - return - } - } - - i := e.q.d[e.i] - k, v = i.k, i.v - e.k, e.hit = k, true - e.next() - return -} - -func (e *Enumerator) next() error { - if e.q == nil { - e.err = io.EOF - return io.EOF - } - - switch { - case e.i < e.q.c-1: - e.i++ - default: - if e.q, e.i = e.q.n, 0; e.q == nil { - e.err = io.EOF - } - } - return e.err -} - -// Prev returns the currently enumerated item, if it exists and moves to the -// previous item in the key collation order. If there is no item to return, err -// == io.EOF is returned. -func (e *Enumerator) Prev() (k int, v int, err error) { - if err = e.err; err != nil { - return - } - - if e.ver != e.t.ver { - f, _ := e.t.Seek(e.k) - *e = *f - f.Close() - } - if e.q == nil { - e.err, err = io.EOF, io.EOF - return - } - - if !e.hit { - // move to previous because Seek overshoots if there's no hit - if err = e.prev(); err != nil { - return - } - } - - if e.i >= e.q.c { - if err = e.prev(); err != nil { - return - } - } - - i := e.q.d[e.i] - k, v = i.k, i.v - e.k, e.hit = k, true - e.prev() - return -} - -func (e *Enumerator) prev() error { - if e.q == nil { - e.err = io.EOF - return io.EOF - } - - switch { - case e.i > 0: - e.i-- - default: - if e.q = e.q.p; e.q == nil { - e.err = io.EOF - break - } - - e.i = e.q.c - 1 - } - return e.err -} diff --git a/vendor/github.com/cznic/fileutil/LICENSE b/vendor/github.com/cznic/fileutil/LICENSE deleted file mode 100644 index 50bbdd241..000000000 --- a/vendor/github.com/cznic/fileutil/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014 The fileutil Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/fileutil/falloc/docs.go b/vendor/github.com/cznic/fileutil/falloc/docs.go deleted file mode 100644 index 21772fcd0..000000000 --- a/vendor/github.com/cznic/fileutil/falloc/docs.go +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -/* - -WIP: Package falloc provides allocation/deallocation of space within a -file/store (WIP, unstable API). - -Overall structure: - File == n blocks. - Block == n atoms. - Atom == 16 bytes. - -x6..x0 == least significant 7 bytes of a 64 bit integer, highest (7th) byte is -0 and is not stored in the file. - -Block first byte - -Aka block type tag. - ------------------------------------------------------------------------------- - -0xFF: Free atom (free block of size 1). - +------++---------++---------++------+ - | 0 || 1...7 || 8...14 || 15 | - +------++---------++---------++------+ - | 0xFF || p6...p0 || n6...n0 || 0xFF | - +------++---------++---------++------+ - -Link to the previous free block (atom addressed) is p6...p0, next dtto in -n6...n0. Doubly linked lists of "compatible" free blocks allows for free space -reclaiming and merging. "Compatible" == of size at least some K. Heads of all -such lists are organized per K or intervals of Ks elsewhere. - ------------------------------------------------------------------------------- - -0xFE: Free block, size == s6...s0 atoms. - +------++---------++---------++---------++-- - | +0 || 1...7 || 8...14 || 15...21 || 22...16*size-1 - +------++---------++---------++---------++-- - | 0xFE || p6...p0 || n6...n0 || s6...s0 || ... - +------++---------++---------++---------++-- - -Prev and next links as in the 0xFF first byte case. End of this block - see -"Block last byte": 0xFE bellow. Data between == undefined. - ------------------------------------------------------------------------------- - -0xFD: Relocated block. - +------++---------++-----------++------+ - | 0 || 1...7 || 8...14 || 15 | - +------++---------++-----------++------+ - | 0xFD || r6...r0 || undefined || 0x00 | // == used block - +------++---------++-----------++------+ - -Relocation link is r6..r0 == atom address. Relocations MUST NOT chain and MUST -point to a "content" block, i.e. one with the first byte in 0x00...0xFC. - -Relocated block allows to permanently assign a handle/file pointer ("atom" -address) to some content and resize the content anytime afterwards w/o having -to update all the possible existing references to the original handle. - ------------------------------------------------------------------------------- - -0xFC: Used long block. - +------++---------++--------------------++---------+---+ - | 0 || 1...2 || 3...N+2 || | | - +------++---------++--------------------++---------+---+ - | 0xFC || n1...n0 || N bytes of content || padding | Z | - +------++---------++--------------------++---------+---+ - -This block type is used for content of length in N == 238...61680 bytes. N is -encoded as a 2 byte unsigned integer n1..n0 in network byte order. Values -bellow 238 are reserved, those content lengths are to be carried by the -0x00..0xFB block types. - - 1. n in 0x00EE...0xF0F0 is used for content under the same rules - as in the 0x01..0xED type. - - 2. If the last byte of the content is not the last byte of an atom then - the last byte of the block is 0x00. - - 3. If the last byte of the content IS the last byte of an atom: - - 3.1 If the last byte of content is in 0x00..0xFD then everything is OK. - - 3.2 If the last byte of content is 0xFE or 0xFF then the escape - via n > 0xF0F0 MUST be used AND the block's last byte is 0x00 or 0x01, - meaning value 0xFE and 0xFF respectively. - - 4. n in 0xF0F1...0xFFFF is like the escaped 0xEE..0xFB block. - N == 13 + 16(n - 0xF0F1). - -Discussion of the padding and Z fields - see the 0x01..0xED block type. - ------------------------------------------------------------------------------- - -0xEE...0xFB: Used escaped short block. - +---++----------------------++---+ - | 0 || 1...N-1 || | - +---++----------------------++---+ - | X || N-1 bytes of content || Z | - +---++----------------------++---+ - -N == 15 + 16(X - 0xEE). Z is the content last byte encoded as follows. - -case Z == 0x00: The last byte of content is 0xFE - -case Z == 0x01: The last byte of content is 0xFF - ------------------------------------------------------------------------------- - -0x01...0xED: Used short block. - +---++--------------------++---------+---+ - | 0 || 1...N || | | - +---++--------------------++---------+---+ - | N || N bytes of content || padding | Z | - +---++--------------------++---------+---+ - -This block type is used for content of length in 1...237 bytes. The value of -the "padding" field, if of non zero length, is undefined. - -If the last byte of content is the last byte of an atom (== its file byte -offset & 0xF == 0xF) then such last byte MUST be in 0x00...0xFD. - -If the last byte of content is the last byte of an atom AND the last byte of -content is 0xFE or 0xFF then the short escape block type (0xEE...0xFB) MUST be -used. - -If the last byte of content is not the last byte of an atom, then the last byte -of such block, i.e. the Z field, which is also a last byte of some atom, MUST -be 0x00 (i.e. the used block marker). Other "tail" values are reserved. - ------------------------------------------------------------------------------- - -0x00: Used empty block. - +------++-----------++------+ - | 0 || 1...14 || 15 | - +------++-----------++------+ - | 0x00 || undefined || 0x00 | // == used block, other "tail" values reserved. - +------++-----------++------+ - -All of the rules for 0x01..0xED applies. Depicted only for its different -semantics (e.g. an allocated [existing] string but with length of zero). - -============================================================================== - -Block last byte - ------------------------------------------------------------------------------- - -0xFF: Free atom. Layout - see "Block first byte": FF. - ------------------------------------------------------------------------------- - -0xFE: Free block, size n atoms. Preceding 7 bytes == size (s6...s0) of the free -block in atoms, network byte order - --++---------++------+ - || -8...-2 || -1 | - --++---------++------+ - ... || s6...s0 || 0xFE | <- block's last byte - --++---------++------+ - -Layout at start of this block - see "Block first byte": FE. - ------------------------------------------------------------------------------- - -0x00...0xFD: Used (non free) block. - -============================================================================== - -Free lists table - -The free lists table content is stored in the standard layout of a used block. - -A table item is a 7 byte size field followed by a 7 byte atom address field -(both in network byte order), thus every item is 14 contiguous bytes. The -item's address field is pointing to a free block. The size field determines -the minimal size (in atoms) of free blocks on that list. - -The free list table is n above items, thus the content has 14n bytes. Note that -the largest block content is 61680 bytes and as there are 14 bytes per table -item, so the table is limited to at most 4405 entries. - -Items in the table do not have to be sorted according to their size field values. - -No two items can have the same value of the size field. - -When freeing blocks, the block MUST be linked into an item list with the -highest possible size field, which is less or equal to the number of atoms in -the new free block. - -When freeing a block, the block MUST be first merged with any adjacent free -blocks (thus possibly creating a bigger free block) using information derived -from the adjacent blocks first and last bytes. Such merged free blocks MUST be -removed from their original doubly linked lists. Afterwards the new bigger free -block is put to the free list table in the appropriate item. - -Items with address field == 0 are legal. Such item is a placeholder for a empty -list of free blocks of the item's size. - -Items with size field == 0 are legal. Such item is a placeholder, used e.g. to -avoid further reallocations/redirecting of the free lists table. - -The largest possible allocation request (for content length 61680 bytes) is -0xF10 (3856) atoms. All free blocks of this or bigger size are presumably put -into a single table item with the size 3856. It may be useful to additionally -have a free lists table item which links free blocks of some bigger size (say -1M+) and then use the OS sparse file support (if present) to save the physical -space used by such free blocks. - -Smaller (<3856 atoms) free blocks can be organized exactly (every distinct size -has its table item) or the sizes can run using other schema like e.g. "1, 2, -4, 8, ..." (powers of 2) or "1, 2, 3, 5, 8, 13, ..." (the Fibonacci sequence) -or they may be fine tuned to a specific usage pattern. - -============================================================================== - -Header - -The first block of a file (atom address == file offset == 0) is the file header. -The header block has the standard layout of a used short non escaped block. - -Special conditions apply: The header block and its content MUST be like this: - - +------+---------+---------+------+ - | 0 | 1...7 | 8...14 | 15 | - +------+---------+---------+------+ - | 0x0F | m6...m0 | f6...f0 | FLTT | - +------+---------+---------+------+ - -m6..m0 is a "magic" value 0xF1C1A1FE51B1E. - -f6...f0 is the atom address of the free lists table (discussed elsewhere). -If f6...f0 == 0x00 the there is no free lists table (yet). - -FLTT describes the type of the Free List Table. Currently defined values: - ------------------------------------------------------------------------------- - -FLTT == 0: Free List Table is fixed at atom address 2. It has a fixed size for 3856 entries -for free list of size 1..3855 atoms and the last is for the list of free block >= 3856 atoms. -*/ -package falloc - -const ( - INVALID_HANDLE = Handle(-1) -) diff --git a/vendor/github.com/cznic/fileutil/falloc/error.go b/vendor/github.com/cznic/fileutil/falloc/error.go deleted file mode 100644 index dad3d29e6..000000000 --- a/vendor/github.com/cznic/fileutil/falloc/error.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -package falloc - -import "fmt" - -// EBadRequest is an error produced for invalid operation, e.g. for data of more than maximum allowed. -type EBadRequest struct { - Name string - Size int -} - -func (e *EBadRequest) Error() string { - return fmt.Sprintf("%s: size %d", e.Name, e.Size) -} - -// EClose is a file/store close error. -type EClose struct { - Name string - Err error -} - -func (e *EClose) Error() string { - return fmt.Sprintf("%sx: %s", e.Name, e.Err) -} - -// ECorrupted is a file/store format error. -type ECorrupted struct { - Name string - Ofs int64 -} - -func (e *ECorrupted) Error() string { - return fmt.Sprintf("%s: corrupted data @%#x", e.Name, e.Ofs) -} - -// ECreate is a file/store create error. -type ECreate struct { - Name string - Err error -} - -func (e *ECreate) Error() string { - return fmt.Sprintf("%s: %s", e.Name, e.Err) -} - -// EFreeList is a file/store format error. -type EFreeList struct { - Name string - Size int64 - Block int64 -} - -func (e *EFreeList) Error() string { - return fmt.Sprintf("%s: invalid free list item, size %#x, block %#x", e.Name, e.Size, e.Block) -} - -// EHandle is an error type reported for invalid Handles. -type EHandle struct { - Name string - Handle Handle -} - -func (e EHandle) Error() string { - return fmt.Sprintf("%s: invalid handle %#x", e.Name, e.Handle) -} - -// EHeader is a file/store format error. -type EHeader struct { - Name string - Header []byte - Expected []byte -} - -func (e *EHeader) Error() string { - return fmt.Sprintf("%s: invalid header, got [% x], expected [% x]", e.Name, e.Header, e.Expected) -} - -// ENullHandle is a file/store access error via a null handle. -type ENullHandle string - -func (e ENullHandle) Error() string { - return fmt.Sprintf("%s: access via null handle", e) -} - -// EOpen is a file/store open error. -type EOpen struct { - Name string - Err error -} - -func (e *EOpen) Error() string { - return fmt.Sprintf("%s: %s", e.Name, e.Err) -} - -// ERead is a file/store read error. -type ERead struct { - Name string - Ofs int64 - Err error -} - -func (e *ERead) Error() string { - return fmt.Sprintf("%s, %#x: %s", e.Name, e.Ofs, e.Err) -} - -// ESize is a file/store size error. -type ESize struct { - Name string - Size int64 -} - -func (e *ESize) Error() string { - return fmt.Sprintf("%s: invalid size %#x(%d), size %%16 != 0", e.Name, e.Size, e.Size) -} - -// EWrite is a file/store write error. -type EWrite struct { - Name string - Ofs int64 - Err error -} - -func (e *EWrite) Error() string { - return fmt.Sprintf("%s, %#x: %s", e.Name, e.Ofs, e.Err) -} diff --git a/vendor/github.com/cznic/fileutil/falloc/falloc.go b/vendor/github.com/cznic/fileutil/falloc/falloc.go deleted file mode 100644 index 066a7047f..000000000 --- a/vendor/github.com/cznic/fileutil/falloc/falloc.go +++ /dev/null @@ -1,676 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -/* - -This is an mostly (WIP) conforming implementation of the "specs" in docs.go. - -The main incompletness is support for only one kind of FTL, though this table kind is still per "specs". - -*/ - -package falloc - -import ( - "bytes" - "github.com/cznic/fileutil/storage" - "sync" -) - -// Handle is a reference to a block in a file/store. -// Handle is an uint56 wrapped in an in64, i.e. the most significant byte must be always zero. -type Handle int64 - -// Put puts the 7 least significant bytes of h into b. The MSB of h should be zero. -func (h Handle) Put(b []byte) { - for ofs := 6; ofs >= 0; ofs-- { - b[ofs] = byte(h) - h >>= 8 - } -} - -// Get gets the 7 least significant bytes of h from b. The MSB of h is zeroed. -func (h *Handle) Get(b []byte) { - var x Handle - for ofs := 0; ofs <= 6; ofs++ { - x = x<<8 | Handle(b[ofs]) - } - *h = x -} - -// File is a file/store with space allocation/deallocation support. -type File struct { - f storage.Accessor - atoms int64 // current file size in atom units - canfree int64 // only blocks >= canfree can be subject to Free() - freetab [3857]int64 // freetab[0] is unused, freetab[1] is size 1 ptr, freetab[2] is size 2 ptr, ... - rwm sync.RWMutex -} - -func (f *File) read(b []byte, off int64) { - if n, err := f.f.ReadAt(b, off); n != len(b) { - panic(&ERead{f.f.Name(), off, err}) - } -} - -func (f *File) write(b []byte, off int64) { - if n, err := f.f.WriteAt(b, off); n != len(b) { - panic(&EWrite{f.f.Name(), off, err}) - } -} - -var ( // R/O - hdr = []byte{0x0f, 0xf1, 0xc1, 0xa1, 0xfe, 0xa5, 0x1b, 0x1e, 0, 0, 0, 0, 0, 0, 2, 0} // free lists table @2 - empty = make([]byte, 16) - zero = []byte{0} - zero7 = make([]byte, 7) -) - -// New returns a new File backed by store or an error if any. -// Any existing data in store are discarded. -func New(store storage.Accessor) (f *File, err error) { - f = &File{f: store} - return f, storage.Mutate(store, func() (err error) { - if err = f.f.Truncate(0); err != nil { - return &ECreate{f.f.Name(), err} - } - - if _, err = f.Alloc(hdr[1:]); err != nil { //TODO internal panicking versions of the exported fns. - return - } - - if _, err = f.Alloc(nil); err != nil { // (empty) root @1 - return - } - - b := make([]byte, 3856*14) - for i := 1; i <= 3856; i++ { - Handle(i).Put(b[(i-1)*14:]) - } - if _, err = f.Alloc(b); err != nil { - return - } - - f.canfree = f.atoms - return - }) -} - -// Open returns a new File backed by store or an error if any. -// Store already has to be in a valid format. -func Open(store storage.Accessor) (f *File, err error) { - defer func() { - if e := recover(); e != nil { - f = nil - err = e.(error) - } - }() - - fi, err := store.Stat() - if err != nil { - panic(&EOpen{store.Name(), err}) - } - - fs := fi.Size() - if fs&0xf != 0 { - panic(&ESize{store.Name(), fi.Size()}) - } - - f = &File{f: store, atoms: fs >> 4} - b := make([]byte, len(hdr)) - f.read(b, 0) - if !bytes.Equal(b, hdr) { - panic(&EHeader{store.Name(), b, append([]byte{}, hdr...)}) - } - - var atoms int64 - b, atoms = f.readUsed(2) - f.canfree = atoms + 2 - ofs := 0 - var size, p Handle - for ofs < len(b) { - size.Get(b[ofs:]) - ofs += 7 - p.Get(b[ofs:]) - ofs += 7 - if sz, pp := int64(size), int64(p); size == 0 || size > 3856 || (pp != 0 && pp < f.canfree) || pp<<4 > fs-16 { - panic(&EFreeList{store.Name(), sz, pp}) - } - - f.freetab[size] = int64(p) - } - return -} - -// Accessor returns the File's underlying Accessor. -func (f *File) Accessor() storage.Accessor { - return f.f -} - -// Close closes f and returns an error if any. -func (f *File) Close() (err error) { - return storage.Mutate(f.Accessor(), func() (err error) { - if err = f.f.Close(); err != nil { - err = &EClose{f.f.Name(), err} - } - return - }) -} - -// Root returns the handle of the DB root (top level directory, ...). -func (f *File) Root() Handle { - return 1 -} - -func (f *File) readUsed(atom int64) (content []byte, atoms int64) { - b, redirected := make([]byte, 7), false -redir: - ofs := atom << 4 - f.read(b[:1], ofs) - switch pre := b[0]; { - default: - panic(&ECorrupted{f.f.Name(), ofs}) - case pre == 0x00: // Empty block - case pre >= 1 && pre <= 237: // Short - content = make([]byte, pre) - f.read(content, ofs+1) - case pre >= 0xee && pre <= 0xfb: // Short esc - content = make([]byte, 15+16*(pre-0xee)) - f.read(content, ofs+1) - content[len(content)-1] += 0xfe - case pre == 0xfc: // Long - f.read(b[:2], ofs+1) - n := int(b[0])<<8 + int(b[1]) - switch { - default: - panic(&ECorrupted{f.f.Name(), ofs + 1}) - case n >= 238 && n <= 61680: // Long non esc - content = make([]byte, n) - f.read(content, ofs+3) - case n >= 61681: // Long esc - content = make([]byte, 13+16*(n-0xf0f1)) - f.read(content, ofs+3) - content[len(content)-1] += 0xfe - } - case pre == 0xfd: // redir - if redirected { - panic(&ECorrupted{f.f.Name(), ofs}) - } - - f.read(b[:7], ofs+1) - (*Handle)(&atom).Get(b) - redirected = true - goto redir - } - return content, rq2Atoms(len(content)) -} - -func (f *File) writeUsed(b []byte, atom int64) { - n := len(b) - switch ofs, atoms, endmark := atom<<4, rq2Atoms(n), true; { - default: - panic("internal error") - case n == 0: - f.write(empty, ofs) - case n <= 237: - if (n+1)&0xf == 0 { // content end == atom end - if v := b[n-1]; v >= 0xfe { // escape - pre := []byte{byte((16*0xee + n - 15) >> 4)} - f.write(pre, ofs) - f.write(b[:n-1], ofs+1) - f.write([]byte{v - 0xfe}, ofs+atoms<<4-1) - return - } - endmark = false - } - // non esacpe - pre := []byte{byte(n)} - f.write(pre, ofs) - f.write(b, ofs+1) - if endmark { - f.write(zero, ofs+atoms<<4-1) // last block byte <- used block - } - case n > 237 && n <= 61680: - if (n+3)&0xf == 0 { // content end == atom end - if v := b[n-1]; v >= 0xfe { // escape - x := (16*0xf0f1 + n - 13) >> 4 - pre := []byte{0xFC, byte(x >> 8), byte(x)} - f.write(pre, ofs) - f.write(b[:n-1], ofs+3) - f.write([]byte{v - 0xfe}, ofs+atoms<<4-1) - return - } - endmark = false - } - // non esacpe - pre := []byte{0xfc, byte(n >> 8), byte(n)} - f.write(pre, ofs) - f.write(b, ofs+3) - if endmark { - f.write(zero, ofs+atoms<<4-1) // last block byte <- used block - } - } -} - -func rq2Atoms(rqbytes int) (rqatoms int64) { - if rqbytes > 237 { - rqbytes += 2 - } - return int64(rqbytes>>4 + 1) -} - -func (f *File) extend(b []byte) (handle int64) { - handle = f.atoms - f.writeUsed(b, handle) - f.atoms += rq2Atoms(len(b)) - return -} - -// Alloc stores b in a newly allocated space and returns its handle and an error if any. -func (f *File) Alloc(b []byte) (handle Handle, err error) { - err = storage.Mutate(f.Accessor(), func() (err error) { - rqAtoms := rq2Atoms(len(b)) - if rqAtoms > 3856 { - return &EBadRequest{f.f.Name(), len(b)} - } - - for foundsize, foundp := range f.freetab[rqAtoms:] { - if foundp != 0 { - // this works only for the current unique sizes list (except the last item!) - size := int64(foundsize) + rqAtoms - handle = Handle(foundp) - if size == 3856 { - buf := make([]byte, 7) - f.read(buf, int64(handle)<<4+15) - (*Handle)(&size).Get(buf) - } - f.delFree(int64(handle), size) - if rqAtoms < size { - f.addFree(int64(handle)+rqAtoms, size-rqAtoms) - } - f.writeUsed(b, int64(handle)) - return - } - } - - handle = Handle(f.extend(b)) - return - }) - return -} - -// checkLeft returns the atom size of a free bleck left adjacent to block @atom. -// If that block is not free the returned size is 0. -func (f *File) checkLeft(atom int64) (size int64) { - if atom <= f.canfree { - return - } - - b := make([]byte, 7) - fp := atom << 4 - f.read(b[:1], fp-1) - switch last := b[0]; { - case last <= 0xfd: - // used block - case last == 0xfe: - f.read(b, fp-8) - (*Handle)(&size).Get(b) - case last == 0xff: - size = 1 - } - return -} - -// getInfo returns the block @atom type and size. -func (f *File) getInfo(atom int64) (pref byte, size int64) { - b := make([]byte, 7) - fp := atom << 4 - f.read(b[:1], fp) - switch pref = b[0]; { - case pref == 0: // Empty used - size = 1 - case pref >= 1 && pref <= 237: // Short - size = rq2Atoms(int(pref)) - case pref >= 0xee && pref <= 0xfb: // Short esc - size = rq2Atoms(15 + 16*int(pref-0xee)) - case pref == 0xfc: // Long - f.read(b[:2], fp+1) - n := int(b[0])<<8 + int(b[1]) - switch { - default: - panic(&ECorrupted{f.f.Name(), fp + 1}) - case n >= 238 && n <= 61680: // Long non esc - size = rq2Atoms(n) - case n >= 61681: // Long esc - size = rq2Atoms(13 + 16*(n-0xf0f1)) - } - case pref == 0xfd: // reloc - size = 1 - case pref == 0xfe: - f.read(b, fp+15) - (*Handle)(&size).Get(b) - case pref == 0xff: - size = 1 - } - return -} - -// getSize returns the atom size of the block @atom and wheter it is free. -func (f *File) getSize(atom int64) (size int64, isFree bool) { - var typ byte - typ, size = f.getInfo(atom) - isFree = typ >= 0xfe - return -} - -// checkRight returns the atom size of a free bleck right adjacent to block @atom,atoms. -// If that block is not free the returned size is 0. -func (f *File) checkRight(atom, atoms int64) (size int64) { - if atom+atoms >= f.atoms { - return - } - - if sz, free := f.getSize(atom + atoms); free { - size = sz - } - return -} - -// delFree removes the atoms@atom free block from the free block list -func (f *File) delFree(atom, atoms int64) { - b := make([]byte, 15) - size := int(atoms) - if n := len(f.freetab); atoms >= int64(n) { - size = n - 1 - } - fp := atom << 4 - f.read(b[1:], fp+1) - var prev, next Handle - prev.Get(b[1:]) - next.Get(b[8:]) - - switch { - case prev == 0 && next != 0: - next.Put(b) - f.write(b[:7], int64(32+3+7+(size-1)*14)) - f.write(zero7, int64(next)<<4+1) - f.freetab[size] = int64(next) - case prev != 0 && next == 0: - f.write(zero7, int64(prev)<<4+8) - case prev != 0 && next != 0: - prev.Put(b) - f.write(b[:7], int64(next)<<4+1) - next.Put(b) - f.write(b[:7], int64(prev)<<4+8) - default: // prev == 0 && next == 0: - f.write(zero7, int64(32+3+7+(size-1)*14)) - f.freetab[size] = 0 - } -} - -// addFree adds atoms@atom to the free block lists and marks it free. -func (f *File) addFree(atom, atoms int64) { - b := make([]byte, 7) - size := int(atoms) - if n := len(f.freetab); atoms >= int64(n) { - size = n - 1 - } - head := f.freetab[size] - if head == 0 { // empty list - f.makeFree(0, atom, atoms, 0) - Handle(atom).Put(b) - f.write(b, int64(32+3+7+(size-1)*14)) - f.freetab[size] = atom - return - } - - Handle(atom).Put(b) - f.write(b, head<<4+1) // head.prev = atom - f.makeFree(0, atom, atoms, head) // atom.next = head - f.write(b, int64(32+3+7+(size-1)*14)) - f.freetab[size] = atom -} - -// makeFree sets up the content of a free block atoms@atom, fills the prev and next links. -func (f *File) makeFree(prev, atom, atoms, next int64) { - b := make([]byte, 23) - fp := atom << 4 - if atoms == 1 { - b[0] = 0xff - Handle(prev).Put(b[1:]) - Handle(next).Put(b[8:]) - b[15] = 0xff - f.write(b[:16], fp) - return - } - - b[0] = 0xfe - Handle(prev).Put(b[1:]) - Handle(next).Put(b[8:]) - Handle(atoms).Put(b[15:]) - f.write(b[:22], fp) - b[22] = 0xfe - f.write(b[15:], fp+atoms<<4-8) -} - -// Read reads and return the data associated with handle and an error if any. -// Passing an invalid handle to Read may return invalid data without error. -// It's like getting garbage via passing an invalid pointer to C.memcopy(). -func (f *File) Read(handle Handle) (b []byte, err error) { - defer func() { - if e := recover(); e != nil { - b = nil - err = e.(error) - } - }() - - switch handle { - case 0: - panic(ENullHandle(f.f.Name())) - case 2: - panic(&EHandle{f.f.Name(), handle}) - default: - b, _ = f.readUsed(int64(handle)) - } - return -} - -// Free frees space associated with handle and returns an error if any. Passing an invalid -// handle to Free or reusing handle afterwards will probably corrupt the database or provide -// invalid data on Read. It's like corrupting memory via passing an invalid pointer to C.free() -// or reusing that pointer. -func (f *File) Free(handle Handle) (err error) { - return storage.Mutate(f.Accessor(), func() (err error) { - atom := int64(handle) - atoms, isFree := f.getSize(atom) - if isFree || atom < f.canfree { - return &EHandle{f.f.Name(), handle} - } - - leftFree, rightFree := f.checkLeft(atom), f.checkRight(atom, atoms) - switch { - case leftFree != 0 && rightFree != 0: - f.delFree(atom-leftFree, leftFree) - f.delFree(atom+atoms, rightFree) - f.addFree(atom-leftFree, leftFree+atoms+rightFree) - case leftFree != 0 && rightFree == 0: - f.delFree(atom-leftFree, leftFree) - if atom+atoms == f.atoms { // the left free neighbour and this block together are an empy tail - f.atoms = atom - leftFree - f.f.Truncate(f.atoms << 4) - return - } - - f.addFree(atom-leftFree, leftFree+atoms) - case leftFree == 0 && rightFree != 0: - f.delFree(atom+atoms, rightFree) - f.addFree(atom, atoms+rightFree) - default: // leftFree == 0 && rightFree == 0 - if atom+atoms < f.atoms { // isolated inner block - f.addFree(atom, atoms) - return - } - - f.f.Truncate(atom << 4) // isolated tail block, shrink file - f.atoms = atom - } - return - }) -} - -// Realloc reallocates space associted with handle to acomodate b, returns the newhandle -// newly associated with b and an error if any. If keepHandle == true then Realloc guarantees -// newhandle == handle even if the new data are larger then the previous content associated -// with handle. If !keepHandle && newhandle != handle then reusing handle will probably corrupt -// the database. -// The above effects are like corrupting memory/data via passing an invalid pointer to C.realloc(). -func (f *File) Realloc(handle Handle, b []byte, keepHandle bool) (newhandle Handle, err error) { - err = storage.Mutate(f.Accessor(), func() (err error) { - switch handle { - case 0, 2: - return &EHandle{f.f.Name(), handle} - case 1: - keepHandle = true - } - newhandle = handle - atom, newatoms := int64(handle), rq2Atoms(len(b)) - if newatoms > 3856 { - return &EBadRequest{f.f.Name(), len(b)} - } - - typ, oldatoms := f.getInfo(atom) - switch { - default: - return &ECorrupted{f.f.Name(), atom << 4} - case typ <= 0xfc: // non relocated used block - switch { - case newatoms == oldatoms: // in place replace - f.writeUsed(b, atom) - case newatoms < oldatoms: // in place shrink - rightFree := f.checkRight(atom, oldatoms) - if rightFree > 0 { // right join - f.delFree(atom+oldatoms, rightFree) - } - f.addFree(atom+newatoms, oldatoms+rightFree-newatoms) - f.writeUsed(b, atom) - case newatoms > oldatoms: - if rightFree := f.checkRight(atom, oldatoms); rightFree > 0 && newatoms <= oldatoms+rightFree { - f.delFree(atom+oldatoms, rightFree) - if newatoms < oldatoms+rightFree { - f.addFree(atom+newatoms, oldatoms+rightFree-newatoms) - } - f.writeUsed(b, atom) - return - } - - if !keepHandle { - f.Free(Handle(atom)) - newhandle, err = f.Alloc(b) - return - } - - // reloc - newatom, e := f.Alloc(b) - if e != nil { - return e - } - - buf := make([]byte, 16) - buf[0] = 0xfd - Handle(newatom).Put(buf[1:]) - f.Realloc(Handle(atom), buf[1:], true) - f.write(buf[:1], atom<<4) - } - case typ == 0xfd: // reloc - var target Handle - buf := make([]byte, 7) - f.read(buf, atom<<4+1) - target.Get(buf) - switch { - case newatoms == 1: - f.writeUsed(b, atom) - f.Free(target) - default: - if rightFree := f.checkRight(atom, 1); rightFree > 0 && newatoms <= 1+rightFree { - f.delFree(atom+1, rightFree) - if newatoms < 1+rightFree { - f.addFree(atom+newatoms, 1+rightFree-newatoms) - } - f.writeUsed(b, atom) - f.Free(target) - return - } - - newtarget, e := f.Realloc(Handle(target), b, false) - if e != nil { - return e - } - - if newtarget != target { - Handle(newtarget).Put(buf) - f.write(buf, atom<<4+1) - } - } - } - return - }) - return -} - -// Lock locks f for writing. If the lock is already locked for reading or writing, -// Lock blocks until the lock is available. To ensure that the lock eventually becomes available, -// a blocked Lock call excludes new readers from acquiring the lock. -func (f *File) Lock() { - f.rwm.Lock() -} - -// RLock locks f for reading. If the lock is already locked for writing or there is a writer -// already waiting to release the lock, RLock blocks until the writer has released the lock. -func (f *File) RLock() { - f.rwm.RLock() -} - -// Unlock unlocks f for writing. It is a run-time error if f is not locked for writing on entry to Unlock. -// -// As with Mutexes, a locked RWMutex is not associated with a particular goroutine. -// One goroutine may RLock (Lock) f and then arrange for another goroutine to RUnlock (Unlock) it. -func (f *File) Unlock() { - f.rwm.Unlock() -} - -// RUnlock undoes a single RLock call; it does not affect other simultaneous readers. -// It is a run-time error if f is not locked for reading on entry to RUnlock. -func (f *File) RUnlock() { - f.rwm.RUnlock() -} - -// LockedAlloc wraps Alloc in a Lock/Unlock pair. -func (f *File) LockedAlloc(b []byte) (handle Handle, err error) { - f.Lock() - defer f.Unlock() - return f.Alloc(b) -} - -// LockedFree wraps Free in a Lock/Unlock pair. -func (f *File) LockedFree(handle Handle) (err error) { - f.Lock() - defer f.Unlock() - return f.Free(handle) -} - -// LockedRead wraps Read in a RLock/RUnlock pair. -func (f *File) LockedRead(handle Handle) (b []byte, err error) { - f.RLock() - defer f.RUnlock() - return f.Read(handle) -} - -// LockedRealloc wraps Realloc in a Lock/Unlock pair. -func (f *File) LockedRealloc(handle Handle, b []byte, keepHandle bool) (newhandle Handle, err error) { - f.Lock() - defer f.Unlock() - return f.Realloc(handle, b, keepHandle) -} diff --git a/vendor/github.com/cznic/fileutil/falloc/test_deps.go b/vendor/github.com/cznic/fileutil/falloc/test_deps.go deleted file mode 100644 index 3bdd39f2b..000000000 --- a/vendor/github.com/cznic/fileutil/falloc/test_deps.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -package falloc - -// Pull test dependencies too. -// Enables easy 'go test X' after 'go get X' -import ( - _ "github.com/cznic/fileutil" - _ "github.com/cznic/fileutil/storage" - _ "github.com/cznic/mathutil" -) diff --git a/vendor/github.com/cznic/fileutil/fileutil.go b/vendor/github.com/cznic/fileutil/fileutil.go deleted file mode 100644 index 9c2fc038e..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil.go +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package fileutil collects some file utility functions. -package fileutil - -import ( - "fmt" - "io" - "os" - "path/filepath" - "runtime" - "strconv" - "sync" - "time" -) - -// GoMFile is a concurrent access safe version of MFile. -type GoMFile struct { - mfile *MFile - mutex sync.Mutex -} - -// NewGoMFile return a newly created GoMFile. -func NewGoMFile(fname string, flag int, perm os.FileMode, delta_ns int64) (m *GoMFile, err error) { - m = &GoMFile{} - if m.mfile, err = NewMFile(fname, flag, perm, delta_ns); err != nil { - m = nil - } - return -} - -func (m *GoMFile) File() (file *os.File, err error) { - m.mutex.Lock() - defer m.mutex.Unlock() - return m.mfile.File() -} - -func (m *GoMFile) SetChanged() { - m.mutex.Lock() - defer m.mutex.Unlock() - m.mfile.SetChanged() -} - -func (m *GoMFile) SetHandler(h MFileHandler) { - m.mutex.Lock() - defer m.mutex.Unlock() - m.mfile.SetHandler(h) -} - -// MFileHandler resolves modifications of File. -// Possible File context is expected to be a part of the handler's closure. -type MFileHandler func(*os.File) error - -// MFile represents an os.File with a guard/handler on change/modification. -// Example use case is an app with a configuration file which can be modified at any time -// and have to be reloaded in such event prior to performing something configurable by that -// file. The checks are made only on access to the MFile file by -// File() and a time threshold/hysteresis value can be chosen on creating a new MFile. -type MFile struct { - file *os.File - handler MFileHandler - t0 int64 - delta int64 - ctime int64 -} - -// NewMFile returns a newly created MFile or Error if any. -// The fname, flag and perm parameters have the same meaning as in os.Open. -// For meaning of the delta_ns parameter please see the (m *MFile) File() docs. -func NewMFile(fname string, flag int, perm os.FileMode, delta_ns int64) (m *MFile, err error) { - m = &MFile{} - m.t0 = time.Now().UnixNano() - if m.file, err = os.OpenFile(fname, flag, perm); err != nil { - return - } - - var fi os.FileInfo - if fi, err = m.file.Stat(); err != nil { - return - } - - m.ctime = fi.ModTime().UnixNano() - m.delta = delta_ns - runtime.SetFinalizer(m, func(m *MFile) { - m.file.Close() - }) - return -} - -// SetChanged forces next File() to unconditionally handle modification of the wrapped os.File. -func (m *MFile) SetChanged() { - m.ctime = -1 -} - -// SetHandler sets a function to be invoked when modification of MFile is to be processed. -func (m *MFile) SetHandler(h MFileHandler) { - m.handler = h -} - -// File returns an os.File from MFile. If time elapsed between the last invocation of this function -// and now is at least delta_ns ns (a parameter of NewMFile) then the file is checked for -// change/modification. For delta_ns == 0 the modification is checked w/o getting os.Time(). -// If a change is detected a handler is invoked on the MFile file. -// Any of these steps can produce an Error. If that happens the function returns nil, Error. -func (m *MFile) File() (file *os.File, err error) { - var now int64 - - mustCheck := m.delta == 0 - if !mustCheck { - now = time.Now().UnixNano() - mustCheck = now-m.t0 > m.delta - } - - if mustCheck { // check interval reached - var fi os.FileInfo - if fi, err = m.file.Stat(); err != nil { - return - } - - if fi.ModTime().UnixNano() != m.ctime { // modification detected - if m.handler == nil { - return nil, fmt.Errorf("no handler set for modified file %q", m.file.Name()) - } - if err = m.handler(m.file); err != nil { - return - } - - m.ctime = fi.ModTime().UnixNano() - } - m.t0 = now - } - - return m.file, nil -} - -// Read reads buf from r. It will either fill the full buf or fail. -// It wraps the functionality of an io.Reader which may return less bytes than requested, -// but may block if not all data are ready for the io.Reader. -func Read(r io.Reader, buf []byte) (err error) { - have := 0 - remain := len(buf) - got := 0 - for remain > 0 { - if got, err = r.Read(buf[have:]); err != nil { - return - } - - remain -= got - have += got - } - return -} - -// "os" and/or "syscall" extensions - -// FadviseAdvice is used by Fadvise. -type FadviseAdvice int - -// FAdviseAdvice values. -const ( - // $ grep FADV /usr/include/bits/fcntl.h - POSIX_FADV_NORMAL FadviseAdvice = iota // No further special treatment. - POSIX_FADV_RANDOM // Expect random page references. - POSIX_FADV_SEQUENTIAL // Expect sequential page references. - POSIX_FADV_WILLNEED // Will need these pages. - POSIX_FADV_DONTNEED // Don't need these pages. - POSIX_FADV_NOREUSE // Data will be accessed once. -) - -// TempFile creates a new temporary file in the directory dir with a name -// ending with suffix, basename starting with prefix, opens the file for -// reading and writing, and returns the resulting *os.File. If dir is the -// empty string, TempFile uses the default directory for temporary files (see -// os.TempDir). Multiple programs calling TempFile simultaneously will not -// choose the same file. The caller can use f.Name() to find the pathname of -// the file. It is the caller's responsibility to remove the file when no -// longer needed. -// -// NOTE: This function differs from ioutil.TempFile. -func TempFile(dir, prefix, suffix string) (f *os.File, err error) { - if dir == "" { - dir = os.TempDir() - } - - nconflict := 0 - for i := 0; i < 10000; i++ { - name := filepath.Join(dir, prefix+nextInfix()+suffix) - f, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) - if os.IsExist(err) { - if nconflict++; nconflict > 10 { - randmu.Lock() - rand = reseed() - randmu.Unlock() - } - continue - } - break - } - return -} - -// Random number state. -// We generate random temporary file names so that there's a good -// chance the file doesn't exist yet - keeps the number of tries in -// TempFile to a minimum. -var rand uint32 -var randmu sync.Mutex - -func reseed() uint32 { - return uint32(time.Now().UnixNano() + int64(os.Getpid())) -} - -func nextInfix() string { - randmu.Lock() - r := rand - if r == 0 { - r = reseed() - } - r = r*1664525 + 1013904223 // constants from Numerical Recipes - rand = r - randmu.Unlock() - return strconv.Itoa(int(1e9 + r%1e9))[1:] -} diff --git a/vendor/github.com/cznic/fileutil/fileutil_arm.go b/vendor/github.com/cznic/fileutil/fileutil_arm.go deleted file mode 100644 index c7b54f02b..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil_arm.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package fileutil - -import ( - "io" - "os" -) - -const hasPunchHole = false - -// PunchHole deallocates space inside a file in the byte range starting at -// offset and continuing for len bytes. Not supported on ARM. -func PunchHole(f *os.File, off, len int64) error { - return nil -} - -// Fadvise predeclares an access pattern for file data. See also 'man 2 -// posix_fadvise'. Not supported on ARM. -func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error { - return nil -} - -// IsEOF reports whether err is an EOF condition. -func IsEOF(err error) bool { return err == io.EOF } diff --git a/vendor/github.com/cznic/fileutil/fileutil_darwin.go b/vendor/github.com/cznic/fileutil/fileutil_darwin.go deleted file mode 100644 index 5d939b2fa..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil_darwin.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !arm - -package fileutil - -import ( - "io" - "os" -) - -const hasPunchHole = false - -// PunchHole deallocates space inside a file in the byte range starting at -// offset and continuing for len bytes. Not supported on OSX. -func PunchHole(f *os.File, off, len int64) error { - return nil -} - -// Fadvise predeclares an access pattern for file data. See also 'man 2 -// posix_fadvise'. Not supported on OSX. -func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error { - return nil -} - -// IsEOF reports whether err is an EOF condition. -func IsEOF(err error) bool { return err == io.EOF } diff --git a/vendor/github.com/cznic/fileutil/fileutil_freebsd.go b/vendor/github.com/cznic/fileutil/fileutil_freebsd.go deleted file mode 100644 index 5a769939d..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil_freebsd.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !arm - -package fileutil - -import ( - "io" - "os" -) - -const hasPunchHole = false - -// PunchHole deallocates space inside a file in the byte range starting at -// offset and continuing for len bytes. Unimplemented on FreeBSD. -func PunchHole(f *os.File, off, len int64) error { - return nil -} - -// Fadvise predeclares an access pattern for file data. See also 'man 2 -// posix_fadvise'. Unimplemented on FreeBSD. -func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error { - return nil -} - -// IsEOF reports whether err is an EOF condition. -func IsEOF(err error) bool { return err == io.EOF } diff --git a/vendor/github.com/cznic/fileutil/fileutil_linux.go b/vendor/github.com/cznic/fileutil/fileutil_linux.go deleted file mode 100644 index a894cb726..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil_linux.go +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !arm - -package fileutil - -import ( - "bytes" - "io" - "io/ioutil" - "os" - "strconv" - "syscall" -) - -const hasPunchHole = true - -func n(s []byte) byte { - for i, c := range s { - if c < '0' || c > '9' { - s = s[:i] - break - } - } - v, _ := strconv.Atoi(string(s)) - return byte(v) -} - -func init() { - b, err := ioutil.ReadFile("/proc/sys/kernel/osrelease") - if err != nil { - panic(err) - } - - tokens := bytes.Split(b, []byte(".")) - if len(tokens) > 3 { - tokens = tokens[:3] - } - switch len(tokens) { - case 3: - // Supported since kernel 2.6.38 - if bytes.Compare([]byte{n(tokens[0]), n(tokens[1]), n(tokens[2])}, []byte{2, 6, 38}) < 0 { - puncher = func(*os.File, int64, int64) error { return nil } - } - case 2: - if bytes.Compare([]byte{n(tokens[0]), n(tokens[1])}, []byte{2, 7}) < 0 { - puncher = func(*os.File, int64, int64) error { return nil } - } - default: - puncher = func(*os.File, int64, int64) error { return nil } - } -} - -var puncher = func(f *os.File, off, len int64) error { - const ( - /* - /usr/include/linux$ grep FL_ falloc.h - */ - _FALLOC_FL_KEEP_SIZE = 0x01 // default is extend size - _FALLOC_FL_PUNCH_HOLE = 0x02 // de-allocates range - ) - - _, _, errno := syscall.Syscall6( - syscall.SYS_FALLOCATE, - uintptr(f.Fd()), - uintptr(_FALLOC_FL_KEEP_SIZE|_FALLOC_FL_PUNCH_HOLE), - uintptr(off), - uintptr(len), - 0, 0) - if errno != 0 { - return os.NewSyscallError("SYS_FALLOCATE", errno) - } - return nil -} - -// PunchHole deallocates space inside a file in the byte range starting at -// offset and continuing for len bytes. No-op for kernels < 2.6.38 (or < 2.7). -func PunchHole(f *os.File, off, len int64) error { - return puncher(f, off, len) -} - -// Fadvise predeclares an access pattern for file data. See also 'man 2 -// posix_fadvise'. -func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error { - _, _, errno := syscall.Syscall6( - syscall.SYS_FADVISE64, - uintptr(f.Fd()), - uintptr(off), - uintptr(len), - uintptr(advice), - 0, 0) - return os.NewSyscallError("SYS_FADVISE64", errno) -} - -// IsEOF reports whether err is an EOF condition. -func IsEOF(err error) bool { return err == io.EOF } diff --git a/vendor/github.com/cznic/fileutil/fileutil_netbsd.go b/vendor/github.com/cznic/fileutil/fileutil_netbsd.go deleted file mode 100644 index d64102143..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil_netbsd.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !arm - -package fileutil - -import ( - "io" - "os" -) - -const hasPunchHole = false - -// PunchHole deallocates space inside a file in the byte range starting at -// offset and continuing for len bytes. Similar to FreeBSD, this is -// unimplemented. -func PunchHole(f *os.File, off, len int64) error { - return nil -} - -// Unimplemented on NetBSD. -func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error { - return nil -} - -// IsEOF reports whether err is an EOF condition. -func IsEOF(err error) bool { return err == io.EOF } diff --git a/vendor/github.com/cznic/fileutil/fileutil_openbsd.go b/vendor/github.com/cznic/fileutil/fileutil_openbsd.go deleted file mode 100644 index 5c0898916..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil_openbsd.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package fileutil - -import ( - "io" - "os" -) - -const hasPunchHole = false - -// PunchHole deallocates space inside a file in the byte range starting at -// offset and continuing for len bytes. Similar to FreeBSD, this is -// unimplemented. -func PunchHole(f *os.File, off, len int64) error { - return nil -} - -// Unimplemented on OpenBSD. -func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error { - return nil -} - -// IsEOF reports whether err is an EOF condition. -func IsEOF(err error) bool { return err == io.EOF } diff --git a/vendor/github.com/cznic/fileutil/fileutil_plan9.go b/vendor/github.com/cznic/fileutil/fileutil_plan9.go deleted file mode 100644 index 86787e5a9..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil_plan9.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package fileutil - -import ( - "io" - "os" -) - -const hasPunchHole = false - -// PunchHole deallocates space inside a file in the byte range starting at -// offset and continuing for len bytes. Unimplemented on Plan 9. -func PunchHole(f *os.File, off, len int64) error { - return nil -} - -// Fadvise predeclares an access pattern for file data. See also 'man 2 -// posix_fadvise'. Unimplemented on Plan 9. -func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error { - return nil -} - -// IsEOF reports whether err is an EOF condition. -func IsEOF(err error) bool { return err == io.EOF } diff --git a/vendor/github.com/cznic/fileutil/fileutil_solaris.go b/vendor/github.com/cznic/fileutil/fileutil_solaris.go deleted file mode 100644 index 3866686b6..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil_solaris.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2013 jnml. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build go1.3 - -package fileutil - -import ( - "io" - "os" -) - -const hasPunchHole = false - -// PunchHole deallocates space inside a file in the byte range starting at -// offset and continuing for len bytes. Not supported on Solaris. -func PunchHole(f *os.File, off, len int64) error { - return nil -} - -// Fadvise predeclares an access pattern for file data. See also 'man 2 -// posix_fadvise'. Not supported on Solaris. -func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error { - return nil -} - -// IsEOF reports whether err is an EOF condition. -func IsEOF(err error) bool { return err == io.EOF } diff --git a/vendor/github.com/cznic/fileutil/fileutil_windows.go b/vendor/github.com/cznic/fileutil/fileutil_windows.go deleted file mode 100644 index 1e5d62978..000000000 --- a/vendor/github.com/cznic/fileutil/fileutil_windows.go +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package fileutil - -import ( - "io" - "os" - "sync" - "syscall" - "unsafe" -) - -const hasPunchHole = true - -// PunchHole deallocates space inside a file in the byte range starting at -// offset and continuing for len bytes. Not supported on Windows. -func PunchHole(f *os.File, off, len int64) error { - return puncher(f, off, len) -} - -// Fadvise predeclares an access pattern for file data. See also 'man 2 -// posix_fadvise'. Not supported on Windows. -func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error { - return nil -} - -// IsEOF reports whether err is an EOF condition. -func IsEOF(err error) bool { - if err == io.EOF { - return true - } - - // http://social.technet.microsoft.com/Forums/windowsserver/en-US/1a16311b-c625-46cf-830b-6a26af488435/how-to-solve-error-38-0x26-errorhandleeof-using-fsctlgetretrievalpointers - x, ok := err.(*os.PathError) - return ok && x.Op == "read" && x.Err.(syscall.Errno) == 0x26 -} - -var ( - modkernel32 = syscall.NewLazyDLL("kernel32.dll") - - procDeviceIOControl = modkernel32.NewProc("DeviceIoControl") - - sparseFilesMu sync.Mutex - sparseFiles map[uintptr]struct{} -) - -func init() { - // sparseFiles is an fd set for already "sparsed" files - according to - // msdn.microsoft.com/en-us/library/windows/desktop/aa364225(v=vs.85).aspx - // the file handles are unique per process. - sparseFiles = make(map[uintptr]struct{}) -} - -// puncHoleWindows punches a hole into the given file starting at offset, -// measuring "size" bytes -// (http://msdn.microsoft.com/en-us/library/windows/desktop/aa364597%28v=vs.85%29.aspx) -func puncher(file *os.File, offset, size int64) error { - if err := ensureFileSparse(file); err != nil { - return err - } - - // http://msdn.microsoft.com/en-us/library/windows/desktop/aa364411%28v=vs.85%29.aspx - // typedef struct _FILE_ZERO_DATA_INFORMATION { - // LARGE_INTEGER FileOffset; - // LARGE_INTEGER BeyondFinalZero; - //} FILE_ZERO_DATA_INFORMATION, *PFILE_ZERO_DATA_INFORMATION; - type fileZeroDataInformation struct { - FileOffset, BeyondFinalZero int64 - } - - lpInBuffer := fileZeroDataInformation{ - FileOffset: offset, - BeyondFinalZero: offset + size} - return deviceIOControl(false, file.Fd(), uintptr(unsafe.Pointer(&lpInBuffer)), 16) -} - -// // http://msdn.microsoft.com/en-us/library/windows/desktop/cc948908%28v=vs.85%29.aspx -// type fileSetSparseBuffer struct { -// SetSparse bool -// } - -func ensureFileSparse(file *os.File) (err error) { - fd := file.Fd() - sparseFilesMu.Lock() - if _, ok := sparseFiles[fd]; ok { - sparseFilesMu.Unlock() - return nil - } - - if err = deviceIOControl(true, fd, 0, 0); err == nil { - sparseFiles[fd] = struct{}{} - } - sparseFilesMu.Unlock() - return err -} - -func deviceIOControl(setSparse bool, fd, inBuf, inBufLen uintptr) (err error) { - const ( - //http://source.winehq.org/source/include/winnt.h#L4605 - file_read_data = 1 - file_write_data = 2 - - // METHOD_BUFFERED 0 - method_buffered = 0 - // FILE_ANY_ACCESS 0 - file_any_access = 0 - // FILE_DEVICE_FILE_SYSTEM 0x00000009 - file_device_file_system = 0x00000009 - // FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS) - file_special_access = file_any_access - file_read_access = file_read_data - file_write_access = file_write_data - - // http://source.winehq.org/source/include/winioctl.h - // #define CTL_CODE ( DeviceType, - // Function, - // Method, - // Access ) - // ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) - - // FSCTL_SET_COMPRESSION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 16, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA) - fsctl_set_compression = (file_device_file_system << 16) | ((file_read_access | file_write_access) << 14) | (16 << 2) | method_buffered - // FSCTL_SET_SPARSE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) - fsctl_set_sparse = (file_device_file_system << 16) | (file_special_access << 14) | (49 << 2) | method_buffered - // FSCTL_SET_ZERO_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 50, METHOD_BUFFERED, FILE_WRITE_DATA) - fsctl_set_zero_data = (file_device_file_system << 16) | (file_write_data << 14) | (50 << 2) | method_buffered - ) - retPtr := uintptr(unsafe.Pointer(&(make([]byte, 8)[0]))) - var r1 uintptr - var e1 syscall.Errno - if setSparse { - // BOOL - // WINAPI - // DeviceIoControl( (HANDLE) hDevice, // handle to a file - // FSCTL_SET_SPARSE, // dwIoControlCode - // (PFILE_SET_SPARSE_BUFFER) lpInBuffer, // input buffer - // (DWORD) nInBufferSize, // size of input buffer - // NULL, // lpOutBuffer - // 0, // nOutBufferSize - // (LPDWORD) lpBytesReturned, // number of bytes returned - // (LPOVERLAPPED) lpOverlapped ); // OVERLAPPED structure - r1, _, e1 = syscall.Syscall9(procDeviceIOControl.Addr(), 8, - fd, - uintptr(fsctl_set_sparse), - // If the lpInBuffer parameter is NULL, the operation will behave the same as if the SetSparse member of the FILE_SET_SPARSE_BUFFER structure were TRUE. In other words, the operation sets the file to a sparse file. - 0, // uintptr(unsafe.Pointer(&lpInBuffer)), - 0, // 1, - 0, - 0, - retPtr, - 0, - 0) - } else { - // BOOL - // WINAPI - // DeviceIoControl( (HANDLE) hDevice, // handle to a file - // FSCTL_SET_ZERO_DATA, // dwIoControlCode - // (LPVOID) lpInBuffer, // input buffer - // (DWORD) nInBufferSize, // size of input buffer - // NULL, // lpOutBuffer - // 0, // nOutBufferSize - // (LPDWORD) lpBytesReturned, // number of bytes returned - // (LPOVERLAPPED) lpOverlapped ); // OVERLAPPED structure - r1, _, e1 = syscall.Syscall9(procDeviceIOControl.Addr(), 8, - fd, - uintptr(fsctl_set_zero_data), - inBuf, - inBufLen, - 0, - 0, - retPtr, - 0, - 0) - } - if r1 == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return err -} diff --git a/vendor/github.com/cznic/fileutil/hdb/hdb.go b/vendor/github.com/cznic/fileutil/hdb/hdb.go deleted file mode 100644 index 7c7113d9d..000000000 --- a/vendor/github.com/cznic/fileutil/hdb/hdb.go +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -/* -WIP: Package hdb provides a "handle"/value DB like store, but actually it's -closer to the model of a process's virtual memory and its alloc, free and move -methods. - -The hdb package is a thin layer around falloc.File providing stable-only -handles and the basic synchronizing primitives. The central functionality of -hdb are the New, Set, Get and Delete methods of Store. - -Conceptual analogy: - New alloc(sizeof(content)), return new "memory" pointer (a handle). - - Get memmove() from "memory" "pointed to" by handle to the result content. - Note: Handle "knows" the size of its content. - - Set memmove() from content to "memory" pointed to by handle. - In contrast to real memory, the new content may have different - size than the previously stored one w/o additional handling - and the "pointer" handle remains the same. - - Delete free() the "memory" "pointed to" by handle. -*/ -package hdb - -import ( - "github.com/cznic/fileutil/falloc" - "github.com/cznic/fileutil/storage" -) - -type Store struct { - f *falloc.File -} - -// New returns a newly created Store backed by accessor, discarding its conents if any. -// If successful, methods on the returned Store can be used for I/O. -// It returns the Store and an error, if any. -func New(accessor storage.Accessor) (store *Store, err error) { - s := &Store{} - if s.f, err = falloc.New(accessor); err == nil { - store = s - } - return -} - -// Open opens the Store from accessor. -// If successful, methods on the returned Store can be used for data exchange. -// It returns the Store and an error, if any. -func Open(accessor storage.Accessor) (store *Store, err error) { - s := &Store{} - if s.f, err = falloc.Open(accessor); err == nil { - store = s - } - return -} - -// Close closes the store. Further access to the store has undefined behavior and may panic. -// It returns an error, if any. -func (s *Store) Close() (err error) { - defer func() { - s.f = nil - }() - - return s.f.Close() -} - -// Delete deletes the data associated with handle. -// It returns an error if any. -func (s *Store) Delete(handle falloc.Handle) (err error) { - return s.f.Free(handle) -} - -// Get gets the data associated with handle. -// It returns the data and an error, if any. -func (s *Store) Get(handle falloc.Handle) (b []byte, err error) { - return s.f.Read(handle) -} - -// New associates data with a new handle. -// It returns the handle and an error, if any. -func (s *Store) New(b []byte) (handle falloc.Handle, err error) { - return s.f.Alloc(b) -} - -// Set associates data with an existing handle. -// It returns an error, if any. -func (s *Store) Set(handle falloc.Handle, b []byte) (err error) { - _, err = s.f.Realloc(handle, b, true) - return -} - -// Root returns the handle of the DB root (top level directory, ...). -func (s *Store) Root() falloc.Handle { - return s.f.Root() -} - -// File returns the underlying falloc.File of 's'. -func (s *Store) File() *falloc.File { - return s.f -} - -// Lock locks 's' for writing. If the lock is already locked for reading or writing, -// Lock blocks until the lock is available. To ensure that the lock eventually becomes available, -// a blocked Lock call excludes new readers from acquiring the lock. -func (s *Store) Lock() { - s.f.Lock() -} - -// RLock locks 's' for reading. If the lock is already locked for writing or there is a writer -// already waiting to release the lock, RLock blocks until the writer has released the lock. -func (s *Store) RLock() { - s.f.RLock() -} - -// Unlock unlocks 's' for writing. It's a run-time error if 's' is not locked for writing on entry to Unlock. -// -// As with Mutexes, a locked RWMutex is not associated with a particular goroutine. -// One goroutine may RLock (Lock) 's' and then arrange for another goroutine to RUnlock (Unlock) it. -func (s *Store) Unlock() { - s.f.Unlock() -} - -// RUnlock undoes a single RLock call; it does not affect other simultaneous readers. -// It's a run-time error if 's' is not locked for reading on entry to RUnlock. -func (s *Store) RUnlock() { - s.f.RUnlock() -} - -// LockedNew wraps New in a Lock/Unlock pair. -func (s *Store) LockedNew(b []byte) (handle falloc.Handle, err error) { - return s.f.LockedAlloc(b) -} - -// LockedDelete wraps Delete in a Lock/Unlock pair. -func (s *Store) LockedDelete(handle falloc.Handle) (err error) { - return s.f.LockedFree(handle) -} - -// LockedGet wraps Get in a RLock/RUnlock pair. -func (s *Store) LockedGet(handle falloc.Handle) (b []byte, err error) { - return s.f.LockedRead(handle) -} - -// LockedSet wraps Set in a Lock/Unlock pair. -func (s *Store) LockedSet(handle falloc.Handle, b []byte) (err error) { - _, err = s.f.Realloc(handle, b, true) - return -} diff --git a/vendor/github.com/cznic/fileutil/hdb/test_deps.go b/vendor/github.com/cznic/fileutil/hdb/test_deps.go deleted file mode 100644 index 3164f63ae..000000000 --- a/vendor/github.com/cznic/fileutil/hdb/test_deps.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -package hdb - -// Pull test dependencies too. -// Enables easy 'go test X' after 'go get X' -import ( -// nothing yet -) diff --git a/vendor/github.com/cznic/fileutil/storage/cache.go b/vendor/github.com/cznic/fileutil/storage/cache.go deleted file mode 100644 index 3a6115a71..000000000 --- a/vendor/github.com/cznic/fileutil/storage/cache.go +++ /dev/null @@ -1,322 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -package storage - -import ( - "container/list" - "io" - "math" - "os" - "sync" - "sync/atomic" -) - -type cachepage struct { - b [512]byte - dirty bool - lru *list.Element - pi int64 - valid int // page content is b[:valid] -} - -func (p *cachepage) wr(b []byte, off int) (wasDirty bool) { - copy(p.b[off:], b) - if n := off + len(b); n > p.valid { - p.valid = n - } - wasDirty = p.dirty - p.dirty = true - return -} - -func (c *Cache) rd(off int64, read bool) (p *cachepage, ok bool) { - c.Rq++ - pi := off >> 9 - if p, ok = c.m[pi]; ok { - c.lru.MoveToBack(p.lru) - return - } - - if !read { - return - } - - fp := off &^ 511 - if fp >= c.size { - return - } - - rq := 512 - if fp+512 > c.size { - rq = int(c.size - fp) - } - p = &cachepage{pi: pi, valid: rq} - p.lru = c.lru.PushBack(p) - if n, err := c.f.ReadAt(p.b[:p.valid], fp); n != rq { - panic(err) - } - - c.Load++ - if c.advise != nil { - c.advise(fp, 512, false) - } - c.m[pi], ok = p, true - return -} - -func (c *Cache) wr(off int64) (p *cachepage) { - var ok bool - if p, ok = c.rd(off, false); ok { - return - } - - pi := off >> 9 - p = &cachepage{pi: pi} - p.lru = c.lru.PushBack(p) - c.m[pi] = p - return -} - -// Cache provides caching support for another store Accessor. -type Cache struct { - advise func(int64, int, bool) - clean chan bool - cleaning int32 - close chan bool - f Accessor - fi *FileInfo - lock sync.Mutex - lru *list.List - m map[int64]*cachepage - maxpages int - size int64 - sync chan bool - wlist *list.List - write chan bool - writing int32 - Rq int64 // Pages requested from cache - Load int64 // Pages loaded (cache miss) - Purge int64 // Pages purged - Top int // "High water" pages -} - -// Implementation of Accessor. -func (c *Cache) BeginUpdate() error { return nil } - -// Implementation of Accessor. -func (c *Cache) EndUpdate() error { return nil } - -// NewCache creates a caching Accessor from store with total of maxcache bytes. -// NewCache returns the new Cache, implementing Accessor or an error if any. -// -// The LRU mechanism is used, so the cache tries to keep often accessed pages cached. -// -func NewCache(store Accessor, maxcache int64, advise func(int64, int, bool)) (c *Cache, err error) { - var fi os.FileInfo - if fi, err = store.Stat(); err != nil { - return - } - - x := maxcache >> 9 - if x > math.MaxInt32/2 { - x = math.MaxInt32 / 2 - } - c = &Cache{ - advise: advise, - clean: make(chan bool, 1), - close: make(chan bool), - f: store, - lru: list.New(), // front == oldest used, back == last recently used - m: make(map[int64]*cachepage), - maxpages: int(x), - size: fi.Size(), - sync: make(chan bool), - wlist: list.New(), - write: make(chan bool, 1), - } - c.fi = NewFileInfo(fi, c) - go c.writer() - go c.cleaner(int((int64(c.maxpages) * 95) / 100)) // hysteresis - return -} - -func (c *Cache) Accessor() Accessor { - return c.f -} - -func (c *Cache) Close() (err error) { - close(c.write) - <-c.close - close(c.clean) - <-c.close - return c.f.Close() -} - -func (c *Cache) Name() (s string) { - return c.f.Name() -} - -func (c *Cache) ReadAt(b []byte, off int64) (n int, err error) { - po := int(off) & 0x1ff - bp := 0 - rem := len(b) - m := 0 - for rem != 0 { - c.lock.Lock() // X1+ - p, ok := c.rd(off, true) - if !ok { - c.lock.Unlock() // X1- - return -1, io.EOF - } - - rq := rem - if po+rq > 512 { - rq = 512 - po - } - if n := copy(b[bp:bp+rq], p.b[po:p.valid]); n != rq { - c.lock.Unlock() // X1- - return -1, io.EOF - } - - m = len(c.m) - c.lock.Unlock() // X1- - po = 0 - bp += rq - off += int64(rq) - rem -= rq - n += rq - } - if m > c.maxpages && atomic.CompareAndSwapInt32(&c.cleaning, 0, 1) { - if m > c.Top { - c.Top = m - } - c.clean <- true - } - return -} - -func (c *Cache) Stat() (fi os.FileInfo, err error) { - c.lock.Lock() - defer c.lock.Unlock() - return c.fi, nil -} - -func (c *Cache) Sync() (err error) { - c.write <- false - <-c.sync - return -} - -func (c *Cache) Truncate(size int64) (err error) { - c.Sync() //TODO improve (discard pages, the writer goroutine should also be aware, ...) - c.lock.Lock() - defer c.lock.Unlock() - c.size = size - return c.f.Truncate(size) -} - -func (c *Cache) WriteAt(b []byte, off int64) (n int, err error) { - po := int(off) & 0x1ff - bp := 0 - rem := len(b) - m := 0 - for rem != 0 { - c.lock.Lock() // X+ - p := c.wr(off) - rq := rem - if po+rq > 512 { - rq = 512 - po - } - if wasDirty := p.wr(b[bp:bp+rq], po); !wasDirty { - c.wlist.PushBack(p) - } - m = len(c.m) - po = 0 - bp += rq - off += int64(rq) - if off > c.size { - c.size = off - } - c.lock.Unlock() // X- - rem -= rq - n += rq - } - if atomic.CompareAndSwapInt32(&c.writing, 0, 1) { - c.write <- true - } - if m > c.maxpages && atomic.CompareAndSwapInt32(&c.cleaning, 0, 1) { - if m > c.Top { - c.Top = m - } - c.clean <- true - } - return -} - -func (c *Cache) writer() { - for ok := true; ok; { - var wr bool - var off int64 - wr, ok = <-c.write - for { - c.lock.Lock() // X1+ - item := c.wlist.Front() - if item == nil { - c.lock.Unlock() // X1- - break - } - - p := item.Value.(*cachepage) - off = p.pi << 9 - if n, err := c.f.WriteAt(p.b[:p.valid], off); n != p.valid { - c.lock.Unlock() // X1- - panic("TODO Cache.writer errchan") //TODO +errchan - panic(err) - } - - p.dirty = false - c.wlist.Remove(item) - if c.advise != nil { - c.advise(off, 512, true) - } - c.lock.Unlock() // X1- - } - switch { - case wr: - atomic.AddInt32(&c.writing, -1) - case ok: - c.sync <- true - } - } - c.close <- true -} - -func (c *Cache) cleaner(limit int) { - for _ = range c.clean { - var item *list.Element - for { - c.lock.Lock() // X1+ - if len(c.m) < limit { - c.lock.Unlock() // X1- - break - } - - if item == nil { - item = c.lru.Front() - } - if p := item.Value.(*cachepage); !p.dirty { - delete(c.m, p.pi) - c.lru.Remove(item) - c.Purge++ - } - item = item.Next() - c.lock.Unlock() // X1- - } - atomic.AddInt32(&c.cleaning, -1) - } - c.close <- true -} diff --git a/vendor/github.com/cznic/fileutil/storage/file.go b/vendor/github.com/cznic/fileutil/storage/file.go deleted file mode 100644 index 94feda5ef..000000000 --- a/vendor/github.com/cznic/fileutil/storage/file.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -package storage - -import ( - "os" -) - -// FileAccessor is the concrete type returned by NewFile and OpenFile. -type FileAccessor struct { - *os.File -} - -// Implementation of Accessor. -func (f *FileAccessor) BeginUpdate() error { return nil } - -// Implementation of Accessor. -func (f *FileAccessor) EndUpdate() error { return nil } - -// NewFile returns an Accessor backed by an os.File named name, It opens the -// named file with specified flag (os.O_RDWR etc.) and perm, (0666 etc.) if -// applicable. If successful, methods on the returned Accessor can be used for -// I/O. It returns the Accessor and an Error, if any. -// -// NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op. -func NewFile(name string, flag int, perm os.FileMode) (store Accessor, err error) { - var f FileAccessor - if f.File, err = os.OpenFile(name, flag, perm); err == nil { - store = &f - } - return -} - -// OpenFile returns an Accessor backed by an existing os.File named name, It -// opens the named file with specified flag (os.O_RDWR etc.) and perm, (0666 -// etc.) if applicable. If successful, methods on the returned Accessor can be -// used for I/O. It returns the Accessor and an Error, if any. -// -// NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op. -func OpenFile(name string, flag int, perm os.FileMode) (store Accessor, err error) { - var f FileAccessor - if f.File, err = os.OpenFile(name, flag, perm); err == nil { - store = &f - } - return -} diff --git a/vendor/github.com/cznic/fileutil/storage/mem.go b/vendor/github.com/cznic/fileutil/storage/mem.go deleted file mode 100644 index 7cda0b667..000000000 --- a/vendor/github.com/cznic/fileutil/storage/mem.go +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -package storage - -import ( - "errors" - "fmt" - "io/ioutil" - "math" - "os" -) - -//TODO -> exported type w/ exported fields -type memaccessor struct { - f *os.File - fi *FileInfo - b []byte -} - -// Implementation of Accessor. -func (m *memaccessor) BeginUpdate() error { return nil } - -// Implementation of Accessor. -func (f *memaccessor) EndUpdate() error { return nil } - -// NewMem returns a new Accessor backed by an os.File. The returned Accessor -// keeps all of the store content in memory. The memory and file images are -// synced only by Sync and Close. Recomended for small amounts of data only -// and content which may be lost on process kill/crash. NewMem return the -// Accessor or an error of any. -// -// NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op. -func NewMem(f *os.File) (store Accessor, err error) { - a := &memaccessor{f: f} - if err = f.Truncate(0); err != nil { - return - } - - var fi os.FileInfo - if fi, err = a.f.Stat(); err != nil { - return - } - - a.fi = NewFileInfo(fi, a) - store = a - return -} - -// OpenMem return a new Accessor backed by an os.File. The store content is -// loaded from f. The returned Accessor keeps all of the store content in -// memory. The memory and file images are synced only Sync and Close. -// Recomended for small amounts of data only and content which may be lost on -// process kill/crash. OpenMem return the Accessor or an error of any. -// -// NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op. -func OpenMem(f *os.File) (store Accessor, err error) { - a := &memaccessor{f: f} - if a.b, err = ioutil.ReadAll(a.f); err != nil { - a.f.Close() - return - } - - var fi os.FileInfo - if fi, err = a.f.Stat(); err != nil { - a.f.Close() - return - } - - a.fi = NewFileInfo(fi, a) - store = a - return -} - -// Close implements Accessor. Specifically it synchronizes the memory and file images. -func (a *memaccessor) Close() (err error) { - defer func() { - a.b = nil - if a.f != nil { - if e := a.f.Close(); e != nil && err == nil { - err = e - } - } - a.f = nil - }() - - return a.Sync() -} - -func (a *memaccessor) Name() string { - return a.f.Name() -} - -func (a *memaccessor) ReadAt(b []byte, off int64) (n int, err error) { - if off < 0 || off > math.MaxInt32 { - return -1, fmt.Errorf("ReadAt: illegal offset %#x", off) - } - - rq, fp := len(b), int(off) - if fp+rq > len(a.b) { - return -1, fmt.Errorf("ReadAt: illegal rq %#x @ offset %#x, len %#x", rq, fp, len(a.b)) - } - - copy(b, a.b[fp:]) - return -} - -func (a *memaccessor) Stat() (fi os.FileInfo, err error) { - i := a.fi - i.FSize = int64(len(a.b)) - fi = i - return -} - -// Sync implements Accessor. Specifically it synchronizes the memory and file images. -func (a *memaccessor) Sync() (err error) { - var n int - if n, err = a.f.WriteAt(a.b, 0); n != len(a.b) { - return - } - - return a.f.Truncate(int64(len(a.b))) -} - -func (a *memaccessor) Truncate(size int64) (err error) { - defer func() { - if e := recover(); e != nil { - err = e.(error) - } - }() - - if size > math.MaxInt32 { - panic(errors.New("truncate: illegal size")) - } - - a.b = a.b[:int(size)] - return -} - -func (a *memaccessor) WriteAt(b []byte, off int64) (n int, err error) { - if off < 0 || off > math.MaxInt32 { - return -1, errors.New("WriteAt: illegal offset") - } - - rq, fp, size := len(b), int(off), len(a.b) - if need := rq + fp; need > size { - if need <= cap(a.b) { - a.b = a.b[:need] - } else { - nb := make([]byte, need, 2*need) - copy(nb, a.b) - a.b = nb - } - } - - copy(a.b[int(off):], b) - return -} diff --git a/vendor/github.com/cznic/fileutil/storage/probe.go b/vendor/github.com/cznic/fileutil/storage/probe.go deleted file mode 100644 index 53b146a6e..000000000 --- a/vendor/github.com/cznic/fileutil/storage/probe.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -package storage - -import "sync/atomic" - -// Probe collects usage statistics of the embeded Accessor. -// Probe itself IS an Accessor. -type Probe struct { - Accessor - Chain *Probe - OpsRd int64 - OpsWr int64 - BytesRd int64 - BytesWr int64 - SectorsRd int64 // Assuming 512 byte sector size - SectorsWr int64 -} - -// NewProbe returns a newly created probe which embedes the src Accessor. -// The retuned *Probe satisfies Accessor. if chain != nil then Reset() -// is cascaded down the chained Probes. -func NewProbe(src Accessor, chain *Probe) *Probe { - return &Probe{Accessor: src, Chain: chain} -} - -func reset(n *int64) { - atomic.AddInt64(n, -atomic.AddInt64(n, 0)) -} - -// Reset zeroes the collected statistics of p. -func (p *Probe) Reset() { - if p.Chain != nil { - p.Chain.Reset() - } - reset(&p.OpsRd) - reset(&p.OpsWr) - reset(&p.BytesRd) - reset(&p.BytesWr) - reset(&p.SectorsRd) - reset(&p.SectorsWr) -} - -func (p *Probe) ReadAt(b []byte, off int64) (n int, err error) { - n, err = p.Accessor.ReadAt(b, off) - atomic.AddInt64(&p.OpsRd, 1) - atomic.AddInt64(&p.BytesRd, int64(n)) - if n <= 0 { - return - } - - sectorFirst := off >> 9 - sectorLast := (off + int64(n) - 1) >> 9 - atomic.AddInt64(&p.SectorsRd, sectorLast-sectorFirst+1) - return -} - -func (p *Probe) WriteAt(b []byte, off int64) (n int, err error) { - n, err = p.Accessor.WriteAt(b, off) - atomic.AddInt64(&p.OpsWr, 1) - atomic.AddInt64(&p.BytesWr, int64(n)) - if n <= 0 { - return - } - - sectorFirst := off >> 9 - sectorLast := (off + int64(n) - 1) >> 9 - atomic.AddInt64(&p.SectorsWr, sectorLast-sectorFirst+1) - return -} diff --git a/vendor/github.com/cznic/fileutil/storage/storage.go b/vendor/github.com/cznic/fileutil/storage/storage.go deleted file mode 100644 index 4956053a0..000000000 --- a/vendor/github.com/cznic/fileutil/storage/storage.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -// WIP: Package storage defines and implements storage providers and store accessors. -package storage - -import ( - "os" - "sync" - "time" -) - -// FileInfo is a type implementing os.FileInfo which has setable fields, like -// the older os.FileInfo used to have. It is used wehere e.g. the Size is -// needed to be faked (encapsulated/memory only file, file cache, etc.). -type FileInfo struct { - FName string // base name of the file - FSize int64 // length in bytes - FMode os.FileMode // file mode bits - FModTime time.Time // modification time - FIsDir bool // abbreviation for Mode().IsDir() - sys interface{} // underlying data source (can be nil) -} - -// NewFileInfo creates FileInfo from os.FileInfo fi. -func NewFileInfo(fi os.FileInfo, sys interface{}) *FileInfo { - return &FileInfo{fi.Name(), fi.Size(), fi.Mode(), fi.ModTime(), fi.IsDir(), sys} -} - -// Implementation of os.FileInfo -func (fi *FileInfo) Name() string { - return fi.FName -} - -// Implementation of os.FileInfo -func (fi *FileInfo) Size() int64 { - return fi.FSize -} - -// Implementation of os.FileInfo -func (fi *FileInfo) Mode() os.FileMode { - return fi.FMode -} - -// Implementation of os.FileInfo -func (fi *FileInfo) ModTime() time.Time { - return fi.FModTime -} - -// Implementation of os.FileInfo -func (fi *FileInfo) IsDir() bool { - return fi.FIsDir -} - -func (fi *FileInfo) Sys() interface{} { - return fi.sys -} - -// Accessor provides I/O methods to access a store. -type Accessor interface { - - // Close closes the store, rendering it unusable for I/O. It returns an - // error, if any. - Close() error - - // Name returns the name of the file as presented to Open. - Name() string - - // ReadAt reads len(b) bytes from the store starting at byte offset off. - // It returns the number of bytes read and the error, if any. - // EOF is signaled by a zero count with err set to os.EOF. - // ReadAt always returns a non-nil Error when n != len(b). - ReadAt(b []byte, off int64) (n int, err error) - - // Stat returns the FileInfo structure describing the store. It returns - // the os.FileInfo and an error, if any. - Stat() (fi os.FileInfo, err error) - - // Sync commits the current contents of the store to stable storage. - // Typically, this means flushing the file system's in-memory copy of - // recently written data to disk. - Sync() (err error) - - // Truncate changes the size of the store. It does not change the I/O - // offset. - Truncate(size int64) error - - // WriteAt writes len(b) bytes to the store starting at byte offset off. - // It returns the number of bytes written and an error, if any. - // WriteAt returns a non-nil Error when n != len(b). - WriteAt(b []byte, off int64) (n int, err error) - - // Before every [structural] change of a store the BeginUpdate is to be - // called and paired with EndUpdate after the change makes the store's - // state consistent again. Invocations of BeginUpdate may nest. On - // invoking the last non nested EndUpdate an implicit "commit" should - // be performed by the store/provider. The concrete mechanism is - // unspecified. It could be for example a write-ahead log. Stores may - // implement BeginUpdate and EndUpdate as a (documented) no op. - BeginUpdate() error - EndUpdate() error -} - -// Mutate is a helper/wrapper for executing f in between a.BeginUpdate and -// a.EndUpdate. Any parameters and/or return values except an error should be -// captured by a function literal passed as f. The returned err is either nil -// or the first non nil error returned from the sequence of execution: -// BeginUpdate, [f,] EndUpdate. The pair BeginUpdate/EndUpdate *is* invoked -// always regardles of any possible errors produced. Mutate doesn't handle -// panic, it should be used only with a function [literal] which doesn't panic. -// Otherwise the pairing of BeginUpdate/EndUpdate is not guaranteed. -// -// NOTE: If BeginUpdate, which is invoked before f, returns a non-nil error, -// then f is not invoked at all (but EndUpdate still is). -func Mutate(a Accessor, f func() error) (err error) { - defer func() { - if e := a.EndUpdate(); e != nil && err == nil { - err = e - } - }() - - if err = a.BeginUpdate(); err != nil { - return - } - - return f() -} - -// LockedMutate wraps Mutate in yet another layer consisting of a -// l.Lock/l.Unlock pair. All other limitations apply as in Mutate, e.g. no -// panics are allowed to happen - otherwise no guarantees can be made about -// Unlock matching the Lock. -func LockedMutate(a Accessor, l sync.Locker, f func() error) (err error) { - l.Lock() - defer l.Unlock() - - return Mutate(a, f) -} diff --git a/vendor/github.com/cznic/fileutil/storage/test_deps.go b/vendor/github.com/cznic/fileutil/storage/test_deps.go deleted file mode 100644 index 92ac44a5b..000000000 --- a/vendor/github.com/cznic/fileutil/storage/test_deps.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -package storage - -// Pull test dependencies too. -// Enables easy 'go test X' after 'go get X' -import ( -// nothing yet -) diff --git a/vendor/github.com/cznic/fileutil/test_deps.go b/vendor/github.com/cznic/fileutil/test_deps.go deleted file mode 100644 index eec608ab3..000000000 --- a/vendor/github.com/cznic/fileutil/test_deps.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2014 The fileutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -package fileutil - -// Pull test dependencies too. -// Enables easy 'go test X' after 'go get X' -import ( -// nothing yet -) diff --git a/vendor/github.com/cznic/golex/lex/LICENSE b/vendor/github.com/cznic/golex/lex/LICENSE deleted file mode 100644 index cbf406347..000000000 --- a/vendor/github.com/cznic/golex/lex/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014 The golex Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/golex/lex/api.go b/vendor/github.com/cznic/golex/lex/api.go deleted file mode 100644 index 3f8439037..000000000 --- a/vendor/github.com/cznic/golex/lex/api.go +++ /dev/null @@ -1,410 +0,0 @@ -// Copyright (c) 2015 The golex Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package lex - -import ( - "bytes" - "fmt" - "go/token" - "io" - "os" -) - -// BOM handling modes which can be set by the BOMMode Option. Default is BOMIgnoreFirst. -const ( - BOMError = iota // BOM is an error anywhere. - BOMIgnoreFirst // Skip BOM if at beginning, report as error if anywhere else. - BOMPassAll // No special handling of BOM. - BOMPassFirst // No special handling of BOM if at beginning, report as error if anywhere else. -) - -const ( - NonASCII = 0x80 // DefaultRuneClass returns NonASCII for non ASCII runes. - RuneEOF = -1 // Distinct from any valid Unicode rune value. -) - -// DefaultRuneClass returns the character class of r. If r is an ASCII code -// then its class equals the ASCII code. Any other rune is of class NonASCII. -// -// DefaultRuneClass is the default implementation Lexer will use to convert -// runes (21 bit entities) to scanner classes (8 bit entities). -// -// Non ASCII aware lexical analyzers will typically use their own -// categorization function. To assign such custom function use the RuneClass -// option. -func DefaultRuneClass(r rune) int { - if r >= 0 && r < 0x80 { - return int(r) - } - - return NonASCII -} - -// Char represents a rune and its position. -type Char struct { - Rune rune - pos int32 -} - -// NewChar returns a new Char value. -func NewChar(pos token.Pos, r rune) Char { return Char{pos: int32(pos), Rune: r} } - -// IsValid reports whether c is not a zero Char. -func (c Char) IsValid() bool { return c.Pos().IsValid() } - -// Pos returns the token.Pos associated with c. -func (c Char) Pos() token.Pos { return token.Pos(c.pos) } - -// CharReader is a RuneReader providing additionally explicit position -// information by returning a Char instead of a rune as its first result. -type CharReader interface { - ReadChar() (c Char, size int, err error) -} - -// Lexer suports golex[0] generated lexical analyzers. -type Lexer struct { - File *token.File // The *token.File passed to New. - First Char // First remembers the lookahead char when Rule0 was invoked. - Last Char // Last remembers the last Char returned by Next. - Prev Char // Prev remembers the Char previous to Last. - bomMode int // See the BOM* constants. - bytesBuf bytes.Buffer // Used by TokenBytes. - charSrc CharReader // Lexer alternative input. - classf func(rune) int // - errorf func(token.Pos, string) // - lookahead Char // Lookahead if non zero. - mark int // Longest match marker. - off int // Used for File.AddLine. - src io.RuneReader // Lexer input. - tokenBuf []Char // Lexeme collector. - ungetBuf []Char // Unget buffer. -} - -// New returns a new *Lexer. The result can be amended using opts. -// -// Non Unicode Input -// -// To consume sources in other encodings and still have exact position -// information, pass an io.RuneReader which returns the next input character -// reencoded as an Unicode rune but returns the size (number of bytes used to -// encode it) of the original character, not the size of its UTF-8 -// representation after converted to an Unicode rune. Size is the second -// returned value of io.RuneReader.ReadRune method[4]. -// -// When src optionally implements CharReader its ReadChar method is used -// instead of io.ReadRune. -func New(file *token.File, src io.RuneReader, opts ...Option) (*Lexer, error) { - r := &Lexer{ - File: file, - bomMode: BOMIgnoreFirst, - classf: DefaultRuneClass, - src: src, - } - if x, ok := src.(CharReader); ok { - r.charSrc = x - } - r.errorf = r.defaultErrorf - for _, o := range opts { - if err := o(r); err != nil { - return nil, err - } - } - return r, nil -} - -// Abort handles the situation when the scanner does not successfully recognize -// any token or when an attempt to find the longest match "overruns" from an -// accepting state only to never reach an accepting state again. In the first -// case the scanner was never in an accepting state since last call to Rule0 -// and then (true, previousLookahead rune) is returned, effectively consuming a -// single Char token, avoiding scanner stall. Otherwise there was at least one -// accepting scanner state marked using Mark. In this case Abort rollbacks the -// lexer state to the marked state and returns (false, 0). The scanner must -// then execute a prescribed goto statement. For example: -// -// %yyc c -// %yyn c = l.Next() -// %yym l.Mark() -// -// %{ -// package foo -// -// import (...) -// -// type lexer struct { -// *lex.Lexer -// ... -// } -// -// func newLexer(...) *lexer { -// return &lexer{ -// lex.NewLexer(...), -// ... -// } -// } -// -// func (l *lexer) scan() int { -// c := l.Enter() -// %} -// -// ... more lex defintions -// -// %% -// -// c = l.Rule0() -// -// ... lex rules -// -// %% -// -// if c, ok := l.Abort(); ok { -// return c -// } -// -// goto yyAction -// } -func (l *Lexer) Abort() (int, bool) { - if l.mark >= 0 { - if len(l.tokenBuf) > l.mark { - l.Unget(l.lookahead) - for i := len(l.tokenBuf) - 1; i >= l.mark; i-- { - l.Unget(l.tokenBuf[i]) - } - } - l.tokenBuf = l.tokenBuf[:l.mark] - return 0, false - } - - switch n := len(l.tokenBuf); n { - case 0: // [] z - c := l.lookahead - l.Next() - return int(c.Rune), true - case 1: // [a] z - return int(l.tokenBuf[0].Rune), true - default: // [a, b, ...], z - c := l.tokenBuf[0] // a - l.Unget(l.lookahead) // z - for i := n - 1; i > 1; i-- { - l.Unget(l.tokenBuf[i]) // ... - } - l.lookahead = l.tokenBuf[1] // b - l.tokenBuf = l.tokenBuf[:1] - return int(c.Rune), true - } -} - -func (l *Lexer) class() int { return l.classf(l.lookahead.Rune) } - -func (l *Lexer) defaultErrorf(pos token.Pos, msg string) { - l.Error(fmt.Sprintf("%v: %v", l.File.Position(pos), msg)) -} - -// Enter ensures the lexer has a valid lookahead Char and returns its class. -// Typical use in an .l file -// -// func (l *lexer) scan() lex.Char { -// c := l.Enter() -// ... -func (l *Lexer) Enter() int { - if !l.lookahead.IsValid() { - l.Next() - } - return l.class() -} - -// Error Implements yyLexer[2] by printing the msg to stderr. -func (l *Lexer) Error(msg string) { - fmt.Fprintf(os.Stderr, "%s\n", msg) -} - -// Lookahead returns the current lookahead. -func (l *Lexer) Lookahead() Char { - if !l.lookahead.IsValid() { - l.Next() - } - return l.lookahead -} - -// Mark records the current state of scanner as accepting. It implements the -// golex macro %yym. Typical usage in an .l file: -// -// %yym l.Mark() -func (l *Lexer) Mark() { l.mark = len(l.tokenBuf) } - -func (l *Lexer) next() int { - const bom = '\ufeff' - - if c := l.lookahead; c.IsValid() { - l.tokenBuf = append(l.tokenBuf, c) - } - if n := len(l.ungetBuf); n != 0 { - l.lookahead = l.ungetBuf[n-1] - l.ungetBuf = l.ungetBuf[:n-1] - return l.class() - } - - if l.src == nil { - return RuneEOF - } - - var r rune - var sz int - var err error - var pos token.Pos - var c Char -again: - off0 := l.off - switch cs := l.charSrc; { - case cs != nil: - c, sz, err = cs.ReadChar() - r = c.Rune - pos = c.Pos() - default: - r, sz, err = l.src.ReadRune() - pos = l.File.Pos(l.off) - } - l.off += sz - if err != nil { - l.src = nil - r = RuneEOF - if err != io.EOF { - l.errorf(pos, err.Error()) - } - } - - if r == bom { - switch l.bomMode { - default: - fallthrough - case BOMIgnoreFirst: - if off0 != 0 { - l.errorf(pos, "unicode (UTF-8) BOM in middle of file") - } - goto again - case BOMPassAll: - // nop - case BOMPassFirst: - if off0 != 0 { - l.errorf(pos, "unicode (UTF-8) BOM in middle of file") - goto again - } - case BOMError: - switch { - case off0 == 0: - l.errorf(pos, "unicode (UTF-8) BOM at beginnig of file") - default: - l.errorf(pos, "unicode (UTF-8) BOM in middle of file") - } - goto again - } - } - - l.lookahead = NewChar(pos, r) - if r == '\n' { - l.File.AddLine(l.off) - } - return l.class() -} - -// Next advances the scanner for one rune and returns the respective character -// class of the new lookahead. Typical usage in an .l file: -// -// %yyn c = l.Next() -func (l *Lexer) Next() int { - l.Prev = l.Last - r := l.next() - l.Last = l.lookahead - return r -} - -// Offset returns the current reading offset of the lexer's source. -func (l *Lexer) Offset() int { return l.off } - -// Rule0 initializes the scanner state before the attempt to recognize a token -// starts. The token collecting buffer is cleared. Rule0 records the current -// lookahead in l.First and returns its class. Typical usage in an .l file: -// -// ... lex definitions -// -// %% -// -// c := l.Rule0() -// -// first-pattern-regexp -func (l *Lexer) Rule0() int { - if !l.lookahead.IsValid() { - l.Next() - } - l.First = l.lookahead - l.mark = -1 - if len(l.tokenBuf) > 1<<18 { //DONE constant tuned - l.tokenBuf = nil - } else { - l.tokenBuf = l.tokenBuf[:0] - } - return l.class() -} - -// Token returns the currently collected token chars. The result is R/O. -func (l *Lexer) Token() []Char { return l.tokenBuf } - -// TokenBytes returns the UTF-8 encoding of Token. If builder is not nil then -// it's called instead to build the encoded token byte value into the buffer -// passed to it. -// -// The Result is R/O. -func (l *Lexer) TokenBytes(builder func(*bytes.Buffer)) []byte { - if len(l.bytesBuf.Bytes()) < 1<<18 { //DONE constant tuned - l.bytesBuf.Reset() - } else { - l.bytesBuf = bytes.Buffer{} - } - switch { - case builder != nil: - builder(&l.bytesBuf) - default: - for _, c := range l.Token() { - l.bytesBuf.WriteRune(c.Rune) - } - } - return l.bytesBuf.Bytes() -} - -// Unget unreads all chars in c. -func (l *Lexer) Unget(c ...Char) { - l.ungetBuf = append(l.ungetBuf, c...) - l.lookahead = Char{} // Must invalidate lookahead. -} - -// Option is a function which can be passed as an optional argument to New. -type Option func(*Lexer) error - -// BOMMode option selects how the lexer handles BOMs. See the BOM* constants for details. -func BOMMode(mode int) Option { - return func(l *Lexer) error { - l.bomMode = mode - return nil - } -} - -// ErrorFunc option sets a function called when an, for example I/O error, -// occurs. The default is to call Error with the position and message already -// formated as a string. -func ErrorFunc(f func(token.Pos, string)) Option { - return func(l *Lexer) error { - l.errorf = f - return nil - } -} - -// RuneClass option sets the function used to convert runes to character -// classes. -func RuneClass(f func(rune) int) Option { - return func(l *Lexer) error { - l.classf = f - return nil - } -} diff --git a/vendor/github.com/cznic/golex/lex/doc.go b/vendor/github.com/cznic/golex/lex/doc.go deleted file mode 100644 index 10b0b4307..000000000 --- a/vendor/github.com/cznic/golex/lex/doc.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2015 The golex Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package lex is a Unicode-friendly run time library for golex[0] generated -// lexical analyzers[1]. -// -// Changelog -// -// 2015-04-08: Initial release. -// -// Character classes -// -// Golex internally handles only 8 bit "characters". Many Unicode-aware -// tokenizers do not actually need to recognize every Unicode rune, but only -// some particular partitions/subsets. Like, for example, a particular Unicode -// category, say upper case letters: Lu. -// -// The idea is to convert all runes in a particular set as a single 8 bit -// character allocated outside the ASCII range of codes. The token value, a -// string of runes and their exact positions is collected as usual (see the -// Token and TokenBytes method), but the tokenizer DFA is simpler (and thus -// smaller and perhaps also faster) when this technique is used. In the example -// program (see below), recognizing (and skipping) white space, integer -// literals, one keyword and Go identifiers requires only an 8 state DFA[5]. -// -// To provide the conversion from runes to character classes, "install" your -// converting function using the RuneClass option. -// -// References -// -// - -// -// [0]: http://godoc.org/github.com/cznic/golex -// [1]: http://en.wikipedia.org/wiki/Lexical_analysis -// [2]: http://golang.org/cmd/yacc/ -// [3]: https://github.com/cznic/golex/blob/master/lex/example.l -// [4]: http://golang.org/pkg/io/#RuneReader -// [5]: https://github.com/cznic/golex/blob/master/lex/dfa -package lex diff --git a/vendor/github.com/cznic/internal/buffer/LICENSE b/vendor/github.com/cznic/internal/buffer/LICENSE deleted file mode 100644 index 9b9e98b16..000000000 --- a/vendor/github.com/cznic/internal/buffer/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2016 The Internal Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/internal/buffer/buffer.go b/vendor/github.com/cznic/internal/buffer/buffer.go deleted file mode 100644 index 683687537..000000000 --- a/vendor/github.com/cznic/internal/buffer/buffer.go +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright 2016 The Internal Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package buffer implements a pool of pointers to byte slices. -// -// Example usage pattern -// -// p := buffer.Get(size) -// b := *p // Now you can use b in any way you need. -// ... -// // When b will not be used anymore -// buffer.Put(p) -// ... -// // If b or p are not going out of scope soon, optionally -// b = nil -// p = nil -// -// Otherwise the pool cannot release the buffer on garbage collection. -// -// Do not do -// -// p := buffer.Get(size) -// b := *p -// ... -// buffer.Put(&b) -// -// or -// -// b := *buffer.Get(size) -// ... -// buffer.Put(&b) -package buffer - -import ( - "github.com/cznic/internal/slice" - "io" -) - -// CGet returns a pointer to a byte slice of len size. The pointed to byte -// slice is zeroed up to its cap. CGet panics for size < 0. -// -// CGet is safe for concurrent use by multiple goroutines. -func CGet(size int) *[]byte { return slice.Bytes.CGet(size).(*[]byte) } - -// Get returns a pointer to a byte slice of len size. The pointed to byte slice -// is not zeroed. Get panics for size < 0. -// -// Get is safe for concurrent use by multiple goroutines. -func Get(size int) *[]byte { return slice.Bytes.Get(size).(*[]byte) } - -// Put puts a pointer to a byte slice into a pool for possible later reuse by -// CGet or Get. -// -// Put is safe for concurrent use by multiple goroutines. -func Put(p *[]byte) { slice.Bytes.Put(p) } - -// Bytes is similar to bytes.Buffer but may generate less garbage when properly -// Closed. Zero value is ready to use. -type Bytes struct { - p *[]byte -} - -// Bytes return the content of b. The result is R/O. -func (b *Bytes) Bytes() []byte { - if b.p != nil { - return *b.p - } - - return nil -} - -// Close will recycle the underlying storage, if any. After Close, b is again -// the zero value. -func (b *Bytes) Close() error { - if b.p != nil { - Put(b.p) - b.p = nil - } - return nil -} - -// Len returns the size of content in b. -func (b *Bytes) Len() int { - if b.p != nil { - return len(*b.p) - } - - return 0 -} - -// Reset discard the content of Bytes while keeping the internal storage, if any. -func (b *Bytes) Reset() { - if b.p != nil { - *b.p = (*b.p)[:0] - } -} - -// Write writes p into b and returns (len(p), nil). -func (b *Bytes) Write(p []byte) (int, error) { - n := b.Len() - b.grow(n + len(p)) - copy((*b.p)[n:], p) - return len(p), nil -} - -// WriteByte writes p into b and returns nil. -func (b *Bytes) WriteByte(p byte) error { - n := b.Len() - b.grow(n + 1) - (*b.p)[n] = p - return nil -} - -// WriteTo writes b's content to w and returns the number of bytes written to w -// and an error, if any. -func (b *Bytes) WriteTo(w io.Writer) (int64, error) { - n, err := w.Write(b.Bytes()) - return int64(n), err -} - -// WriteString writes s to b and returns (len(s), nil). -func (b *Bytes) WriteString(s string) (int, error) { - n := b.Len() - b.grow(n + len(s)) - copy((*b.p)[n:], s) - return len(s), nil -} - -func (b *Bytes) grow(n int) { - if b.p != nil { - if n <= cap(*b.p) { - *b.p = (*b.p)[:n] - return - } - - np := Get(2 * n) - *np = (*np)[:n] - copy(*np, *b.p) - Put(b.p) - b.p = np - return - } - - b.p = Get(n) -} diff --git a/vendor/github.com/cznic/internal/file/LICENSE b/vendor/github.com/cznic/internal/file/LICENSE deleted file mode 100644 index 9b9e98b16..000000000 --- a/vendor/github.com/cznic/internal/file/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2016 The Internal Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/internal/file/file.go b/vendor/github.com/cznic/internal/file/file.go deleted file mode 100644 index 6d93d6e52..000000000 --- a/vendor/github.com/cznic/internal/file/file.go +++ /dev/null @@ -1,466 +0,0 @@ -// Copyright 2016 The Internal Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package file provides an os.File-like interface of a memory mapped file. -package file - -import ( - "fmt" - "io" - "os" - "time" - - "github.com/cznic/fileutil" - "github.com/cznic/internal/buffer" - "github.com/cznic/mathutil" - "github.com/edsrzf/mmap-go" -) - -const copyBufSize = 1 << 20 // 1 MB. - -var ( - _ Interface = (*mem)(nil) - _ Interface = (*file)(nil) - - _ os.FileInfo = stat{} - - sysPage = os.Getpagesize() -) - -// Interface is a os.File-like entity. -type Interface interface { - io.ReaderAt - io.ReaderFrom - io.WriterAt - io.WriterTo - - Close() error - Stat() (os.FileInfo, error) - Sync() error - Truncate(int64) error -} - -// Open returns a new Interface backed by f, or an error, if any. -func Open(f *os.File) (Interface, error) { return newFile(f, 1<<30, 20) } - -// OpenMem returns a new Interface, or an error, if any. The Interface content -// is volatile, it's backed only by process' memory. -func OpenMem(name string) (Interface, error) { return newMem(name, 18), nil } - -type memMap map[int64]*[]byte - -type mem struct { - m memMap - modTime time.Time - name string - pgBits uint - pgMask int - pgSize int - size int64 -} - -func newMem(name string, pgBits uint) *mem { - pgSize := 1 << pgBits - return &mem{ - m: memMap{}, - modTime: time.Now(), - name: name, - pgBits: pgBits, - pgMask: pgSize - 1, - pgSize: pgSize, - } -} - -func (f *mem) IsDir() bool { return false } -func (f *mem) Mode() os.FileMode { return os.ModeTemporary + 0600 } -func (f *mem) ModTime() time.Time { return f.modTime } -func (f *mem) Name() string { return f.name } -func (f *mem) ReadFrom(r io.Reader) (n int64, err error) { return readFrom(f, r) } -func (f *mem) Size() (n int64) { return f.size } -func (f *mem) Stat() (os.FileInfo, error) { return f, nil } -func (f *mem) Sync() error { return nil } -func (f *mem) Sys() interface{} { return nil } -func (f *mem) WriteTo(w io.Writer) (n int64, err error) { return writeTo(f, w) } - -func (f *mem) Close() error { - f.Truncate(0) - f.m = nil - return nil -} - -func (f *mem) ReadAt(b []byte, off int64) (n int, err error) { - avail := f.size - off - pi := off >> f.pgBits - po := int(off) & f.pgMask - rem := len(b) - if int64(rem) >= avail { - rem = int(avail) - err = io.EOF - } - var zeroPage *[]byte - for rem != 0 && avail > 0 { - pg := f.m[pi] - if pg == nil { - if zeroPage == nil { - zeroPage = buffer.CGet(f.pgSize) - defer buffer.Put(zeroPage) - } - pg = zeroPage - } - nc := copy(b[:mathutil.Min(rem, f.pgSize)], (*pg)[po:]) - pi++ - po = 0 - rem -= nc - n += nc - b = b[nc:] - } - return n, err -} - -func (f *mem) Truncate(size int64) (err error) { - if size < 0 { - return fmt.Errorf("invalid truncate size: %d", size) - } - - first := size >> f.pgBits - if po := size & int64(f.pgMask); po != 0 { - if p := f.m[first]; p != nil { - b := (*p)[po:] - for i := range b { - b[i] = 0 - } - } - first++ - } - last := f.size >> f.pgBits - if po := f.size & int64(f.pgMask); po != 0 { - if p := f.m[last]; p != nil { - b := (*p)[po:] - for i := range b { - b[i] = 0 - } - } - last++ - } - for ; first <= last; first++ { - if p := f.m[first]; p != nil { - buffer.Put(p) - } - delete(f.m, first) - } - - f.size = size - return nil -} - -func (f *mem) WriteAt(b []byte, off int64) (n int, err error) { - if len(b) == 0 { - return 0, nil - } - - pi := off >> f.pgBits - po := int(off) & f.pgMask - n = len(b) - rem := n - var nc int - for rem != 0 { - pg := f.m[pi] - if pg == nil { - pg = buffer.CGet(f.pgSize) - f.m[pi] = pg - } - nc = copy((*pg)[po:], b) - pi++ - po = 0 - rem -= nc - b = b[nc:] - } - f.size = mathutil.MaxInt64(f.size, off+int64(n)) - return n, nil -} - -type stat struct { - os.FileInfo - size int64 -} - -func (s stat) Size() int64 { return s.size } - -type fileMap map[int64]mmap.MMap - -type file struct { - f *os.File - m fileMap - maxPages int - pgBits uint - pgMask int - pgSize int - size int64 - fsize int64 -} - -func newFile(f *os.File, maxSize int64, pgBits uint) (*file, error) { - if maxSize < 0 { - panic("internal error") - } - - pgSize := 1 << pgBits - switch { - case sysPage > pgSize: - pgBits = uint(mathutil.Log2Uint64(uint64(sysPage))) - default: - pgBits = uint(mathutil.Log2Uint64(uint64(pgSize / sysPage * sysPage))) - } - pgSize = 1 << pgBits - fi := &file{ - f: f, - m: fileMap{}, - maxPages: int(mathutil.MinInt64( - 1024, - mathutil.MaxInt64(maxSize/int64(pgSize), 1)), - ), - pgBits: pgBits, - pgMask: pgSize - 1, - pgSize: pgSize, - } - info, err := f.Stat() - if err != nil { - return nil, err - } - - if err = fi.Truncate(info.Size()); err != nil { - return nil, err - } - - return fi, nil -} - -func (f *file) ReadFrom(r io.Reader) (n int64, err error) { return readFrom(f, r) } -func (f *file) Sync() (err error) { return f.f.Sync() } -func (f *file) WriteTo(w io.Writer) (n int64, err error) { return writeTo(f, w) } - -func (f *file) Close() (err error) { - for _, p := range f.m { - if err = p.Unmap(); err != nil { - return err - } - } - - if err = f.f.Truncate(f.size); err != nil { - return err - } - - if err = f.f.Sync(); err != nil { - return err - } - - if err = f.f.Close(); err != nil { - return err - } - - f.m = nil - f.f = nil - return nil -} - -func (f *file) page(index int64) (mmap.MMap, error) { - if len(f.m) == f.maxPages { - for i, p := range f.m { - if err := p.Unmap(); err != nil { - return nil, err - } - - delete(f.m, i) - break - } - } - - off := index << f.pgBits - fsize := off + int64(f.pgSize) - if fsize > f.fsize { - if err := f.f.Truncate(fsize); err != nil { - return nil, err - } - - f.fsize = fsize - } - p, err := mmap.MapRegion(f.f, f.pgSize, mmap.RDWR, 0, off) - if err != nil { - return nil, err - } - - f.m[index] = p - return p, nil -} - -func (f *file) ReadAt(b []byte, off int64) (n int, err error) { - avail := f.size - off - pi := off >> f.pgBits - po := int(off) & f.pgMask - rem := len(b) - if int64(rem) >= avail { - rem = int(avail) - err = io.EOF - } - for rem != 0 && avail > 0 { - pg := f.m[pi] - if pg == nil { - if pg, err = f.page(pi); err != nil { - return n, err - } - } - nc := copy(b[:mathutil.Min(rem, f.pgSize)], pg[po:]) - pi++ - po = 0 - rem -= nc - n += nc - b = b[nc:] - } - return n, err -} - -func (f *file) Stat() (os.FileInfo, error) { - fi, err := f.f.Stat() - if err != nil { - return nil, err - } - - return stat{fi, f.size}, nil -} - -func (f *file) Truncate(size int64) (err error) { - if size < 0 { - return fmt.Errorf("invalid truncate size: %d", size) - } - - first := size >> f.pgBits - if po := size & int64(f.pgMask); po != 0 { - if p := f.m[first]; p != nil { - b := p[po:] - for i := range b { - b[i] = 0 - } - } - first++ - } - last := f.size >> f.pgBits - if po := f.size & int64(f.pgMask); po != 0 { - if p := f.m[last]; p != nil { - b := p[po:] - for i := range b { - b[i] = 0 - } - } - last++ - } - for ; first <= last; first++ { - if p := f.m[first]; p != nil { - if err := p.Unmap(); err != nil { - return err - } - } - - delete(f.m, first) - } - - f.size = size - fsize := (size + int64(f.pgSize) - 1) &^ int64(f.pgMask) - if fsize != f.fsize { - if err := f.f.Truncate(fsize); err != nil { - return err - } - - } - f.fsize = fsize - return nil -} - -func (f *file) WriteAt(b []byte, off int64) (n int, err error) { - if len(b) == 0 { - return 0, nil - } - - pi := off >> f.pgBits - po := int(off) & f.pgMask - n = len(b) - rem := n - var nc int - for rem != 0 { - pg := f.m[pi] - if pg == nil { - pg, err = f.page(pi) - if err != nil { - return n, err - } - } - nc = copy(pg[po:], b) - pi++ - po = 0 - rem -= nc - b = b[nc:] - } - f.size = mathutil.MaxInt64(f.size, off+int64(n)) - return n, nil -} - -// ---------------------------------------------------------------------------- - -func readFrom(f Interface, r io.Reader) (n int64, err error) { - f.Truncate(0) - p := buffer.Get(copyBufSize) - b := *p - defer buffer.Put(p) - - var off int64 - var werr error - for { - rn, rerr := r.Read(b) - if rn != 0 { - _, werr = f.WriteAt(b[:rn], off) - n += int64(rn) - off += int64(rn) - } - if rerr != nil { - if !fileutil.IsEOF(rerr) { - err = rerr - } - break - } - - if werr != nil { - err = werr - break - } - } - return n, err -} - -func writeTo(f Interface, w io.Writer) (n int64, err error) { - p := buffer.Get(copyBufSize) - b := *p - defer buffer.Put(p) - - var off int64 - var werr error - for { - rn, rerr := f.ReadAt(b, off) - if rn != 0 { - _, werr = w.Write(b[:rn]) - n += int64(rn) - off += int64(rn) - } - if rerr != nil { - if !fileutil.IsEOF(rerr) { - err = rerr - } - break - } - - if werr != nil { - err = werr - break - } - } - return n, err -} diff --git a/vendor/github.com/cznic/internal/slice/LICENSE b/vendor/github.com/cznic/internal/slice/LICENSE deleted file mode 100644 index 9b9e98b16..000000000 --- a/vendor/github.com/cznic/internal/slice/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2016 The Internal Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/internal/slice/pool.go b/vendor/github.com/cznic/internal/slice/pool.go deleted file mode 100644 index f3ee2295c..000000000 --- a/vendor/github.com/cznic/internal/slice/pool.go +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright 2016 The Internal Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package slice implements pools of pointers to slices. -package slice - -import ( - "sync" - - "github.com/cznic/mathutil" -) - -var ( - // Bytes is a ready to use *[]byte Pool. - Bytes *Pool - // Ints is a ready to use *[]int Pool. - Ints *Pool -) - -func init() { - Bytes = newBytes() - Ints = NewPool( - func(size int) interface{} { // create - b := make([]int, size) - return &b - }, - func(s interface{}) { // clear - b := *s.(*[]int) - b = b[:cap(b)] - for i := range b { - b[i] = 0 - } - }, - func(s interface{}, size int) { // setSize - p := s.(*[]int) - *p = (*p)[:size] - }, - func(s interface{}) int { return cap(*s.(*[]int)) }, // cap - ) -} - -func newBytes() *Pool { - return NewPool( - func(size int) interface{} { // create - b := make([]byte, size) - return &b - }, - func(s interface{}) { // clear - b := *s.(*[]byte) - b = b[:cap(b)] - for i := range b { - b[i] = 0 - } - }, - func(s interface{}, size int) { // setSize - p := s.(*[]byte) - *p = (*p)[:size] - }, - func(s interface{}) int { return cap(*s.(*[]byte)) }, // cap - ) -} - -// Pool implements a pool of pointers to slices. -// -// Example usage pattern (assuming pool is, for example, a *[]byte Pool) -// -// p := pool.Get(size).(*[]byte) -// b := *p // Now you can use b in any way you need. -// ... -// // When b will not be used anymore -// pool.Put(p) -// ... -// // If b or p are not going out of scope soon, optionally -// b = nil -// p = nil -// -// Otherwise the pool cannot release the slice on garbage collection. -// -// Do not do -// -// p := pool.Get(size).(*[]byte) -// b := *p -// ... -// pool.Put(&b) -// -// or -// -// b := *pool.Get(size).(*[]byte) -// ... -// pool.Put(&b) -type Pool struct { - cap func(interface{}) int - clear func(interface{}) - m [63]sync.Pool - null interface{} - setSize func(interface{}, int) -} - -// NewPool returns a newly created Pool. Assuming the desired slice type is -// []T: -// -// The create function returns a *[]T of len == cap == size. -// -// The argument of clear is *[]T and the function sets all the slice elements -// to the respective zero value. -// -// The setSize function gets a *[]T and sets its len to size. -// -// The cap function gets a *[]T and returns its capacity. -func NewPool( - create func(size int) interface{}, - clear func(interface{}), - setSize func(p interface{}, size int), - cap func(p interface{}) int, -) *Pool { - p := &Pool{clear: clear, setSize: setSize, cap: cap, null: create(0)} - for i := range p.m { - size := 1 << uint(i) - p.m[i] = sync.Pool{New: func() interface{} { - // 0: 1 - 1 - // 1: 10 - 10 - // 2: 11 - 100 - // 3: 101 - 1000 - // 4: 1001 - 10000 - // 5: 10001 - 100000 - return create(size) - }} - } - return p -} - -// CGet returns a *[]T of len size. The pointed to slice is zeroed up to its -// cap. CGet panics for size < 0. -// -// CGet is safe for concurrent use by multiple goroutines. -func (p *Pool) CGet(size int) interface{} { - s := p.Get(size) - p.clear(s) - return s -} - -// Get returns a *[]T of len size. The pointed to slice is not zeroed. Get -// panics for size < 0. -// -// Get is safe for concurrent use by multiple goroutines. -func (p *Pool) Get(size int) interface{} { - var index int - switch { - case size < 0: - panic("Pool.Get: negative size") - case size == 0: - return p.null - case size > 1: - index = mathutil.Log2Uint64(uint64(size-1)) + 1 - } - s := p.m[index].Get() - p.setSize(s, size) - return s -} - -// Put puts a *[]T into a pool for possible later reuse by CGet or Get. Put -// panics is its argument is not of type *[]T. -// -// Put is safe for concurrent use by multiple goroutines. -func (p *Pool) Put(b interface{}) { - size := p.cap(b) - if size == 0 { - return - } - - p.m[mathutil.Log2Uint64(uint64(size))].Put(b) -} diff --git a/vendor/github.com/cznic/lldb/2pc.go b/vendor/github.com/cznic/lldb/2pc.go deleted file mode 100644 index 396ffabce..000000000 --- a/vendor/github.com/cznic/lldb/2pc.go +++ /dev/null @@ -1,400 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Two Phase Commit & Structural ACID - -package lldb - -import ( - "bufio" - "encoding/binary" - "fmt" - "io" - "os" - - "github.com/cznic/fileutil" - "github.com/cznic/mathutil" -) - -var _ Filer = &ACIDFiler0{} // Ensure ACIDFiler0 is a Filer - -type acidWrite struct { - b []byte - off int64 -} - -type acidWriter0 ACIDFiler0 - -func (a *acidWriter0) WriteAt(b []byte, off int64) (n int, err error) { - f := (*ACIDFiler0)(a) - if f.newEpoch { - f.newEpoch = false - f.data = f.data[:0] - if err = a.writePacket([]interface{}{wpt00Header, walTypeACIDFiler0, ""}); err != nil { - return - } - } - - if err = a.writePacket([]interface{}{wpt00WriteData, b, off}); err != nil { - return - } - - f.data = append(f.data, acidWrite{b, off}) - return len(b), nil -} - -func (a *acidWriter0) writePacket(items []interface{}) (err error) { - f := (*ACIDFiler0)(a) - b, err := EncodeScalars(items...) - if err != nil { - return - } - - var b4 [4]byte - binary.BigEndian.PutUint32(b4[:], uint32(len(b))) - if _, err = f.bwal.Write(b4[:]); err != nil { - return - } - - if _, err = f.bwal.Write(b); err != nil { - return - } - - if m := (4 + len(b)) % 16; m != 0 { - var pad [15]byte - _, err = f.bwal.Write(pad[:16-m]) - } - return -} - -// WAL Packet Tags -const ( - wpt00Header = iota - wpt00WriteData - wpt00Checkpoint - wpt00Empty -) - -const ( - walTypeACIDFiler0 = iota -) - -// ACIDFiler0 is a very simple, synchronous implementation of 2PC. It uses a -// single write ahead log file to provide the structural atomicity -// (BeginUpdate/EndUpdate/Rollback) and durability (DB can be recovered from -// WAL if a crash occurred). -// -// ACIDFiler0 is a Filer. -// -// NOTE: Durable synchronous 2PC involves three fsyncs in this implementation -// (WAL, DB, zero truncated WAL). Where possible, it's recommended to collect -// transactions for, say one second before performing the two phase commit as -// the typical performance for rotational hard disks is about few tens of -// fsyncs per second atmost. For an example of such collective transaction -// approach please see the colecting FSM STT in Dbm's documentation[1]. -// -// [1]: http://godoc.org/github.com/cznic/exp/dbm -type ACIDFiler0 struct { - *RollbackFiler - bwal *bufio.Writer - data []acidWrite - newEpoch bool - peakWal int64 // tracks WAL maximum used size - testHook bool // keeps WAL untruncated (once) - wal *os.File - walOptions walOptions -} - -type walOptions struct { - headroom int64 // Minimum WAL size. -} - -// WALOption amends WAL properties. -type WALOption func(*walOptions) error - -// MinWAL sets the minimum size a WAL file will have. The "extra" allocated -// file space serves as a headroom. Commits that fit into the headroom should -// not fail due to 'not enough space on the volume' errors. -// -// The min parameter is first rounded-up to a non negative multiple of the size -// of the Allocator atom. -// -// Note: Setting minimum WAL size may render the DB non-recoverable when a -// crash occurs and the DB is opened in an earlier version of LLDB that does -// not support minimum WAL sizes. -func MinWAL(min int64) WALOption { - min = mathutil.MaxInt64(0, min) - if r := min % 16; r != 0 { - min += 16 - r - } - return func(o *walOptions) error { - o.headroom = min - return nil - } -} - -// NewACIDFiler0 returns a newly created ACIDFiler0 with WAL in wal. -// -// If the WAL is zero sized then a previous clean shutdown of db is taken for -// granted and no recovery procedure is taken. -// -// If the WAL is of non zero size then it is checked for having a -// committed/fully finished transaction not yet been reflected in db. If such -// transaction exists it's committed to db. If the recovery process finishes -// successfully, the WAL is truncated to the minimum WAL size and fsync'ed -// prior to return from NewACIDFiler0. -// -// opts allow to amend WAL properties. -func NewACIDFiler(db Filer, wal *os.File, opts ...WALOption) (r *ACIDFiler0, err error) { - fi, err := wal.Stat() - if err != nil { - return - } - - r = &ACIDFiler0{wal: wal} - for _, o := range opts { - if err := o(&r.walOptions); err != nil { - return nil, err - } - } - - if fi.Size() != 0 { - if err = r.recoverDb(db); err != nil { - return - } - } - - r.bwal = bufio.NewWriter(r.wal) - r.newEpoch = true - acidWriter := (*acidWriter0)(r) - - if r.RollbackFiler, err = NewRollbackFiler( - db, - func(sz int64) (err error) { - // Checkpoint - if err = acidWriter.writePacket([]interface{}{wpt00Checkpoint, sz}); err != nil { - return - } - - if err = r.bwal.Flush(); err != nil { - return - } - - if err = r.wal.Sync(); err != nil { - return - } - - var wfi os.FileInfo - if wfi, err = r.wal.Stat(); err != nil { - return - } - r.peakWal = mathutil.MaxInt64(wfi.Size(), r.peakWal) - - // Phase 1 commit complete - - for _, v := range r.data { - n := len(v.b) - if m := v.off + int64(n); m > sz { - if n -= int(m - sz); n <= 0 { - continue - } - } - - if _, err = db.WriteAt(v.b[:n], v.off); err != nil { - return err - } - } - - if err = db.Truncate(sz); err != nil { - return - } - - if err = db.Sync(); err != nil { - return - } - - // Phase 2 commit complete - - if !r.testHook { - if err := r.emptyWAL(); err != nil { - return err - } - } - - r.testHook = false - r.bwal.Reset(r.wal) - r.newEpoch = true - return r.wal.Sync() - - }, - acidWriter, - ); err != nil { - return - } - - return r, nil -} - -func (a *ACIDFiler0) emptyWAL() error { - if err := a.wal.Truncate(a.walOptions.headroom); err != nil { - return err - } - - if _, err := a.wal.Seek(0, 0); err != nil { - return err - } - - if a.walOptions.headroom != 0 { - a.bwal.Reset(a.wal) - if err := (*acidWriter0)(a).writePacket([]interface{}{wpt00Empty}); err != nil { - return err - } - - if err := a.bwal.Flush(); err != nil { - return err - } - - if _, err := a.wal.Seek(0, 0); err != nil { - return err - } - } - - return nil -} - -// PeakWALSize reports the maximum size WAL has ever used. -func (a ACIDFiler0) PeakWALSize() int64 { - return a.peakWal -} - -func (a *ACIDFiler0) readPacket(f *bufio.Reader) (items []interface{}, err error) { - var b4 [4]byte - n, err := io.ReadAtLeast(f, b4[:], 4) - if n != 4 { - return - } - - ln := int(binary.BigEndian.Uint32(b4[:])) - m := (4 + ln) % 16 - padd := (16 - m) % 16 - b := make([]byte, ln+padd) - if n, err = io.ReadAtLeast(f, b, len(b)); n != len(b) { - return - } - - return DecodeScalars(b[:ln]) -} - -func (a *ACIDFiler0) recoverDb(db Filer) (err error) { - fi, err := a.wal.Stat() - if err != nil { - return &ErrILSEQ{Type: ErrInvalidWAL, Name: a.wal.Name(), More: err} - } - - if sz := fi.Size(); sz%16 != 0 { - return &ErrILSEQ{Type: ErrFileSize, Name: a.wal.Name(), Arg: sz} - } - - f := bufio.NewReader(a.wal) - items, err := a.readPacket(f) - if err != nil { - return - } - - if items[0] == int64(wpt00Empty) { - if len(items) != 1 { - return &ErrILSEQ{Type: ErrInvalidWAL, Name: a.wal.Name(), More: fmt.Sprintf("invalid packet items %#v", items)} - } - - return nil - } - - if len(items) != 3 || items[0] != int64(wpt00Header) || items[1] != int64(walTypeACIDFiler0) { - return &ErrILSEQ{Type: ErrInvalidWAL, Name: a.wal.Name(), More: fmt.Sprintf("invalid packet items %#v", items)} - } - - tr := NewBTree(nil) - - for { - items, err = a.readPacket(f) - if err != nil { - return - } - - if len(items) < 2 { - return &ErrILSEQ{Type: ErrInvalidWAL, Name: a.wal.Name(), More: fmt.Sprintf("too few packet items %#v", items)} - } - - switch items[0] { - case int64(wpt00WriteData): - if len(items) != 3 { - return &ErrILSEQ{Type: ErrInvalidWAL, Name: a.wal.Name(), More: fmt.Sprintf("invalid data packet items %#v", items)} - } - - b, off := items[1].([]byte), items[2].(int64) - var key [8]byte - binary.BigEndian.PutUint64(key[:], uint64(off)) - if err = tr.Set(key[:], b); err != nil { - return - } - case int64(wpt00Checkpoint): - var b1 [1]byte - if n, err := f.Read(b1[:]); n != 0 || err == nil { - return &ErrILSEQ{Type: ErrInvalidWAL, Name: a.wal.Name(), More: fmt.Sprintf("checkpoint n %d, err %v", n, err)} - } - - if len(items) != 2 { - return &ErrILSEQ{Type: ErrInvalidWAL, Name: a.wal.Name(), More: fmt.Sprintf("checkpoint packet invalid items %#v", items)} - } - - sz := items[1].(int64) - enum, err := tr.seekFirst() - if err != nil { - return err - } - - for { - var k, v []byte - k, v, err = enum.current() - if err != nil { - if fileutil.IsEOF(err) { - break - } - - return err - } - - if _, err = db.WriteAt(v, int64(binary.BigEndian.Uint64(k))); err != nil { - return err - } - - if err = enum.next(); err != nil { - if fileutil.IsEOF(err) { - break - } - - return err - } - } - - if err = db.Truncate(sz); err != nil { - return err - } - - if err = db.Sync(); err != nil { - return err - } - - // Recovery complete - - if err := a.emptyWAL(); err != nil { - return err - } - - return a.wal.Sync() - default: - return &ErrILSEQ{Type: ErrInvalidWAL, Name: a.wal.Name(), More: fmt.Sprintf("packet tag %v", items[0])} - } - } -} diff --git a/vendor/github.com/cznic/lldb/2pc_docs.go b/vendor/github.com/cznic/lldb/2pc_docs.go deleted file mode 100644 index e045865f2..000000000 --- a/vendor/github.com/cznic/lldb/2pc_docs.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* - -Anatomy of a WAL file - -WAL file - A sequence of packets - -WAL packet, parts in slice notation - [0:4], 4 bytes: N uint32 // network byte order - [4:4+N], N bytes: payload []byte // gb encoded scalars - -Packets, including the 4 byte 'size' prefix, MUST BE padded to size == 0 (mod -16). The values of the padding bytes MUST BE zero. - -Encoded scalars first item is a packet type number (packet tag). The meaning of -any other item(s) of the payload depends on the packet tag. - -Packet definitions - - {wpt00Header int, typ int, s string} - typ: Must be zero (ACIDFiler0 file). - s: Any comment string, empty string is okay. - - This packet must be present only once - as the first packet of - a WAL file. - - {wpt00WriteData int, b []byte, off int64} - Write data (WriteAt(b, off)). - - {wpt00Checkpoint int, sz int64} - Checkpoint (Truncate(sz)). - - This packet must be present only once - as the last packet of - a WAL file. - - {wpt00Empty int} - The WAL size is of non-zero size due to configured headroom, - but empty otherwise. - -*/ - -package lldb - -//TODO optimize bitfiler/wal/2pc data above final size diff --git a/vendor/github.com/cznic/lldb/LICENSE b/vendor/github.com/cznic/lldb/LICENSE deleted file mode 100644 index 27e4447a4..000000000 --- a/vendor/github.com/cznic/lldb/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014 The lldb Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/lldb/btree.go b/vendor/github.com/cznic/lldb/btree.go deleted file mode 100644 index dcd671a8e..000000000 --- a/vendor/github.com/cznic/lldb/btree.go +++ /dev/null @@ -1,2346 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package lldb - -import ( - "bytes" - "errors" - "fmt" - "io" - "sort" - "strings" - - "github.com/cznic/fileutil" - "github.com/cznic/internal/buffer" - "github.com/cznic/sortutil" -) - -const ( - kData = 256 // [1, 512] - kIndex = 256 // [2, 2048] - kKV = 19 // Size of the key/value field in btreeDataPage - kSz = kKV - 1 - 7 // Content prefix size - kH = kKV - 7 // Content field offset for handle - tagBTreeDataPage = 1 - tagBTreeIndexPage = 0 -) - -// BTree is a B+tree[1][2], i.e. a variant which speeds up -// enumeration/iteration of the BTree. According to its origin it can be -// volatile (backed only by memory) or non-volatile (backed by a non-volatile -// Allocator). -// -// The specific implementation of BTrees in this package are B+trees with -// delayed split/concatenation (discussed in e.g. [3]). -// -// Note: No BTree methods returns io.EOF for physical Filer reads/writes. The -// io.EOF is returned only by bTreeEnumerator methods to indicate "no more K-V -// pair". -// -// [1]: http://en.wikipedia.org/wiki/B+tree -// [2]: http://zgking.com:8080/home/donghui/publications/books/dshandbook_BTree.pdf -// [3]: http://people.cs.aau.dk/~simas/aalg06/UbiquitBtree.pdf -type BTree struct { - store btreeStore - root btree - collate func(a, b []byte) int - serial uint64 -} - -// NewBTree returns a new, memory-only BTree. -func NewBTree(collate func(a, b []byte) int) *BTree { - store := newMemBTreeStore() - root, err := newBTree(store) - if err != nil { // should not happen - panic(err.Error()) - } - - return &BTree{store, root, collate, 0} -} - -// IsMem reports if t is a memory only BTree. -func (t *BTree) IsMem() (r bool) { - _, r = t.store.(*memBTreeStore) - return -} - -// Clear empties the tree. -func (t *BTree) Clear() (err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - t.serial++ - return t.root.clear(t.store) -} - -// Delete deletes key and its associated value from the tree. -func (t *BTree) Delete(key []byte) (err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - t.serial++ - _, err = t.root.extract(t.store, nil, t.collate, key) - return -} - -// DeleteAny deletes one key and its associated value from the tree. If the -// tree is empty on return then empty is true. -func (t *BTree) DeleteAny() (empty bool, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - t.serial++ - return t.root.deleteAny(t.store) -} - -func elem(v interface{}) string { - switch x := v.(type) { - default: - panic("internal error") - case nil: - return "nil" - case bool: - if x { - return "true" - } - - return "false" - case int64: - return fmt.Sprint(x) - case uint64: - return fmt.Sprint(x) - case float64: - s := fmt.Sprintf("%g", x) - if !strings.Contains(s, ".") { - s += "." - } - return s - case complex128: - s := fmt.Sprint(x) - return s[1 : len(s)-1] - case []byte: - return fmt.Sprintf("[]byte{% 02x}", x) - case string: - return fmt.Sprintf("%q", x) - } -} - -// Dump outputs a human readable dump of t to w. It is usable iff t keys and -// values are encoded scalars (see EncodeScalars). Intended use is only for -// examples or debugging. Some type information is lost in the rendering, for -// example a float value '17.' and an integer value '17' may both output as -// '17'. -func (t *BTree) Dump(w io.Writer) (err error) { - enum, err := t.seekFirst() - if err != nil { - return - } - - for { - bkey, bval, err := enum.current() - if err != nil { - return err - } - - key, err := DecodeScalars(bkey) - if err != nil { - return err - } - - val, err := DecodeScalars(bval) - if err != nil { - return err - } - - kk := []string{} - if key == nil { - kk = []string{"null"} - } - for _, v := range key { - kk = append(kk, elem(v)) - } - vv := []string{} - if val == nil { - vv = []string{"null"} - } - for _, v := range val { - vv = append(vv, elem(v)) - } - skey := strings.Join(kk, ", ") - sval := strings.Join(vv, ", ") - if len(vv) > 1 { - sval = fmt.Sprintf("[]interface{%s}", sval) - } - if _, err = fmt.Fprintf(w, "%s → %s\n", skey, sval); err != nil { - return err - } - - err = enum.next() - if err != nil { - if fileutil.IsEOF(err) { - err = nil - break - } - - return err - } - } - return -} - -// Extract is a combination of Get and Delete. If the key exists in the tree, -// it is returned (like Get) and also deleted from a tree in a more efficient -// way which doesn't walk it twice. The returned slice may be a sub-slice of -// buf if buf was large enough to hold the entire content. Otherwise, a newly -// allocated slice will be returned. It is valid to pass a nil buf. -func (t *BTree) Extract(buf, key []byte) (value []byte, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - t.serial++ - return t.root.extract(t.store, buf, t.collate, key) -} - -// First returns the first KV pair of the tree, if it exists. Otherwise key == nil -// and value == nil. -func (t *BTree) First() (key, value []byte, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - var p btreeDataPage - if _, p, err = t.root.first(t.store); err != nil || p == nil { - return - } - - if key, err = p.key(t.store, 0); err != nil { - return - } - - value, err = p.value(t.store, 0) - return -} - -// Get returns the value associated with key, or nil if no such value exists. -// The returned slice may be a sub-slice of buf if buf was large enough to hold -// the entire content. Otherwise, a newly allocated slice will be returned. -// It is valid to pass a nil buf. -// -// Get is safe for concurrent access by multiple goroutines iff no other -// goroutine mutates the tree. -func (t *BTree) Get(buf, key []byte) (value []byte, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - pbuffer := buffer.Get(maxBuf) - defer buffer.Put(pbuffer) - buffer := *pbuffer - if buffer, err = t.root.get(t.store, buffer, t.collate, key); buffer == nil || err != nil { - return - } - - if len(buffer) != 0 { - // The buffer cache returns nil for empty buffers, bypass it - value = need(len(buffer), buf) - } else { - value = []byte{} - } - copy(value, buffer) - return -} - -// Handle reports t's handle. -func (t *BTree) Handle() int64 { - return int64(t.root) -} - -// Last returns the last KV pair of the tree, if it exists. Otherwise key == nil -// and value == nil. -func (t *BTree) Last() (key, value []byte, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - var p btreeDataPage - if _, p, err = t.root.last(t.store); err != nil || p == nil { - return - } - - index := p.len() - 1 - if key, err = p.key(t.store, index); err != nil { - return - } - - value, err = p.value(t.store, index) - return -} - -// Put combines Get and Set in a more efficient way where the tree is walked -// only once. The upd(ater) receives the current (key, old-value), if that -// exists or (key, nil) otherwise. It can then return a (new-value, true, nil) -// to create or overwrite the existing value in the KV pair, or (whatever, -// false, nil) if it decides not to create or not to update the value of the KV -// pair. -// -// tree.Set(k, v) -// -// conceptually equals -// -// tree.Put(k, func(k, v []byte){ return v, true }([]byte, bool)) -// -// modulo the differing return values. -// -// The returned slice may be a sub-slice of buf if buf was large enough to hold -// the entire content. Otherwise, a newly allocated slice will be returned. -// It is valid to pass a nil buf. -func (t *BTree) Put(buf, key []byte, upd func(key, old []byte) (new []byte, write bool, err error)) (old []byte, written bool, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - t.serial++ - return t.root.put2(buf, t.store, t.collate, key, upd) -} - -// Seek returns an Enumerator with "position" or an error of any. Normally the -// position is on a KV pair such that key >= KV.key. Then hit is key == KV.key. -// The position is possibly "after" the last KV pair, but that is not an error. -// -// Seek is safe for concurrent access by multiple goroutines iff no other -// goroutine mutates the tree. -func (t *BTree) Seek(key []byte) (enum *BTreeEnumerator, hit bool, err error) { - enum0, hit, err := t.seek(key) - if err != nil { - return - } - - enum = &BTreeEnumerator{ - enum: enum0, - firstHit: hit, - key: append([]byte(nil), key...), - } - return -} - -func (t *BTree) seek(key []byte) (enum *bTreeEnumerator, hit bool, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - r := &bTreeEnumerator{t: t, collate: t.collate, serial: t.serial} - if r.p, r.index, hit, err = t.root.seek(t.store, r.collate, key); err != nil { - return - } - - enum = r - return -} - -// IndexSeek returns an Enumerator with "position" or an error of any. Normally -// the position is on a KV pair such that key >= KV.key. Then hit is key == -// KV.key. The position is possibly "after" the last KV pair, but that is not -// an error. The collate function originally passed to CreateBTree is used for -// enumerating the tree but a custom collate function c is used for IndexSeek. -// -// IndexSeek is safe for concurrent access by multiple goroutines iff no other -// goroutine mutates the tree. -func (t *BTree) IndexSeek(key []byte, c func(a, b []byte) int) (enum *BTreeEnumerator, hit bool, err error) { //TODO +test - enum0, hit, err := t.indexSeek(key, c) - if err != nil { - return - } - - enum = &BTreeEnumerator{ - enum: enum0, - firstHit: hit, - key: append([]byte(nil), key...), - } - return -} - -func (t *BTree) indexSeek(key []byte, c func(a, b []byte) int) (enum *bTreeEnumerator, hit bool, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - r := &bTreeEnumerator{t: t, collate: t.collate, serial: t.serial} - if r.p, r.index, hit, err = t.root.seek(t.store, c, key); err != nil { - return - } - - enum = r - return -} - -// seekFirst returns an enumerator positioned on the first KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returend. -// -// SeekFirst is safe for concurrent access by multiple goroutines iff no other -// goroutine mutates the tree. -func (t *BTree) SeekFirst() (enum *BTreeEnumerator, err error) { - enum0, err := t.seekFirst() - if err != nil { - return - } - - var key []byte - if key, _, err = enum0.current(); err != nil { - return - } - - enum = &BTreeEnumerator{ - enum: enum0, - firstHit: true, - key: append([]byte(nil), key...), - } - return -} - -func (t *BTree) seekFirst() (enum *bTreeEnumerator, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - var p btreeDataPage - if _, p, err = t.root.first(t.store); err == nil && p == nil { - err = io.EOF - } - if err != nil { - return - } - - return &bTreeEnumerator{t: t, collate: t.collate, p: p, index: 0, serial: t.serial}, nil -} - -// seekLast returns an enumerator positioned on the last KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returend. -// -// SeekLast is safe for concurrent access by multiple goroutines iff no other -// goroutine mutates the tree. -func (t *BTree) SeekLast() (enum *BTreeEnumerator, err error) { - enum0, err := t.seekLast() - if err != nil { - return - } - - var key []byte - if key, _, err = enum0.current(); err != nil { - return - } - - enum = &BTreeEnumerator{ - enum: enum0, - firstHit: true, - key: append([]byte(nil), key...), - } - return -} - -func (t *BTree) seekLast() (enum *bTreeEnumerator, err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - var p btreeDataPage - if _, p, err = t.root.last(t.store); err == nil && p == nil { - err = io.EOF - } - if err != nil { - return - } - - return &bTreeEnumerator{t: t, collate: t.collate, p: p, index: p.len() - 1, serial: t.serial}, nil -} - -// Set sets the value associated with key. Any previous value, if existed, is -// overwritten by the new one. -func (t *BTree) Set(key, value []byte) (err error) { - if t == nil { - err = errors.New("BTree method invoked on nil receiver") - return - } - - t.serial++ - pdst := buffer.Get(maxBuf) - dst := *pdst - _, err = t.root.put(dst, t.store, t.collate, key, value, true) - buffer.Put(pdst) - return -} - -// bTreeEnumerator is a closure of a BTree and a position. It is returned from -// BTree.seek. -// -// NOTE: bTreeEnumerator cannot be used after its BTree was mutated after the -// bTreeEnumerator was acquired from any of the seek, seekFirst, seekLast -// methods. -type bTreeEnumerator struct { - t *BTree - collate func(a, b []byte) int - p btreeDataPage - index int - serial uint64 -} - -// Current returns the KV pair the enumerator is currently positioned on. If -// the position is before the first KV pair in the tree or after the last KV -// pair in the tree then err == io.EOF is returned. -// -// If the enumerator has been invalidated by updating the tree, ErrINVAL is -// returned. -func (e *bTreeEnumerator) current() (key, value []byte, err error) { - if e == nil { - err = errors.New("bTreeEnumerator method invoked on nil receiver") - return - } - - if e.serial != e.t.serial { - err = &ErrINVAL{Src: "bTreeEnumerator invalidated by updating the tree"} - return - } - - if e.p == nil || e.index == e.p.len() { - return nil, nil, io.EOF - } - - if key, err = e.p.key(e.t.store, e.index); err != nil { - return - } - - value, err = e.p.value(e.t.store, e.index) - return -} - -// Next attempts to position the enumerator onto the next KV pair wrt the -// current position. If there is no "next" KV pair, io.EOF is returned. -// -// If the enumerator has been invalidated by updating the tree, ErrINVAL is -// returned. -func (e *bTreeEnumerator) next() (err error) { - if e == nil { - err = errors.New("bTreeEnumerator method invoked on nil receiver") - return - } - - if e.serial != e.t.serial { - err = &ErrINVAL{Src: "bTreeEnumerator invalidated by updating the tree"} - return - } - - if e.p == nil { - return io.EOF - } - - switch { - case e.index < e.p.len()-1: - e.index++ - default: - ph := e.p.next() - if ph == 0 { - err = io.EOF - break - } - - if e.p, err = e.t.store.Get(e.p, ph); err != nil { - e.p = nil - return - } - e.index = 0 - } - return -} - -// Prev attempts to position the enumerator onto the previous KV pair wrt the -// current position. If there is no "previous" KV pair, io.EOF is returned. -// -// If the enumerator has been invalidated by updating the tree, ErrINVAL is -// returned. -func (e *bTreeEnumerator) prev() (err error) { - if e == nil { - err = errors.New("bTreeEnumerator method invoked on nil receiver") - return - } - - if e.serial != e.t.serial { - err = &ErrINVAL{Src: "bTreeEnumerator invalidated by updating the tree"} - return - } - - if e.p == nil { - return io.EOF - } - - switch { - case e.index > 0: - e.index-- - default: - ph := e.p.prev() - if ph == 0 { - err = io.EOF - break - } - - if e.p, err = e.t.store.Get(e.p, ph); err != nil { - e.p = nil - return - } - e.index = e.p.len() - 1 - } - return -} - -// BTreeEnumerator captures the state of enumerating a tree. It is returned -// from the Seek* methods. The enumerator is aware of any mutations made to -// the tree in the process of enumerating it and automatically resumes the -// enumeration. -type BTreeEnumerator struct { - enum *bTreeEnumerator - err error - key []byte - firstHit bool -} - -// Next returns the currently enumerated KV pair, if it exists and moves to the -// next KV in the key collation order. If there is no KV pair to return, err == -// io.EOF is returned. -// -// Next is safe for concurrent access by multiple goroutines iff no other -// goroutine mutates the tree. -func (e *BTreeEnumerator) Next() (key, value []byte, err error) { - if err = e.err; err != nil { - return - } - - canRetry := true -retry: - if e.enum.p == nil { - e.err = io.EOF - return nil, nil, e.err - } - - if e.enum.index == e.enum.p.len() && e.enum.serial == e.enum.t.serial { - if err = e.enum.next(); err != nil { - e.err = err - return nil, nil, e.err - } - } - - if key, value, err = e.enum.current(); err != nil { - if _, ok := err.(*ErrINVAL); !ok || !canRetry { - e.err = err - return - } - - canRetry = false - var hit bool - if e.enum, hit, err = e.enum.t.seek(e.key); err != nil { - e.err = err - return - } - - if !e.firstHit && hit { - err = e.enum.next() - if err != nil { - e.err = err - return - } - } - - goto retry - } - - e.firstHit = false - e.key = append([]byte(nil), key...) - e.err = e.enum.next() - return -} - -// Prev returns the currently enumerated KV pair, if it exists and moves to the -// previous KV in the key collation order. If there is no KV pair to return, -// err == io.EOF is returned. -// -// Prev is safe for concurrent access by multiple goroutines iff no other -// goroutine mutates the tree. -func (e *BTreeEnumerator) Prev() (key, value []byte, err error) { - if err = e.err; err != nil { - return - } - - canRetry := true -retry: - if key, value, err = e.enum.current(); err != nil { - if _, ok := err.(*ErrINVAL); !ok || !canRetry { - e.err = err - return - } - - canRetry = false - var hit bool - if e.enum, hit, err = e.enum.t.seek(e.key); err != nil { - e.err = err - return - } - - if !e.firstHit && hit { - err = e.enum.prev() - if err != nil { - e.err = err - return - } - } - - goto retry - } - - e.firstHit = false - e.key = append([]byte(nil), key...) - e.err = e.enum.prev() - return -} - -// CreateBTree creates a new BTree in store. It returns the tree, its (freshly -// assigned) handle (for OpenBTree or RemoveBTree) or an error, if any. -func CreateBTree(store *Allocator, collate func(a, b []byte) int) (bt *BTree, handle int64, err error) { - r := &BTree{store: store, collate: collate} - if r.root, err = newBTree(store); err != nil { - return - } - - return r, int64(r.root), nil -} - -// OpenBTree opens a store's BTree using handle. It returns the tree or an -// error, if any. The same tree may be opened more than once, but operations on -// the separate instances should not ever overlap or void the other instances. -// However, the intended API usage is to open the same tree handle only once -// (handled by some upper layer "dispatcher"). -func OpenBTree(store *Allocator, collate func(a, b []byte) int, handle int64) (bt *BTree, err error) { - r := &BTree{store: store, root: btree(handle), collate: collate} - pb := buffer.Get(7) - defer buffer.Put(pb) - b := *pb - if b, err = store.Get(b, handle); err != nil { - return - } - - if len(b) != 7 { - return nil, &ErrILSEQ{Off: h2off(handle), More: "btree.go:671"} - } - - return r, nil -} - -// RemoveBTree removes tree, represented by handle from store. Empty trees are -// cheap, each uses only few bytes of the store. If there's a chance that a -// tree will eventually get reused (non empty again), it's recommended to -// not/never remove it. One advantage of such approach is a stable handle of -// such tree. -func RemoveBTree(store *Allocator, handle int64) (err error) { - tree, err := OpenBTree(store, nil, handle) - if err != nil { - return - } - - if err = tree.Clear(); err != nil { - return - } - - return store.Free(handle) -} - -type btreeStore interface { - Alloc(b []byte) (handle int64, err error) - Free(handle int64) (err error) - Get(dst []byte, handle int64) (b []byte, err error) - Realloc(handle int64, b []byte) (err error) -} - -// Read only zero bytes -var zeros [2 * kKV]byte - -func init() { - if kData < 1 || kData > 512 { - panic(fmt.Errorf("kData %d: out of limits", kData)) - } - - if kIndex < 2 || kIndex > 2048 { - panic(fmt.Errorf("kIndex %d: out of limits", kIndex)) - } - - if kKV < 8 || kKV > 23 { - panic(fmt.Errorf("kKV %d: out of limits", kKV)) - } - - if n := len(zeros); n < 15 { - panic(fmt.Errorf("not enough zeros: %d", n)) - } -} - -type memBTreeStore struct { - h int64 - m map[int64][]byte -} - -func newMemBTreeStore() *memBTreeStore { - return &memBTreeStore{h: 0, m: map[int64][]byte{}} -} - -func (s *memBTreeStore) String() string { - var a sortutil.Int64Slice - for k := range s.m { - a = append(a, k) - } - sort.Sort(a) - var sa []string - for _, k := range a { - sa = append(sa, fmt.Sprintf("%#x:|% x|", k, s.m[k])) - } - return strings.Join(sa, "\n") -} - -func (s *memBTreeStore) Alloc(b []byte) (handle int64, err error) { - s.h++ - handle = s.h - s.m[handle] = bpack(b) - return -} - -func (s *memBTreeStore) Free(handle int64) (err error) { - if _, ok := s.m[handle]; !ok { - return &ErrILSEQ{Type: ErrOther, Off: h2off(handle), More: "btree.go:754"} - } - - delete(s.m, handle) - return -} - -func (s *memBTreeStore) Get(dst []byte, handle int64) (b []byte, err error) { - r, ok := s.m[handle] - if !ok { - return nil, &ErrILSEQ{Type: ErrOther, Off: h2off(handle), More: "btree.go:764"} - } - - b = need(len(r), dst) - copy(b, r) - return -} - -func (s *memBTreeStore) Realloc(handle int64, b []byte) (err error) { - if _, ok := s.m[handle]; !ok { - return &ErrILSEQ{Type: ErrOther, Off: h2off(handle), More: "btree.go:774"} - } - - s.m[handle] = bpack(b) - return -} - -/* - -0...0 (1 bytes): -Flag - - 0 - +---+ - | 0 | - +---+ - -0 indicates an index page - -1...count*14-1 -"array" of items, 14 bytes each. Count of items in kIndex-1..2*kIndex+2 - - Count = (len(raw) - 8) / 14 - - 0..6 7..13 - +-------+----------+ - | Child | DataPage | - +-------+----------+ - - Child == handle of a child index page - DataPage == handle of a data page - -Offsets into the raw []byte: -Child[X] == 1+14*X -DataPage[X] == 8+14*X - -*/ -type btreeIndexPage []byte - -func newBTreeIndexPage(leftmostChild int64) (p btreeIndexPage) { - p = (*buffer.Get(1 + (kIndex+1)*2*7))[:8] - p[0] = tagBTreeIndexPage - h2b(p[1:], leftmostChild) - return -} - -func (p btreeIndexPage) len() int { - return (len(p) - 8) / 14 -} - -func (p btreeIndexPage) child(index int) int64 { - return b2h(p[1+14*index:]) -} - -func (p btreeIndexPage) setChild(index int, dp int64) { - h2b(p[1+14*index:], dp) -} - -func (p btreeIndexPage) dataPage(index int) int64 { - return b2h(p[8+14*index:]) -} - -func (p btreeIndexPage) setDataPage(index int, dp int64) { - h2b(p[8+14*index:], dp) -} - -func (q btreeIndexPage) insert(index int) btreeIndexPage { - switch len0 := q.len(); { - case index < len0: - has := len(q) - need := has + 14 - switch { - case cap(q) >= need: - q = q[:need] - default: - q = append(q, zeros[:14]...) - } - copy(q[8+14*(index+1):8+14*(index+1)+2*(len0-index)*7], q[8+14*index:]) - case index == len0: - has := len(q) - need := has + 14 - switch { - case cap(q) >= need: - q = q[:need] - default: - q = append(q, zeros[:14]...) - } - } - return q -} - -func (p btreeIndexPage) insert3(index int, dataPage, child int64) btreeIndexPage { - p = p.insert(index) - p.setDataPage(index, dataPage) - p.setChild(index+1, child) - return p -} - -func (p btreeIndexPage) cmp(a btreeStore, c func(a, b []byte) int, keyA []byte, keyBIndex int) (int, error) { - pb := buffer.Get(maxBuf) - defer buffer.Put(pb) - b := *pb - dp, err := a.Get(b, p.dataPage(keyBIndex)) - if err != nil { - return 0, err - } - - return btreeDataPage(dp).cmp(a, c, keyA, 0) -} - -func (q btreeIndexPage) setLen(n int) btreeIndexPage { - q = q[:cap(q)] - need := 8 + 14*n - if need < len(q) { - return q[:need] - } - return append(q, make([]byte, need-len(q))...) -} - -func (p btreeIndexPage) split(a btreeStore, root btree, ph *int64, parent int64, parentIndex int, index *int) (btreeIndexPage, error) { - right := newBTreeIndexPage(0) - right = right.setLen(kIndex) - copy(right[1:1+(2*kIndex+1)*7], p[1+14*(kIndex+1):]) - p = p.setLen(kIndex) - if err := a.Realloc(*ph, p); err != nil { - return nil, err - } - - rh, err := a.Alloc(right) - if err != nil { - return nil, err - } - - if parentIndex >= 0 { - ppp := buffer.Get(maxBuf) - defer buffer.Put(ppp) - pp := btreeIndexPage(*ppp) - if pp, err = a.Get(pp, parent); err != nil { - return nil, err - } - pp = pp.insert3(parentIndex, p.dataPage(kIndex), rh) - if err = a.Realloc(parent, pp); err != nil { - return nil, err - } - - } else { - nr := newBTreeIndexPage(*ph) - nr = nr.insert3(0, p.dataPage(kIndex), rh) - nrh, err := a.Alloc(nr) - if err != nil { - return nil, err - } - - if err = a.Realloc(int64(root), h2b(make([]byte, 7), nrh)); err != nil { - return nil, err - } - } - if *index > kIndex { - p = right - *ph = rh - *index -= kIndex + 1 - } - return p, nil -} - -// p is dirty on return -func (p btreeIndexPage) extract(index int) btreeIndexPage { - n := p.len() - 1 - if index < n { - sz := (n-index)*14 + 7 - copy(p[1+14*index:1+14*index+sz], p[1+14*(index+1):]) - } - return p.setLen(n) -} - -// must persist all changes made -func (p btreeIndexPage) underflow(a btreeStore, root, iroot, parent int64, ph *int64, parentIndex int, index *int) (btreeIndexPage, error) { - lh, rh, err := checkSiblings(a, parent, parentIndex) - if err != nil { - return nil, err - } - - pleft := buffer.Get(maxBuf) - defer buffer.Put(pleft) - left := btreeIndexPage(*pleft) - - if lh != 0 { - if left, err = a.Get(left, lh); err != nil { - return nil, err - } - - if lc := left.len(); lc > kIndex { - ppp := buffer.Get(maxBuf) - defer buffer.Put(ppp) - pp := *ppp - if pp, err = a.Get(pp, parent); err != nil { - return nil, err - } - - pc := p.len() - p = p.setLen(pc + 1) - di, si, sz := 1+1*14, 1+0*14, (2*pc+1)*7 - copy(p[di:di+sz], p[si:]) - p.setChild(0, left.child(lc)) - p.setDataPage(0, btreeIndexPage(pp).dataPage(parentIndex-1)) - *index++ - btreeIndexPage(pp).setDataPage(parentIndex-1, left.dataPage(lc-1)) - left = left.setLen(lc - 1) - if err = a.Realloc(parent, pp); err != nil { - return nil, err - } - - if err = a.Realloc(*ph, p); err != nil { - return nil, err - } - - return p, a.Realloc(lh, left) - } - } - - if rh != 0 { - pright := buffer.Get(maxBuf) - defer buffer.Put(pright) - right := *pright - if right, err = a.Get(right, rh); err != nil { - return nil, err - } - - if rc := btreeIndexPage(right).len(); rc > kIndex { - ppp := buffer.Get(maxBuf) - defer buffer.Put(ppp) - pp := *ppp - if pp, err = a.Get(pp, parent); err != nil { - return nil, err - } - - pc := p.len() - p = p.setLen(pc + 1) - p.setDataPage(pc, btreeIndexPage(pp).dataPage(parentIndex)) - pc++ - p.setChild(pc, btreeIndexPage(right).child(0)) - btreeIndexPage(pp).setDataPage(parentIndex, btreeIndexPage(right).dataPage(0)) - di, si, sz := 1+0*14, 1+1*14, (2*rc+1)*7 - copy(right[di:di+sz], right[si:]) - right = btreeIndexPage(right).setLen(rc - 1) - if err = a.Realloc(parent, pp); err != nil { - return nil, err - } - - if err = a.Realloc(*ph, p); err != nil { - return nil, err - } - - return p, a.Realloc(rh, right) - } - } - - if lh != 0 { - *index += left.len() + 1 - if left, err = left.concat(a, root, iroot, parent, lh, *ph, parentIndex-1); err != nil { - return p, err - } - - p, *ph = left, lh - return p, nil - } - - return p.concat(a, root, iroot, parent, *ph, rh, parentIndex) -} - -// must persist all changes made -func (p btreeIndexPage) concat(a btreeStore, root, iroot, parent, ph, rh int64, parentIndex int) (btreeIndexPage, error) { - ppp := buffer.Get(maxBuf) - defer buffer.Put(ppp) - pp := *ppp - pp, err := a.Get(pp, parent) - if err != nil { - return nil, err - } - - pright := buffer.Get(maxBuf) - defer buffer.Put(pright) - right := *pright - if right, err = a.Get(right, rh); err != nil { - return nil, err - } - - pc := p.len() - rc := btreeIndexPage(right).len() - p = p.setLen(pc + rc + 1) - p.setDataPage(pc, btreeIndexPage(pp).dataPage(parentIndex)) - di, si, sz := 1+14*(pc+1), 1+0*14, (2*rc+1)*7 - copy(p[di:di+sz], right[si:]) - if err := a.Realloc(ph, p); err != nil { - return nil, err - } - - if err := a.Free(rh); err != nil { - return nil, err - } - - if pc := btreeIndexPage(pp).len(); pc > 1 { - if parentIndex < pc-1 { - di, si, sz := 8+parentIndex*14, 8+(parentIndex+1)*14, 2*(pc-1-parentIndex)*7 - copy(pp[di:si+sz], pp[si:]) - } - pp = btreeIndexPage(pp).setLen(pc - 1) - return p, a.Realloc(parent, pp) - } - - if err := a.Free(iroot); err != nil { - return nil, err - } - - pb7 := buffer.Get(7) - defer buffer.Put(pb7) - b7 := *pb7 - return p, a.Realloc(root, h2b(b7[:7], ph)) -} - -/* - -0...0 (1 bytes): -Flag - - 0 - +---+ - | 1 | - +---+ - -1 indicates a data page - -1...14 (14 bytes) - - 1..7 8..14 - +------+------+ - | Prev | Next | - +------+------+ - - Prev, Next == Handles of the data pages doubly linked list - - Count = (len(raw) - 15) / (2*kKV) - -15...count*2*kKV-1 -"array" of items, 2*kKV bytes each. Count of items in kData-1..2*kData - -Item - 0..kKV-1 kKV..2*kKV-1 - +----------+--------------+ - | Key | Value | - +----------+--------------+ - -Key/Value encoding - -Length 0...kKV-1 - - 0 1...N N+1...kKV-1 - +---+---------+-------------+ - | N | Data | Padding | - +---+---------+-------------+ - - N == content length - Data == Key or Value content - Padding == MUST be zero bytes - -Length >= kKV - - 0 1...kkV-8 kKV-7...kkV-1 - +------+-----------+--------------+ - | 0xFF | Data | H | - +------+-----------+--------------+ - - Data == Key or Value content, first kKV-7 bytes - H == Handle to THE REST of the content, w/o the first bytes in Data. - -Offsets into the raw []byte: -Key[X] == 15+2*kKV*X -Value[X] == 15+kKV+2*kKV*X -*/ -type btreeDataPage []byte - -func newBTreeDataPage() (p btreeDataPage) { - p = (*buffer.CGet(1 + 2*7 + (kData+1)*2*kKV))[:1+2*7] - p[0] = tagBTreeDataPage - return -} - -func newBTreeDataPageAlloc(a btreeStore) (p btreeDataPage, h int64, err error) { - p = newBTreeDataPage() - h, err = a.Alloc(p) - return -} - -func (p btreeDataPage) len() int { - return (len(p) - 15) / (2 * kKV) -} - -func (q btreeDataPage) setLen(n int) btreeDataPage { - q = q[:cap(q)] - need := 15 + 2*kKV*n - if need < len(q) { - return q[:need] - } - return append(q, make([]byte, need-len(q))...) -} - -func (p btreeDataPage) prev() int64 { - return b2h(p[1:]) -} - -func (p btreeDataPage) next() int64 { - return b2h(p[8:]) -} - -func (p btreeDataPage) setPrev(h int64) { - h2b(p[1:], h) -} - -func (p btreeDataPage) setNext(h int64) { - h2b(p[8:], h) -} - -func (q btreeDataPage) insert(index int) btreeDataPage { - switch len0 := q.len(); { - case index < len0: - has := len(q) - need := has + 2*kKV - switch { - case cap(q) >= need: - q = q[:need] - default: - q = append(q, zeros[:2*kKV]...) - } - q.copy(q, index+1, index, len0-index) - return q - case index == len0: - has := len(q) - need := has + 2*kKV - switch { - case cap(q) >= need: - return q[:need] - default: - return append(q, zeros[:2*kKV]...) - } - } - panic("internal error") -} - -func (p btreeDataPage) contentField(off int) (b []byte, h int64) { - p = p[off:] - switch n := int(p[0]); { - case n >= kKV: // content has a handle - b = append([]byte(nil), p[1:1+kSz]...) - h = b2h(p[kH:]) - default: // content is embedded - b, h = append([]byte(nil), p[1:1+n]...), 0 - } - return -} - -func (p btreeDataPage) content(a btreeStore, off int) (b []byte, err error) { - b, h := p.contentField(off) - if h == 0 { - return - } - - // content has a handle - b2, err := a.Get(nil, h) //TODO buffers: Later, not a public API - if err != nil { - return nil, err - } - - return append(b, b2...), nil -} - -func (p btreeDataPage) setContent(a btreeStore, off int, b []byte) (err error) { - p = p[off:] - switch { - case p[0] >= kKV: // existing content has a handle - switch n := len(b); { - case n < kKV: - p[0] = byte(n) - if err = a.Free(b2h(p[kH:])); err != nil { - return - } - copy(p[1:], b) - default: - // reuse handle - copy(p[1:1+kSz], b) - return a.Realloc(b2h(p[kH:]), b[kSz:]) - } - default: // existing content is embedded - switch n := len(b); { - case n < kKV: - p[0] = byte(n) - copy(p[1:], b) - default: - p[0] = 0xff - copy(p[1:1+kSz], b) - h, err := a.Alloc(b[kSz:]) - if err != nil { - return err - } - - h2b(p[kH:], h) - } - } - return -} - -func (p btreeDataPage) keyField(index int) (b []byte, h int64) { - return p.contentField(15 + 2*kKV*index) -} - -func (p btreeDataPage) key(a btreeStore, index int) (b []byte, err error) { - return p.content(a, 15+2*kKV*index) -} - -func (p btreeDataPage) valueField(index int) (b []byte, h int64) { - return p.contentField(15 + kKV + 2*kKV*index) -} - -func (p btreeDataPage) value(a btreeStore, index int) (b []byte, err error) { - value, err := p.content(a, 15+kKV+2*kKV*index) - if err == nil && value == nil { - // We have a valid page, no fetch error, the key is valid so return - // non-nil data - return []byte{}, nil - } - return value, err -} - -func (p btreeDataPage) valueCopy(a btreeStore, index int) (b []byte, err error) { - if b, err = p.content(a, 15+kKV+2*kKV*index); err != nil { - return - } - - return append([]byte(nil), b...), nil -} - -func (p btreeDataPage) setKey(a btreeStore, index int, key []byte) (err error) { - return p.setContent(a, 15+2*kKV*index, key) -} - -func (p btreeDataPage) setValue(a btreeStore, index int, value []byte) (err error) { - return p.setContent(a, 15+kKV+2*kKV*index, value) -} - -func (p btreeDataPage) cmp(a btreeStore, c func(a, b []byte) int, keyA []byte, keyBIndex int) (y int, err error) { - var keyB []byte - if keyB, err = p.content(a, 15+2*kKV*keyBIndex); err != nil { - return - } - - return c(keyA, keyB), nil -} - -func (p btreeDataPage) copy(src btreeDataPage, di, si, n int) { - do, so := 15+2*kKV*di, 15+2*kKV*si - copy(p[do:do+2*kKV*n], src[so:]) -} - -// {p,left} dirty on exit -func (p btreeDataPage) moveLeft(left btreeDataPage, n int) (btreeDataPage, btreeDataPage) { - nl, np := left.len(), p.len() - left = left.setLen(nl + n) - left.copy(p, nl, 0, n) - p.copy(p, 0, n, np-n) - return p.setLen(np - n), left -} - -func (p btreeDataPage) moveRight(right btreeDataPage, n int) (btreeDataPage, btreeDataPage) { - nr, np := right.len(), p.len() - right = right.setLen(nr + n) - right.copy(right, n, 0, nr) - right.copy(p, 0, np-n, n) - return p.setLen(np - n), right -} - -func (p btreeDataPage) insertItem(a btreeStore, index int, key, value []byte) (btreeDataPage, error) { - p = p.insert(index) - di, sz := 15+2*kKV*index, 2*kKV - copy(p[di:di+sz], zeros[:sz]) - if err := p.setKey(a, index, key); err != nil { - return nil, err - } - return p, p.setValue(a, index, value) -} - -func (p btreeDataPage) split(a btreeStore, root, ph, parent int64, parentIndex, index int, key, value []byte) (btreeDataPage, error) { - right, rh, err := newBTreeDataPageAlloc(a) - if err != nil { - return nil, err - } - - if next := p.next(); next != 0 { - right.setNext(p.next()) - nxh := right.next() - pnx := buffer.Get(maxBuf) - defer buffer.Put(pnx) - nx := *pnx - if nx, err = a.Get(nx, nxh); err != nil { - return nil, err - } - - btreeDataPage(nx).setPrev(rh) - if err = a.Realloc(nxh, nx); err != nil { - return nil, err - } - } - - p.setNext(rh) - right.setPrev(ph) - right = right.setLen(kData) - right.copy(p, 0, kData, kData) - p = p.setLen(kData) - - if parentIndex >= 0 { - ppp := buffer.Get(maxBuf) - defer buffer.Put(ppp) - pp := btreeIndexPage(*ppp) - if pp, err = a.Get(pp, parent); err != nil { - return nil, err - } - - pp = pp.insert3(parentIndex, rh, rh) - if err = a.Realloc(parent, pp); err != nil { - return nil, err - } - - } else { - nr := newBTreeIndexPage(ph) - nr = nr.insert3(0, rh, rh) - - var nrh int64 - if nrh, err = a.Alloc(nr); err != nil { - return nil, err - } - - if err = a.Realloc(root, h2b(make([]byte, 7), nrh)); err != nil { - return nil, err - } - - } - if index > kData { - if right, err = right.insertItem(a, index-kData, key, value); err != nil { - return nil, err - } - } else { - if p, err = p.insertItem(a, index, key, value); err != nil { - return nil, err - } - } - if err = a.Realloc(ph, p); err != nil { - return nil, err - } - - return p, a.Realloc(rh, right) -} - -func (p btreeDataPage) overflow(a btreeStore, root, ph, parent int64, parentIndex, index int, key, value []byte) (btreeDataPage, error) { - leftH, rightH, err := checkSiblings(a, parent, parentIndex) - if err != nil { - return nil, err - } - - if leftH != 0 { - pleft := buffer.Get(maxBuf) - defer buffer.Put(pleft) - left := btreeDataPage(*pleft) - if left, err = a.Get(left, leftH); err != nil { - return nil, err - } - - if left.len() < 2*kData && index > 0 { - - p, left = p.moveLeft(left, 1) - if err = a.Realloc(leftH, left); err != nil { - return nil, err - } - - if p, err = p.insertItem(a, index-1, key, value); err != nil { - return nil, err - } - - return p, a.Realloc(ph, p) - } - } - - if rightH != 0 { - pright := buffer.Get(maxBuf) - defer buffer.Put(pright) - right := btreeDataPage(*pright) - if right, err = a.Get(right, rightH); err != nil { - return nil, err - } - - if right.len() < 2*kData { - if index < 2*kData { - p, right = p.moveRight(right, 1) - if err = a.Realloc(rightH, right); err != nil { - return nil, err - } - - if p, err = p.insertItem(a, index, key, value); err != nil { - return nil, err - } - - return p, a.Realloc(ph, p) - } else { - if right, err = right.insertItem(a, 0, key, value); err != nil { - return nil, err - } - - return p, a.Realloc(rightH, right) - } - } - } - return p.split(a, root, ph, parent, parentIndex, index, key, value) -} - -func (p btreeDataPage) swap(a btreeStore, di int, value []byte, canOverwrite bool) (oldValue []byte, err error) { - if oldValue, err = p.value(a, di); err != nil { - return - } - - if !canOverwrite { - return - } - - oldValue = append([]byte(nil), oldValue...) - err = p.setValue(a, di, value) - return -} - -type btreePage []byte - -func (p btreePage) isIndex() bool { - return p[0] == tagBTreeIndexPage -} - -func (p btreePage) len() int { - if p.isIndex() { - return btreeIndexPage(p).len() - } - - return btreeDataPage(p).len() -} - -func (p btreePage) find(a btreeStore, c func(a, b []byte) int, key []byte) (index int, ok bool, err error) { - l := 0 - h := p.len() - 1 - isIndex := p.isIndex() - if c == nil { - c = bytes.Compare - } - for l <= h { - index = (l + h) >> 1 - var cmp int - if isIndex { - if cmp, err = btreeIndexPage(p).cmp(a, c, key, index); err != nil { - return - } - } else { - if cmp, err = btreeDataPage(p).cmp(a, c, key, index); err != nil { - return - } - } - switch ok = cmp == 0; { - case cmp > 0: - l = index + 1 - case ok: - return - default: - h = index - 1 - } - } - return l, false, nil -} - -// p is dirty after extract! -func (p btreeDataPage) extract(a btreeStore, index int) (btreeDataPage, []byte, error) { - value, err := p.valueCopy(a, index) - if err != nil { - return nil, nil, err - } - - if _, h := p.keyField(index); h != 0 { - if err = a.Free(h); err != nil { - return nil, nil, err - } - } - - if _, h := p.valueField(index); h != 0 { - if err = a.Free(h); err != nil { - return nil, nil, err - } - } - - n := p.len() - 1 - if index < n { - p.copy(p, index, index+1, n-index) - } - return p.setLen(n), value, nil -} - -func checkSiblings(a btreeStore, parent int64, parentIndex int) (left, right int64, err error) { - if parentIndex >= 0 { - pp := buffer.Get(maxBuf) - defer buffer.Put(pp) - p := btreeIndexPage(*pp) - if p, err = a.Get(p, parent); err != nil { - return - } - - if parentIndex > 0 { - left = p.child(parentIndex - 1) - } - if parentIndex < p.len() { - right = p.child(parentIndex + 1) - } - } - return -} - -// underflow must persist all changes made. -func (p btreeDataPage) underflow(a btreeStore, root, iroot, parent, ph int64, parentIndex int) (err error) { - lh, rh, err := checkSiblings(a, parent, parentIndex) - if err != nil { - return err - } - - if lh != 0 { - pleft := buffer.Get(maxBuf) - defer buffer.Put(pleft) - left := *pleft - if left, err = a.Get(left, lh); err != nil { - return err - } - - if btreeDataPage(left).len()+p.len() >= 2*kData { - left, p = btreeDataPage(left).moveRight(p, 1) - if err = a.Realloc(lh, left); err != nil { - return err - } - - return a.Realloc(ph, p) - } - } - - if rh != 0 { - pright := buffer.Get(maxBuf) - defer buffer.Put(pright) - right := *pright - if right, err = a.Get(right, rh); err != nil { - return err - } - - if p.len()+btreeDataPage(right).len() > 2*kData { - right, p = btreeDataPage(right).moveLeft(p, 1) - if err = a.Realloc(rh, right); err != nil { - return err - } - - return a.Realloc(ph, p) - } - } - - if lh != 0 { - pleft := buffer.Get(maxBuf) - defer buffer.Put(pleft) - left := *pleft - if left, err = a.Get(left, lh); err != nil { - return err - } - - if err = a.Realloc(ph, p); err != nil { - return err - } - - return btreeDataPage(left).concat(a, root, iroot, parent, lh, ph, parentIndex-1) - } - - return p.concat(a, root, iroot, parent, ph, rh, parentIndex) -} - -// concat must persist all changes made. -func (p btreeDataPage) concat(a btreeStore, root, iroot, parent, ph, rh int64, parentIndex int) (err error) { - pright := buffer.Get(maxBuf) - defer buffer.Put(pright) - right := *pright - if right, err = a.Get(right, rh); err != nil { - return err - } - - right, p = btreeDataPage(right).moveLeft(p, btreeDataPage(right).len()) - nxh := btreeDataPage(right).next() - if nxh != 0 { - pnx := buffer.Get(maxBuf) - defer buffer.Put(pnx) - nx := *pnx - if nx, err = a.Get(nx, nxh); err != nil { - return err - } - - btreeDataPage(nx).setPrev(ph) - if err = a.Realloc(nxh, nx); err != nil { - return err - } - } - p.setNext(nxh) - if err = a.Free(rh); err != nil { - return err - } - - ppp := buffer.Get(maxBuf) - defer buffer.Put(ppp) - pp := *ppp - if pp, err = a.Get(pp, parent); err != nil { - return err - } - - if btreeIndexPage(pp).len() > 1 { - pp = btreeIndexPage(pp).extract(parentIndex) - btreeIndexPage(pp).setChild(parentIndex, ph) - if err = a.Realloc(parent, pp); err != nil { - return err - } - - return a.Realloc(ph, p) - } - - if err = a.Free(iroot); err != nil { - return err - } - - if err = a.Realloc(ph, p); err != nil { - return err - } - - var b7 [7]byte - return a.Realloc(root, h2b(b7[:], ph)) -} - -// external "root" is stable and contains the real root. -type btree int64 - -func newBTree(a btreeStore) (btree, error) { - r, err := a.Alloc(zeros[:7]) - return btree(r), err -} - -func (root btree) String(a btreeStore) string { - pr := buffer.Get(16) - defer buffer.Put(pr) - r := *pr - r, err := a.Get(r, int64(root)) - if err != nil { - panic(err) - } - - iroot := b2h(r) - m := map[int64]bool{int64(root): true} - - s := []string{fmt.Sprintf("tree %#x -> %#x\n====", root, iroot)} - if iroot == 0 { - return s[0] - } - - var f func(int64, string) - f = func(h int64, ind string) { - if m[h] { - return - } - - m[h] = true - pb := buffer.Get(maxBuf) - defer buffer.Put(pb) - b := btreePage(*pb) - var err error - if b, err = a.Get(b, h); err != nil { - panic(err) - } - - s = append(s, fmt.Sprintf("%s@%#x", ind, h)) - switch b.isIndex() { - case true: - da := []int64{} - b := btreeIndexPage(b) - for i := 0; i < b.len(); i++ { - c, d := b.child(i), b.dataPage(i) - s = append(s, fmt.Sprintf("%schild[%d] %#x dataPage[%d] %#x", ind, i, c, i, d)) - da = append(da, c) - da = append(da, d) - } - i := b.len() - c := b.child(i) - s = append(s, fmt.Sprintf("%schild[%d] %#x", ind, i, c)) - for _, c := range da { - f(c, ind+" ") - } - f(c, ind+" ") - case false: - b := btreeDataPage(b) - s = append(s, fmt.Sprintf("%sprev %#x next %#x", ind, b.prev(), b.next())) - for i := 0; i < b.len(); i++ { - k, err := b.key(a, i) - if err != nil { - panic(err) - } - - v, err := b.value(a, i) - if err != nil { - panic(err) - } - - s = append(s, fmt.Sprintf("%sK[%d]|% x| V[%d]|% x|", ind, i, k, i, v)) - } - } - } - - f(iroot, "") - return strings.Join(s, "\n") -} - -func (root btree) put(dst []byte, a btreeStore, c func(a, b []byte) int, key, value []byte, canOverwrite bool) (prev []byte, err error) { - prev, _, err = root.put2(dst, a, c, key, func(key, old []byte) (new []byte, write bool, err error) { - new, write = value, true - return - }) - return -} - -func (root btree) put2(dst []byte, a btreeStore, c func(a, b []byte) int, key []byte, upd func(key, old []byte) (new []byte, write bool, err error)) (old []byte, written bool, err error) { - var r, value []byte - if r, err = a.Get(dst, int64(root)); err != nil { - return - } - - iroot := b2h(r) - var h int64 - if iroot == 0 { - p := newBTreeDataPage() - if value, written, err = upd(key, nil); err != nil || !written { - return - } - - if p, err = p.insertItem(a, 0, key, value); err != nil { - return - } - - h, err = a.Alloc(p) - if err != nil { - return nil, true, err - } - - err = a.Realloc(int64(root), h2b(r, h)[:7]) - return - } - - parentIndex := -1 - var parent int64 - ph := iroot - - pp := buffer.Get(maxBuf) - defer buffer.Put(pp) - p := *pp - - for { - if p, err = a.Get(p[:cap(p)], ph); err != nil { - return - } - - var index int - var ok bool - - if index, ok, err = btreePage(p).find(a, c, key); err != nil { - return - } - - switch { - case ok: // Key found - if btreePage(p).isIndex() { - ph = btreeIndexPage(p).dataPage(index) - if p, err = a.Get(p, ph); err != nil { - return - } - - if old, err = btreeDataPage(p).valueCopy(a, 0); err != nil { - return - } - - if value, written, err = upd(key, old); err != nil || !written { - return - } - - if _, err = btreeDataPage(p).swap(a, 0, value, true); err != nil { - return - } - - err = a.Realloc(ph, p) - return - } - - if old, err = btreeDataPage(p).valueCopy(a, index); err != nil { - return - } - - if value, written, err = upd(key, old); err != nil || !written { - return - } - - if _, err = btreeDataPage(p).swap(a, index, value, true); err != nil { - return - } - - err = a.Realloc(ph, p) - return - case btreePage(p).isIndex(): - if btreePage(p).len() > 2*kIndex { - if p, err = btreeIndexPage(p).split(a, root, &ph, parent, parentIndex, &index); err != nil { - return - } - } - parentIndex = index - parent = ph - ph = btreeIndexPage(p).child(index) - default: - if value, written, err = upd(key, nil); err != nil || !written { - return - } - - if btreePage(p).len() < 2*kData { // page is not full - if p, err = btreeDataPage(p).insertItem(a, index, key, value); err != nil { - return - } - - err = a.Realloc(ph, p) - return - } - - // page is full - p, err = btreeDataPage(p).overflow(a, int64(root), ph, parent, parentIndex, index, key, value) - return - } - } -} - -//TODO actually use 'dst' to return 'value' -func (root btree) get(a btreeStore, dst []byte, c func(a, b []byte) int, key []byte) (b []byte, err error) { - var r []byte - if r, err = a.Get(dst, int64(root)); err != nil { - return - } - - iroot := b2h(r) - if iroot == 0 { - return - } - - ph := iroot - - for { - var p btreePage - if p, err = a.Get(p, ph); err != nil { - return - } - - var index int - var ok bool - if index, ok, err = p.find(a, c, key); err != nil { - return - } - - switch { - case ok: - if p.isIndex() { - dh := btreeIndexPage(p).dataPage(index) - dp, err := a.Get(dst, dh) - if err != nil { - return nil, err - } - - return btreeDataPage(dp).value(a, 0) - } - - return btreeDataPage(p).value(a, index) - case p.isIndex(): - ph = btreeIndexPage(p).child(index) - default: - return - } - } -} - -//TODO actually use 'dst' to return 'value' -func (root btree) extract(a btreeStore, dst []byte, c func(a, b []byte) int, key []byte) (value []byte, err error) { - var r []byte - if r, err = a.Get(dst, int64(root)); err != nil { - return - } - - iroot := b2h(r) - if iroot == 0 { - return - } - - ph := iroot - parentIndex := -1 - var parent int64 - - pp := buffer.Get(maxBuf) - defer buffer.Put(pp) - p := *pp - - for { - if p, err = a.Get(p[:cap(p)], ph); err != nil { - return - } - - var index int - var ok bool - if index, ok, err = btreePage(p).find(a, c, key); err != nil { - return - } - - if ok { - if btreePage(p).isIndex() { - dph := btreeIndexPage(p).dataPage(index) - - var dp []byte - if dp, err = a.Get(dst, dph); err != nil { - return nil, err - } - - if btreeDataPage(dp).len() > kData { - if dp, value, err = btreeDataPage(dp).extract(a, 0); err != nil { - return nil, err - } - - return value, a.Realloc(dph, dp) - } - - if btreeIndexPage(p).len() < kIndex && ph != iroot { - if p, err = btreeIndexPage(p).underflow(a, int64(root), iroot, parent, &ph, parentIndex, &index); err != nil { - return nil, err - } - } - parentIndex = index + 1 - parent = ph - ph = btreeIndexPage(p).child(parentIndex) - continue - } - - p, value, err = btreeDataPage(p).extract(a, index) - if btreePage(p).len() >= kData { - err = a.Realloc(ph, p) - return - } - - if ph != iroot { - err = btreeDataPage(p).underflow(a, int64(root), iroot, parent, ph, parentIndex) - return - } - - if btreePage(p).len() == 0 { - if err = a.Free(ph); err != nil { - return - } - - err = a.Realloc(int64(root), zeros[:7]) - return - } - err = a.Realloc(ph, p) - return - } - - if !btreePage(p).isIndex() { - return - } - - if btreePage(p).len() < kIndex && ph != iroot { - if p, err = btreeIndexPage(p).underflow(a, int64(root), iroot, parent, &ph, parentIndex, &index); err != nil { - return nil, err - } - } - parentIndex = index - parent = ph - ph = btreeIndexPage(p).child(index) - } -} - -func (root btree) deleteAny(a btreeStore) (bool, error) { - pr := buffer.Get(7) - defer buffer.Put(pr) - r := *pr - var err error - if r, err = a.Get(r, int64(root)); err != nil { - return false, err - } - - iroot := b2h(r) - if iroot == 0 { - return true, nil - } - - ph := iroot - parentIndex := -1 - var parent int64 - pp := buffer.Get(maxBuf) - defer buffer.Put(pp) - p := *pp - - for { - if p, err = a.Get(p, ph); err != nil { - return false, err - } - - index := btreePage(p).len() / 2 - if btreePage(p).isIndex() { - dph := btreeIndexPage(p).dataPage(index) - pdp := buffer.Get(maxBuf) - defer buffer.Put(pdp) - dp := *pdp - if dp, err = a.Get(dp, dph); err != nil { - return false, err - } - - if btreeDataPage(dp).len() > kData { - if dp, _, err = btreeDataPage(dp).extract(a, 0); err != nil { - return false, err - } - - return false, a.Realloc(dph, dp) - } - - if btreeIndexPage(p).len() < kIndex && ph != iroot { - if p, err = btreeIndexPage(p).underflow(a, int64(root), iroot, parent, &ph, parentIndex, &index); err != nil { - return false, err - } - } - parentIndex = index + 1 - parent = ph - ph = btreeIndexPage(p).child(parentIndex) - continue - } - - p, _, err = btreeDataPage(p).extract(a, index) - if btreePage(p).len() >= kData { - err = a.Realloc(ph, p) - return false, err - } - - if ph != iroot { - err = btreeDataPage(p).underflow(a, int64(root), iroot, parent, ph, parentIndex) - return false, err - } - - if btreePage(p).len() == 0 { - if err = a.Free(ph); err != nil { - return true, err - } - - return true, a.Realloc(int64(root), zeros[:7]) - } - - return false, a.Realloc(ph, p) - } -} - -func (root btree) first(a btreeStore) (ph int64, p btreeDataPage, err error) { - pr := buffer.Get(7) - defer buffer.Put(pr) - r := *pr - if r, err = a.Get(r, int64(root)); err != nil { - return - } - - for ph = b2h(r); ph != 0; ph = btreeIndexPage(p).child(0) { - if p, err = a.Get(p, ph); err != nil { - return - } - - if !btreePage(p).isIndex() { - break - } - } - - return -} - -func (root btree) last(a btreeStore) (ph int64, p btreeDataPage, err error) { - pr := buffer.Get(7) - defer buffer.Put(pr) - r := *pr - if r, err = a.Get(r, int64(root)); err != nil { - return - } - - for ph = b2h(r); ph != 0; ph = btreeIndexPage(p).child(btreeIndexPage(p).len()) { - if p, err = a.Get(p, ph); err != nil { - return - } - - if !btreePage(p).isIndex() { - break - } - } - - return -} - -// key >= p[index].key -func (root btree) seek(a btreeStore, c func(a, b []byte) int, key []byte) (p btreeDataPage, index int, equal bool, err error) { - pr := buffer.Get(7) - defer buffer.Put(pr) - r := *pr - if r, err = a.Get(r, int64(root)); err != nil { - return - } - - for ph := b2h(r); ph != 0; ph = btreeIndexPage(p).child(index) { - if p, err = a.Get(p, ph); err != nil { - break - } - - if index, equal, err = btreePage(p).find(a, c, key); err != nil { - break - } - - if equal { - if !btreePage(p).isIndex() { - break - } - - p, err = a.Get(p, btreeIndexPage(p).dataPage(index)) - index = 0 - break - } - - if !btreePage(p).isIndex() { - break - } - } - return -} - -func (root btree) clear(a btreeStore) (err error) { - pr := buffer.Get(7) - defer buffer.Put(pr) - r := *pr - if r, err = a.Get(r, int64(root)); err != nil { - return - } - - iroot := b2h(r) - if iroot == 0 { - return - } - - if err = root.clear2(a, iroot); err != nil { - return - } - - var b [7]byte - return a.Realloc(int64(root), b[:]) -} - -func (root btree) clear2(a btreeStore, ph int64) (err error) { - pp := buffer.Get(maxBuf) - defer buffer.Put(pp) - p := *pp - if p, err = a.Get(p, ph); err != nil { - return - } - - switch btreePage(p).isIndex() { - case true: - ip := btreeIndexPage(p) - for i := 0; i <= ip.len(); i++ { - if err = root.clear2(a, ip.child(i)); err != nil { - return err - } - } - case false: - dp := btreeDataPage(p) - for i := 0; i < dp.len(); i++ { - if err = dp.setKey(a, i, nil); err != nil { - return - } - - if err = dp.setValue(a, i, nil); err != nil { - return - } - } - } - return a.Free(ph) -} diff --git a/vendor/github.com/cznic/lldb/errors.go b/vendor/github.com/cznic/lldb/errors.go deleted file mode 100644 index de4de8766..000000000 --- a/vendor/github.com/cznic/lldb/errors.go +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Some errors returned by this package. -// -// Note that this package can return more errors than declared here, for -// example io.EOF from Filer.ReadAt(). - -package lldb - -import ( - "fmt" -) - -// ErrDecodeScalars is possibly returned from DecodeScalars -type ErrDecodeScalars struct { - B []byte // Data being decoded - I int // offending offset -} - -// Error implements the built in error type. -func (e *ErrDecodeScalars) Error() string { - return fmt.Sprintf("DecodeScalars: corrupted data @ %d/%d", e.I, len(e.B)) -} - -// ErrINVAL reports invalid values passed as parameters, for example negative -// offsets where only non-negative ones are allowed or read from the DB. -type ErrINVAL struct { - Src string - Val interface{} -} - -// Error implements the built in error type. -func (e *ErrINVAL) Error() string { - return fmt.Sprintf("%s: %+v", e.Src, e.Val) -} - -// ErrPERM is for example reported when a Filer is closed while BeginUpdate(s) -// are not balanced with EndUpdate(s)/Rollback(s) or when EndUpdate or Rollback -// is invoked which is not paired with a BeginUpdate. -type ErrPERM struct { - Src string -} - -// Error implements the built in error type. -func (e *ErrPERM) Error() string { - return fmt.Sprintf("%s: Operation not permitted", e.Src) -} - -// ErrTag represents an ErrILSEQ kind. -type ErrType int - -// ErrILSEQ types -const ( - ErrOther ErrType = iota - - ErrAdjacentFree // Adjacent free blocks (.Off and .Arg) - ErrDecompress // Used compressed block: corrupted compression - ErrExpFreeTag // Expected a free block tag, got .Arg - ErrExpUsedTag // Expected a used block tag, got .Arg - ErrFLT // Free block is invalid or referenced multiple times - ErrFLTLoad // FLT truncated to .Off, need size >= .Arg - ErrFLTSize // Free block size (.Arg) doesn't belong to its list min size: .Arg2 - ErrFileSize // File .Name size (.Arg) != 0 (mod 16) - ErrFreeChaining // Free block, .prev.next doesn't point back to this block - ErrFreeTailBlock // Last block is free - ErrHead // Head of a free block list has non zero Prev (.Arg) - ErrInvalidRelocTarget // Reloc doesn't target (.Arg) a short or long used block - ErrInvalidWAL // Corrupted write ahead log. .Name: file name, .More: more - ErrLongFreeBlkTooLong // Long free block spans beyond EOF, size .Arg - ErrLongFreeBlkTooShort // Long free block must have at least 2 atoms, got only .Arg - ErrLongFreeNextBeyondEOF // Long free block .Next (.Arg) spans beyond EOF - ErrLongFreePrevBeyondEOF // Long free block .Prev (.Arg) spans beyond EOF - ErrLongFreeTailTag // Expected a long free block tail tag, got .Arg - ErrLostFreeBlock // Free block is not in any FLT list - ErrNullReloc // Used reloc block with nil target - ErrRelocBeyondEOF // Used reloc points (.Arg) beyond EOF - ErrShortFreeTailTag // Expected a short free block tail tag, got .Arg - ErrSmall // Request for a free block (.Arg) returned a too small one (.Arg2) at .Off - ErrTailTag // Block at .Off has invalid tail CC (compression code) tag, got .Arg - ErrUnexpReloc // Unexpected reloc block referred to from reloc block .Arg - ErrVerifyPadding // Used block has nonzero padding - ErrVerifyTailSize // Long free block size .Arg but tail size .Arg2 - ErrVerifyUsedSpan // Used block size (.Arg) spans beyond EOF -) - -// ErrILSEQ reports a corrupted file format. Details in fields according to Type. -type ErrILSEQ struct { - Type ErrType - Off int64 - Arg int64 - Arg2 int64 - Arg3 int64 - Name string - More interface{} -} - -// Error implements the built in error type. -func (e *ErrILSEQ) Error() string { - switch e.Type { - case ErrAdjacentFree: - return fmt.Sprintf("Adjacent free blocks at offset %#x and %#x", e.Off, e.Arg) - case ErrDecompress: - return fmt.Sprintf("Compressed block at offset %#x: Corrupted compressed content", e.Off) - case ErrExpFreeTag: - return fmt.Sprintf("Block at offset %#x: Expected a free block tag, got %#2x", e.Off, e.Arg) - case ErrExpUsedTag: - return fmt.Sprintf("Block at ofset %#x: Expected a used block tag, got %#2x", e.Off, e.Arg) - case ErrFLT: - return fmt.Sprintf("Free block at offset %#x is invalid or referenced multiple times", e.Off) - case ErrFLTLoad: - return fmt.Sprintf("FLT truncated to size %d, expected at least %d", e.Off, e.Arg) - case ErrFLTSize: - return fmt.Sprintf("Free block at offset %#x has size (%#x) should be at least (%#x)", e.Off, e.Arg, e.Arg2) - case ErrFileSize: - return fmt.Sprintf("File %q size (%#x) != 0 (mod 16)", e.Name, e.Arg) - case ErrFreeChaining: - return fmt.Sprintf("Free block at offset %#x: .prev.next doesn point back here.", e.Off) - case ErrFreeTailBlock: - return fmt.Sprintf("Free block at offset %#x: Cannot be last file block", e.Off) - case ErrHead: - return fmt.Sprintf("Block at offset %#x: Head of free block list has non zero .prev %#x", e.Off, e.Arg) - case ErrInvalidRelocTarget: - return fmt.Sprintf("Used reloc block at offset %#x: Target (%#x) is not a short or long used block", e.Off, e.Arg) - case ErrInvalidWAL: - return fmt.Sprintf("Corrupted write ahead log file: %q %v", e.Name, e.More) - case ErrLongFreeBlkTooLong: - return fmt.Sprintf("Long free block at offset %#x: Size (%#x) beyond EOF", e.Off, e.Arg) - case ErrLongFreeBlkTooShort: - return fmt.Sprintf("Long free block at offset %#x: Size (%#x) too small", e.Off, e.Arg) - case ErrLongFreeNextBeyondEOF: - return fmt.Sprintf("Long free block at offset %#x: Next (%#x) points beyond EOF", e.Off, e.Arg) - case ErrLongFreePrevBeyondEOF: - return fmt.Sprintf("Long free block at offset %#x: Prev (%#x) points beyond EOF", e.Off, e.Arg) - case ErrLongFreeTailTag: - return fmt.Sprintf("Block at offset %#x: Expected long free tail tag, got %#2x", e.Off, e.Arg) - case ErrLostFreeBlock: - return fmt.Sprintf("Free block at offset %#x: not in any FLT list", e.Off) - case ErrNullReloc: - return fmt.Sprintf("Used reloc block at offset %#x: Nil target", e.Off) - case ErrRelocBeyondEOF: - return fmt.Sprintf("Used reloc block at offset %#x: Link (%#x) points beyond EOF", e.Off, e.Arg) - case ErrShortFreeTailTag: - return fmt.Sprintf("Block at offset %#x: Expected short free tail tag, got %#2x", e.Off, e.Arg) - case ErrSmall: - return fmt.Sprintf("Request for of free block of size %d returned a too small (%d) one at offset %#x", e.Arg, e.Arg2, e.Off) - case ErrTailTag: - return fmt.Sprintf("Block at offset %#x: Invalid tail CC tag, got %#2x", e.Off, e.Arg) - case ErrUnexpReloc: - return fmt.Sprintf("Block at offset %#x: Unexpected reloc block. Referred to from reloc block at offset %#x", e.Off, e.Arg) - case ErrVerifyPadding: - return fmt.Sprintf("Used block at offset %#x: Nonzero padding", e.Off) - case ErrVerifyTailSize: - return fmt.Sprintf("Long free block at offset %#x: Size %#x, but tail size %#x", e.Off, e.Arg, e.Arg2) - case ErrVerifyUsedSpan: - return fmt.Sprintf("Used block at offset %#x: Size %#x spans beyond EOF", e.Off, e.Arg) - } - - more := "" - if e.More != nil { - more = fmt.Sprintf(", %v", e.More) - } - off := "" - if e.Off != 0 { - off = fmt.Sprintf(", off: %#x", e.Off) - } - - return fmt.Sprintf("Error%s%s", off, more) -} diff --git a/vendor/github.com/cznic/lldb/falloc.go b/vendor/github.com/cznic/lldb/falloc.go deleted file mode 100644 index 87687a767..000000000 --- a/vendor/github.com/cznic/lldb/falloc.go +++ /dev/null @@ -1,1999 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// The storage space management. - -package lldb - -import ( - "bytes" - "errors" - "fmt" - "io" - "sort" - "strings" - "sync" - - "github.com/cznic/internal/buffer" - "github.com/cznic/mathutil" - "github.com/cznic/zappy" -) - -const ( - maxBuf = maxRq + 20 -) - -// Options are passed to the NewAllocator to amend some configuration. The -// compatibility promise is the same as of struct types in the Go standard -// library - introducing changes can be made only by adding new exported -// fields, which is backward compatible as long as client code uses field names -// to assign values of imported struct types literals. -// -// NOTE: No options are currently defined. -type Options struct{} - -// AllocStats record statistics about a Filer. It can be optionally filled by -// Allocator.Verify, if successful. -type AllocStats struct { - Handles int64 // total valid handles in use - Compression int64 // number of compressed blocks - TotalAtoms int64 // total number of atoms == AllocAtoms + FreeAtoms - AllocBytes int64 // bytes allocated (after decompression, if/where used) - AllocAtoms int64 // atoms allocated/used, including relocation atoms - Relocations int64 // number of relocated used blocks - FreeAtoms int64 // atoms unused - AllocMap map[int64]int64 // allocated block size in atoms -> count of such blocks - FreeMap map[int64]int64 // free block size in atoms -> count of such blocks -} - -/* - -Allocator implements "raw" storage space management (allocation and -deallocation) for a low level of a DB engine. The storage is an abstraction -provided by a Filer. - -The terms MUST or MUST NOT, if/where used in the documentation of Allocator, -written in all caps as seen here, are a requirement for any possible -alternative implementations aiming for compatibility with this one. - -Filer file - -A Filer file, or simply 'file', is a linear, contiguous sequence of blocks. -Blocks may be either free (currently unused) or allocated (currently used). -Some blocks may eventually become virtual in a sense as they may not be -realized in the storage (sparse files). - -Free Lists Table - -File starts with a FLT. This table records heads of 14 doubly linked free -lists. The zero based index (I) vs minimal size of free blocks in that list, -except the last one which registers free blocks of size 4112+ atoms: - - MinSize == 2^I - - For example 0 -> 1, 1 -> 2, ... 12 -> 4096. - -Each entry in the FLT is 8 bytes in netwtork order, MSB MUST be zero, ie. the -slot value is effectively only 7 bytes. The value is the handle of the head of -the respective doubly linked free list. The FLT size is 14*8 == 112(0x70) -bytes. If the free blocks list for any particular size is empty, the respective -FLT slot is zero. Sizes of free blocks in one list MUST NOT overlap with sizes -of free lists in other list. For example, even though a free block of size 2 -technically is of minimal size >= 1, it MUST NOT be put to the list for slot 0 -(minimal size 1), but in slot 1( minimal size 2). - - slot 0: sizes [1, 2) - slot 1: sizes [2, 4) - slot 2: sizes [4, 8) - ... - slot 11: sizes [2048, 4096) - slot 12: sizes [4096, 4112) - slot 13: sizes [4112, inf) - -The last FLT slot collects all free blocks bigger than its minimal size. That -still respects the 'no overlap' invariant. - -File blocks - -A block is a linear, contiguous sequence of atoms. The first and last atoms of -a block provide information about, for example, whether the block is free or -used, what is the size of the block, etc. Details are discussed elsewhere. The -first block of a file starts immediately after FLT, ie. at file offset -112(0x70). - -Block atoms - -An atom is a fixed size piece of a block (and thus of a file too); it is 16 -bytes long. A consequence is that for a valid file: - - filesize == 0 (mod 16) - -The first atom of the first block is considered to be atom #1. - -Block handles - -A handle is an integer referring to a block. The reference is the number of the -atom the block starts with. Put in other way: - - handle == offset/16 - 6 - offset == 16 * (handle + 6) - -`offset` is the offset of the first byte of the block, measured in bytes -- as in fseek(3). Handle has type `int64`, but only the lower 7 bytes may be -nonzero while referring to a block, both in code as well as when persisted in -the the file's internal bookkeeping structures - see 'Block types' bellow. So a -handle is effectively only `uint56`. This also means that the maximum usable -size of a file is 2^56 atoms. That is 2^60 bytes == 1 exabyte (10^18 bytes). - -Nil handles - -A handle with numeric value of '0' refers to no block. - -Zero padding - -A padding is used to round-up a block size to be a whole number of atoms. Any -padding, if present, MUST be all zero bytes. Note that the size of padding is -in [0, 15]. - -Content wiping - -When a block is deallocated, its data content is not wiped as the added -overhead may be substantial while not necessarily needed. Client code should -however overwrite the content of any block having sensitive data with eg. zeros -(good compression) - before deallocating the block. - -Block tags - -Every block is tagged in its first byte (a head tag) and last byte (tail tag). -Block types are: - - 1. Short content used block (head tags 0x00-0xFB) - 2. Long content used block (head tag 0xFC) - 3. Relocated used block (head tag 0xFD) - 4. Short, single atom, free block (head tag 0xFE) - 5. Long free block (head tag 0xFF) - -Note: Relocated used block, 3. above (head tag 0xFD) MUST NOT refer to blocks -other then 1. or 2. above (head tags 0x00-0xFC). - -Content blocks - -Used blocks (head tags 0x00-0xFC) tail tag distinguish used/unused block and if -content is compressed or not. - -Content compression - -The tail flag of an used block is one of - - CC == 0 // Content is not compressed. - CC == 1 // Content is in zappy compression format. - -If compression of written content is enabled, there are two cases: If -compressed size < original size then the compressed content should be written -if it will save at least one atom of the block. If compressed size >= original -size then the compressed content should not be used. - -It's recommended to use compression. For example the BTrees implementation -assumes compression is used. Using compression may cause a slowdown in some -cases while it may as well cause a speedup. - -Short content block - -Short content block carries content of length between N == 0(0x00) and N == -251(0xFB) bytes. - - |<-first atom start ... last atom end->| - +---++-- ... --+-- ... --++------+ - | 0 || 1... | 0x*...0x*E || 0x*F | - +---++-- ... --+-- ... --++------+ - | N || content | padding || CC | - +---++-- ... --+-- ... --++------+ - - A == (N+1)/16 + 1 // The number of atoms in the block [1, 16] - padding == 15 - (N+1)%16 // Length of the zero padding - -Long content block - -Long content block carries content of length between N == 252(0xFC) and N == -65787(0x100FB) bytes. - - |<-first atom start ... last atom end->| - +------++------+-- ... --+-- ... --++------+ - | 0 || 1..2 | 3... | 0x*...0x*E || 0x*F | - +------++------+-- ... --+-- ... --++------+ - | 0xFC || M | content | padding || CC | - +------++------+-- ... --+-- ... --++------+ - - A == (N+3)/16 + 1 // The number of atoms in the block [16, 4112] - M == N % 0x10000 // Stored as 2 bytes in network byte order - padding == 15 - (N+3)%16 // Length of the zero padding - -Relocated used block - -Relocated block allows to permanently assign a handle to some content and -resize the content anytime afterwards without having to update all the possible -existing references; the handle can be constant while the content size may be -dynamic. When relocating a block, any space left by the original block content, -above this single atom block, MUST be reclaimed. - -Relocations MUST point only to a used short or long block == blocks with tags -0x00...0xFC. - - +------++------+---------++----+ - | 0 || 1..7 | 8...14 || 15 | - +------++------+---------++----+ - | 0xFD || H | padding || 0 | - +------++------+---------++----+ - -H is the handle of the relocated block in network byte order. - -Free blocks - -Free blocks are the result of space deallocation. Free blocks are organized in -one or more doubly linked lists, abstracted by the FLT interface. Free blocks -MUST be "registered" by putting them in such list. Allocator MUST reuse a big -enough free block, if such exists, before growing the file size. When a free -block is created by deallocation or reallocation it MUST be joined with any -adjacently existing free blocks before "registering". If the resulting free -block is now a last block of a file, the free block MUST be discarded and the -file size MUST be truncated accordingly instead. Put differently, there MUST -NOT ever be a free block at the file end. - -A single free atom - -Is an unused block of size 1 atom. - - +------++------+--------++------+ - | 0 || 1..7 | 8...14 || 15 | - +------++------+--------++------+ - | 0xFE || P | N || 0xFE | - +------++------+--------++------+ - -P and N, stored in network byte order, are the previous and next free block -handles in the doubly linked list to which this free block belongs. - -A long unused block - -Is an unused block of size > 1 atom. - - +------++------+-------+---------+- ... -+----------++------+ - | 0 || 1..7 | 8..14 | 15...21 | | Z-7..Z-1 || Z | - +------++------+-------+---------+- ... -+----------++------+ - | 0xFF || S | P | N | Leak | S || 0xFF | - +------++------+-------+---------+- ... -+----------++------+ - - Z == 16 * S - 1 - -S is the size of this unused block in atoms. P and N are the previous and next -free block handles in the doubly linked list to which this free block belongs. -Leak contains any data the block had before deallocating this block. See also -the subtitle 'Content wiping' above. S, P and N are stored in network byte -order. Large free blocks may trigger a consideration of file hole punching of -the Leak field - for some value of 'large'. - -Note: Allocator methods vs CRUD[1]: - - Alloc [C]reate - Get [R]ead - Realloc [U]pdate - Free [D]elete - -Note: No Allocator method returns io.EOF. - - [1]: http://en.wikipedia.org/wiki/Create,_read,_update_and_delete - -*/ -type Allocator struct { - f Filer - flt flt - cache cache - m map[int64]*node - lru lst - mu sync.Mutex - expHit int64 - expMiss int64 - cacheSz int - hit uint16 - miss uint16 - Compress bool // enables content compression -} - -// NewAllocator returns a new Allocator. To open an existing file, pass its -// Filer. To create a "new" file, pass a Filer which file is of zero size. -func NewAllocator(f Filer, opts *Options) (a *Allocator, err error) { - if opts == nil { // Enforce *Options is always passed - return nil, errors.New("NewAllocator: nil opts passed") - } - - a = &Allocator{ - f: f, - cacheSz: 10, - } - - a.cinit() - switch x := f.(type) { - case *RollbackFiler: - x.afterRollback = func() error { - a.cinit() - return a.flt.load(a.f, 0) - } - case *ACIDFiler0: - x.RollbackFiler.afterRollback = func() error { - a.cinit() - return a.flt.load(a.f, 0) - } - } - - sz, err := f.Size() - if err != nil { - return - } - - a.flt.init() - if sz == 0 { - var b [fltSz]byte - if err = a.f.BeginUpdate(); err != nil { - return - } - - if _, err = f.WriteAt(b[:], 0); err != nil { - _ = a.f.Rollback() - return - } - - return a, a.f.EndUpdate() - } - - return a, a.flt.load(f, 0) -} - -// CacheStats reports cache statistics. -// -//TODO return a struct perhaps. -func (a *Allocator) CacheStats() (buffersUsed, buffersTotal int, bytesUsed, bytesTotal, hits, misses int64) { - buffersUsed = len(a.m) - buffersTotal = buffersUsed + len(a.cache) - bytesUsed = a.lru.size() - bytesTotal = bytesUsed + a.cache.size() - hits = a.expHit - misses = a.expMiss - return -} - -func (a *Allocator) cinit() { - for h, n := range a.m { - a.cache.put(a.lru.remove(n)) - delete(a.m, h) - } - if a.m == nil { - a.m = map[int64]*node{} - } -} - -func (a *Allocator) cadd(b []byte, h int64) { - if len(a.m) < a.cacheSz { - n := a.cache.get(len(b)) - n.h = h - copy(n.b, b) - a.m[h] = a.lru.pushFront(n) - return - } - - // cache full - delete(a.m, a.cache.put(a.lru.removeBack()).h) - n := a.cache.get(len(b)) - n.h = h - copy(n.b, b) - a.m[h] = a.lru.pushFront(n) - return -} - -func (a *Allocator) cfree(h int64) { - n, ok := a.m[h] - if !ok { // must have been evicted - return - } - - a.cache.put(a.lru.remove(n)) - delete(a.m, h) -} - -// Alloc allocates storage space for b and returns the handle of the new block -// with content set to b or an error, if any. The returned handle is valid only -// while the block is used - until the block is deallocated. No two valid -// handles share the same value within the same Filer, but any value of a -// handle not referring to any used block may become valid any time as a result -// of Alloc. -// -// Invoking Alloc on an empty Allocator is guaranteed to return handle with -// value 1. The intended use of content of handle 1 is a root "directory" of -// other data held by an Allocator. -// -// Passing handles not obtained initially from Alloc or not anymore valid to -// any other Allocator methods can result in an irreparably corrupted database. -func (a *Allocator) Alloc(b []byte) (handle int64, err error) { - pbuf := buffer.Get(zappy.MaxEncodedLen(len(b))) - defer buffer.Put(pbuf) - buf := *pbuf - buf, _, cc, err := a.makeUsedBlock(buf, b) - if err != nil { - return - } - - if handle, err = a.alloc(buf, cc); err == nil { - a.cadd(b, handle) - } - return -} - -func (a *Allocator) alloc(b []byte, cc byte) (h int64, err error) { - rqAtoms := n2atoms(len(b)) - if h = a.flt.find(rqAtoms); h == 0 { // must grow - var sz int64 - if sz, err = a.f.Size(); err != nil { - return - } - - h = off2h(sz) - err = a.writeUsedBlock(h, cc, b) - return - } - - // Handle is the first item of a free blocks list. - tag, s, prev, next, err := a.nfo(h) - if err != nil { - return - } - - if tag != tagFreeShort && tag != tagFreeLong { - err = &ErrILSEQ{Type: ErrExpFreeTag, Off: h2off(h), Arg: int64(tag)} - return - } - - if prev != 0 { - err = &ErrILSEQ{Type: ErrHead, Off: h2off(h), Arg: prev} - return - } - - if s < int64(rqAtoms) { - err = &ErrILSEQ{Type: ErrSmall, Arg: int64(rqAtoms), Arg2: s, Off: h2off(h)} - return - } - - if err = a.unlink(h, s, prev, next); err != nil { - return - } - - if s > int64(rqAtoms) { - freeH := h + int64(rqAtoms) - freeAtoms := s - int64(rqAtoms) - if err = a.link(freeH, freeAtoms); err != nil { - return - } - } - return h, a.writeUsedBlock(h, cc, b) -} - -// Free deallocates the block referred to by handle or returns an error, if -// any. -// -// After Free succeeds, handle is invalid and must not be used. -// -// Handle must have been obtained initially from Alloc and must be still valid, -// otherwise a database may get irreparably corrupted. -func (a *Allocator) Free(handle int64) (err error) { - if handle <= 0 || handle > maxHandle { - return &ErrINVAL{"Allocator.Free: handle out of limits", handle} - } - - a.cfree(handle) - return a.free(handle, 0, true) -} - -func (a *Allocator) free(h, from int64, acceptRelocs bool) (err error) { - tag, atoms, _, n, err := a.nfo(h) - if err != nil { - return - } - - switch tag { - default: - // nop - case tagUsedLong: - // nop - case tagUsedRelocated: - if !acceptRelocs { - return &ErrILSEQ{Type: ErrUnexpReloc, Off: h2off(h), Arg: h2off(from)} - } - - if err = a.free(n, h, false); err != nil { - return - } - case tagFreeShort, tagFreeLong: - return &ErrINVAL{"Allocator.Free: attempt to free a free block at off", h2off(h)} - } - - return a.free2(h, atoms) -} - -func (a *Allocator) free2(h, atoms int64) (err error) { - sz, err := a.f.Size() - if err != nil { - return - } - - ltag, latoms, lp, ln, err := a.leftNfo(h) - if err != nil { - return - } - - if ltag != tagFreeShort && ltag != tagFreeLong { - latoms = 0 - } - - var rtag byte - var ratoms, rp, rn int64 - - isTail := h2off(h)+atoms*16 == sz - if !isTail { - if rtag, ratoms, rp, rn, err = a.nfo(h + atoms); err != nil { - return - } - } - - if rtag != tagFreeShort && rtag != tagFreeLong { - ratoms = 0 - } - - switch { - case latoms == 0 && ratoms == 0: - // -> isolated <- - if isTail { // cut tail - return a.f.Truncate(h2off(h)) - } - - return a.link(h, atoms) - case latoms == 0 && ratoms != 0: - // right join -> - if err = a.unlink(h+atoms, ratoms, rp, rn); err != nil { - return - } - - return a.link(h, atoms+ratoms) - case latoms != 0 && ratoms == 0: - // <- left join - if err = a.unlink(h-latoms, latoms, lp, ln); err != nil { - return - } - - if isTail { - return a.f.Truncate(h2off(h - latoms)) - } - - return a.link(h-latoms, latoms+atoms) - } - - // case latoms != 0 && ratoms != 0: - // <- middle join -> - lh, rh := h-latoms, h+atoms - if err = a.unlink(lh, latoms, lp, ln); err != nil { - return - } - - // Prev unlink may have invalidated rp or rn - if _, _, rp, rn, err = a.nfo(rh); err != nil { - return - } - - if err = a.unlink(rh, ratoms, rp, rn); err != nil { - return - } - - return a.link(h-latoms, latoms+atoms+ratoms) -} - -// Add a free block h to the appropriate free list -func (a *Allocator) link(h, atoms int64) (err error) { - if err = a.makeFree(h, atoms, 0, a.flt.head(atoms)); err != nil { - return - } - - return a.flt.setHead(h, atoms, a.f) -} - -// Remove free block h from the free list -func (a *Allocator) unlink(h, atoms, p, n int64) (err error) { - switch { - case p == 0 && n == 0: - // single item list, must be head - return a.flt.setHead(0, atoms, a.f) - case p == 0 && n != 0: - // head of list (has next item[s]) - if err = a.prev(n, 0); err != nil { - return - } - - // new head - return a.flt.setHead(n, atoms, a.f) - case p != 0 && n == 0: - // last item in list - return a.next(p, 0) - } - // case p != 0 && n != 0: - // intermediate item in a list - if err = a.next(p, n); err != nil { - return - } - - return a.prev(n, p) -} - -//TODO remove ? -// Return len(slice) == n, reuse src if possible. -func need(n int, src []byte) []byte { - if cap(src) < n { - return *buffer.Get(n) - } - - return src[:n] -} - -// Get returns the data content of a block referred to by handle or an error if -// any. The returned slice may be a sub-slice of buf if buf was large enough -// to hold the entire content. Otherwise, a newly allocated slice will be -// returned. It is valid to pass a nil buf. -// -// If the content was stored using compression then it is transparently -// returned decompressed. -// -// Handle must have been obtained initially from Alloc and must be still valid, -// otherwise invalid data may be returned without detecting the error. -// -// Get is safe for concurrent access by multiple goroutines iff no other -// goroutine mutates the DB. -func (a *Allocator) Get(buf []byte, handle int64) (b []byte, err error) { - buf = buf[:cap(buf)] - a.mu.Lock() // X1+ - if n, ok := a.m[handle]; ok { - a.lru.moveToFront(n) - b = need(len(n.b), buf) - copy(b, n.b) - a.expHit++ - a.hit++ - a.mu.Unlock() // X1- - return - } - - a.expMiss++ - a.miss++ - if a.miss > 10 && len(a.m) < 500 { - if 100*a.hit/a.miss < 95 { - a.cacheSz++ - } - a.hit, a.miss = 0, 0 - } - a.mu.Unlock() // X1- - - defer func(h int64) { - if err == nil { - a.mu.Lock() // X2+ - a.cadd(b, h) - a.mu.Unlock() // X2- - } - }(handle) - - pfirst := buffer.Get(16) - defer buffer.Put(pfirst) - first := *pfirst - relocated := false - relocSrc := handle -reloc: - if handle <= 0 || handle > maxHandle { - return nil, &ErrINVAL{"Allocator.Get: handle out of limits", handle} - } - - off := h2off(handle) - if err = a.read(first, off); err != nil { - return - } - - switch tag := first[0]; tag { - default: - dlen := int(tag) - atoms := n2atoms(dlen) - switch atoms { - case 1: - switch tag = first[15]; tag { - default: - return nil, &ErrILSEQ{Type: ErrTailTag, Off: off, Arg: int64(tag)} - case tagNotCompressed: - b = need(dlen, buf) - copy(b, first[1:]) - return - case tagCompressed: - return zappy.Decode(buf, first[1:dlen+1]) - } - default: - pcc := buffer.Get(1) - defer buffer.Put(pcc) - cc := *pcc - dlen := int(tag) - atoms := n2atoms(dlen) - tailOff := off + 16*int64(atoms) - 1 - if err = a.read(cc, tailOff); err != nil { - return - } - - switch tag = cc[0]; tag { - default: - return nil, &ErrILSEQ{Type: ErrTailTag, Off: off, Arg: int64(tag)} - case tagNotCompressed: - b = need(dlen, buf) - off += 1 - if err = a.read(b, off); err != nil { - b = buf[:0] - } - return - case tagCompressed: - pzbuf := buffer.Get(dlen) - defer buffer.Put(pzbuf) - zbuf := *pzbuf - off += 1 - if err = a.read(zbuf, off); err != nil { - return buf[:0], err - } - - return zappy.Decode(buf, zbuf) - } - } - case 0: - return buf[:0], nil - case tagUsedLong: - pcc := buffer.Get(1) - defer buffer.Put(pcc) - cc := *pcc - dlen := m2n(int(first[1])<<8 | int(first[2])) - atoms := n2atoms(dlen) - tailOff := off + 16*int64(atoms) - 1 - if err = a.read(cc, tailOff); err != nil { - return - } - - switch tag = cc[0]; tag { - default: - return nil, &ErrILSEQ{Type: ErrTailTag, Off: off, Arg: int64(tag)} - case tagNotCompressed: - b = need(dlen, buf) - off += 3 - if err = a.read(b, off); err != nil { - b = buf[:0] - } - return - case tagCompressed: - pzbuf := buffer.Get(dlen) - defer buffer.Put(pzbuf) - zbuf := *pzbuf - off += 3 - if err = a.read(zbuf, off); err != nil { - return buf[:0], err - } - - return zappy.Decode(buf, zbuf) - } - case tagFreeShort, tagFreeLong: - return nil, &ErrILSEQ{Type: ErrExpUsedTag, Off: off, Arg: int64(tag)} - case tagUsedRelocated: - if relocated { - return nil, &ErrILSEQ{Type: ErrUnexpReloc, Off: off, Arg: relocSrc} - } - - handle = b2h(first[1:]) - relocated = true - goto reloc - } -} - -var reallocTestHook bool - -// Realloc sets the content of a block referred to by handle or returns an -// error, if any. -// -// Handle must have been obtained initially from Alloc and must be still valid, -// otherwise a database may get irreparably corrupted. -func (a *Allocator) Realloc(handle int64, b []byte) (err error) { - if handle <= 0 || handle > maxHandle { - return &ErrINVAL{"Realloc: handle out of limits", handle} - } - - a.cfree(handle) - if err = a.realloc(handle, b); err != nil { - return - } - - if reallocTestHook { - if err = cacheAudit(a.m, &a.lru); err != nil { - return - } - } - - a.cadd(b, handle) - return -} - -func (a *Allocator) realloc(handle int64, b []byte) (err error) { - var dlen, needAtoms0 int - - pb8 := buffer.Get(8) - defer buffer.Put(pb8) - b8 := *pb8 - pdst := buffer.Get(zappy.MaxEncodedLen(len(b))) - defer buffer.Put(pdst) - dst := *pdst - b, needAtoms0, cc, err := a.makeUsedBlock(dst, b) - if err != nil { - return - } - - needAtoms := int64(needAtoms0) - off := h2off(handle) - if err = a.read(b8[:], off); err != nil { - return - } - - switch tag := b8[0]; tag { - default: - dlen = int(b8[0]) - case tagUsedLong: - dlen = m2n(int(b8[1])<<8 | int(b8[2])) - case tagUsedRelocated: - if err = a.free(b2h(b8[1:]), handle, false); err != nil { - return err - } - - dlen = 0 - case tagFreeShort, tagFreeLong: - return &ErrINVAL{"Allocator.Realloc: invalid handle", handle} - } - - atoms := int64(n2atoms(dlen)) -retry: - switch { - case needAtoms < atoms: - // in place shrink - if err = a.writeUsedBlock(handle, cc, b); err != nil { - return - } - - fh, fa := handle+needAtoms, atoms-needAtoms - var sz int64 - if sz, err = a.f.Size(); err != nil { - return err - } - - if h2off(fh)+16*fa == sz { - return a.f.Truncate(h2off(fh)) - } - - return a.free2(fh, fa) - case needAtoms == atoms: - // in place replace - return a.writeUsedBlock(handle, cc, b) - } - - // case needAtoms > atoms: - // in place extend or relocate - var sz int64 - if sz, err = a.f.Size(); err != nil { - return - } - - off = h2off(handle) - switch { - case off+atoms*16 == sz: - // relocating tail block - shortcut - return a.writeUsedBlock(handle, cc, b) - default: - if off+atoms*16 < sz { - // handle is not a tail block, check right neighbour - rh := handle + atoms - rtag, ratoms, p, n, e := a.nfo(rh) - if e != nil { - return e - } - - if rtag == tagFreeShort || rtag == tagFreeLong { - // Right neighbour is a free block - if needAtoms <= atoms+ratoms { - // can expand in place - if err = a.unlink(rh, ratoms, p, n); err != nil { - return - } - - atoms += ratoms - goto retry - - } - } - } - } - - if atoms > 1 { - if err = a.realloc(handle, nil); err != nil { - return - } - } - - var newH int64 - if newH, err = a.alloc(b, cc); err != nil { - return err - } - - prb := buffer.CGet(16) - defer buffer.Put(prb) - rb := *prb - rb[0] = tagUsedRelocated - h2b(rb[1:], newH) - if err = a.writeAt(rb[:], h2off(handle)); err != nil { - return - } - - return a.writeUsedBlock(newH, cc, b) -} - -func (a *Allocator) writeAt(b []byte, off int64) (err error) { - var n int - if n, err = a.f.WriteAt(b, off); err != nil { - return - } - - if n != len(b) { - err = io.ErrShortWrite - } - return -} - -func (a *Allocator) write(off int64, b ...[]byte) (err error) { - rq := 0 - for _, part := range b { - rq += len(part) - } - pbuf := buffer.Get(rq) - defer buffer.Put(pbuf) - buf := *pbuf - buf = buf[:0] - for _, part := range b { - buf = append(buf, part...) - } - return a.writeAt(buf, off) -} - -func (a *Allocator) read(b []byte, off int64) (err error) { - var rn int - if rn, err = a.f.ReadAt(b, off); rn != len(b) { - return &ErrILSEQ{Type: ErrOther, Off: off, More: err} - } - - return nil -} - -// nfo returns h's tag. If it's a free block then return also (s)ize (in -// atoms), (p)rev and (n)ext. If it's a used block then only (s)ize is returned -// (again in atoms). If it's a used relocate block then (n)ext is set to the -// relocation target handle. -func (a *Allocator) nfo(h int64) (tag byte, s, p, n int64, err error) { - off := h2off(h) - rq := int64(22) - sz, err := a.f.Size() - if err != nil { - return - } - - if off+rq >= sz { - if rq = sz - off; rq < 15 { - err = io.ErrUnexpectedEOF - return - } - } - - pbuf := buffer.Get(22) - defer buffer.Put(pbuf) - buf := *pbuf - if err = a.read(buf[:rq], off); err != nil { - return - } - - switch tag = buf[0]; tag { - default: - s = int64(n2atoms(int(tag))) - case tagUsedLong: - s = int64(n2atoms(m2n(int(buf[1])<<8 | int(buf[2])))) - case tagFreeLong: - if rq < 22 { - err = io.ErrUnexpectedEOF - return - } - - s, p, n = b2h(buf[1:]), b2h(buf[8:]), b2h(buf[15:]) - case tagUsedRelocated: - s, n = 1, b2h(buf[1:]) - case tagFreeShort: - s, p, n = 1, b2h(buf[1:]), b2h(buf[8:]) - } - return -} - -// leftNfo returns nfo for h's left neighbor if h > 1 and the left neighbor is -// a free block. Otherwise all zero values are returned instead. -func (a *Allocator) leftNfo(h int64) (tag byte, s, p, n int64, err error) { - if !(h > 1) { - return - } - - pbuf := buffer.Get(8) - defer buffer.Put(pbuf) - buf := *pbuf - off := h2off(h) - if err = a.read(buf[:], off-8); err != nil { - return - } - - switch tag := buf[7]; tag { - case tagFreeShort: - return a.nfo(h - 1) - case tagFreeLong: - return a.nfo(h - b2h(buf[:])) - } - return -} - -// Set h.prev = p -func (a *Allocator) prev(h, p int64) (err error) { - pb := buffer.Get(7) - defer buffer.Put(pb) - b := *pb - off := h2off(h) - if err = a.read(b[:1], off); err != nil { - return - } - - switch tag := b[0]; tag { - default: - return &ErrILSEQ{Type: ErrExpFreeTag, Off: off, Arg: int64(tag)} - case tagFreeShort: - off += 1 - case tagFreeLong: - off += 8 - } - return a.writeAt(h2b(b[:7], p), off) -} - -// Set h.next = n -func (a *Allocator) next(h, n int64) (err error) { - pb := buffer.Get(7) - defer buffer.Put(pb) - b := *pb - off := h2off(h) - if err = a.read(b[:1], off); err != nil { - return - } - - switch tag := b[0]; tag { - default: - return &ErrILSEQ{Type: ErrExpFreeTag, Off: off, Arg: int64(tag)} - case tagFreeShort: - off += 8 - case tagFreeLong: - off += 15 - } - return a.writeAt(h2b(b[:7], n), off) -} - -// Make the filer image @h a free block. -func (a *Allocator) makeFree(h, atoms, prev, next int64) (err error) { - pbuf := buffer.Get(22) - defer buffer.Put(pbuf) - buf := *pbuf - switch { - case atoms == 1: - buf[0], buf[15] = tagFreeShort, tagFreeShort - h2b(buf[1:], prev) - h2b(buf[8:], next) - if err = a.write(h2off(h), buf[:16]); err != nil { - return - } - default: - - buf[0] = tagFreeLong - h2b(buf[1:], atoms) - h2b(buf[8:], prev) - h2b(buf[15:], next) - if err = a.write(h2off(h), buf[:22]); err != nil { - return - } - - h2b(buf[:], atoms) - buf[7] = tagFreeLong - if err = a.write(h2off(h+atoms)-8, buf[:8]); err != nil { - return - } - } - if prev != 0 { - if err = a.next(prev, h); err != nil { - return - } - } - - if next != 0 { - err = a.prev(next, h) - } - return -} - -func (a *Allocator) makeUsedBlock(dst []byte, b []byte) (w []byte, rqAtoms int, cc byte, err error) { - cc = tagNotCompressed - w = b - - var n int - if n = len(b); n > maxRq { - return nil, 0, 0, &ErrINVAL{"Allocator.makeUsedBlock: content size out of limits", n} - } - - rqAtoms = n2atoms(n) - if a.Compress && n > 14 { // attempt compression - if dst, err = zappy.Encode(dst, b); err != nil { - return - } - - n2 := len(dst) - if rqAtoms2 := n2atoms(n2); rqAtoms2 < rqAtoms { // compression saved at least a single atom - w, rqAtoms, cc = dst, rqAtoms2, tagCompressed - } - } - return -} - -func (a *Allocator) writeUsedBlock(h int64, cc byte, b []byte) (err error) { - n := len(b) - rq := n2atoms(n) << 4 - pbuf := buffer.Get(rq) - defer buffer.Put(pbuf) - buf := *pbuf - switch n <= maxShort { - case true: - buf[0] = byte(n) - copy(buf[1:], b) - case false: - m := n2m(n) - buf[0], buf[1], buf[2] = tagUsedLong, byte(m>>8), byte(m) - copy(buf[3:], b) - } - if p := n2padding(n); p != 0 { - copy(buf[rq-1-p:], zeros[:]) - } - buf[rq-1] = cc - return a.writeAt(buf, h2off(h)) -} - -func (a *Allocator) verifyUnused(h, totalAtoms int64, tag byte, log func(error) bool, fast bool) (atoms, prev, next int64, err error) { - switch tag { - default: - panic("internal error") - case tagFreeShort: - var b [16]byte - off := h2off(h) - if err = a.read(b[:], off); err != nil { - return - } - - if b[15] != tagFreeShort { - err = &ErrILSEQ{Type: ErrShortFreeTailTag, Off: off, Arg: int64(b[15])} - log(err) - return - } - - atoms, prev, next = 1, b2h(b[1:]), b2h(b[8:]) - case tagFreeLong: - var b [22]byte - off := h2off(h) - if err = a.read(b[:], off); err != nil { - return - } - - atoms, prev, next = b2h(b[1:]), b2h(b[8:]), b2h(b[15:]) - if fast { - return - } - - if atoms < 2 { - err = &ErrILSEQ{Type: ErrLongFreeBlkTooShort, Off: off, Arg: atoms} - break - } - - if h+atoms-1 > totalAtoms { - err = &ErrILSEQ{Type: ErrLongFreeBlkTooLong, Off: off, Arg: atoms} - break - } - - if prev > totalAtoms { - err = &ErrILSEQ{Type: ErrLongFreePrevBeyondEOF, Off: off, Arg: next} - break - } - - if next > totalAtoms { - err = &ErrILSEQ{Type: ErrLongFreeNextBeyondEOF, Off: off, Arg: next} - break - } - - toff := h2off(h+atoms) - 8 - if err = a.read(b[:8], toff); err != nil { - return - } - - if b[7] != tag { - err = &ErrILSEQ{Type: ErrLongFreeTailTag, Off: off, Arg: int64(b[7])} - break - } - - if s2 := b2h(b[:]); s2 != atoms { - err = &ErrILSEQ{Type: ErrVerifyTailSize, Off: off, Arg: atoms, Arg2: s2} - break - } - - } - if err != nil { - log(err) - } - return -} - -func (a *Allocator) verifyUsed(h, totalAtoms int64, tag byte, buf, ubuf []byte, log func(error) bool, fast bool) (compressed bool, dlen int, atoms, link int64, err error) { - var ( - padding int - doff int64 - padZeros [15]byte - tailBuf [16]byte - ) - - switch tag { - default: // Short used - dlen = int(tag) - atoms = int64((dlen+1)/16) + 1 - padding = 15 - (dlen+1)%16 - doff = h2off(h) + 1 - case tagUsedLong: - off := h2off(h) + 1 - var b2 [2]byte - if err = a.read(b2[:], off); err != nil { - return - } - - dlen = m2n(int(b2[0])<<8 | int(b2[1])) - atoms = int64((dlen+3)/16) + 1 - padding = 15 - (dlen+3)%16 - doff = h2off(h) + 3 - case tagUsedRelocated: - dlen = 7 - atoms = 1 - padding = 7 - doff = h2off(h) + 1 - case tagFreeShort, tagFreeLong: - panic("internal error") - } - - if fast { - if tag == tagUsedRelocated { - dlen = 0 - if err = a.read(buf[:7], doff); err != nil { - return - } - - link = b2h(buf) - } - - return false, dlen, atoms, link, nil - } - - if ok := h+atoms-1 <= totalAtoms; !ok { // invalid last block - err = &ErrILSEQ{Type: ErrVerifyUsedSpan, Off: h2off(h), Arg: atoms} - log(err) - return - } - - tailsz := 1 + padding - off := h2off(h) + 16*atoms - int64(tailsz) - if err = a.read(tailBuf[:tailsz], off); err != nil { - return false, 0, 0, 0, err - } - - if ok := bytes.Equal(padZeros[:padding], tailBuf[:padding]); !ok { - err = &ErrILSEQ{Type: ErrVerifyPadding, Off: h2off(h)} - log(err) - return - } - - var cc byte - switch cc = tailBuf[padding]; cc { - default: - err = &ErrILSEQ{Type: ErrTailTag, Off: h2off(h)} - log(err) - return - case tagCompressed: - compressed = true - if tag == tagUsedRelocated { - err = &ErrILSEQ{Type: ErrTailTag, Off: h2off(h)} - log(err) - return - } - - fallthrough - case tagNotCompressed: - if err = a.read(buf[:dlen], doff); err != nil { - return false, 0, 0, 0, err - } - } - - if cc == tagCompressed { - if ubuf, err = zappy.Decode(ubuf, buf[:dlen]); err != nil || len(ubuf) > maxRq { - err = &ErrILSEQ{Type: ErrDecompress, Off: h2off(h)} - log(err) - return - } - - dlen = len(ubuf) - } - - if tag == tagUsedRelocated { - link = b2h(buf) - if link == 0 { - err = &ErrILSEQ{Type: ErrNullReloc, Off: h2off(h)} - log(err) - return - } - - if link > totalAtoms { // invalid last block - err = &ErrILSEQ{Type: ErrRelocBeyondEOF, Off: h2off(h), Arg: link} - log(err) - return - } - } - - return -} - -var nolog = func(error) bool { return false } - -// Verify attempts to find any structural errors in a Filer wrt the -// organization of it as defined by Allocator. 'bitmap' is a scratch pad for -// necessary bookkeeping and will grow to at most to Allocator's -// Filer.Size()/128 (0,78%). Any problems found are reported to 'log' except -// non verify related errors like disk read fails etc. If 'log' returns false -// or the error doesn't allow to (reliably) continue, the verification process -// is stopped and an error is returned from the Verify function. Passing a nil -// log works like providing a log function always returning false. Any -// non-structural errors, like for instance Filer read errors, are NOT reported -// to 'log', but returned as the Verify's return value, because Verify cannot -// proceed in such cases. Verify returns nil only if it fully completed -// verifying Allocator's Filer without detecting any error. -// -// It is recommended to limit the number reported problems by returning false -// from 'log' after reaching some limit. Huge and corrupted DB can produce an -// overwhelming error report dataset. -// -// The verifying process will scan the whole DB at least 3 times (a trade -// between processing space and time consumed). It doesn't read the content of -// free blocks above the head/tail info bytes. If the 3rd phase detects lost -// free space, then a 4th scan (a faster one) is performed to precisely report -// all of them. -// -// If the DB/Filer to be verified is reasonably small, respective if its -// size/128 can comfortably fit within process's free memory, then it is -// recommended to consider using a MemFiler for the bit map. -// -// Statistics are returned via 'stats' if non nil. The statistics are valid -// only if Verify succeeded, ie. it didn't reported anything to log and it -// returned a nil error. -func (a *Allocator) Verify(bitmap Filer, log func(error) bool, stats *AllocStats) (err error) { - if log == nil { - log = nolog - } - - n, err := bitmap.Size() - if err != nil { - return - } - - if n != 0 { - return &ErrINVAL{"Allocator.Verify: bit map initial size non zero (%d)", n} - } - - var bits int64 - bitMask := [8]byte{1, 2, 4, 8, 16, 32, 64, 128} - byteBuf := []byte{0} - - //DONE - // +performance, this implementation is hopefully correct but _very_ - // naive, probably good as a prototype only. Use maybe a MemFiler - // "cache" etc. - // ---- - // Turns out the OS caching is as effective as it can probably get. - bit := func(on bool, h int64) (wasOn bool, err error) { - m := bitMask[h&7] - off := h >> 3 - var v byte - sz, err := bitmap.Size() - if err != nil { - return - } - - if off < sz { - if n, err := bitmap.ReadAt(byteBuf, off); n != 1 { - return false, &ErrILSEQ{Type: ErrOther, Off: off, More: fmt.Errorf("Allocator.Verify - reading bitmap: %s", err)} - } - - v = byteBuf[0] - } - switch wasOn = v&m != 0; on { - case true: - if !wasOn { - v |= m - bits++ - } - case false: - if wasOn { - v ^= m - bits-- - } - } - byteBuf[0] = v - if n, err := bitmap.WriteAt(byteBuf, off); n != 1 || err != nil { - return false, &ErrILSEQ{Type: ErrOther, Off: off, More: fmt.Errorf("Allocator.Verify - writing bitmap: %s", err)} - } - - return - } - - // Phase 1 - sequentially scan a.f to reliably determine block - // boundaries. Set a bit for every block start. - var ( - buf, ubuf [maxRq]byte - prevH, h, atoms int64 - wasOn bool - tag byte - st = AllocStats{ - AllocMap: map[int64]int64{}, - FreeMap: map[int64]int64{}, - } - dlen int - ) - - fsz, err := a.f.Size() - if err != nil { - return - } - - ok := fsz%16 == 0 - totalAtoms := (fsz - fltSz) / atomLen - if !ok { - err = &ErrILSEQ{Type: ErrFileSize, Name: a.f.Name(), Arg: fsz} - log(err) - return - } - - st.TotalAtoms = totalAtoms - prevTag := -1 - lastH := int64(-1) - - for h = 1; h <= totalAtoms; h += atoms { - prevH = h // For checking last block == used - - off := h2off(h) - if err = a.read(buf[:1], off); err != nil { - return - } - - switch tag = buf[0]; tag { - default: // Short used - fallthrough - case tagUsedLong, tagUsedRelocated: - var compressed bool - if compressed, dlen, atoms, _, err = a.verifyUsed(h, totalAtoms, tag, buf[:], ubuf[:], log, false); err != nil { - return - } - - if compressed { - st.Compression++ - } - st.AllocAtoms += atoms - switch { - case tag == tagUsedRelocated: - st.AllocMap[1]++ - st.Relocations++ - default: - st.AllocMap[atoms]++ - st.AllocBytes += int64(dlen) - st.Handles++ - } - case tagFreeShort, tagFreeLong: - if prevTag == tagFreeShort || prevTag == tagFreeLong { - err = &ErrILSEQ{Type: ErrAdjacentFree, Off: h2off(lastH), Arg: off} - log(err) - return - } - - if atoms, _, _, err = a.verifyUnused(h, totalAtoms, tag, log, false); err != nil { - return - } - - st.FreeMap[atoms]++ - st.FreeAtoms += atoms - } - - if wasOn, err = bit(true, h); err != nil { - return - } - - if wasOn { - panic("internal error") - } - - prevTag = int(tag) - lastH = h - } - - if totalAtoms != 0 && (tag == tagFreeShort || tag == tagFreeLong) { - err = &ErrILSEQ{Type: ErrFreeTailBlock, Off: h2off(prevH)} - log(err) - return - } - - // Phase 2 - check used blocks, turn off the map bit for every used - // block. - for h = 1; h <= totalAtoms; h += atoms { - off := h2off(h) - if err = a.read(buf[:1], off); err != nil { - return - } - - var link int64 - switch tag = buf[0]; tag { - default: // Short used - fallthrough - case tagUsedLong, tagUsedRelocated: - if _, _, atoms, link, err = a.verifyUsed(h, totalAtoms, tag, buf[:], ubuf[:], log, true); err != nil { - return - } - case tagFreeShort, tagFreeLong: - if atoms, _, _, err = a.verifyUnused(h, totalAtoms, tag, log, true); err != nil { - return - } - } - - turnoff := true - switch tag { - case tagUsedRelocated: - if err = a.read(buf[:1], h2off(link)); err != nil { - return - } - - switch linkedTag := buf[0]; linkedTag { - case tagFreeShort, tagFreeLong, tagUsedRelocated: - err = &ErrILSEQ{Type: ErrInvalidRelocTarget, Off: off, Arg: link} - log(err) - return - } - - case tagFreeShort, tagFreeLong: - turnoff = false - } - - if !turnoff { - continue - } - - if wasOn, err = bit(false, h); err != nil { - return - } - - if !wasOn { - panic("internal error") - } - - } - - // Phase 3 - using the flt check heads link to proper free blocks. For - // every free block, walk the list, verify the {next, prev} links and - // turn the respective map bit off. After processing all free lists, - // the map bits count should be zero. Otherwise there are "lost" free - // blocks. - - var prev, next, fprev, fnext int64 - rep := a.flt - - for _, list := range rep { - prev, next = 0, list.head - for ; next != 0; prev, next = next, fnext { - if wasOn, err = bit(false, next); err != nil { - return - } - - if !wasOn { - err = &ErrILSEQ{Type: ErrFLT, Off: h2off(next), Arg: h} - log(err) - return - } - - off := h2off(next) - if err = a.read(buf[:1], off); err != nil { - return - } - - switch tag = buf[0]; tag { - default: - panic("internal error") - case tagFreeShort, tagFreeLong: - if atoms, fprev, fnext, err = a.verifyUnused(next, totalAtoms, tag, log, true); err != nil { - return - } - - if min := list.minSize; atoms < min { - err = &ErrILSEQ{Type: ErrFLTSize, Off: h2off(next), Arg: atoms, Arg2: min} - log(err) - return - } - - if fprev != prev { - err = &ErrILSEQ{Type: ErrFreeChaining, Off: h2off(next)} - log(err) - return - } - } - } - - } - - if bits == 0 { // Verify succeeded - if stats != nil { - *stats = st - } - return - } - - // Phase 4 - if after phase 3 there are lost free blocks, report all of - // them to 'log' - for i := range ubuf { // setup zeros for compares - ubuf[i] = 0 - } - - var off, lh int64 - rem, err := bitmap.Size() - if err != nil { - return err - } - - for rem != 0 { - rq := int(mathutil.MinInt64(64*1024, rem)) - var n int - if n, err = bitmap.ReadAt(buf[:rq], off); n != rq { - return &ErrILSEQ{Type: ErrOther, Off: off, More: fmt.Errorf("bitmap ReadAt(size %d, off %#x): %s", rq, off, err)} - } - - if !bytes.Equal(buf[:rq], ubuf[:rq]) { - for d, v := range buf[:rq] { - if v != 0 { - for i, m := range bitMask { - if v&m != 0 { - lh = 8*(off+int64(d)) + int64(i) - err = &ErrILSEQ{Type: ErrLostFreeBlock, Off: h2off(lh)} - log(err) - return - } - } - } - } - } - - off += int64(rq) - rem -= int64(rq) - } - - return -} - -type fltSlot struct { - head int64 - minSize int64 -} - -func (f fltSlot) String() string { - return fmt.Sprintf("head %#x, minSize %#x\n", f.head, f.minSize) -} - -type flt [14]fltSlot - -func (f *flt) init() { - sz := 1 - for i := range *f { - f[i].minSize, f[i].head = int64(sz), 0 - sz <<= 1 - } - f[13].minSize = 4112 -} - -func (f *flt) load(fi Filer, off int64) (err error) { - pb := buffer.Get(fltSz) - defer buffer.Put(pb) - b := *pb - if _, err = fi.ReadAt(b[:], off); err != nil { - return - } - - for i := range *f { - off := 8*i + 1 - f[i].head = b2h(b[off:]) - } - return -} - -func (f *flt) find(rq int) (h int64) { - switch { - case rq < 1: - panic(rq) - case rq >= maxFLTRq: - h, f[13].head = f[13].head, 0 - return - default: - g := f[mathutil.Log2Uint16(uint16(rq)):] - for i := range g { - p := &g[i] - if rq <= int(p.minSize) { - if h = p.head; h != 0 { - p.head = 0 - return - } - } - } - return - } -} - -func (f *flt) head(atoms int64) (h int64) { - switch { - case atoms < 1: - panic(atoms) - case atoms >= maxFLTRq: - return f[13].head - default: - lg := mathutil.Log2Uint16(uint16(atoms)) - g := f[lg:] - for i := range g { - if atoms < g[i+1].minSize { - return g[i].head - } - } - panic("internal error") - } -} - -func (f *flt) setHead(h, atoms int64, fi Filer) (err error) { - switch { - case atoms < 1: - panic(atoms) - case atoms >= maxFLTRq: - pb := buffer.Get(7) - defer buffer.Put(pb) - b := *pb - if _, err = fi.WriteAt(h2b(b[:], h), 8*13+1); err != nil { - return - } - - f[13].head = h - return - default: - lg := mathutil.Log2Uint16(uint16(atoms)) - g := f[lg:] - for i := range f { - if atoms < g[i+1].minSize { - pb := buffer.Get(7) - defer buffer.Put(pb) - b := *pb - if _, err = fi.WriteAt(h2b(b[:], h), 8*int64(i+lg)+1); err != nil { - return - } - - g[i].head = h - return - } - } - panic("internal error") - } -} - -func (f *flt) String() string { - a := []string{} - for i, v := range *f { - a = append(a, fmt.Sprintf("[%2d] %s", i, v)) - } - return strings.Join(a, "") -} - -type node struct { - b []byte - h int64 - prev, next *node -} - -type cache []*node - -func (c *cache) get(n int) *node { - r, _ := c.get2(n) - return r -} - -func (c *cache) get2(n int) (r *node, isZeroed bool) { - s := *c - lens := len(s) - if lens == 0 { - return &node{b: make([]byte, n, mathutil.Min(2*n, maxBuf))}, true - } - - i := sort.Search(lens, func(x int) bool { return len(s[x].b) >= n }) - if i == lens { - i-- - s[i].b, isZeroed = make([]byte, n, mathutil.Min(2*n, maxBuf)), true - } - - r = s[i] - r.b = r.b[:n] - copy(s[i:], s[i+1:]) - s = s[:lens-1] - *c = s - return -} - -func (c *cache) cget(n int) (r *node) { - r, ok := c.get2(n) - if ok { - return - } - - for i := range r.b { - r.b[i] = 0 - } - return -} - -func (c *cache) size() (sz int64) { - for _, n := range *c { - sz += int64(cap(n.b)) - } - return -} - -func (c *cache) put(n *node) *node { - s := *c - n.b = n.b[:cap(n.b)] - lenb := len(n.b) - lens := len(s) - i := sort.Search(lens, func(x int) bool { return len(s[x].b) >= lenb }) - s = append(s, nil) - copy(s[i+1:], s[i:]) - s[i] = n - *c = s - return n -} - -type lst struct { - front, back *node -} - -func (l *lst) pushFront(n *node) *node { - if l.front == nil { - l.front, l.back, n.prev, n.next = n, n, nil, nil - return n - } - - n.prev, n.next, l.front.prev, l.front = nil, l.front, n, n - return n -} - -func (l *lst) remove(n *node) *node { - if n.prev == nil { - l.front = n.next - } else { - n.prev.next = n.next - } - if n.next == nil { - l.back = n.prev - } else { - n.next.prev = n.prev - } - n.prev, n.next = nil, nil - return n -} - -func (l *lst) removeBack() *node { - return l.remove(l.back) -} - -func (l *lst) moveToFront(n *node) *node { - return l.pushFront(l.remove(n)) -} - -func (l *lst) size() (sz int64) { - for n := l.front; n != nil; n = n.next { - sz += int64(cap(n.b)) - } - return -} - -func cacheAudit(m map[int64]*node, l *lst) (err error) { - cnt := 0 - for h, n := range m { - if g, e := n.h, h; g != e { - return fmt.Errorf("cacheAudit: invalid node handle %d != %d", g, e) - } - - if cnt, err = l.audit(n, true); err != nil { - return - } - } - - if g, e := cnt, len(m); g != e { - return fmt.Errorf("cacheAudit: invalid cache size %d != %d", g, e) - } - - return -} - -func (l *lst) audit(n *node, onList bool) (cnt int, err error) { - if !onList && (n.prev != nil || n.next != nil) { - return -1, fmt.Errorf("lst.audit: free node with non nil linkage") - } - - if l.front == nil && l.back != nil || l.back == nil && l.front != nil { - return -1, fmt.Errorf("lst.audit: one of .front/.back is nil while the other is non nil") - } - - if l.front == l.back && l.front != nil { - x := l.front - if x.prev != nil || x.next != nil { - return -1, fmt.Errorf("lst.audit: single node has non nil linkage") - } - - if onList && x != n { - return -1, fmt.Errorf("lst.audit: single node is alien") - } - } - - seen := false - var prev *node - x := l.front - for x != nil { - cnt++ - if x.prev != prev { - return -1, fmt.Errorf("lst.audit: broken .prev linkage") - } - - if x == n { - seen = true - } - - prev = x - x = x.next - } - - if prev != l.back { - return -1, fmt.Errorf("lst.audit: broken .back linkage") - } - - if onList && !seen { - return -1, fmt.Errorf("lst.audit: node missing in list") - } - - if !onList && seen { - return -1, fmt.Errorf("lst.audit: node should not be on the list") - } - - return -} diff --git a/vendor/github.com/cznic/lldb/filer.go b/vendor/github.com/cznic/lldb/filer.go deleted file mode 100644 index f7793ed9c..000000000 --- a/vendor/github.com/cznic/lldb/filer.go +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// An abstraction of file like (persistent) storage with optional (abstracted) -// support for structural integrity. - -package lldb - -import "github.com/cznic/mathutil" - -// A Filer is a []byte-like model of a file or similar entity. It may -// optionally implement support for structural transaction safety. In contrast -// to a file stream, a Filer is not sequentially accessible. ReadAt and WriteAt -// are always "addressed" by an offset and are assumed to perform atomically. -// A Filer is not safe for concurrent access, it's designed for consumption by -// the other objects in package, which should use a Filer from one goroutine -// only or via a mutex. BeginUpdate, EndUpdate and Rollback must be either all -// implemented by a Filer for structural integrity - or they should be all -// no-ops; where/if that requirement is relaxed. -// -// If a Filer wraps another Filer implementation, it usually invokes the same -// methods on the "inner" one, after some possible argument translations etc. -// If a Filer implements the structural transactions handling methods -// (BeginUpdate, EndUpdate and Rollback) as no-ops _and_ wraps another Filer: -// it then still MUST invoke those methods on the inner Filer. This is -// important for the case where a RollbackFiler exists somewhere down the -// chain. It's also important for an Allocator - to know when it must -// invalidate its FLT cache. -type Filer interface { - // BeginUpdate increments the "nesting" counter (initially zero). Every - // call to BeginUpdate must be eventually "balanced" by exactly one of - // EndUpdate or Rollback. Calls to BeginUpdate may nest. - BeginUpdate() error - - // Analogous to os.File.Close(). - Close() error - - // EndUpdate decrements the "nesting" counter. If it's zero after that - // then assume the "storage" has reached structural integrity (after a - // batch of partial updates). If a Filer implements some support for - // that (write ahead log, journal, etc.) then the appropriate actions - // are to be taken for nesting == 0. Invocation of an unbalanced - // EndUpdate is an error. - EndUpdate() error - - // Analogous to os.File.Name(). - Name() string - - // PunchHole deallocates space inside a "file" in the byte range - // starting at off and continuing for size bytes. The actual hole - // created by PunchHole may be smaller than requested. The Filer size - // (as reported by `Size()` does not change when hole punching, even - // when punching the end of a file off. In contrast to the Linux - // implementation of FALLOC_FL_PUNCH_HOLE in `fallocate`(2); a Filer is - // free not only to ignore `PunchHole()` (implement it as a nop), but - // additionally no guarantees about the content of the hole, when - // eventually read back, are required, i.e. any data, not only zeros, - // can be read from the "hole", including just anything what was left - // there - with all of the possible security problems. - PunchHole(off, size int64) error - - // As os.File.ReadAt. Note: `off` is an absolute "file pointer" - // address and cannot be negative even when a Filer is a InnerFiler. - ReadAt(b []byte, off int64) (n int, err error) - - // Rollback cancels and undoes the innermost pending update level. - // Rollback decrements the "nesting" counter. If a Filer implements - // some support for keeping structural integrity (write ahead log, - // journal, etc.) then the appropriate actions are to be taken. - // Invocation of an unbalanced Rollback is an error. - Rollback() error - - // Analogous to os.File.FileInfo().Size(). - Size() (int64, error) - - // Analogous to os.Sync(). - Sync() (err error) - - // Analogous to os.File.Truncate(). - Truncate(size int64) error - - // Analogous to os.File.WriteAt(). Note: `off` is an absolute "file - // pointer" address and cannot be negative even when a Filer is a - // InnerFiler. - WriteAt(b []byte, off int64) (n int, err error) -} - -var _ Filer = &InnerFiler{} // Ensure InnerFiler is a Filer. - -// A InnerFiler is a Filer with added addressing/size translation. -type InnerFiler struct { - outer Filer - off int64 -} - -// NewInnerFiler returns a new InnerFiler wrapped by `outer` in a way which -// adds `off` to every access. -// -// For example, considering: -// -// inner := NewInnerFiler(outer, 10) -// -// then -// -// inner.WriteAt([]byte{42}, 4) -// -// translates to -// -// outer.WriteAt([]byte{42}, 14) -// -// But an attempt to emulate -// -// outer.WriteAt([]byte{17}, 9) -// -// by -// -// inner.WriteAt([]byte{17}, -1) -// -// will fail as the `off` parameter can never be < 0. Also note that -// -// inner.Size() == outer.Size() - off, -// -// i.e. `inner` pretends no `outer` exists. Finally, after e.g. -// -// inner.Truncate(7) -// outer.Size() == 17 -// -// will be true. -func NewInnerFiler(outer Filer, off int64) *InnerFiler { return &InnerFiler{outer, off} } - -// BeginUpdate implements Filer. -func (f *InnerFiler) BeginUpdate() error { return f.outer.BeginUpdate() } - -// Close implements Filer. -func (f *InnerFiler) Close() (err error) { return f.outer.Close() } - -// EndUpdate implements Filer. -func (f *InnerFiler) EndUpdate() error { return f.outer.EndUpdate() } - -// Name implements Filer. -func (f *InnerFiler) Name() string { return f.outer.Name() } - -// PunchHole implements Filer. `off`, `size` must be >= 0. -func (f *InnerFiler) PunchHole(off, size int64) error { return f.outer.PunchHole(f.off+off, size) } - -// ReadAt implements Filer. `off` must be >= 0. -func (f *InnerFiler) ReadAt(b []byte, off int64) (n int, err error) { - if off < 0 { - return 0, &ErrINVAL{f.outer.Name() + ":ReadAt invalid off", off} - } - - return f.outer.ReadAt(b, f.off+off) -} - -// Rollback implements Filer. -func (f *InnerFiler) Rollback() error { return f.outer.Rollback() } - -// Size implements Filer. -func (f *InnerFiler) Size() (int64, error) { - sz, err := f.outer.Size() - if err != nil { - return 0, err - } - - return mathutil.MaxInt64(sz-f.off, 0), nil -} - -// Sync() implements Filer. -func (f *InnerFiler) Sync() (err error) { - return f.outer.Sync() -} - -// Truncate implements Filer. -func (f *InnerFiler) Truncate(size int64) error { return f.outer.Truncate(size + f.off) } - -// WriteAt implements Filer. `off` must be >= 0. -func (f *InnerFiler) WriteAt(b []byte, off int64) (n int, err error) { - if off < 0 { - return 0, &ErrINVAL{f.outer.Name() + ":WriteAt invalid off", off} - } - - return f.outer.WriteAt(b, f.off+off) -} diff --git a/vendor/github.com/cznic/lldb/gb.go b/vendor/github.com/cznic/lldb/gb.go deleted file mode 100644 index 5bc3e404e..000000000 --- a/vendor/github.com/cznic/lldb/gb.go +++ /dev/null @@ -1,812 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Utilities to encode/decode and collate Go predeclared scalar types (and the -// typeless nil and []byte). The encoding format is a variation of the one -// used by the "encoding/gob" package. - -package lldb - -import ( - "bytes" - "fmt" - "math" - - "github.com/cznic/mathutil" -) - -const ( - gbNull = iota // 0x00 - gbFalse // 0x01 - gbTrue // 0x02 - gbFloat0 // 0x03 - gbFloat1 // 0x04 - gbFloat2 // 0x05 - gbFloat3 // 0x06 - gbFloat4 // 0x07 - gbFloat5 // 0x08 - gbFloat6 // 0x09 - gbFloat7 // 0x0a - gbFloat8 // 0x0b - gbComplex0 // 0x0c - gbComplex1 // 0x0d - gbComplex2 // 0x0e - gbComplex3 // 0x0f - gbComplex4 // 0x10 - gbComplex5 // 0x11 - gbComplex6 // 0x12 - gbComplex7 // 0x13 - gbComplex8 // 0x14 - gbBytes00 // 0x15 - gbBytes01 // 0x16 - gbBytes02 // 0x17 - gbBytes03 // 0x18 - gbBytes04 // 0x19 - gbBytes05 // 0x1a - gbBytes06 // 0x1b - gbBytes07 // 0x1c - gbBytes08 // 0x1d - gbBytes09 // 0x1e - gbBytes10 // 0x1f - gbBytes11 // 0x20 - gbBytes12 // 0x21 - gbBytes13 // 0x22 - gbBytes14 // 0x23 - gbBytes15 // 0x24 - gbBytes16 // 0x25 - gbBytes17 // Ox26 - gbBytes1 // 0x27 - gbBytes2 // 0x28: Offset by one to allow 64kB sized []byte. - gbString00 // 0x29 - gbString01 // 0x2a - gbString02 // 0x2b - gbString03 // 0x2c - gbString04 // 0x2d - gbString05 // 0x2e - gbString06 // 0x2f - gbString07 // 0x30 - gbString08 // 0x31 - gbString09 // 0x32 - gbString10 // 0x33 - gbString11 // 0x34 - gbString12 // 0x35 - gbString13 // 0x36 - gbString14 // 0x37 - gbString15 // 0x38 - gbString16 // 0x39 - gbString17 // 0x3a - gbString1 // 0x3b - gbString2 // 0x3c - gbUintP1 // 0x3d - gbUintP2 // 0x3e - gbUintP3 // 0x3f - gbUintP4 // 0x40 - gbUintP5 // 0x41 - gbUintP6 // 0x42 - gbUintP7 // 0x43 - gbUintP8 // 0x44 - gbIntM8 // 0x45 - gbIntM7 // 0x46 - gbIntM6 // 0x47 - gbIntM5 // 0x48 - gbIntM4 // 0x49 - gbIntM3 // 0x4a - gbIntM2 // 0x4b - gbIntM1 // 0x4c - gbIntP1 // 0x4d - gbIntP2 // 0x4e - gbIntP3 // 0x4f - gbIntP4 // 0x50 - gbIntP5 // 0x51 - gbIntP6 // 0x52 - gbIntP7 // 0x53 - gbIntP8 // 0x54 - gbInt0 // 0x55 - - gbIntMax = 255 - gbInt0 // 0xff == 170 -) - -// EncodeScalars encodes a vector of predeclared scalar type values to a -// []byte, making it suitable to store it as a "record" in a DB or to use it as -// a key of a BTree. -func EncodeScalars(scalars ...interface{}) (b []byte, err error) { - for _, scalar := range scalars { - switch x := scalar.(type) { - default: - return nil, &ErrINVAL{"EncodeScalars: unsupported type", fmt.Sprintf("%T in `%#v`", x, scalars)} - - case nil: - b = append(b, gbNull) - - case bool: - switch x { - case false: - b = append(b, gbFalse) - case true: - b = append(b, gbTrue) - } - - case float32: - encFloat(float64(x), &b) - case float64: - encFloat(x, &b) - - case complex64: - encComplex(complex128(x), &b) - case complex128: - encComplex(x, &b) - - case string: - n := len(x) - if n <= 17 { - b = append(b, byte(gbString00+n)) - b = append(b, []byte(x)...) - break - } - - if n > 65535 { - return nil, fmt.Errorf("EncodeScalars: cannot encode string of length %d (limit 65536)", n) - } - - pref := byte(gbString1) - if n > 255 { - pref++ - } - b = append(b, pref) - encUint0(uint64(n), &b) - b = append(b, []byte(x)...) - - case int8: - encInt(int64(x), &b) - case int16: - encInt(int64(x), &b) - case int32: - encInt(int64(x), &b) - case int64: - encInt(x, &b) - case int: - encInt(int64(x), &b) - - case uint8: - encUint(uint64(x), &b) - case uint16: - encUint(uint64(x), &b) - case uint32: - encUint(uint64(x), &b) - case uint64: - encUint(x, &b) - case uint: - encUint(uint64(x), &b) - case []byte: - n := len(x) - if n <= 17 { - b = append(b, byte(gbBytes00+n)) - b = append(b, x...) - break - } - - if n > 655356 { - return nil, fmt.Errorf("EncodeScalars: cannot encode []byte of length %d (limit 65536)", n) - } - - pref := byte(gbBytes1) - if n > 255 { - pref++ - } - b = append(b, pref) - if n <= 255 { - b = append(b, byte(n)) - } else { - n-- - b = append(b, byte(n>>8), byte(n)) - } - b = append(b, x...) - } - } - return -} - -func encComplex(f complex128, b *[]byte) { - encFloatPrefix(gbComplex0, real(f), b) - encFloatPrefix(gbComplex0, imag(f), b) -} - -func encFloatPrefix(prefix byte, f float64, b *[]byte) { - u := math.Float64bits(f) - var n uint64 - for i := 0; i < 8; i++ { - n <<= 8 - n |= u & 0xFF - u >>= 8 - } - bits := mathutil.BitLenUint64(n) - if bits == 0 { - *b = append(*b, prefix) - return - } - - // 0 1 2 3 4 5 6 7 8 9 - // . 1 1 1 1 1 1 1 1 2 - encUintPrefix(prefix+1+byte((bits-1)>>3), n, b) -} - -func encFloat(f float64, b *[]byte) { - encFloatPrefix(gbFloat0, f, b) -} - -func encUint0(n uint64, b *[]byte) { - switch { - case n <= 0xff: - *b = append(*b, byte(n)) - case n <= 0xffff: - *b = append(*b, byte(n>>8), byte(n)) - case n <= 0xffffff: - *b = append(*b, byte(n>>16), byte(n>>8), byte(n)) - case n <= 0xffffffff: - *b = append(*b, byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n <= 0xffffffffff: - *b = append(*b, byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n <= 0xffffffffffff: - *b = append(*b, byte(n>>40), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n <= 0xffffffffffffff: - *b = append(*b, byte(n>>48), byte(n>>40), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n <= math.MaxUint64: - *b = append(*b, byte(n>>56), byte(n>>48), byte(n>>40), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - } -} - -func encUintPrefix(prefix byte, n uint64, b *[]byte) { - *b = append(*b, prefix) - encUint0(n, b) -} - -func encUint(n uint64, b *[]byte) { - bits := mathutil.Max(1, mathutil.BitLenUint64(n)) - encUintPrefix(gbUintP1+byte((bits-1)>>3), n, b) -} - -func encInt(n int64, b *[]byte) { - switch { - case n < -0x100000000000000: - *b = append(*b, byte(gbIntM8), byte(n>>56), byte(n>>48), byte(n>>40), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n < -0x1000000000000: - *b = append(*b, byte(gbIntM7), byte(n>>48), byte(n>>40), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n < -0x10000000000: - *b = append(*b, byte(gbIntM6), byte(n>>40), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n < -0x100000000: - *b = append(*b, byte(gbIntM5), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n < -0x1000000: - *b = append(*b, byte(gbIntM4), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n < -0x10000: - *b = append(*b, byte(gbIntM3), byte(n>>16), byte(n>>8), byte(n)) - case n < -0x100: - *b = append(*b, byte(gbIntM2), byte(n>>8), byte(n)) - case n < 0: - *b = append(*b, byte(gbIntM1), byte(n)) - case n <= gbIntMax: - *b = append(*b, byte(gbInt0+n)) - case n <= 0xff: - *b = append(*b, gbIntP1, byte(n)) - case n <= 0xffff: - *b = append(*b, gbIntP2, byte(n>>8), byte(n)) - case n <= 0xffffff: - *b = append(*b, gbIntP3, byte(n>>16), byte(n>>8), byte(n)) - case n <= 0xffffffff: - *b = append(*b, gbIntP4, byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n <= 0xffffffffff: - *b = append(*b, gbIntP5, byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n <= 0xffffffffffff: - *b = append(*b, gbIntP6, byte(n>>40), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n <= 0xffffffffffffff: - *b = append(*b, gbIntP7, byte(n>>48), byte(n>>40), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - case n <= 0x7fffffffffffffff: - *b = append(*b, gbIntP8, byte(n>>56), byte(n>>48), byte(n>>40), byte(n>>32), byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) - } -} - -func decodeFloat(b []byte) float64 { - var u uint64 - for i, v := range b { - u |= uint64(v) << uint((i+8-len(b))*8) - } - return math.Float64frombits(u) -} - -// DecodeScalars decodes a []byte produced by EncodeScalars. -func DecodeScalars(b []byte) (scalars []interface{}, err error) { - b0 := b - for len(b) != 0 { - switch tag := b[0]; tag { - //default: - //return nil, fmt.Errorf("tag %d(%#x) not supported", b[0], b[0]) - case gbNull: - scalars = append(scalars, nil) - b = b[1:] - case gbFalse: - scalars = append(scalars, false) - b = b[1:] - case gbTrue: - scalars = append(scalars, true) - b = b[1:] - case gbFloat0: - scalars = append(scalars, 0.0) - b = b[1:] - case gbFloat1, gbFloat2, gbFloat3, gbFloat4, gbFloat5, gbFloat6, gbFloat7, gbFloat8: - n := 1 + int(tag) - gbFloat0 - if len(b) < n-1 { - goto corrupted - } - - scalars = append(scalars, decodeFloat(b[1:n])) - b = b[n:] - case gbComplex0, gbComplex1, gbComplex2, gbComplex3, gbComplex4, gbComplex5, gbComplex6, gbComplex7, gbComplex8: - n := 1 + int(tag) - gbComplex0 - if len(b) < n-1 { - goto corrupted - } - - re := decodeFloat(b[1:n]) - b = b[n:] - - if len(b) == 0 { - goto corrupted - } - - tag = b[0] - if tag < gbComplex0 || tag > gbComplex8 { - goto corrupted - } - - n = 1 + int(tag) - gbComplex0 - if len(b) < n-1 { - goto corrupted - } - - scalars = append(scalars, complex(re, decodeFloat(b[1:n]))) - b = b[n:] - case gbBytes00, gbBytes01, gbBytes02, gbBytes03, gbBytes04, - gbBytes05, gbBytes06, gbBytes07, gbBytes08, gbBytes09, - gbBytes10, gbBytes11, gbBytes12, gbBytes13, gbBytes14, - gbBytes15, gbBytes16, gbBytes17: - n := int(tag - gbBytes00) - if len(b) < n+1 { - goto corrupted - } - - scalars = append(scalars, append([]byte(nil), b[1:n+1]...)) - b = b[n+1:] - case gbBytes1: - if len(b) < 2 { - goto corrupted - } - - n := int(b[1]) - b = b[2:] - if len(b) < n { - goto corrupted - } - - scalars = append(scalars, append([]byte(nil), b[:n]...)) - b = b[n:] - case gbBytes2: - if len(b) < 3 { - goto corrupted - } - - n := int(b[1])<<8 | int(b[2]) + 1 - b = b[3:] - if len(b) < n { - goto corrupted - } - - scalars = append(scalars, append([]byte(nil), b[:n]...)) - b = b[n:] - case gbString00, gbString01, gbString02, gbString03, gbString04, - gbString05, gbString06, gbString07, gbString08, gbString09, - gbString10, gbString11, gbString12, gbString13, gbString14, - gbString15, gbString16, gbString17: - n := int(tag - gbString00) - if len(b) < n+1 { - goto corrupted - } - - scalars = append(scalars, string(b[1:n+1])) - b = b[n+1:] - case gbString1: - if len(b) < 2 { - goto corrupted - } - - n := int(b[1]) - b = b[2:] - if len(b) < n { - goto corrupted - } - - scalars = append(scalars, string(b[:n])) - b = b[n:] - case gbString2: - if len(b) < 3 { - goto corrupted - } - - n := int(b[1])<<8 | int(b[2]) - b = b[3:] - if len(b) < n { - goto corrupted - } - - scalars = append(scalars, string(b[:n])) - b = b[n:] - case gbUintP1, gbUintP2, gbUintP3, gbUintP4, gbUintP5, gbUintP6, gbUintP7, gbUintP8: - b = b[1:] - n := 1 + int(tag) - gbUintP1 - if len(b) < n { - goto corrupted - } - - var u uint64 - for _, v := range b[:n] { - u = u<<8 | uint64(v) - } - scalars = append(scalars, u) - b = b[n:] - case gbIntM8, gbIntM7, gbIntM6, gbIntM5, gbIntM4, gbIntM3, gbIntM2, gbIntM1: - b = b[1:] - n := 8 - (int(tag) - gbIntM8) - if len(b) < n { - goto corrupted - } - u := uint64(math.MaxUint64) - for _, v := range b[:n] { - u = u<<8 | uint64(v) - } - scalars = append(scalars, int64(u)) - b = b[n:] - case gbIntP1, gbIntP2, gbIntP3, gbIntP4, gbIntP5, gbIntP6, gbIntP7, gbIntP8: - b = b[1:] - n := 1 + int(tag) - gbIntP1 - if len(b) < n { - goto corrupted - } - - i := int64(0) - for _, v := range b[:n] { - i = i<<8 | int64(v) - } - scalars = append(scalars, i) - b = b[n:] - default: - scalars = append(scalars, int64(b[0])-gbInt0) - b = b[1:] - } - } - return append([]interface{}(nil), scalars...), nil - -corrupted: - return nil, &ErrDecodeScalars{append([]byte(nil), b0...), len(b0) - len(b)} -} - -func collateComplex(x, y complex128) int { - switch rx, ry := real(x), real(y); { - case rx < ry: - return -1 - case rx == ry: - switch ix, iy := imag(x), imag(y); { - case ix < iy: - return -1 - case ix == iy: - return 0 - case ix > iy: - return 1 - } - } - //case rx > ry: - return 1 -} - -func collateFloat(x, y float64) int { - switch { - case x < y: - return -1 - case x == y: - return 0 - } - //case x > y: - return 1 -} - -func collateInt(x, y int64) int { - switch { - case x < y: - return -1 - case x == y: - return 0 - } - //case x > y: - return 1 -} - -func collateUint(x, y uint64) int { - switch { - case x < y: - return -1 - case x == y: - return 0 - } - //case x > y: - return 1 -} - -func collateIntUint(x int64, y uint64) int { - if y > math.MaxInt64 { - return -1 - } - - return collateInt(x, int64(y)) -} - -func collateUintInt(x uint64, y int64) int { - return -collateIntUint(y, x) -} - -func collateType(i interface{}) (r interface{}, err error) { - switch x := i.(type) { - default: - return nil, fmt.Errorf("invalid collate type %T", x) - case nil: - return i, nil - case bool: - return i, nil - case int8: - return int64(x), nil - case int16: - return int64(x), nil - case int32: - return int64(x), nil - case int64: - return i, nil - case int: - return int64(x), nil - case uint8: - return uint64(x), nil - case uint16: - return uint64(x), nil - case uint32: - return uint64(x), nil - case uint64: - return i, nil - case uint: - return uint64(x), nil - case float32: - return float64(x), nil - case float64: - return i, nil - case complex64: - return complex128(x), nil - case complex128: - return i, nil - case []byte: - return i, nil - case string: - return i, nil - } -} - -// Collate collates two arrays of Go predeclared scalar types (and the typeless -// nil or []byte). If any other type appears in x or y, Collate will return a -// non nil error. String items are collated using strCollate or lexically -// byte-wise (as when using Go comparison operators) when strCollate is nil. -// []byte items are collated using bytes.Compare. -// -// Collate returns: -// -// -1 if x < y -// 0 if x == y -// +1 if x > y -// -// The same value as defined above must be returned from strCollate. -// -// The "outer" ordering is: nil, bool, number, []byte, string. IOW, nil is -// "smaller" than anything else except other nil, numbers collate before -// []byte, []byte collate before strings, etc. -// -// Integers and real numbers collate as expected in math. However, complex -// numbers are not ordered in Go. Here the ordering is defined: Complex numbers -// are in comparison considered first only by their real part. Iff the result -// is equality then the imaginary part is used to determine the ordering. In -// this "second order" comparing, integers and real numbers are considered as -// complex numbers with a zero imaginary part. -func Collate(x, y []interface{}, strCollate func(string, string) int) (r int, err error) { - nx, ny := len(x), len(y) - - switch { - case nx == 0 && ny != 0: - return -1, nil - case nx == 0 && ny == 0: - return 0, nil - case nx != 0 && ny == 0: - return 1, nil - } - - r = 1 - if nx > ny { - x, y, r = y, x, -r - } - - var c int - for i, xi0 := range x { - yi0 := y[i] - xi, err := collateType(xi0) - if err != nil { - return 0, err - } - - yi, err := collateType(yi0) - if err != nil { - return 0, err - } - - switch x := xi.(type) { - default: - panic(fmt.Errorf("internal error: %T", x)) - - case nil: - switch yi.(type) { - case nil: - // nop - default: - return -r, nil - } - - case bool: - switch y := yi.(type) { - case nil: - return r, nil - case bool: - switch { - case !x && y: - return -r, nil - case x == y: - // nop - case x && !y: - return r, nil - } - default: - return -r, nil - } - - case int64: - switch y := yi.(type) { - case nil, bool: - return r, nil - case int64: - c = collateInt(x, y) - case uint64: - c = collateIntUint(x, y) - case float64: - c = collateFloat(float64(x), y) - case complex128: - c = collateComplex(complex(float64(x), 0), y) - case []byte: - return -r, nil - case string: - return -r, nil - } - - if c != 0 { - return c * r, nil - } - - case uint64: - switch y := yi.(type) { - case nil, bool: - return r, nil - case int64: - c = collateUintInt(x, y) - case uint64: - c = collateUint(x, y) - case float64: - c = collateFloat(float64(x), y) - case complex128: - c = collateComplex(complex(float64(x), 0), y) - case []byte: - return -r, nil - case string: - return -r, nil - } - - if c != 0 { - return c * r, nil - } - - case float64: - switch y := yi.(type) { - case nil, bool: - return r, nil - case int64: - c = collateFloat(x, float64(y)) - case uint64: - c = collateFloat(x, float64(y)) - case float64: - c = collateFloat(x, y) - case complex128: - c = collateComplex(complex(x, 0), y) - case []byte: - return -r, nil - case string: - return -r, nil - } - - if c != 0 { - return c * r, nil - } - - case complex128: - switch y := yi.(type) { - case nil, bool: - return r, nil - case int64: - c = collateComplex(x, complex(float64(y), 0)) - case uint64: - c = collateComplex(x, complex(float64(y), 0)) - case float64: - c = collateComplex(x, complex(y, 0)) - case complex128: - c = collateComplex(x, y) - case []byte: - return -r, nil - case string: - return -r, nil - } - - if c != 0 { - return c * r, nil - } - - case []byte: - switch y := yi.(type) { - case nil, bool, int64, uint64, float64, complex128: - return r, nil - case []byte: - c = bytes.Compare(x, y) - case string: - return -r, nil - } - - if c != 0 { - return c * r, nil - } - - case string: - switch y := yi.(type) { - case nil, bool, int64, uint64, float64, complex128: - return r, nil - case []byte: - return r, nil - case string: - switch { - case strCollate != nil: - c = strCollate(x, y) - case x < y: - return -r, nil - case x == y: - c = 0 - case x > y: - return r, nil - } - } - - if c != 0 { - return c * r, nil - } - } - } - - if nx == ny { - return 0, nil - } - - return -r, nil -} diff --git a/vendor/github.com/cznic/lldb/lldb.go b/vendor/github.com/cznic/lldb/lldb.go deleted file mode 100644 index 670fffd48..000000000 --- a/vendor/github.com/cznic/lldb/lldb.go +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package lldb implements a low level database engine. The database model used -// could be considered a specific implementation of some small(est) -// intersection of models listed in [1]. As a settled term is lacking, it'll be -// called here a 'Virtual memory model' (VMM). -// -// Changelog -// -// 2016-07-24: v1.0.4 brings some performance improvements. -// -// 2016-07-22: v1.0.3 brings some small performance improvements. -// -// 2016-07-12: v1.0.2 now uses packages from cznic/internal. -// -// 2016-07-12: v1.0.1 adds a license for testdata/fortunes.txt. -// -// 2016-07-11: First standalone release v1.0.0 of the package previously -// published as experimental (github.com/cznic/exp/lldb). -// -// Filers -// -// A Filer is an abstraction of storage. A Filer may be a part of some process' -// virtual address space, an OS file, a networked, remote file etc. Persistence -// of the storage is optional, opaque to VMM and it is specific to a concrete -// Filer implementation. -// -// Space management -// -// Mechanism to allocate, reallocate (resize), deallocate (and later reclaim -// the unused) contiguous parts of a Filer, called blocks. Blocks are -// identified and referred to by a handle, an int64. -// -// BTrees -// -// In addition to the VMM like services, lldb provides volatile and -// non-volatile BTrees. Keys and values of a BTree are limited in size to 64kB -// each (a bit more actually). Support for larger keys/values, if desired, can -// be built atop a BTree to certain limits. -// -// Handles vs pointers -// -// A handle is the abstracted storage counterpart of a memory address. There -// is one fundamental difference, though. Resizing a block never results in a -// change to the handle which refers to the resized block, so a handle is more -// akin to an unique numeric id/key. Yet it shares one property of pointers - -// handles can be associated again with blocks after the original handle block -// was deallocated. In other words, a handle uniqueness domain is the state of -// the database and is not something comparable to e.g. an ever growing -// numbering sequence. -// -// Also, as with memory pointers, dangling handles can be created and blocks -// overwritten when such handles are used. Using a zero handle to refer to a -// block will not panic; however, the resulting error is effectively the same -// exceptional situation as dereferencing a nil pointer. -// -// Blocks -// -// Allocated/used blocks, are limited in size to only a little bit more than -// 64kB. Bigger semantic entities/structures must be built in lldb's client -// code. The content of a block has no semantics attached, it's only a fully -// opaque `[]byte`. -// -// Scalars -// -// Use of "scalars" applies to EncodeScalars, DecodeScalars and Collate. Those -// first two "to bytes" and "from bytes" functions are suggested for handling -// multi-valued Allocator content items and/or keys/values of BTrees (using -// Collate for keys). Types called "scalar" are: -// -// nil (the typeless one) -// bool -// all integral types: [u]int8, [u]int16, [u]int32, [u]int, [u]int64 -// all floating point types: float32, float64 -// all complex types: complex64, complex128 -// []byte (64kB max) -// string (64kb max) -// -// Specific implementations -// -// Included are concrete implementations of some of the VMM interfaces included -// to ease serving simple client code or for testing and possibly as an -// example. More details in the documentation of such implementations. -// -// [1]: http://en.wikipedia.org/wiki/Database_model -package lldb - -const ( - fltSz = 0x70 // size of the FLT - maxShort = 251 - maxRq = 65787 - maxFLTRq = 4112 - maxHandle = 1<<56 - 1 - atomLen = 16 - tagUsedLong = 0xfc - tagUsedRelocated = 0xfd - tagFreeShort = 0xfe - tagFreeLong = 0xff - tagNotCompressed = 0 - tagCompressed = 1 -) - -// Content size n -> blocksize in atoms. -func n2atoms(n int) int { - if n > maxShort { - n += 2 - } - return (n+1)/16 + 1 -} - -// Content size n -> number of padding zeros. -func n2padding(n int) int { - if n > maxShort { - n += 2 - } - return 15 - (n+1)&15 -} - -// Handle <-> offset -func h2off(h int64) int64 { return (h + 6) * 16 } -func off2h(off int64) int64 { return off/16 - 6 } - -// Get a 7B int64 from b -func b2h(b []byte) (h int64) { - for _, v := range b[:7] { - h = h<<8 | int64(v) - } - return -} - -// Put a 7B int64 into b -func h2b(b []byte, h int64) []byte { - for i := range b[:7] { - b[i], h = byte(h>>48), h<<8 - } - return b -} - -// Content length N (must be in [252, 65787]) to long used block M field. -func n2m(n int) (m int) { - return n % 0x10000 -} - -// Long used block M (must be in [0, 65535]) field to content length N. -func m2n(m int) (n int) { - if m <= maxShort { - m += 0x10000 - } - return m -} - -func bpack(a []byte) []byte { - if cap(a) > len(a) { - return append([]byte(nil), a...) - } - - return a -} diff --git a/vendor/github.com/cznic/lldb/memfiler.go b/vendor/github.com/cznic/lldb/memfiler.go deleted file mode 100644 index 3085d4e9b..000000000 --- a/vendor/github.com/cznic/lldb/memfiler.go +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// A memory-only implementation of Filer. - -package lldb - -import ( - "fmt" - "io" - - "github.com/cznic/internal/file" -) - -var _ Filer = &MemFiler{} - -// MemFiler is a memory backed Filer. It implements BeginUpdate, EndUpdate and -// Rollback as no-ops. MemFiler is not automatically persistent, but it has -// ReadFrom and WriteTo methods. -type MemFiler struct { - fi file.Interface - nest int -} - -// NewMemFiler returns a new MemFiler. -func NewMemFiler() *MemFiler { - fi, err := file.OpenMem("") - if err != nil { - return nil - } - - return &MemFiler{fi: fi} -} - -// BeginUpdate implements Filer. -func (f *MemFiler) BeginUpdate() error { - f.nest++ - return nil -} - -// Close implements Filer. -func (f *MemFiler) Close() (err error) { - if f.nest != 0 { - return &ErrPERM{(f.Name() + ":Close")} - } - - return f.fi.Close() -} - -// EndUpdate implements Filer. -func (f *MemFiler) EndUpdate() (err error) { - if f.nest == 0 { - return &ErrPERM{(f.Name() + ": EndUpdate")} - } - - f.nest-- - return -} - -// Name implements Filer. -func (f *MemFiler) Name() string { return fmt.Sprintf("%p.memfiler", f) } - -// PunchHole implements Filer. -func (f *MemFiler) PunchHole(off, size int64) (err error) { return nil } - -// ReadAt implements Filer. -func (f *MemFiler) ReadAt(b []byte, off int64) (n int, err error) { return f.fi.ReadAt(b, off) } - -// ReadFrom is a helper to populate MemFiler's content from r. 'n' reports the -// number of bytes read from 'r'. -func (f *MemFiler) ReadFrom(r io.Reader) (n int64, err error) { return f.fi.ReadFrom(r) } - -// Rollback implements Filer. -func (f *MemFiler) Rollback() (err error) { return nil } - -// Size implements Filer. -func (f *MemFiler) Size() (int64, error) { - info, err := f.fi.Stat() - if err != nil { - return 0, err - } - - return info.Size(), nil -} - -// Sync implements Filer. -func (f *MemFiler) Sync() error { return nil } - -// Truncate implements Filer. -func (f *MemFiler) Truncate(size int64) (err error) { return f.fi.Truncate(size) } - -// WriteAt implements Filer. -func (f *MemFiler) WriteAt(b []byte, off int64) (n int, err error) { return f.fi.WriteAt(b, off) } - -// WriteTo is a helper to copy/persist MemFiler's content to w. If w is also -// an io.WriterAt then WriteTo may attempt to _not_ write any big, for some -// value of big, runs of zeros, i.e. it will attempt to punch holes, where -// possible, in `w` if that happens to be a freshly created or to zero length -// truncated OS file. 'n' reports the number of bytes written to 'w'. -func (f *MemFiler) WriteTo(w io.Writer) (n int64, err error) { return f.fi.WriteTo(w) } diff --git a/vendor/github.com/cznic/lldb/osfiler.go b/vendor/github.com/cznic/lldb/osfiler.go deleted file mode 100644 index d6e189a18..000000000 --- a/vendor/github.com/cznic/lldb/osfiler.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package lldb - -import ( - "io" - "os" - - "github.com/cznic/mathutil" -) - -var _ Filer = (*OSFiler)(nil) - -// OSFile is an os.File like minimal set of methods allowing to construct a -// Filer. -type OSFile interface { - Name() string - Stat() (fi os.FileInfo, err error) - Sync() (err error) - Truncate(size int64) (err error) - io.Closer - io.Reader - io.ReaderAt - io.Seeker - io.Writer - io.WriterAt -} - -// OSFiler is like a SimpleFileFiler but based on an OSFile. -type OSFiler struct { - f OSFile - nest int - size int64 // not set if < 0 -} - -// NewOSFiler returns a Filer from an OSFile. This Filer is like the -// SimpleFileFiler, it does not implement the transaction related methods. -func NewOSFiler(f OSFile) (r *OSFiler) { - return &OSFiler{ - f: f, - size: -1, - } -} - -// BeginUpdate implements Filer. -func (f *OSFiler) BeginUpdate() (err error) { - f.nest++ - return nil -} - -// Close implements Filer. -func (f *OSFiler) Close() (err error) { - if f.nest != 0 { - return &ErrPERM{(f.Name() + ":Close")} - } - - return f.f.Close() -} - -// EndUpdate implements Filer. -func (f *OSFiler) EndUpdate() (err error) { - if f.nest == 0 { - return &ErrPERM{(f.Name() + ":EndUpdate")} - } - - f.nest-- - return -} - -// Name implements Filer. -func (f *OSFiler) Name() string { - return f.f.Name() -} - -// PunchHole implements Filer. -func (f *OSFiler) PunchHole(off, size int64) (err error) { - return -} - -// ReadAt implements Filer. -func (f *OSFiler) ReadAt(b []byte, off int64) (n int, err error) { - return f.f.ReadAt(b, off) -} - -// Rollback implements Filer. -func (f *OSFiler) Rollback() (err error) { return } - -// Size implements Filer. -func (f *OSFiler) Size() (n int64, err error) { - if f.size < 0 { // boot - fi, err := f.f.Stat() - if err != nil { - return 0, err - } - - f.size = fi.Size() - } - return f.size, nil -} - -// Sync implements Filer. -func (f *OSFiler) Sync() (err error) { - return f.f.Sync() -} - -// Truncate implements Filer. -func (f *OSFiler) Truncate(size int64) (err error) { - if size < 0 { - return &ErrINVAL{"Truncate size", size} - } - - f.size = size - return f.f.Truncate(size) -} - -// WriteAt implements Filer. -func (f *OSFiler) WriteAt(b []byte, off int64) (n int, err error) { - if f.size < 0 { // boot - fi, err := os.Stat(f.f.Name()) - if err != nil { - return 0, err - } - - f.size = fi.Size() - } - f.size = mathutil.MaxInt64(f.size, int64(len(b))+off) - return f.f.WriteAt(b, off) -} diff --git a/vendor/github.com/cznic/lldb/simplefilefiler.go b/vendor/github.com/cznic/lldb/simplefilefiler.go deleted file mode 100644 index 71ee67417..000000000 --- a/vendor/github.com/cznic/lldb/simplefilefiler.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// A basic os.File backed Filer. - -package lldb - -import ( - "os" - - "github.com/cznic/internal/file" -) - -var _ Filer = &SimpleFileFiler{} - -// SimpleFileFiler is an os.File backed Filer intended for use where structural -// consistency can be reached by other means (SimpleFileFiler is for example -// wrapped in eg. an RollbackFiler or ACIDFiler0) or where persistence is not -// required (temporary/working data sets). -// -// SimpleFileFiler is the most simple os.File backed Filer implementation as it -// does not really implement BeginUpdate and EndUpdate/Rollback in any way -// which would protect the structural integrity of data. If misused e.g. as a -// real database storage w/o other measures, it can easily cause data loss -// when, for example, a power outage occurs or the updating process terminates -// abruptly. -type SimpleFileFiler struct { - fi file.Interface - name string - nest int -} - -// NewSimpleFileFiler returns a new SimpleFileFiler. -func NewSimpleFileFiler(f *os.File) *SimpleFileFiler { - fi, err := file.Open(f) - if err != nil { - return nil - } - - sf := &SimpleFileFiler{fi: fi, name: f.Name()} - return sf -} - -// BeginUpdate implements Filer. -func (f *SimpleFileFiler) BeginUpdate() error { - f.nest++ - return nil -} - -// Close implements Filer. -func (f *SimpleFileFiler) Close() (err error) { - if f.nest != 0 { - return &ErrPERM{(f.Name() + ":Close")} - } - - return f.fi.Close() -} - -// EndUpdate implements Filer. -func (f *SimpleFileFiler) EndUpdate() (err error) { - if f.nest == 0 { - return &ErrPERM{(f.Name() + ":EndUpdate")} - } - - f.nest-- - return -} - -// Name implements Filer. -func (f *SimpleFileFiler) Name() string { return f.name } - -// PunchHole implements Filer. -func (f *SimpleFileFiler) PunchHole(off, size int64) (err error) { return nil } - -// ReadAt implements Filer. -func (f *SimpleFileFiler) ReadAt(b []byte, off int64) (n int, err error) { return f.fi.ReadAt(b, off) } - -// Rollback implements Filer. -func (f *SimpleFileFiler) Rollback() (err error) { return nil } - -// Size implements Filer. -func (f *SimpleFileFiler) Size() (int64, error) { - info, err := f.fi.Stat() - if err != nil { - return 0, err - } - - return info.Size(), nil -} - -// Sync implements Filer. -func (f *SimpleFileFiler) Sync() error { return f.fi.Sync() } - -// Truncate implements Filer. -func (f *SimpleFileFiler) Truncate(size int64) (err error) { return f.fi.Truncate(size) } - -// WriteAt implements Filer. -func (f *SimpleFileFiler) WriteAt(b []byte, off int64) (n int, err error) { return f.fi.WriteAt(b, off) } diff --git a/vendor/github.com/cznic/lldb/xact.go b/vendor/github.com/cznic/lldb/xact.go deleted file mode 100644 index 70887ec2a..000000000 --- a/vendor/github.com/cznic/lldb/xact.go +++ /dev/null @@ -1,615 +0,0 @@ -// Copyright 2014 The lldb Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Structural transactions. - -package lldb - -//DONE+ TransactionalMemoryFiler -// ---- -// Use NewRollbackFiler(myMemFiler, ...) - -/* - -bfBits: 3 -BenchmarkRollbackFiler 20000000 102 ns/op 9.73 MB/s - -bfBits: 4 -BenchmarkRollbackFiler 50000000 55.7 ns/op 17.95 MB/s - -bfBits: 5 -BenchmarkRollbackFiler 100000000 32.2 ns/op 31.06 MB/s - -bfBits: 6 -BenchmarkRollbackFiler 100000000 20.6 ns/op 48.46 MB/s - -bfBits: 7 -BenchmarkRollbackFiler 100000000 15.1 ns/op 66.12 MB/s - -bfBits: 8 -BenchmarkRollbackFiler 100000000 10.5 ns/op 95.66 MB/s - -bfBits: 9 -BenchmarkRollbackFiler 200000000 8.02 ns/op 124.74 MB/s - -bfBits: 10 -BenchmarkRollbackFiler 200000000 9.25 ns/op 108.09 MB/s - -bfBits: 11 -BenchmarkRollbackFiler 100000000 11.7 ns/op 85.47 MB/s - -bfBits: 12 -BenchmarkRollbackFiler 100000000 17.2 ns/op 57.99 MB/s - -bfBits: 13 -BenchmarkRollbackFiler 100000000 32.7 ns/op 30.58 MB/s - -bfBits: 14 -BenchmarkRollbackFiler 50000000 39.6 ns/op 25.27 MB/s - -*/ - -import ( - "fmt" - "io" - "sync" - - "github.com/cznic/fileutil" - "github.com/cznic/internal/buffer" - "github.com/cznic/mathutil" -) - -var ( - _ Filer = &bitFiler{} // Ensure bitFiler is a Filer. - _ Filer = &RollbackFiler{} // ditto -) - -const ( - bfBits = 12 - bfSize = 1 << bfBits - bfMask = bfSize - 1 -) - -type ( - bitPage struct { - prev, next *bitPage - pdata *[]byte - data []byte - dirty bool - } - - bitFilerMap map[int64]*bitPage - - bitFiler struct { - parent Filer - m bitFilerMap - size int64 - } -) - -func newBitFiler(parent Filer) (f *bitFiler, err error) { - sz, err := parent.Size() - if err != nil { - return - } - - return &bitFiler{parent: parent, m: bitFilerMap{}, size: sz}, nil -} - -func (f *bitFiler) BeginUpdate() error { panic("internal error") } -func (f *bitFiler) EndUpdate() error { panic("internal error") } -func (f *bitFiler) Rollback() error { panic("internal error") } -func (f *bitFiler) Sync() error { panic("internal error") } - -func (f *bitFiler) Close() (err error) { return } -func (f *bitFiler) Name() string { return fmt.Sprintf("%p.bitfiler", f) } -func (f *bitFiler) Size() (int64, error) { return f.size, nil } - -func (f *bitFiler) free() { - for _, pg := range f.m { - buffer.Put(pg.pdata) - } -} - -func (f *bitFiler) PunchHole(off, size int64) (err error) { - first := off >> bfBits - if off&bfMask != 0 { - first++ - } - off += size - 1 - last := off >> bfBits - if off&bfMask != 0 { - last-- - } - if limit := f.size >> bfBits; last > limit { - last = limit - } - for pgI := first; pgI <= last; pgI++ { - pg := &bitPage{} - pg.pdata = buffer.CGet(bfSize) - pg.data = *pg.pdata - pg.dirty = true - f.m[pgI] = pg - } - return -} - -func (f *bitFiler) ReadAt(b []byte, off int64) (n int, err error) { - avail := f.size - off - pgI := off >> bfBits - pgO := int(off & bfMask) - rem := len(b) - if int64(rem) >= avail { - rem = int(avail) - err = io.EOF - } - for rem != 0 && avail > 0 { - pg := f.m[pgI] - if pg == nil { - pg = &bitPage{} - pg.pdata = buffer.CGet(bfSize) - pg.data = *pg.pdata - if f.parent != nil { - _, err = f.parent.ReadAt(pg.data, off&^bfMask) - if err != nil && !fileutil.IsEOF(err) { - return - } - - err = nil - } - f.m[pgI] = pg - } - nc := copy(b[:mathutil.Min(rem, bfSize)], pg.data[pgO:]) - pgI++ - pgO = 0 - rem -= nc - n += nc - b = b[nc:] - off += int64(nc) - } - return -} - -func (f *bitFiler) Truncate(size int64) (err error) { - switch { - case size < 0: - return &ErrINVAL{"Truncate size", size} - case size == 0: - f.m = bitFilerMap{} - f.size = 0 - return - } - - first := size >> bfBits - if size&bfMask != 0 { - first++ - } - last := f.size >> bfBits - if f.size&bfMask != 0 { - last++ - } - for ; first < last; first++ { - if bp, ok := f.m[first]; ok { - buffer.Put(bp.pdata) - } - delete(f.m, first) - } - - f.size = size - return -} - -func (f *bitFiler) WriteAt(b []byte, off int64) (n int, err error) { - off0 := off - pgI := off >> bfBits - pgO := int(off & bfMask) - n = len(b) - rem := n - var nc int - for rem != 0 { - pg := f.m[pgI] - if pg == nil { - pg = &bitPage{} - pg.pdata = buffer.CGet(bfSize) - pg.data = *pg.pdata - if f.parent != nil { - _, err = f.parent.ReadAt(pg.data, off&^bfMask) - if err != nil && !fileutil.IsEOF(err) { - return - } - - err = nil - } - f.m[pgI] = pg - } - nc = copy(pg.data[pgO:], b) - pgI++ - pg.dirty = true - pgO = 0 - rem -= nc - b = b[nc:] - off += int64(nc) - } - f.size = mathutil.MaxInt64(f.size, off0+int64(n)) - return -} - -func (f *bitFiler) link() { - for pgI, pg := range f.m { - nx, ok := f.m[pgI+1] - if !ok || !nx.dirty { - continue - } - - nx.prev, pg.next = pg, nx - } -} - -func (f *bitFiler) dumpDirty(w io.WriterAt) (nwr int, err error) { - f.link() - for pgI, pg := range f.m { - if !pg.dirty { - continue - } - - for pg.prev != nil && pg.prev.dirty { - pg = pg.prev - pgI-- - } - - for pg != nil && pg.dirty { - if _, err := w.WriteAt(pg.data, pgI< deadlock - if err != nil { - return - } - - r.tlevel-- - bf := r.bitFiler - parent := bf.parent - w := r.writerAt - if r.tlevel != 0 { - w = parent - } - nwr, err := bf.dumpDirty(w) - if err != nil { - return - } - - switch { - case r.tlevel == 0: - defer func() { - r.bitFiler.free() - r.bitFiler = nil - }() - - if nwr == 0 { - return - } - - return r.checkpoint(sz) - default: - r.bitFiler.free() - r.bitFiler = parent.(*bitFiler) - sz, _ := bf.Size() // bitFiler.Size() never returns err != nil - return parent.Truncate(sz) - } -} - -// Implements Filer. -func (r *RollbackFiler) Name() string { - r.mu.RLock() - defer r.mu.RUnlock() - - return r.f.Name() -} - -// Implements Filer. -func (r *RollbackFiler) PunchHole(off, size int64) error { - r.mu.Lock() - defer r.mu.Unlock() - - if r.tlevel == 0 { - return &ErrPERM{r.f.Name() + ": PunchHole outside of a transaction"} - } - - if off < 0 { - return &ErrINVAL{r.f.Name() + ": PunchHole off", off} - } - - if size < 0 || off+size > r.bitFiler.size { - return &ErrINVAL{r.f.Name() + ": PunchHole size", size} - } - - return r.bitFiler.PunchHole(off, size) -} - -// Implements Filer. -func (r *RollbackFiler) ReadAt(b []byte, off int64) (n int, err error) { - r.inCallbackMu.RLock() - defer r.inCallbackMu.RUnlock() - if !r.inCallback { - r.mu.RLock() - defer r.mu.RUnlock() - } - if r.tlevel == 0 { - return r.f.ReadAt(b, off) - } - - return r.bitFiler.ReadAt(b, off) -} - -// Implements Filer. -func (r *RollbackFiler) Rollback() (err error) { - r.mu.Lock() - defer r.mu.Unlock() - - if r.tlevel == 0 { - return &ErrPERM{r.f.Name() + ": Rollback outside of a transaction"} - } - - if r.tlevel > 1 { - r.bitFiler.free() - r.bitFiler = r.bitFiler.parent.(*bitFiler) - } - r.tlevel-- - if f := r.afterRollback; f != nil { - r.inCallbackMu.Lock() - r.inCallback = true - r.inCallbackMu.Unlock() - defer func() { - r.inCallbackMu.Lock() - r.inCallback = false - r.inCallbackMu.Unlock() - }() - return f() - } - return -} - -func (r *RollbackFiler) size() (sz int64, err error) { - if r.tlevel == 0 { - return r.f.Size() - } - - return r.bitFiler.Size() -} - -// Implements Filer. -func (r *RollbackFiler) Size() (sz int64, err error) { - r.mu.Lock() - defer r.mu.Unlock() - - return r.size() -} - -// Implements Filer. -func (r *RollbackFiler) Sync() error { - r.mu.Lock() - defer r.mu.Unlock() - - return r.f.Sync() -} - -// Implements Filer. -func (r *RollbackFiler) Truncate(size int64) error { - r.mu.Lock() - defer r.mu.Unlock() - - if r.tlevel == 0 { - return &ErrPERM{r.f.Name() + ": Truncate outside of a transaction"} - } - - return r.bitFiler.Truncate(size) -} - -// Implements Filer. -func (r *RollbackFiler) WriteAt(b []byte, off int64) (n int, err error) { - r.mu.Lock() - defer r.mu.Unlock() - - if r.tlevel == 0 { - return 0, &ErrPERM{r.f.Name() + ": WriteAt outside of a transaction"} - } - - return r.bitFiler.WriteAt(b, off) -} diff --git a/vendor/github.com/cznic/mathutil/LICENSE b/vendor/github.com/cznic/mathutil/LICENSE deleted file mode 100644 index 128a1b64a..000000000 --- a/vendor/github.com/cznic/mathutil/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014 The mathutil Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/mathutil/bits.go b/vendor/github.com/cznic/mathutil/bits.go deleted file mode 100644 index fee4c0363..000000000 --- a/vendor/github.com/cznic/mathutil/bits.go +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright (c) 2014 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mathutil - -import ( - "math/big" -) - -// BitLenByte returns the bit width of the non zero part of n. -func BitLenByte(n byte) int { - return log2[n] + 1 -} - -// BitLenUint16 returns the bit width of the non zero part of n. -func BitLenUint16(n uint16) int { - if b := n >> 8; b != 0 { - return log2[b] + 8 + 1 - } - - return log2[n] + 1 -} - -// BitLenUint32 returns the bit width of the non zero part of n. -func BitLenUint32(n uint32) int { - if b := n >> 24; b != 0 { - return log2[b] + 24 + 1 - } - - if b := n >> 16; b != 0 { - return log2[b] + 16 + 1 - } - - if b := n >> 8; b != 0 { - return log2[b] + 8 + 1 - } - - return log2[n] + 1 -} - -// BitLen returns the bit width of the non zero part of n. -func BitLen(n int) int { // Should handle correctly [future] 64 bit Go ints - if IntBits == 64 { - return BitLenUint64(uint64(n)) - } - - if b := byte(n >> 24); b != 0 { - return log2[b] + 24 + 1 - } - - if b := byte(n >> 16); b != 0 { - return log2[b] + 16 + 1 - } - - if b := byte(n >> 8); b != 0 { - return log2[b] + 8 + 1 - } - - return log2[byte(n)] + 1 -} - -// BitLenUint returns the bit width of the non zero part of n. -func BitLenUint(n uint) int { // Should handle correctly [future] 64 bit Go uints - if IntBits == 64 { - return BitLenUint64(uint64(n)) - } - - if b := n >> 24; b != 0 { - return log2[b] + 24 + 1 - } - - if b := n >> 16; b != 0 { - return log2[b] + 16 + 1 - } - - if b := n >> 8; b != 0 { - return log2[b] + 8 + 1 - } - - return log2[n] + 1 -} - -// BitLenUint64 returns the bit width of the non zero part of n. -func BitLenUint64(n uint64) int { - if b := n >> 56; b != 0 { - return log2[b] + 56 + 1 - } - - if b := n >> 48; b != 0 { - return log2[b] + 48 + 1 - } - - if b := n >> 40; b != 0 { - return log2[b] + 40 + 1 - } - - if b := n >> 32; b != 0 { - return log2[b] + 32 + 1 - } - - if b := n >> 24; b != 0 { - return log2[b] + 24 + 1 - } - - if b := n >> 16; b != 0 { - return log2[b] + 16 + 1 - } - - if b := n >> 8; b != 0 { - return log2[b] + 8 + 1 - } - - return log2[n] + 1 -} - -// BitLenUintptr returns the bit width of the non zero part of n. -func BitLenUintptr(n uintptr) int { - if b := n >> 56; b != 0 { - return log2[b] + 56 + 1 - } - - if b := n >> 48; b != 0 { - return log2[b] + 48 + 1 - } - - if b := n >> 40; b != 0 { - return log2[b] + 40 + 1 - } - - if b := n >> 32; b != 0 { - return log2[b] + 32 + 1 - } - - if b := n >> 24; b != 0 { - return log2[b] + 24 + 1 - } - - if b := n >> 16; b != 0 { - return log2[b] + 16 + 1 - } - - if b := n >> 8; b != 0 { - return log2[b] + 8 + 1 - } - - return log2[n] + 1 -} - -// PopCountByte returns population count of n (number of bits set in n). -func PopCountByte(n byte) int { - return int(popcnt[n]) -} - -// PopCountUint16 returns population count of n (number of bits set in n). -func PopCountUint16(n uint16) int { - return int(popcnt[byte(n>>8)]) + int(popcnt[byte(n)]) -} - -// PopCountUint32 returns population count of n (number of bits set in n). -func PopCountUint32(n uint32) int { - return int(popcnt[byte(n>>24)]) + int(popcnt[byte(n>>16)]) + - int(popcnt[byte(n>>8)]) + int(popcnt[byte(n)]) -} - -// PopCount returns population count of n (number of bits set in n). -func PopCount(n int) int { // Should handle correctly [future] 64 bit Go ints - if IntBits == 64 { - return PopCountUint64(uint64(n)) - } - - return PopCountUint32(uint32(n)) -} - -// PopCountUint returns population count of n (number of bits set in n). -func PopCountUint(n uint) int { // Should handle correctly [future] 64 bit Go uints - if IntBits == 64 { - return PopCountUint64(uint64(n)) - } - - return PopCountUint32(uint32(n)) -} - -// PopCountUintptr returns population count of n (number of bits set in n). -func PopCountUintptr(n uintptr) int { - if UintPtrBits == 64 { - return PopCountUint64(uint64(n)) - } - - return PopCountUint32(uint32(n)) -} - -// PopCountUint64 returns population count of n (number of bits set in n). -func PopCountUint64(n uint64) int { - return int(popcnt[byte(n>>56)]) + int(popcnt[byte(n>>48)]) + - int(popcnt[byte(n>>40)]) + int(popcnt[byte(n>>32)]) + - int(popcnt[byte(n>>24)]) + int(popcnt[byte(n>>16)]) + - int(popcnt[byte(n>>8)]) + int(popcnt[byte(n)]) -} - -// PopCountBigInt returns population count of |n| (number of bits set in |n|). -func PopCountBigInt(n *big.Int) (r int) { - for _, v := range n.Bits() { - r += PopCountUintptr(uintptr(v)) - } - return -} diff --git a/vendor/github.com/cznic/mathutil/envelope.go b/vendor/github.com/cznic/mathutil/envelope.go deleted file mode 100644 index ff8e6012a..000000000 --- a/vendor/github.com/cznic/mathutil/envelope.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2014 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mathutil - -import ( - "math" -) - -// Approximation type determines approximation methods used by e.g. Envelope. -type Approximation int - -// Specific approximation method tags -const ( - _ Approximation = iota - Linear // As named - Sinusoidal // Smooth for all derivations -) - -// Envelope is an utility for defining simple curves using a small (usually) -// set of data points. Envelope returns a value defined by x, points and -// approximation. The value of x must be in [0,1) otherwise the result is -// undefined or the function may panic. Points are interpreted as dividing the -// [0,1) interval in len(points)-1 sections, so len(points) must be > 1 or the -// function may panic. According to the left and right points closing/adjacent -// to the section the resulting value is interpolated using the chosen -// approximation method. Unsupported values of approximation are silently -// interpreted as 'Linear'. -func Envelope(x float64, points []float64, approximation Approximation) float64 { - step := 1 / float64(len(points)-1) - fslot := math.Floor(x / step) - mod := x - fslot*step - slot := int(fslot) - l, r := points[slot], points[slot+1] - rmod := mod / step - switch approximation { - case Sinusoidal: - k := (math.Sin(math.Pi*(rmod-0.5)) + 1) / 2 - return l + (r-l)*k - case Linear: - fallthrough - default: - return l + (r-l)*rmod - } -} diff --git a/vendor/github.com/cznic/mathutil/example/example.go b/vendor/github.com/cznic/mathutil/example/example.go deleted file mode 100644 index 30a2d1158..000000000 --- a/vendor/github.com/cznic/mathutil/example/example.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -// +build ignore - -package main - -import ( - "bufio" - "flag" - "github.com/cznic/mathutil" - "log" - "math" - "os" -) - -/* - -$ # Usage e.g.: -$ go run example.go -max 1024 > mathutil.dat # generate 1kB of "random" data - -*/ -func main() { - r, err := mathutil.NewFC32(math.MinInt32, math.MaxInt32, true) - if err != nil { - log.Fatal(err) - } - - var mflag uint64 - flag.Uint64Var(&mflag, "max", 0, "limit output to max bytes") - flag.Parse() - stdout := bufio.NewWriter(os.Stdout) - if mflag != 0 { - for i := uint64(0); i < mflag; i++ { - if err := stdout.WriteByte(byte(r.Next())); err != nil { - log.Fatal(err) - } - } - stdout.Flush() - return - } - - for stdout.WriteByte(byte(r.Next())) == nil { - } -} diff --git a/vendor/github.com/cznic/mathutil/example2/example2.go b/vendor/github.com/cznic/mathutil/example2/example2.go deleted file mode 100644 index 409aeef3e..000000000 --- a/vendor/github.com/cznic/mathutil/example2/example2.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -// +build ignore - -package main - -import ( - "bytes" - "github.com/cznic/mathutil" - "image" - "image/png" - "io/ioutil" - "log" - "math" - "math/rand" -) - -// $ go run example2.go # view rand.png and rnd.png by your favorite pic viewer -// -// see http://www.boallen.com/random-numbers.html -func main() { - sqr := image.Rect(0, 0, 511, 511) - r, err := mathutil.NewFC32(math.MinInt32, math.MaxInt32, true) - if err != nil { - log.Fatal("NewFC32", err) - } - - img := image.NewGray(sqr) - for y := 0; y < 512; y++ { - for x := 0; x < 512; x++ { - if r.Next()&1 != 0 { - img.Set(x, y, image.White) - } - } - } - buf := bytes.NewBuffer(nil) - if err := png.Encode(buf, img); err != nil { - log.Fatal("Encode rnd.png ", err) - } - - if err := ioutil.WriteFile("rnd.png", buf.Bytes(), 0666); err != nil { - log.Fatal("ioutil.WriteFile/rnd.png ", err) - } - - r2 := rand.New(rand.NewSource(0)) - img = image.NewGray(sqr) - for y := 0; y < 512; y++ { - for x := 0; x < 512; x++ { - if r2.Int()&1 != 0 { - img.Set(x, y, image.White) - } - } - } - buf = bytes.NewBuffer(nil) - if err := png.Encode(buf, img); err != nil { - log.Fatal("Encode rand.png ", err) - } - - if err := ioutil.WriteFile("rand.png", buf.Bytes(), 0666); err != nil { - log.Fatal("ioutil.WriteFile/rand.png ", err) - } -} diff --git a/vendor/github.com/cznic/mathutil/example3/example3.go b/vendor/github.com/cznic/mathutil/example3/example3.go deleted file mode 100644 index 572d108b6..000000000 --- a/vendor/github.com/cznic/mathutil/example3/example3.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// blame: jnml, labs.nic.cz - -// +build ignore - -package main - -import ( - "bufio" - "flag" - "log" - "math/rand" - "os" -) - -/* - -$ # Usage e.g.: -$ go run example3.go -max 1024 > rand.dat # generate 1kB of "random" data - -*/ -func main() { - r := rand.New(rand.NewSource(1)) - var mflag uint64 - flag.Uint64Var(&mflag, "max", 0, "limit output to max bytes") - flag.Parse() - stdout := bufio.NewWriter(os.Stdout) - if mflag != 0 { - for i := uint64(0); i < mflag; i++ { - if err := stdout.WriteByte(byte(r.Int())); err != nil { - log.Fatal(err) - } - } - stdout.Flush() - return - } - - for stdout.WriteByte(byte(r.Int())) == nil { - } -} diff --git a/vendor/github.com/cznic/mathutil/example4/main.go b/vendor/github.com/cznic/mathutil/example4/main.go deleted file mode 100644 index 52b35655c..000000000 --- a/vendor/github.com/cznic/mathutil/example4/main.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2011 jnml. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// Let QRN be the number of quadratic residues of N. Let Q be QRN/N. From a -// sorted list of primorial products < 2^32 find "record breakers". "Record -// breaker" is N with new lowest Q. -// -// There are only 49 "record breakers" < 2^32. -// -// To run the example $ go run main.go -package main - -import ( - "fmt" - "math" - "sort" - "time" - - "github.com/cznic/mathutil" - "github.com/cznic/sortutil" -) - -func main() { - pp := mathutil.PrimorialProductsUint32(0, math.MaxUint32, 32) - sort.Sort(sortutil.Uint32Slice(pp)) - var bestN, bestD uint32 = 1, 1 - order, checks := 0, 0 - var ixDirty uint32 - m := make([]byte, math.MaxUint32>>3) - for _, n := range pp { - for i := range m[:ixDirty+1] { - m[i] = 0 - } - ixDirty = 0 - checks++ - limit0 := mathutil.QScaleUint32(n, bestN, bestD) - if limit0 > math.MaxUint32 { - panic(0) - } - limit := uint32(limit0) - n64 := uint64(n) - hi := n64 >> 1 - hits := uint32(0) - check := true - fmt.Printf("\r%10d %d/%d", n, checks, len(pp)) - t0 := time.Now() - for i := uint64(0); i < hi; i++ { - sq := uint32(i * i % n64) - ix := sq >> 3 - msk := byte(1 << (sq & 7)) - if m[ix]&msk == 0 { - hits++ - if hits >= limit { - check = false - break - } - } - m[ix] |= msk - if ix > ixDirty { - ixDirty = ix - } - } - - adjPrime := ".." // Composite before - if mathutil.IsPrime(n - 1) { - adjPrime = "P." // Prime before - } - switch mathutil.IsPrime(n + 1) { - case true: - adjPrime += "P" // Prime after - case false: - adjPrime += "." // Composite after - } - - if check && mathutil.QCmpUint32(hits, n, bestN, bestD) < 0 { - order++ - d := time.Since(t0) - bestN, bestD = hits, n - q := float64(hits) / float64(n) - fmt.Printf( - "\r%2s #%03d %d %d %.2f %.2E %s %s %v\n", - adjPrime, order, n, hits, - 1/q, q, d, time.Now().Format("15:04:05"), mathutil.FactorInt(n), - ) - } - } -} diff --git a/vendor/github.com/cznic/mathutil/ff/main.go b/vendor/github.com/cznic/mathutil/ff/main.go deleted file mode 100644 index 6cec57afb..000000000 --- a/vendor/github.com/cznic/mathutil/ff/main.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) jnml. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build ignore - -// Factor Finder - searches for Mersenne number factors of one specific special -// form. -package main - -import ( - "flag" - "fmt" - "math/big" - "runtime" - "time" - - "github.com/cznic/mathutil" -) - -const ( - pp = 1 - pp2 = 10 -) - -var ( - _1 = big.NewInt(1) - _2 = big.NewInt(2) -) - -func main() { - runtime.GOMAXPROCS(2) - oClass := flag.Uint64("c", 2, `factor "class" number`) - oDuration := flag.Duration("d", time.Second, "duration to spend on one class") - flag.Parse() - class := *oClass - for class&1 != 0 { - class >>= 1 - } - class = mathutil.MaxUint64(class, 2) - - for { - c := time.After(*oDuration) - factor := big.NewInt(0) - factor.SetUint64(class) - exp := big.NewInt(0) - oneClass: - for { - select { - case <-c: - break oneClass - default: - } - - exp.Set(factor) - factor.Lsh(factor, 1) - factor.Add(factor, _1) - if !factor.ProbablyPrime(pp) { - continue - } - - if !exp.ProbablyPrime(pp) { - continue - } - - if mathutil.ModPowBigInt(_2, exp, factor).Cmp(_1) != 0 { - continue - } - - if !factor.ProbablyPrime(pp2) { - continue - } - - if !exp.ProbablyPrime(pp2) { - continue - } - - fmt.Printf("%d: %s | M%s (%d bits)\n", class, factor, exp, factor.BitLen()) - } - - class += 2 - } -} diff --git a/vendor/github.com/cznic/mathutil/mathutil.go b/vendor/github.com/cznic/mathutil/mathutil.go deleted file mode 100644 index 6c6ea916d..000000000 --- a/vendor/github.com/cznic/mathutil/mathutil.go +++ /dev/null @@ -1,1108 +0,0 @@ -// Copyright (c) 2014 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package mathutil provides utilities supplementing the standard 'math' and -// 'math/rand' packages. -// -// Release history and compatibility issues -// -// 2017-10-14: New variadic functions for Max/Min. Ex: -// func MaxVal(val int, vals ...int) int { -// func MinVal(val int, vals ...int) int { -// func MaxByteVal(val byte, vals ...byte) byte { -// func MinByteVal(val byte, vals ...byte) byte { -// ... -// -// 2016-10-10: New functions QuadPolyDiscriminant and QuadPolyFactors. -// -// 2013-12-13: The following functions have been REMOVED -// -// func Uint64ToBigInt(n uint64) *big.Int -// func Uint64FromBigInt(n *big.Int) (uint64, bool) -// -// 2013-05-13: The following functions are now DEPRECATED -// -// func Uint64ToBigInt(n uint64) *big.Int -// func Uint64FromBigInt(n *big.Int) (uint64, bool) -// -// These functions will be REMOVED with Go release 1.1+1. -// -// 2013-01-21: The following functions have been REMOVED -// -// func MaxInt() int -// func MinInt() int -// func MaxUint() uint -// func UintPtrBits() int -// -// They are now replaced by untyped constants -// -// MaxInt -// MinInt -// MaxUint -// UintPtrBits -// -// Additionally one more untyped constant was added -// -// IntBits -// -// This change breaks any existing code depending on the above removed -// functions. They should have not been published in the first place, that was -// unfortunate. Instead, defining such architecture and/or implementation -// specific integer limits and bit widths as untyped constants improves -// performance and allows for static dead code elimination if it depends on -// these values. Thanks to minux for pointing it out in the mail list -// (https://groups.google.com/d/msg/golang-nuts/tlPpLW6aJw8/NT3mpToH-a4J). -// -// 2012-12-12: The following functions will be DEPRECATED with Go release -// 1.0.3+1 and REMOVED with Go release 1.0.3+2, b/c of -// http://code.google.com/p/go/source/detail?r=954a79ee3ea8 -// -// func Uint64ToBigInt(n uint64) *big.Int -// func Uint64FromBigInt(n *big.Int) (uint64, bool) -package mathutil - -import ( - "math" - "math/big" -) - -// Architecture and/or implementation specific integer limits and bit widths. -const ( - MaxInt = 1<<(IntBits-1) - 1 - MinInt = -MaxInt - 1 - MaxUint = 1<>32&1 + ^uint(0)>>16&1 + ^uint(0)>>8&1 + 3) - UintPtrBits = 1 << (^uintptr(0)>>32&1 + ^uintptr(0)>>16&1 + ^uintptr(0)>>8&1 + 3) -) - -var ( - _1 = big.NewInt(1) - _2 = big.NewInt(2) -) - -// GCDByte returns the greatest common divisor of a and b. Based on: -// http://en.wikipedia.org/wiki/Euclidean_algorithm#Implementations -func GCDByte(a, b byte) byte { - for b != 0 { - a, b = b, a%b - } - return a -} - -// GCDUint16 returns the greatest common divisor of a and b. -func GCDUint16(a, b uint16) uint16 { - for b != 0 { - a, b = b, a%b - } - return a -} - -// GCDUint32 returns the greatest common divisor of a and b. -func GCDUint32(a, b uint32) uint32 { - for b != 0 { - a, b = b, a%b - } - return a -} - -// GCDUint64 returns the greatest common divisor of a and b. -func GCDUint64(a, b uint64) uint64 { - for b != 0 { - a, b = b, a%b - } - return a -} - -// ISqrt returns floor(sqrt(n)). Typical run time is few hundreds of ns. -func ISqrt(n uint32) (x uint32) { - if n == 0 { - return - } - - if n >= math.MaxUint16*math.MaxUint16 { - return math.MaxUint16 - } - - var px, nx uint32 - for x = n; ; px, x = x, nx { - nx = (x + n/x) / 2 - if nx == x || nx == px { - break - } - } - return -} - -// SqrtUint64 returns floor(sqrt(n)). Typical run time is about 0.5 µs. -func SqrtUint64(n uint64) (x uint64) { - if n == 0 { - return - } - - if n >= math.MaxUint32*math.MaxUint32 { - return math.MaxUint32 - } - - var px, nx uint64 - for x = n; ; px, x = x, nx { - nx = (x + n/x) / 2 - if nx == x || nx == px { - break - } - } - return -} - -// SqrtBig returns floor(sqrt(n)). It panics on n < 0. -func SqrtBig(n *big.Int) (x *big.Int) { - switch n.Sign() { - case -1: - panic(-1) - case 0: - return big.NewInt(0) - } - - var px, nx big.Int - x = big.NewInt(0) - x.SetBit(x, n.BitLen()/2+1, 1) - for { - nx.Rsh(nx.Add(x, nx.Div(n, x)), 1) - if nx.Cmp(x) == 0 || nx.Cmp(&px) == 0 { - break - } - px.Set(x) - x.Set(&nx) - } - return -} - -// Log2Byte returns log base 2 of n. It's the same as index of the highest -// bit set in n. For n == 0 -1 is returned. -func Log2Byte(n byte) int { - return log2[n] -} - -// Log2Uint16 returns log base 2 of n. It's the same as index of the highest -// bit set in n. For n == 0 -1 is returned. -func Log2Uint16(n uint16) int { - if b := n >> 8; b != 0 { - return log2[b] + 8 - } - - return log2[n] -} - -// Log2Uint32 returns log base 2 of n. It's the same as index of the highest -// bit set in n. For n == 0 -1 is returned. -func Log2Uint32(n uint32) int { - if b := n >> 24; b != 0 { - return log2[b] + 24 - } - - if b := n >> 16; b != 0 { - return log2[b] + 16 - } - - if b := n >> 8; b != 0 { - return log2[b] + 8 - } - - return log2[n] -} - -// Log2Uint64 returns log base 2 of n. It's the same as index of the highest -// bit set in n. For n == 0 -1 is returned. -func Log2Uint64(n uint64) int { - if b := n >> 56; b != 0 { - return log2[b] + 56 - } - - if b := n >> 48; b != 0 { - return log2[b] + 48 - } - - if b := n >> 40; b != 0 { - return log2[b] + 40 - } - - if b := n >> 32; b != 0 { - return log2[b] + 32 - } - - if b := n >> 24; b != 0 { - return log2[b] + 24 - } - - if b := n >> 16; b != 0 { - return log2[b] + 16 - } - - if b := n >> 8; b != 0 { - return log2[b] + 8 - } - - return log2[n] -} - -// ModPowByte computes (b^e)%m. It panics for m == 0 || b == e == 0. -// -// See also: http://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method -func ModPowByte(b, e, m byte) byte { - if b == 0 && e == 0 { - panic(0) - } - - if m == 1 { - return 0 - } - - r := uint16(1) - for b, m := uint16(b), uint16(m); e > 0; b, e = b*b%m, e>>1 { - if e&1 == 1 { - r = r * b % m - } - } - return byte(r) -} - -// ModPowUint16 computes (b^e)%m. It panics for m == 0 || b == e == 0. -func ModPowUint16(b, e, m uint16) uint16 { - if b == 0 && e == 0 { - panic(0) - } - - if m == 1 { - return 0 - } - - r := uint32(1) - for b, m := uint32(b), uint32(m); e > 0; b, e = b*b%m, e>>1 { - if e&1 == 1 { - r = r * b % m - } - } - return uint16(r) -} - -// ModPowUint32 computes (b^e)%m. It panics for m == 0 || b == e == 0. -func ModPowUint32(b, e, m uint32) uint32 { - if b == 0 && e == 0 { - panic(0) - } - - if m == 1 { - return 0 - } - - r := uint64(1) - for b, m := uint64(b), uint64(m); e > 0; b, e = b*b%m, e>>1 { - if e&1 == 1 { - r = r * b % m - } - } - return uint32(r) -} - -// ModPowUint64 computes (b^e)%m. It panics for m == 0 || b == e == 0. -func ModPowUint64(b, e, m uint64) (r uint64) { - if b == 0 && e == 0 { - panic(0) - } - - if m == 1 { - return 0 - } - - return modPowBigInt(big.NewInt(0).SetUint64(b), big.NewInt(0).SetUint64(e), big.NewInt(0).SetUint64(m)).Uint64() -} - -func modPowBigInt(b, e, m *big.Int) (r *big.Int) { - r = big.NewInt(1) - for i, n := 0, e.BitLen(); i < n; i++ { - if e.Bit(i) != 0 { - r.Mod(r.Mul(r, b), m) - } - b.Mod(b.Mul(b, b), m) - } - return -} - -// ModPowBigInt computes (b^e)%m. Returns nil for e < 0. It panics for m == 0 || b == e == 0. -func ModPowBigInt(b, e, m *big.Int) (r *big.Int) { - if b.Sign() == 0 && e.Sign() == 0 { - panic(0) - } - - if m.Cmp(_1) == 0 { - return big.NewInt(0) - } - - if e.Sign() < 0 { - return - } - - return modPowBigInt(big.NewInt(0).Set(b), big.NewInt(0).Set(e), m) -} - -var uint64ToBigIntDelta big.Int - -func init() { - uint64ToBigIntDelta.SetBit(&uint64ToBigIntDelta, 63, 1) -} - -var uintptrBits int - -func init() { - x := uint64(math.MaxUint64) - uintptrBits = BitLenUintptr(uintptr(x)) -} - -// UintptrBits returns the bit width of an uintptr at the executing machine. -func UintptrBits() int { - return uintptrBits -} - -// AddUint128_64 returns the uint128 sum of uint64 a and b. -func AddUint128_64(a, b uint64) (hi uint64, lo uint64) { - lo = a + b - if lo < a { - hi = 1 - } - return -} - -// MulUint128_64 returns the uint128 bit product of uint64 a and b. -func MulUint128_64(a, b uint64) (hi, lo uint64) { - /* - 2^(2 W) ahi bhi + 2^W alo bhi + 2^W ahi blo + alo blo - - FEDCBA98 76543210 FEDCBA98 76543210 - ---- alo*blo ---- - ---- alo*bhi ---- - ---- ahi*blo ---- - ---- ahi*bhi ---- - */ - const w = 32 - const m = 1<>w, b>>w, a&m, b&m - lo = alo * blo - mid1 := alo * bhi - mid2 := ahi * blo - c1, lo := AddUint128_64(lo, mid1<>w+mid2>>w+c1+c2) - return -} - -// PowerizeBigInt returns (e, p) such that e is the smallest number for which p -// == b^e is greater or equal n. For n < 0 or b < 2 (0, nil) is returned. -// -// NOTE: Run time for large values of n (above about 2^1e6 ~= 1e300000) can be -// significant and/or unacceptabe. For any smaller values of n the function -// typically performs in sub second time. For "small" values of n (cca bellow -// 2^1e3 ~= 1e300) the same can be easily below 10 µs. -// -// A special (and trivial) case of b == 2 is handled separately and performs -// much faster. -func PowerizeBigInt(b, n *big.Int) (e uint32, p *big.Int) { - switch { - case b.Cmp(_2) < 0 || n.Sign() < 0: - return - case n.Sign() == 0 || n.Cmp(_1) == 0: - return 0, big.NewInt(1) - case b.Cmp(_2) == 0: - p = big.NewInt(0) - e = uint32(n.BitLen() - 1) - p.SetBit(p, int(e), 1) - if p.Cmp(n) < 0 { - p.Mul(p, _2) - e++ - } - return - } - - bw := b.BitLen() - nw := n.BitLen() - p = big.NewInt(1) - var bb, r big.Int - for { - switch p.Cmp(n) { - case -1: - x := uint32((nw - p.BitLen()) / bw) - if x == 0 { - x = 1 - } - e += x - switch x { - case 1: - p.Mul(p, b) - default: - r.Set(_1) - bb.Set(b) - e := x - for { - if e&1 != 0 { - r.Mul(&r, &bb) - } - if e >>= 1; e == 0 { - break - } - - bb.Mul(&bb, &bb) - } - p.Mul(p, &r) - } - case 0, 1: - return - } - } -} - -// PowerizeUint32BigInt returns (e, p) such that e is the smallest number for -// which p == b^e is greater or equal n. For n < 0 or b < 2 (0, nil) is -// returned. -// -// More info: see PowerizeBigInt. -func PowerizeUint32BigInt(b uint32, n *big.Int) (e uint32, p *big.Int) { - switch { - case b < 2 || n.Sign() < 0: - return - case n.Sign() == 0 || n.Cmp(_1) == 0: - return 0, big.NewInt(1) - case b == 2: - p = big.NewInt(0) - e = uint32(n.BitLen() - 1) - p.SetBit(p, int(e), 1) - if p.Cmp(n) < 0 { - p.Mul(p, _2) - e++ - } - return - } - - var bb big.Int - bb.SetInt64(int64(b)) - return PowerizeBigInt(&bb, n) -} - -/* -ProbablyPrimeUint32 returns true if n is prime or n is a pseudoprime to base a. -It implements the Miller-Rabin primality test for one specific value of 'a' and -k == 1. - -Wrt pseudocode shown at -http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time - - Input: n > 3, an odd integer to be tested for primality; - Input: k, a parameter that determines the accuracy of the test - Output: composite if n is composite, otherwise probably prime - write n − 1 as 2^s·d with d odd by factoring powers of 2 from n − 1 - LOOP: repeat k times: - pick a random integer a in the range [2, n − 2] - x ← a^d mod n - if x = 1 or x = n − 1 then do next LOOP - for r = 1 .. s − 1 - x ← x^2 mod n - if x = 1 then return composite - if x = n − 1 then do next LOOP - return composite - return probably prime - -... this function behaves like passing 1 for 'k' and additionally a -fixed/non-random 'a'. Otherwise it's the same algorithm. - -See also: http://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html -*/ -func ProbablyPrimeUint32(n, a uint32) bool { - d, s := n-1, 0 - for ; d&1 == 0; d, s = d>>1, s+1 { - } - x := uint64(ModPowUint32(a, d, n)) - if x == 1 || uint32(x) == n-1 { - return true - } - - for ; s > 1; s-- { - if x = x * x % uint64(n); x == 1 { - return false - } - - if uint32(x) == n-1 { - return true - } - } - return false -} - -// ProbablyPrimeUint64_32 returns true if n is prime or n is a pseudoprime to -// base a. It implements the Miller-Rabin primality test for one specific value -// of 'a' and k == 1. See also ProbablyPrimeUint32. -func ProbablyPrimeUint64_32(n uint64, a uint32) bool { - d, s := n-1, 0 - for ; d&1 == 0; d, s = d>>1, s+1 { - } - x := ModPowUint64(uint64(a), d, n) - if x == 1 || x == n-1 { - return true - } - - bx, bn := big.NewInt(0).SetUint64(x), big.NewInt(0).SetUint64(n) - for ; s > 1; s-- { - if x = bx.Mod(bx.Mul(bx, bx), bn).Uint64(); x == 1 { - return false - } - - if x == n-1 { - return true - } - } - return false -} - -// ProbablyPrimeBigInt_32 returns true if n is prime or n is a pseudoprime to -// base a. It implements the Miller-Rabin primality test for one specific value -// of 'a' and k == 1. See also ProbablyPrimeUint32. -func ProbablyPrimeBigInt_32(n *big.Int, a uint32) bool { - var d big.Int - d.Set(n) - d.Sub(&d, _1) // d <- n-1 - s := 0 - for ; d.Bit(s) == 0; s++ { - } - nMinus1 := big.NewInt(0).Set(&d) - d.Rsh(&d, uint(s)) - - x := ModPowBigInt(big.NewInt(int64(a)), &d, n) - if x.Cmp(_1) == 0 || x.Cmp(nMinus1) == 0 { - return true - } - - for ; s > 1; s-- { - if x = x.Mod(x.Mul(x, x), n); x.Cmp(_1) == 0 { - return false - } - - if x.Cmp(nMinus1) == 0 { - return true - } - } - return false -} - -// ProbablyPrimeBigInt returns true if n is prime or n is a pseudoprime to base -// a. It implements the Miller-Rabin primality test for one specific value of -// 'a' and k == 1. See also ProbablyPrimeUint32. -func ProbablyPrimeBigInt(n, a *big.Int) bool { - var d big.Int - d.Set(n) - d.Sub(&d, _1) // d <- n-1 - s := 0 - for ; d.Bit(s) == 0; s++ { - } - nMinus1 := big.NewInt(0).Set(&d) - d.Rsh(&d, uint(s)) - - x := ModPowBigInt(a, &d, n) - if x.Cmp(_1) == 0 || x.Cmp(nMinus1) == 0 { - return true - } - - for ; s > 1; s-- { - if x = x.Mod(x.Mul(x, x), n); x.Cmp(_1) == 0 { - return false - } - - if x.Cmp(nMinus1) == 0 { - return true - } - } - return false -} - -// Max returns the larger of a and b. -func Max(a, b int) int { - if a > b { - return a - } - - return b -} - -// Min returns the smaller of a and b. -func Min(a, b int) int { - if a < b { - return a - } - - return b -} - -// MaxVal returns the largest argument passed. -func MaxVal(val int, vals ...int) int { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// MinVal returns the smallest argument passed. -func MinVal(val int, vals ...int) int { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// Clamp returns a value restricted between lo and hi. -func Clamp(v, lo, hi int) int { - return Min(Max(v, lo), hi) -} - -// UMax returns the larger of a and b. -func UMax(a, b uint) uint { - if a > b { - return a - } - - return b -} - -// UMin returns the smaller of a and b. -func UMin(a, b uint) uint { - if a < b { - return a - } - - return b -} - -// UMaxVal returns the largest argument passed. -func UMaxVal(val uint, vals ...uint) uint { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// UMinVal returns the smallest argument passed. -func UMinVal(val uint, vals ...uint) uint { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// UClamp returns a value restricted between lo and hi. -func UClamp(v, lo, hi uint) uint { - return UMin(UMax(v, lo), hi) -} - -// MaxByte returns the larger of a and b. -func MaxByte(a, b byte) byte { - if a > b { - return a - } - - return b -} - -// MinByte returns the smaller of a and b. -func MinByte(a, b byte) byte { - if a < b { - return a - } - - return b -} - -// MaxByteVal returns the largest argument passed. -func MaxByteVal(val byte, vals ...byte) byte { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// MinByteVal returns the smallest argument passed. -func MinByteVal(val byte, vals ...byte) byte { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// ClampByte returns a value restricted between lo and hi. -func ClampByte(v, lo, hi byte) byte { - return MinByte(MaxByte(v, lo), hi) -} - -// MaxInt8 returns the larger of a and b. -func MaxInt8(a, b int8) int8 { - if a > b { - return a - } - - return b -} - -// MinInt8 returns the smaller of a and b. -func MinInt8(a, b int8) int8 { - if a < b { - return a - } - - return b -} - -// MaxInt8Val returns the largest argument passed. -func MaxInt8Val(val int8, vals ...int8) int8 { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// MinInt8Val returns the smallest argument passed. -func MinInt8Val(val int8, vals ...int8) int8 { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// ClampInt8 returns a value restricted between lo and hi. -func ClampInt8(v, lo, hi int8) int8 { - return MinInt8(MaxInt8(v, lo), hi) -} - -// MaxUint16 returns the larger of a and b. -func MaxUint16(a, b uint16) uint16 { - if a > b { - return a - } - - return b -} - -// MinUint16 returns the smaller of a and b. -func MinUint16(a, b uint16) uint16 { - if a < b { - return a - } - - return b -} - -// MaxUint16Val returns the largest argument passed. -func MaxUint16Val(val uint16, vals ...uint16) uint16 { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// MinUint16Val returns the smallest argument passed. -func MinUint16Val(val uint16, vals ...uint16) uint16 { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// ClampUint16 returns a value restricted between lo and hi. -func ClampUint16(v, lo, hi uint16) uint16 { - return MinUint16(MaxUint16(v, lo), hi) -} - -// MaxInt16 returns the larger of a and b. -func MaxInt16(a, b int16) int16 { - if a > b { - return a - } - - return b -} - -// MinInt16 returns the smaller of a and b. -func MinInt16(a, b int16) int16 { - if a < b { - return a - } - - return b -} - -// MaxInt16Val returns the largest argument passed. -func MaxInt16Val(val int16, vals ...int16) int16 { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// MinInt16Val returns the smallest argument passed. -func MinInt16Val(val int16, vals ...int16) int16 { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// ClampInt16 returns a value restricted between lo and hi. -func ClampInt16(v, lo, hi int16) int16 { - return MinInt16(MaxInt16(v, lo), hi) -} - -// MaxUint32 returns the larger of a and b. -func MaxUint32(a, b uint32) uint32 { - if a > b { - return a - } - - return b -} - -// MinUint32 returns the smaller of a and b. -func MinUint32(a, b uint32) uint32 { - if a < b { - return a - } - - return b -} - -// MaxUint32Val returns the largest argument passed. -func MaxUint32Val(val uint32, vals ...uint32) uint32 { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// MinUint32Val returns the smallest argument passed. -func MinUint32Val(val uint32, vals ...uint32) uint32 { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// ClampUint32 returns a value restricted between lo and hi. -func ClampUint32(v, lo, hi uint32) uint32 { - return MinUint32(MaxUint32(v, lo), hi) -} - -// MaxInt32 returns the larger of a and b. -func MaxInt32(a, b int32) int32 { - if a > b { - return a - } - - return b -} - -// MinInt32 returns the smaller of a and b. -func MinInt32(a, b int32) int32 { - if a < b { - return a - } - - return b -} - -// MaxInt32Val returns the largest argument passed. -func MaxInt32Val(val int32, vals ...int32) int32 { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// MinInt32Val returns the smallest argument passed. -func MinInt32Val(val int32, vals ...int32) int32 { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// ClampInt32 returns a value restricted between lo and hi. -func ClampInt32(v, lo, hi int32) int32 { - return MinInt32(MaxInt32(v, lo), hi) -} - -// MaxUint64 returns the larger of a and b. -func MaxUint64(a, b uint64) uint64 { - if a > b { - return a - } - - return b -} - -// MinUint64 returns the smaller of a and b. -func MinUint64(a, b uint64) uint64 { - if a < b { - return a - } - - return b -} - -// MaxUint64Val returns the largest argument passed. -func MaxUint64Val(val uint64, vals ...uint64) uint64 { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// MinUint64Val returns the smallest argument passed. -func MinUint64Val(val uint64, vals ...uint64) uint64 { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// ClampUint64 returns a value restricted between lo and hi. -func ClampUint64(v, lo, hi uint64) uint64 { - return MinUint64(MaxUint64(v, lo), hi) -} - -// MaxInt64 returns the larger of a and b. -func MaxInt64(a, b int64) int64 { - if a > b { - return a - } - - return b -} - -// MinInt64 returns the smaller of a and b. -func MinInt64(a, b int64) int64 { - if a < b { - return a - } - - return b -} - -// MaxInt64Val returns the largest argument passed. -func MaxInt64Val(val int64, vals ...int64) int64 { - res := val - for _, v := range vals { - if v > res { - res = v - } - } - return res -} - -// MinInt64Val returns the smallest argument passed. -func MinInt64Val(val int64, vals ...int64) int64 { - res := val - for _, v := range vals { - if v < res { - res = v - } - } - return res -} - -// ClampInt64 returns a value restricted between lo and hi. -func ClampInt64(v, lo, hi int64) int64 { - return MinInt64(MaxInt64(v, lo), hi) -} - -// ToBase produces n in base b. For example -// -// ToBase(2047, 22) -> [1, 5, 4] -// -// 1 * 22^0 1 -// 5 * 22^1 110 -// 4 * 22^2 1936 -// ---- -// 2047 -// -// ToBase panics for bases < 2. -func ToBase(n *big.Int, b int) []int { - var nn big.Int - nn.Set(n) - if b < 2 { - panic("invalid base") - } - - k := 1 - switch nn.Sign() { - case -1: - nn.Neg(&nn) - k = -1 - case 0: - return []int{0} - } - - bb := big.NewInt(int64(b)) - var r []int - rem := big.NewInt(0) - for nn.Sign() != 0 { - nn.QuoRem(&nn, bb, rem) - r = append(r, k*int(rem.Int64())) - } - return r -} diff --git a/vendor/github.com/cznic/mathutil/mersenne/mersenne.go b/vendor/github.com/cznic/mathutil/mersenne/mersenne.go deleted file mode 100644 index 4ab321340..000000000 --- a/vendor/github.com/cznic/mathutil/mersenne/mersenne.go +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright (c) 2014 The mersenne Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* -Package mersenne collects utilities related to Mersenne numbers[1] and/or some -of their properties. - -Exponent - -In this documentation the term 'exponent' refers to 'n' of a Mersenne number Mn -equal to 2^n-1. This package supports only uint32 sized exponents. New() -currently supports exponents only up to math.MaxInt32 (31 bits, up to 256 MB -required to represent such Mn in memory as a big.Int). - -Links - -Referenced from above: - [1] http://en.wikipedia.org/wiki/Mersenne_number -*/ -package mersenne - -import ( - "math" - "math/big" - - "github.com/cznic/mathutil" - "github.com/remyoudompheng/bigfft" -) - -var ( - _0 = big.NewInt(0) - _1 = big.NewInt(1) - _2 = big.NewInt(2) -) - -// Knowns list the exponent of currently (March 2012) known Mersenne primes -// exponents in order. See also: http://oeis.org/A000043 for a partial list. -var Knowns = []uint32{ - 2, // #1 - 3, // #2 - 5, // #3 - 7, // #4 - 13, // #5 - 17, // #6 - 19, // #7 - 31, // #8 - 61, // #9 - 89, // #10 - - 107, // #11 - 127, // #12 - 521, // #13 - 607, // #14 - 1279, // #15 - 2203, // #16 - 2281, // #17 - 3217, // #18 - 4253, // #19 - 4423, // #20 - - 9689, // #21 - 9941, // #22 - 11213, // #23 - 19937, // #24 - 21701, // #25 - 23209, // #26 - 44497, // #27 - 86243, // #28 - 110503, // #29 - 132049, // #30 - - 216091, // #31 - 756839, // #32 - 859433, // #33 - 1257787, // #34 - 1398269, // #35 - 2976221, // #36 - 3021377, // #37 - 6972593, // #38 - 13466917, // #39 - 20996011, // #40 - - 24036583, // #41 - 25964951, // #42 - 30402457, // #43 - 32582657, // #44 - 37156667, // #45 - 42643801, // #46 - 43112609, // #47 - 57885161, // #48 - 74207281, // #49 -} - -// Known maps the exponent of known Mersenne primes its ordinal number/rank. -// Ranks > 41 are currently provisional. -var Known map[uint32]int - -func init() { - Known = map[uint32]int{} - for i, v := range Knowns { - Known[v] = i + 1 - } -} - -// New returns Mn == 2^n-1 for n <= math.MaxInt32 or nil otherwise. -func New(n uint32) (m *big.Int) { - if n > math.MaxInt32 { - return - } - - m = big.NewInt(0) - return m.Sub(m.SetBit(m, int(n), 1), _1) -} - -// HasFactorUint32 returns true if d | Mn. Typical run time for a 32 bit factor -// and a 32 bit exponent is < 1 µs. -func HasFactorUint32(d, n uint32) bool { - return d == 1 || d&1 != 0 && mathutil.ModPowUint32(2, n, d) == 1 -} - -// HasFactorUint64 returns true if d | Mn. Typical run time for a 64 bit factor -// and a 32 bit exponent is < 30 µs. -func HasFactorUint64(d uint64, n uint32) bool { - return d == 1 || d&1 != 0 && mathutil.ModPowUint64(2, uint64(n), d) == 1 -} - -// HasFactorBigInt returns true if d | Mn, d > 0. Typical run time for a 128 -// bit factor and a 32 bit exponent is < 75 µs. -func HasFactorBigInt(d *big.Int, n uint32) bool { - return d.Cmp(_1) == 0 || d.Sign() > 0 && d.Bit(0) == 1 && - mathutil.ModPowBigInt(_2, big.NewInt(int64(n)), d).Cmp(_1) == 0 -} - -// HasFactorBigInt2 returns true if d | Mn, d > 0 -func HasFactorBigInt2(d, n *big.Int) bool { - return d.Cmp(_1) == 0 || d.Sign() > 0 && d.Bit(0) == 1 && - mathutil.ModPowBigInt(_2, n, d).Cmp(_1) == 0 -} - -/* -FromFactorBigInt returns n such that d | Mn if n <= max and d is odd. In other -cases zero is returned. - -It is conjectured that every odd d ∊ N divides infinitely many Mersenne numbers. -The returned n should be the exponent of smallest such Mn. - -NOTE: The computation of n from a given d performs roughly in O(n). It is -thus highly recommended to use the 'max' argument to limit the "searched" -exponent upper bound as appropriate. Otherwise the computation can take a long -time as a large factor can be a divisor of a Mn with exponent above the uint32 -limits. - -The FromFactorBigInt function is a modification of the original Will -Edgington's "reverse method", discussed here: -http://tech.groups.yahoo.com/group/primenumbers/message/15061 -*/ -func FromFactorBigInt(d *big.Int, max uint32) (n uint32) { - if d.Bit(0) == 0 { - return - } - - var m big.Int - for n < max { - m.Add(&m, d) - i := 0 - for ; m.Bit(i) == 1; i++ { - if n == math.MaxUint32 { - return 0 - } - - n++ - } - m.Rsh(&m, uint(i)) - if m.Sign() == 0 { - if n > max { - n = 0 - } - return - } - } - return 0 -} - -// Mod sets mod to n % Mexp and returns mod. It panics for exp == 0 || exp >= -// math.MaxInt32 || n < 0. -func Mod(mod, n *big.Int, exp uint32) *big.Int { - if exp == 0 || exp >= math.MaxInt32 || n.Sign() < 0 { - panic(0) - } - - m := New(exp) - mod.Set(n) - var x big.Int - for mod.BitLen() > int(exp) { - x.Set(mod) - x.Rsh(&x, uint(exp)) - mod.And(mod, m) - mod.Add(mod, &x) - } - if mod.BitLen() == int(exp) && mod.Cmp(m) == 0 { - mod.SetInt64(0) - } - return mod -} - -// ModPow2 returns x such that 2^Me % Mm == 2^x. It panics for m < 2. Typical -// run time is < 1 µs. Use instead of ModPow(2, e, m) wherever possible. -func ModPow2(e, m uint32) (x uint32) { - /* - m < 2 -> panic - e == 0 -> x == 0 - e == 1 -> x == 1 - - 2^M1 % M2 == 2^1 % 3 == 2^1 10 // 2^1, 3, 5, 7 ... +2k - 2^M1 % M3 == 2^1 % 7 == 2^1 010 // 2^1, 4, 7, ... +3k - 2^M1 % M4 == 2^1 % 15 == 2^1 0010 // 2^1, 5, 9, 13... +4k - 2^M1 % M5 == 2^1 % 31 == 2^1 00010 // 2^1, 6, 11, 16... +5k - - 2^M2 % M2 == 2^3 % 3 == 2^1 10.. // 2^3, 5, 7, 9, 11, ... +2k - 2^M2 % M3 == 2^3 % 7 == 2^0 001... // 2^3, 6, 9, 12, 15, ... +3k - 2^M2 % M4 == 2^3 % 15 == 2^3 1000 // 2^3, 7, 11, 15, 19, ... +4k - 2^M2 % M5 == 2^3 % 31 == 2^3 01000 // 2^3, 8, 13, 18, 23, ... +5k - - 2^M3 % M2 == 2^7 % 3 == 2^1 10..--.. // 2^3, 5, 7... +2k - 2^M3 % M3 == 2^7 % 7 == 2^1 010...--- // 2^1, 4, 7... +3k - 2^M3 % M4 == 2^7 % 15 == 2^3 1000.... // +4k - 2^M3 % M5 == 2^7 % 31 == 2^2 00100..... // +5k - 2^M3 % M6 == 2^7 % 63 == 2^1 000010...... // +6k - 2^M3 % M7 == 2^7 % 127 == 2^0 0000001....... - 2^M3 % M8 == 2^7 % 255 == 2^7 10000000 - 2^M3 % M9 == 2^7 % 511 == 2^7 010000000 - - 2^M4 % M2 == 2^15 % 3 == 2^1 10..--..--..--.. - 2^M4 % M3 == 2^15 % 7 == 2^0 1...---...---... - 2^M4 % M4 == 2^15 % 15 == 2^3 1000....----.... - 2^M4 % M5 == 2^15 % 31 == 2^0 1.....-----..... - 2^M4 % M6 == 2^15 % 63 == 2^3 1000......------ - 2^M4 % M7 == 2^15 % 127 == 2^1 10.......------- - 2^M4 % M8 == 2^15 % 255 == 2^7 10000000........ - 2^M4 % M9 == 2^15 % 511 == 2^6 1000000......... - */ - switch { - case m < 2: - panic(0) - case e < 2: - return e - } - - if x = mathutil.ModPowUint32(2, e, m); x == 0 { - return m - 1 - } - - return x - 1 -} - -// ModPow returns b^Me % Mm. Run time grows quickly with 'e' and/or 'm' when b -// != 2 (then ModPow2 is used). -func ModPow(b, e, m uint32) (r *big.Int) { - if m == 1 { - return big.NewInt(0) - } - - if b == 2 { - x := ModPow2(e, m) - r = big.NewInt(0) - r.SetBit(r, int(x), 1) - return - } - - bb := big.NewInt(int64(b)) - r = big.NewInt(1) - for ; e != 0; e-- { - r = bigfft.Mul(r, bb) - Mod(r, r, m) - bb = bigfft.Mul(bb, bb) - Mod(bb, bb, m) - } - return -} - -// ProbablyPrime returns true if Mn is prime or is a pseudoprime to base a. -// Note: Every Mp, prime p, is a prime or is a pseudoprime to base 2, actually -// to every base 2^i, i ∊ [1, p). In contrast - it is conjectured (w/o any -// known counterexamples) that no composite Mp, prime p, is a pseudoprime to -// base 3. -func ProbablyPrime(n, a uint32) bool { - //TODO +test, +bench - if a == 2 { - return ModPow2(n-1, n) == 0 - } - - nMinus1 := New(n) - nMinus1.Sub(nMinus1, _1) - x := ModPow(a, n-1, n) - return x.Cmp(_1) == 0 || x.Cmp(nMinus1) == 0 -} diff --git a/vendor/github.com/cznic/mathutil/permute.go b/vendor/github.com/cznic/mathutil/permute.go deleted file mode 100644 index 82ad791fd..000000000 --- a/vendor/github.com/cznic/mathutil/permute.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2014 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mathutil - -import ( - "sort" -) - -// PermutationFirst generates the first permutation of data. -func PermutationFirst(data sort.Interface) { - sort.Sort(data) -} - -// PermutationNext generates the next permutation of data if possible and -// return true. Return false if there is no more permutation left. Based on -// the algorithm described here: -// http://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order -func PermutationNext(data sort.Interface) bool { - var k, l int - for k = data.Len() - 2; ; k-- { // 1. - if k < 0 { - return false - } - - if data.Less(k, k+1) { - break - } - } - for l = data.Len() - 1; !data.Less(k, l); l-- { // 2. - } - data.Swap(k, l) // 3. - for i, j := k+1, data.Len()-1; i < j; i++ { // 4. - data.Swap(i, j) - j-- - } - return true -} diff --git a/vendor/github.com/cznic/mathutil/poly.go b/vendor/github.com/cznic/mathutil/poly.go deleted file mode 100644 index 98fed28d7..000000000 --- a/vendor/github.com/cznic/mathutil/poly.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2016 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mathutil - -import ( - "fmt" -) - -func abs(n int) uint64 { - if n >= 0 { - return uint64(n) - } - - return uint64(-n) -} - -// QuadPolyDiscriminant returns the discriminant of a quadratic polynomial in -// one variable of the form a*x^2+b*x+c with integer coefficients a, b, c, or -// an error on overflow. -// -// ds is the square of the discriminant. If |ds| is a square number, d is set -// to sqrt(|ds|), otherwise d is < 0. -func QuadPolyDiscriminant(a, b, c int) (ds, d int, _ error) { - if 2*BitLenUint64(abs(b)) > IntBits-1 || - 2+BitLenUint64(abs(a))+BitLenUint64(abs(c)) > IntBits-1 { - return 0, 0, fmt.Errorf("overflow") - } - - ds = b*b - 4*a*c - s := ds - if s < 0 { - s = -s - } - d64 := SqrtUint64(uint64(s)) - if d64*d64 != uint64(s) { - return ds, -1, nil - } - - return ds, int(d64), nil -} - -// PolyFactor describes an irreducible factor of a polynomial in one variable -// with integer coefficients P, Q of the form P*x+Q. -type PolyFactor struct { - P, Q int -} - -// QuadPolyFactors returns the content and the irreducible factors of the -// primitive part of a quadratic polynomial in one variable with integer -// coefficients a, b, c of the form a*x^2+b*x+c in integers, or an error on -// overflow. -// -// If the factorization in integers does not exists, the return value is (nil, -// nil). -// -// See also: -// https://en.wikipedia.org/wiki/Factorization_of_polynomials#Primitive_part.E2.80.93content_factorization -func QuadPolyFactors(a, b, c int) (content int, primitivePart []PolyFactor, _ error) { - content = int(GCDUint64(abs(a), GCDUint64(abs(b), abs(c)))) - switch { - case content == 0: - content = 1 - case content > 0: - if a < 0 || a == 0 && b < 0 { - content = -content - } - } - a /= content - b /= content - c /= content - if a == 0 { - if b == 0 { - return content, []PolyFactor{{0, c}}, nil - } - - if b < 0 && c < 0 { - b = -b - c = -c - } - if b < 0 { - b = -b - c = -c - } - return content, []PolyFactor{{b, c}}, nil - } - - ds, d, err := QuadPolyDiscriminant(a, b, c) - if err != nil { - return 0, nil, err - } - - if ds < 0 || d < 0 { - return 0, nil, nil - } - - x1num := -b + d - x1denom := 2 * a - gcd := int(GCDUint64(abs(x1num), abs(x1denom))) - x1num /= gcd - x1denom /= gcd - - x2num := -b - d - x2denom := 2 * a - gcd = int(GCDUint64(abs(x2num), abs(x2denom))) - x2num /= gcd - x2denom /= gcd - - return content, []PolyFactor{{x1denom, -x1num}, {x2denom, -x2num}}, nil -} diff --git a/vendor/github.com/cznic/mathutil/primes.go b/vendor/github.com/cznic/mathutil/primes.go deleted file mode 100644 index bd10fe6d3..000000000 --- a/vendor/github.com/cznic/mathutil/primes.go +++ /dev/null @@ -1,335 +0,0 @@ -// Copyright (c) 2014 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mathutil - -import ( - "math" -) - -// IsPrimeUint16 returns true if n is prime. Typical run time is few ns. -func IsPrimeUint16(n uint16) bool { - return n > 0 && primes16[n-1] == 1 -} - -// NextPrimeUint16 returns first prime > n and true if successful or an -// undefined value and false if there is no next prime in the uint16 limits. -// Typical run time is few ns. -func NextPrimeUint16(n uint16) (p uint16, ok bool) { - return n + uint16(primes16[n]), n < 65521 -} - -// IsPrime returns true if n is prime. Typical run time is about 100 ns. -// -//TODO rename to IsPrimeUint32 -func IsPrime(n uint32) bool { - switch { - case n&1 == 0: - return n == 2 - case n%3 == 0: - return n == 3 - case n%5 == 0: - return n == 5 - case n%7 == 0: - return n == 7 - case n%11 == 0: - return n == 11 - case n%13 == 0: - return n == 13 - case n%17 == 0: - return n == 17 - case n%19 == 0: - return n == 19 - case n%23 == 0: - return n == 23 - case n%29 == 0: - return n == 29 - case n%31 == 0: - return n == 31 - case n%37 == 0: - return n == 37 - case n%41 == 0: - return n == 41 - case n%43 == 0: - return n == 43 - case n%47 == 0: - return n == 47 - case n%53 == 0: - return n == 53 // Benchmarked optimum - case n < 65536: - // use table data - return IsPrimeUint16(uint16(n)) - default: - mod := ModPowUint32(2, (n+1)/2, n) - if mod != 2 && mod != n-2 { - return false - } - blk := &lohi[n>>24] - lo, hi := blk.lo, blk.hi - for lo <= hi { - index := (lo + hi) >> 1 - liar := liars[index] - switch { - case n > liar: - lo = index + 1 - case n < liar: - hi = index - 1 - default: - return false - } - } - return true - } -} - -// IsPrimeUint64 returns true if n is prime. Typical run time is few tens of µs. -// -// SPRP bases: http://miller-rabin.appspot.com -func IsPrimeUint64(n uint64) bool { - switch { - case n%2 == 0: - return n == 2 - case n%3 == 0: - return n == 3 - case n%5 == 0: - return n == 5 - case n%7 == 0: - return n == 7 - case n%11 == 0: - return n == 11 - case n%13 == 0: - return n == 13 - case n%17 == 0: - return n == 17 - case n%19 == 0: - return n == 19 - case n%23 == 0: - return n == 23 - case n%29 == 0: - return n == 29 - case n%31 == 0: - return n == 31 - case n%37 == 0: - return n == 37 - case n%41 == 0: - return n == 41 - case n%43 == 0: - return n == 43 - case n%47 == 0: - return n == 47 - case n%53 == 0: - return n == 53 - case n%59 == 0: - return n == 59 - case n%61 == 0: - return n == 61 - case n%67 == 0: - return n == 67 - case n%71 == 0: - return n == 71 - case n%73 == 0: - return n == 73 - case n%79 == 0: - return n == 79 - case n%83 == 0: - return n == 83 - case n%89 == 0: - return n == 89 // Benchmarked optimum - case n <= math.MaxUint16: - return IsPrimeUint16(uint16(n)) - case n <= math.MaxUint32: - return ProbablyPrimeUint32(uint32(n), 11000544) && - ProbablyPrimeUint32(uint32(n), 31481107) - case n < 105936894253: - return ProbablyPrimeUint64_32(n, 2) && - ProbablyPrimeUint64_32(n, 1005905886) && - ProbablyPrimeUint64_32(n, 1340600841) - case n < 31858317218647: - return ProbablyPrimeUint64_32(n, 2) && - ProbablyPrimeUint64_32(n, 642735) && - ProbablyPrimeUint64_32(n, 553174392) && - ProbablyPrimeUint64_32(n, 3046413974) - case n < 3071837692357849: - return ProbablyPrimeUint64_32(n, 2) && - ProbablyPrimeUint64_32(n, 75088) && - ProbablyPrimeUint64_32(n, 642735) && - ProbablyPrimeUint64_32(n, 203659041) && - ProbablyPrimeUint64_32(n, 3613982119) - default: - return ProbablyPrimeUint64_32(n, 2) && - ProbablyPrimeUint64_32(n, 325) && - ProbablyPrimeUint64_32(n, 9375) && - ProbablyPrimeUint64_32(n, 28178) && - ProbablyPrimeUint64_32(n, 450775) && - ProbablyPrimeUint64_32(n, 9780504) && - ProbablyPrimeUint64_32(n, 1795265022) - } -} - -// NextPrime returns first prime > n and true if successful or an undefined value and false if there -// is no next prime in the uint32 limits. Typical run time is about 2 µs. -// -//TODO rename to NextPrimeUint32 -func NextPrime(n uint32) (p uint32, ok bool) { - switch { - case n < 65521: - p16, _ := NextPrimeUint16(uint16(n)) - return uint32(p16), true - case n >= math.MaxUint32-4: - return - } - - n++ - var d0, d uint32 - switch mod := n % 6; mod { - case 0: - d0, d = 1, 4 - case 1: - d = 4 - case 2, 3, 4: - d0, d = 5-mod, 2 - case 5: - d = 2 - } - - p = n + d0 - if p < n { // overflow - return - } - - for { - if IsPrime(p) { - return p, true - } - - p0 := p - p += d - if p < p0 { // overflow - break - } - - d ^= 6 - } - return -} - -// NextPrimeUint64 returns first prime > n and true if successful or an undefined value and false if there -// is no next prime in the uint64 limits. Typical run time is in hundreds of µs. -func NextPrimeUint64(n uint64) (p uint64, ok bool) { - switch { - case n < 65521: - p16, _ := NextPrimeUint16(uint16(n)) - return uint64(p16), true - case n >= 18446744073709551557: // last uint64 prime - return - } - - n++ - var d0, d uint64 - switch mod := n % 6; mod { - case 0: - d0, d = 1, 4 - case 1: - d = 4 - case 2, 3, 4: - d0, d = 5-mod, 2 - case 5: - d = 2 - } - - p = n + d0 - if p < n { // overflow - return - } - - for { - if ok = IsPrimeUint64(p); ok { - break - } - - p0 := p - p += d - if p < p0 { // overflow - break - } - - d ^= 6 - } - return -} - -// FactorTerm is one term of an integer factorization. -type FactorTerm struct { - Prime uint32 // The divisor - Power uint32 // Term == Prime^Power -} - -// FactorTerms represent a factorization of an integer -type FactorTerms []FactorTerm - -// FactorInt returns prime factorization of n > 1 or nil otherwise. -// Resulting factors are ordered by Prime. Typical run time is few µs. -func FactorInt(n uint32) (f FactorTerms) { - switch { - case n < 2: - return - case IsPrime(n): - return []FactorTerm{{n, 1}} - } - - f, w := make([]FactorTerm, 9), 0 - for p := 2; p < len(primes16); p += int(primes16[p]) { - if uint(p*p) > uint(n) { - break - } - - power := uint32(0) - for n%uint32(p) == 0 { - n /= uint32(p) - power++ - } - if power != 0 { - f[w] = FactorTerm{uint32(p), power} - w++ - } - if n == 1 { - break - } - } - if n != 1 { - f[w] = FactorTerm{n, 1} - w++ - } - return f[:w] -} - -// PrimorialProductsUint32 returns a slice of numbers in [lo, hi] which are a -// product of max 'max' primorials. The slice is not sorted. -// -// See also: http://en.wikipedia.org/wiki/Primorial -func PrimorialProductsUint32(lo, hi, max uint32) (r []uint32) { - lo64, hi64 := int64(lo), int64(hi) - if max > 31 { // N/A - max = 31 - } - - var f func(int64, int64, uint32) - f = func(n, p int64, emax uint32) { - e := uint32(1) - for n <= hi64 && e <= emax { - n *= p - if n >= lo64 && n <= hi64 { - r = append(r, uint32(n)) - } - if n < hi64 { - p, _ := NextPrime(uint32(p)) - f(n, int64(p), e) - } - e++ - } - } - - f(1, 2, max) - return -} diff --git a/vendor/github.com/cznic/mathutil/rat.go b/vendor/github.com/cznic/mathutil/rat.go deleted file mode 100644 index 91b1c6fb1..000000000 --- a/vendor/github.com/cznic/mathutil/rat.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2014 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mathutil - -// QCmpUint32 compares a/b and c/d and returns: -// -// -1 if a/b < c/d -// 0 if a/b == c/d -// +1 if a/b > c/d -// -func QCmpUint32(a, b, c, d uint32) int { - switch x, y := uint64(a)*uint64(d), uint64(b)*uint64(c); { - case x < y: - return -1 - case x == y: - return 0 - default: // x > y - return 1 - } -} - -// QScaleUint32 returns a such that a/b >= c/d. -func QScaleUint32(b, c, d uint32) (a uint64) { - return 1 + (uint64(b)*uint64(c))/uint64(d) -} diff --git a/vendor/github.com/cznic/mathutil/rnd.go b/vendor/github.com/cznic/mathutil/rnd.go deleted file mode 100644 index 9132dc0d5..000000000 --- a/vendor/github.com/cznic/mathutil/rnd.go +++ /dev/null @@ -1,383 +0,0 @@ -// Copyright (c) 2014 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mathutil - -import ( - "fmt" - "math" - "math/big" -) - -// FC32 is a full cycle PRNG covering the 32 bit signed integer range. -// In contrast to full cycle generators shown at e.g. http://en.wikipedia.org/wiki/Full_cycle, -// this code doesn't produce values at constant delta (mod cycle length). -// The 32 bit limit is per this implementation, the algorithm used has no intrinsic limit on the cycle size. -// Properties include: -// - Adjustable limits on creation (hi, lo). -// - Positionable/randomly accessible (Pos, Seek). -// - Repeatable (deterministic). -// - Can run forward or backward (Next, Prev). -// - For a billion numbers cycle the Next/Prev PRN can be produced in cca 100-150ns. -// That's like 5-10 times slower compared to PRNs generated using the (non FC) rand package. -type FC32 struct { - cycle int64 // On average: 3 * delta / 2, (HQ: 2 * delta) - delta int64 // hi - lo - factors [][]int64 // This trades some space for hopefully a bit of speed (multiple adding vs multiplying). - lo int - mods []int // pos % set - pos int64 // Within cycle. - primes []int64 // Ordered. ∏ primes == cycle. - set []int64 // Reordered primes (magnitude order bases) according to seed. -} - -// NewFC32 returns a newly created FC32 adjusted for the closed interval [lo, hi] or an Error if any. -// If hq == true then trade some generation time for improved (pseudo)randomness. -func NewFC32(lo, hi int, hq bool) (r *FC32, err error) { - if lo > hi { - return nil, fmt.Errorf("invalid range %d > %d", lo, hi) - } - - if uint64(hi)-uint64(lo) > math.MaxUint32 { - return nil, fmt.Errorf("range out of int32 limits %d, %d", lo, hi) - } - - delta := int64(hi) - int64(lo) - // Find the primorial covering whole delta - n, set, p := int64(1), []int64{}, uint32(2) - if hq { - p++ - } - for { - set = append(set, int64(p)) - n *= int64(p) - if n > delta { - break - } - p, _ = NextPrime(p) - } - - // Adjust the set so n ∊ [delta, 2 * delta] (HQ: [delta, 3 * delta]) - // while keeping the cardinality of the set (correlates with the statistic "randomness quality") - // at max, i.e. discard atmost one member. - i := -1 // no candidate prime - if n > 2*(delta+1) { - for j, p := range set { - q := n / p - if q < delta+1 { - break - } - - i = j // mark the highest candidate prime set index - } - } - if i >= 0 { // shrink the inner cycle - n = n / set[i] - set = delete(set, i) - } - r = &FC32{ - cycle: n, - delta: delta, - factors: make([][]int64, len(set)), - lo: lo, - mods: make([]int, len(set)), - primes: set, - } - r.Seed(1) // the default seed should be always non zero - return -} - -// Cycle reports the length of the inner FCPRNG cycle. -// Cycle is atmost the double (HQ: triple) of the generator period (hi - lo + 1). -func (r *FC32) Cycle() int64 { - return r.cycle -} - -// Next returns the first PRN after Pos. -func (r *FC32) Next() int { - return r.step(1) -} - -// Pos reports the current position within the inner cycle. -func (r *FC32) Pos() int64 { - return r.pos -} - -// Prev return the first PRN before Pos. -func (r *FC32) Prev() int { - return r.step(-1) -} - -// Seed uses the provided seed value to initialize the generator to a deterministic state. -// A zero seed produces a "canonical" generator with worse randomness than for most non zero seeds. -// Still, the FC property holds for any seed value. -func (r *FC32) Seed(seed int64) { - u := uint64(seed) - r.set = mix(r.primes, &u) - n := int64(1) - for i, p := range r.set { - k := make([]int64, p) - v := int64(0) - for j := range k { - k[j] = v - v += n - } - n *= p - r.factors[i] = mix(k, &u) - } -} - -// Seek sets Pos to |pos| % Cycle. -func (r *FC32) Seek(pos int64) { //vet:ignore - if pos < 0 { - pos = -pos - } - pos %= r.cycle - r.pos = pos - for i, p := range r.set { - r.mods[i] = int(pos % p) - } -} - -func (r *FC32) step(dir int) int { - for { // avg loops per step: 3/2 (HQ: 2) - y := int64(0) - pos := r.pos - pos += int64(dir) - switch { - case pos < 0: - pos = r.cycle - 1 - case pos >= r.cycle: - pos = 0 - } - r.pos = pos - for i, mod := range r.mods { - mod += dir - p := int(r.set[i]) - switch { - case mod < 0: - mod = p - 1 - case mod >= p: - mod = 0 - } - r.mods[i] = mod - y += r.factors[i][mod] - } - if y <= r.delta { - return int(y) + r.lo - } - } -} - -func delete(set []int64, i int) (y []int64) { - for j, v := range set { - if j != i { - y = append(y, v) - } - } - return -} - -func mix(set []int64, seed *uint64) (y []int64) { - for len(set) != 0 { - *seed = rol(*seed) - i := int(*seed % uint64(len(set))) - y = append(y, set[i]) - set = delete(set, i) - } - return -} - -func rol(u uint64) (y uint64) { - y = u << 1 - if int64(u) < 0 { - y |= 1 - } - return -} - -// FCBig is a full cycle PRNG covering ranges outside of the int32 limits. -// For more info see the FC32 docs. -// Next/Prev PRN on a 1e15 cycle can be produced in about 2 µsec. -type FCBig struct { - cycle *big.Int // On average: 3 * delta / 2, (HQ: 2 * delta) - delta *big.Int // hi - lo - factors [][]*big.Int // This trades some space for hopefully a bit of speed (multiple adding vs multiplying). - lo *big.Int - mods []int // pos % set - pos *big.Int // Within cycle. - primes []int64 // Ordered. ∏ primes == cycle. - set []int64 // Reordered primes (magnitude order bases) according to seed. -} - -// NewFCBig returns a newly created FCBig adjusted for the closed interval [lo, hi] or an Error if any. -// If hq == true then trade some generation time for improved (pseudo)randomness. -func NewFCBig(lo, hi *big.Int, hq bool) (r *FCBig, err error) { - if lo.Cmp(hi) > 0 { - return nil, fmt.Errorf("invalid range %d > %d", lo, hi) - } - - delta := big.NewInt(0) - delta.Add(delta, hi).Sub(delta, lo) - - // Find the primorial covering whole delta - n, set, pp, p := big.NewInt(1), []int64{}, big.NewInt(0), uint32(2) - if hq { - p++ - } - for { - set = append(set, int64(p)) - pp.SetInt64(int64(p)) - n.Mul(n, pp) - if n.Cmp(delta) > 0 { - break - } - p, _ = NextPrime(p) - } - - // Adjust the set so n ∊ [delta, 2 * delta] (HQ: [delta, 3 * delta]) - // while keeping the cardinality of the set (correlates with the statistic "randomness quality") - // at max, i.e. discard atmost one member. - dd1 := big.NewInt(1) - dd1.Add(dd1, delta) - dd2 := big.NewInt(0) - dd2.Lsh(dd1, 1) - i := -1 // no candidate prime - if n.Cmp(dd2) > 0 { - q := big.NewInt(0) - for j, p := range set { - pp.SetInt64(p) - q.Set(n) - q.Div(q, pp) - if q.Cmp(dd1) < 0 { - break - } - - i = j // mark the highest candidate prime set index - } - } - if i >= 0 { // shrink the inner cycle - pp.SetInt64(set[i]) - n.Div(n, pp) - set = delete(set, i) - } - r = &FCBig{ - cycle: n, - delta: delta, - factors: make([][]*big.Int, len(set)), - lo: lo, - mods: make([]int, len(set)), - pos: big.NewInt(0), - primes: set, - } - r.Seed(1) // the default seed should be always non zero - return -} - -// Cycle reports the length of the inner FCPRNG cycle. -// Cycle is atmost the double (HQ: triple) of the generator period (hi - lo + 1). -func (r *FCBig) Cycle() *big.Int { - return r.cycle -} - -// Next returns the first PRN after Pos. -func (r *FCBig) Next() *big.Int { - return r.step(1) -} - -// Pos reports the current position within the inner cycle. -func (r *FCBig) Pos() *big.Int { - return r.pos -} - -// Prev return the first PRN before Pos. -func (r *FCBig) Prev() *big.Int { - return r.step(-1) -} - -// Seed uses the provided seed value to initialize the generator to a deterministic state. -// A zero seed produces a "canonical" generator with worse randomness than for most non zero seeds. -// Still, the FC property holds for any seed value. -func (r *FCBig) Seed(seed int64) { - u := uint64(seed) - r.set = mix(r.primes, &u) - n := big.NewInt(1) - v := big.NewInt(0) - pp := big.NewInt(0) - for i, p := range r.set { - k := make([]*big.Int, p) - v.SetInt64(0) - for j := range k { - k[j] = big.NewInt(0) - k[j].Set(v) - v.Add(v, n) - } - pp.SetInt64(p) - n.Mul(n, pp) - r.factors[i] = mixBig(k, &u) - } -} - -// Seek sets Pos to |pos| % Cycle. -func (r *FCBig) Seek(pos *big.Int) { - r.pos.Set(pos) - r.pos.Abs(r.pos) - r.pos.Mod(r.pos, r.cycle) - mod := big.NewInt(0) - pp := big.NewInt(0) - for i, p := range r.set { - pp.SetInt64(p) - r.mods[i] = int(mod.Mod(r.pos, pp).Int64()) - } -} - -func (r *FCBig) step(dir int) (y *big.Int) { - y = big.NewInt(0) - d := big.NewInt(int64(dir)) - for { // avg loops per step: 3/2 (HQ: 2) - r.pos.Add(r.pos, d) - switch { - case r.pos.Sign() < 0: - r.pos.Add(r.pos, r.cycle) - case r.pos.Cmp(r.cycle) >= 0: - r.pos.SetInt64(0) - } - for i, mod := range r.mods { - mod += dir - p := int(r.set[i]) - switch { - case mod < 0: - mod = p - 1 - case mod >= p: - mod = 0 - } - r.mods[i] = mod - y.Add(y, r.factors[i][mod]) - } - if y.Cmp(r.delta) <= 0 { - y.Add(y, r.lo) - return - } - y.SetInt64(0) - } -} - -func deleteBig(set []*big.Int, i int) (y []*big.Int) { - for j, v := range set { - if j != i { - y = append(y, v) - } - } - return -} - -func mixBig(set []*big.Int, seed *uint64) (y []*big.Int) { - for len(set) != 0 { - *seed = rol(*seed) - i := int(*seed % uint64(len(set))) - y = append(y, set[i]) - set = deleteBig(set, i) - } - return -} diff --git a/vendor/github.com/cznic/mathutil/tables.go b/vendor/github.com/cznic/mathutil/tables.go deleted file mode 100644 index f32952c00..000000000 --- a/vendor/github.com/cznic/mathutil/tables.go +++ /dev/null @@ -1,6995 +0,0 @@ -// Copyright (c) 2014 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// "Static" data - -package mathutil - -var ( - // Set bits count in a byte - popcnt = [256]byte{ - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, // 0 - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, // 1 - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, // 2 - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, // 3 - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, // 4 - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, // 5 - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, // 6 - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, // 7 - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, // 8 - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, // 9 - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, // 10 - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, // 11 - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, // 12 - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, // 13 - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, // 14 - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, // 15 - } - - // Highest set bit index in a byte - log2 = [256]int{ - -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, // 0 - - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 1 - - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 2 - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 3 - - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, // 4 - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, // 5 - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, // 6 - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, // 7 - - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 8 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 9 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 10 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 11 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 12 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 13 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 14 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 15 - } - - // "Predivisors": 2-53 - liars = [3660]uint32{ - 31621, 42799, 49141, 49981, 65077, 65281, 80581, 83333, 88357, 90751, - 104653, 130561, 164737, 188057, 194221, 196093, 215749, 219781, 220729, 253241, - 256999, 271951, 280601, 282133, 357761, 390937, 458989, 486737, 489997, 514447, - 580337, 587861, 611701, 647089, 653333, 657901, 665281, 665333, 688213, 710533, - 721801, 722261, 738541, 741751, 742813, 745889, 769757, 818201, 838861, 873181, - 877099, 916327, 976873, 983401, 1016801, 1018921, 1053761, 1064053, 1073021, 1082401, - 1109461, 1132657, 1145257, 1168513, 1194649, 1207361, 1251949, 1252697, 1302451, 1325843, - 1357441, 1373653, 1397419, 1441091, 1493857, 1507963, 1509709, 1530787, 1584133, 1678541, - 1690501, 1730977, 1735841, 1811573, 1876393, 1969417, 1987021, 2004403, 2081713, 2163001, - 2181961, 2205967, 2261953, 2264369, 2269093, 2284453, 2304167, 2387797, 2487941, 2510569, - 2670361, 2746477, 2748023, 2757241, 2811271, 2909197, 2944261, 2976487, 3048841, 3090091, - 3116107, 3125281, 3225601, 3363121, 3375041, 3400013, 3413533, 3429037, 3539101, 3542533, - 3567481, 3568661, 3605429, 3656449, 3763801, 3828001, 3898129, 3911197, 3985921, 4072729, - 4181921, 4188889, 4209661, 4360621, 4469471, 4480477, 4513841, 4835209, 4863127, 4869313, - 4877641, 4922413, 5016191, 5044033, 5095177, 5173169, 5173601, 5176153, 5256091, 5271841, - 5284333, 5351537, 5489641, 5590621, 5672041, 5919187, 6027193, 6118141, 6140161, 6159301, - 6189121, 6226193, 6233977, 6236257, 6278533, 6334351, 6368689, 6386993, 6631549, 6658669, - 6779137, 6787327, 6836233, 6952037, 6955541, 6998881, 7017193, 7232321, 7306261, 7306561, - 7429117, 7462001, 7674967, 7725901, 7759937, 7820201, 7883731, 8036033, 8095447, 8239477, - 8384513, 8534233, 8725753, 8727391, 8902741, 9006401, 9056501, 9073513, 9131401, 9345541, - 9371251, 9439201, 9480461, 9533701, 9564169, 9567673, 9588151, 9591661, 9729301, 9774181, - 9863461, 10024561, 10084177, 10323769, 10331141, 10386241, 10425511, 10610063, 10700761, 10712857, - 10763653, 10974881, 11081459, 11115037, 11335501, 11541307, 11585293, 11592397, 11777599, 12032021, - 12096613, 12263131, 12322133, 12327121, 12599233, 12854437, 13057787, 13338371, 13446253, 13500313, - 13635289, 13694761, 13747361, 13773061, 14026897, 14154337, 14179537, 14324473, 14469841, 14671801, - 14676481, 14709241, 14794081, 14796289, 14865121, 15101893, 15139199, 15162941, 15188557, 15220951, - 15247621, 15479777, 15525241, 15603391, 15621409, 15700301, 15802681, 15976747, 15978007, 16070429, - 16132321, 16149169, 16153633, 16324001, 16349477, 16360381, 16705021, 16773121, 16822081, 16843009, - 16853077, 16879501, 16973393, 17098369, 17116837, 17134043, 17208601, 17236801, 17327773, 17375249, - 17405537, 17585969, 17870561, 18067501, 18073817, 18366937, 18443701, 18454921, 18535177, 18653353, - 18740971, 19328653, 19384289, 19404139, 19471033, 19607561, 20261251, 20417311, 20647621, 20968501, - 21042001, 21303343, 21306157, 21359521, 21397381, 21400481, 21623659, 21654533, 22075579, 22087477, - 22369621, 22591301, 22669501, 22711873, 22849481, 22953673, 23247901, 23382529, 23464033, 23577497, - 23634181, 23734901, 23828017, 23872213, 23963869, 24214051, 24356377, 25080101, 25150501, 25276421, - 25326001, 25457833, 25629913, 25696133, 25768261, 25909453, 26280073, 26377921, 26821601, 26840269, - 26877421, 26886817, 27108397, 27118601, 27219697, 27271151, 27279409, 27331921, 27380831, 27392041, - 27409541, 27491237, 27509653, 27664033, 27798461, 27808463, 28325881, 28527049, 28572961, 29111881, - 29214541, 29581501, 30022129, 30090817, 30185569, 30219757, 30295141, 30338593, 30388753, 30418957, - 30576151, 30662497, 30740417, 30881551, 30894307, 31040833, 31166803, 31436123, 31735621, 31759121, - 32091781, 32095057, 32168117, 32285041, 32497921, 32676481, 33146717, 33298337, 33600533, 33627301, - 33704101, 33872593, 34003061, 34043101, 34124641, 34540801, 34856167, 34944001, 35576599, 35703361, - 35820937, 35851037, 36291193, 36307981, 36861901, 36919681, 36974341, 37109467, 37376509, 37439201, - 37964809, 37988497, 38010307, 38046817, 38118763, 38210323, 39465091, 39512773, 39655153, 39684157, - 40165093, 40238797, 40315441, 40361197, 40629601, 40782589, 40827473, 40987201, 41121433, 41568101, - 41604109, 41642681, 41662297, 41840809, 42009217, 42485119, 42623017, 42984589, 43224397, 43363601, - 43661257, 44070841, 44314129, 44465221, 44482901, 45100177, 45175201, 45219329, 45414433, 45819541, - 45879941, 46094401, 46325029, 46386589, 46469809, 46517857, 46679761, 46860001, 47220367, 47903701, - 47918581, 48064021, 48191653, 48269761, 48316969, 48400753, 48448661, 48551161, 48563089, 49075417, - 49303801, 49411801, 49459801, 50155733, 50201089, 50443201, 50523661, 51030601, 51129781, 51302353, - 51500521, 52072021, 52119289, 52204237, 53283169, 53399449, 53656021, 53675623, 53695721, 53711113, - 54029741, 54449431, 55109401, 55176097, 55318957, 55729957, 56052361, 56420033, 56479897, 56810137, - 57762433, 58003213, 58422409, 58449847, 58509977, 58679941, 58755877, 59631211, 59840537, 59913157, - 59953741, 60155201, 60352921, 60547831, 60566431, 60581401, 60696661, 60738257, 60957361, 61201009, - 61219789, 61377109, 61832377, 62756641, 63001801, 63002501, 63065281, 63167743, 63318169, 63328469, - 63346999, 63388033, 64148717, 64605041, 64735897, 65144501, 65254393, 65301013, 65350801, 65359477, - 66096253, 67194401, 67642513, 67928221, 68102641, 68154001, 68165761, 68512867, 68621701, 68839597, - 69030901, 69128641, 69176647, 69228967, 69231061, 69485281, 69612061, 69885649, 70149631, 70463489, - 70593931, 70728121, 71079661, 71734417, 72498253, 72543547, 73562833, 73645001, 74411131, 74927161, - 75140137, 75565873, 76725091, 76745101, 77533123, 77648941, 77812153, 77817979, 78939089, 79398901, - 79411201, 79417801, 79464533, 79786523, 80142761, 80146909, 80375707, 80556337, 80687881, 80891009, - 81433591, 81954133, 82273201, 82506439, 82870517, 82929001, 83083001, 83103329, 83204801, 84164033, - 84350561, 84421081, 84487457, 84998503, 85328717, 85519337, 85823401, 86027329, 86438857, 86530621, - 86999837, 87499651, 87694261, 88256449, 88368853, 88661861, 89308771, 89784581, 90270613, 90278161, - 90341197, 90665789, 90698401, 91433281, 91659283, 92438581, 92625121, 93431521, 93541537, 93571633, - 93643201, 93677761, 93926197, 94316401, 94502701, 95451361, 95452781, 96135601, 96618397, 96791881, - 96888641, 96895441, 96904081, 96925921, 97255801, 97496449, 97796953, 97863529, 97924217, 99036001, - 99115297, 99486889, 99789673, 99898801, 100463443, 100618933, 100943201, 101152133, 101218921, 101270251, - 101276579, 101649241, 102004421, 102678031, 102690677, 102690901, 103301633, 104078857, 104524421, 104988673, - 105305443, 105919633, 106485121, 106622353, 106743073, 107360641, 107543333, 108596953, 109231229, 109437751, - 109541461, 109879837, 110135821, 110139499, 110312773, 110413333, 110717861, 111370141, 111654401, 112032001, - 112402981, 112828801, 113589601, 113605201, 113730481, 113892589, 114305441, 114329881, 114701341, 114842677, - 114910489, 115039081, 115174681, 115497901, 115804501, 115873801, 116090081, 116321617, 116617289, 116682721, - 116696161, 116998669, 117987841, 118466401, 118901521, 119092801, 119204809, 119261113, 119327041, 119558011, - 119743537, 119940853, 120296677, 120517021, 120838609, 121062001, 121374241, 121472359, 121609489, 122166307, - 122396737, 122941981, 123481777, 123671671, 123877081, 123987793, 124145473, 124630273, 124818601, 125284141, - 125686241, 125848577, 126132553, 127050067, 128079409, 128124151, 128396921, 128468957, 128665319, 128987429, - 129205781, 129256273, 129357061, 129461617, 129524669, 130556329, 130693393, 130944133, 131023201, 131567929, - 131938561, 132332201, 132338881, 132440521, 132575071, 133216381, 133302781, 133467517, 133800661, 134696801, - 134767153, 134868029, 135263269, 135296053, 135308881, 135945853, 135969401, 136043641, 136661201, 136722433, - 137415821, 137763037, 138030721, 138403981, 138828821, 139295701, 139487041, 140197051, 142525333, 142922413, - 143106133, 143168581, 145348529, 146156617, 146272901, 146659801, 146843929, 146884393, 147028001, 147287141, - 148109473, 148171769, 148910653, 149389633, 150379693, 150960239, 150988753, 151533377, 151589881, 152716537, - 152922001, 152991841, 153369061, 153589801, 153754873, 153928133, 154287451, 154513633, 154944533, 155203361, - 156114061, 156532799, 157069189, 157368661, 157405249, 157725829, 158068153, 158192317, 158397247, 158496911, - 158544401, 158895281, 160348189, 160378861, 160491329, 160587841, 160672201, 160730389, 161184013, 161216021, - 161289649, 161304001, 161423377, 162026869, 162067441, 162690481, 162771337, 162776041, 163442551, 163954561, - 164111281, 165061909, 165224321, 165938653, 166082309, 166339057, 166406561, 166827943, 167579497, 167582377, - 167692141, 167881121, 168566501, 169655641, 170640961, 170782921, 170856533, 171454321, 172116181, 172436713, - 172947529, 173401621, 174479729, 176030977, 176597821, 176609441, 176977921, 177167233, 177254533, 177693521, - 177927641, 177951973, 178837201, 178956971, 179083601, 179285137, 179820257, 180115489, 180497633, 180703451, - 181285001, 181285537, 181542601, 181647497, 182383111, 183677341, 184411567, 185653333, 186183469, 186393481, - 186983521, 187050529, 187667969, 187761241, 188516329, 188985961, 189714193, 189738361, 189941761, 190212181, - 190382161, 190913297, 191233813, 191648161, 191981609, 192346153, 192857761, 193330237, 193638337, 193949641, - 194556451, 196035001, 196049701, 196231393, 198982759, 199674721, 200143351, 200753281, 201261061, 202130197, - 202156813, 202538857, 203505697, 204280501, 204582457, 204766381, 205057561, 206304961, 206453509, 206504033, - 206529737, 207008569, 207030541, 207132481, 207477001, 207618781, 208051201, 208969223, 209246701, 209404369, - 209990881, 210592873, 210842113, 213035761, 214038533, 214110541, 214852609, 214858717, 215436241, 216821881, - 217123069, 217875571, 218603617, 218642029, 218947121, 219621781, 220531501, 220883521, 221368153, 221415781, - 221884001, 222010721, 222630193, 223449463, 223625851, 223782263, 224074369, 224136013, 224769241, 224957893, - 225853633, 226359547, 226450297, 227132641, 227444101, 227475481, 228652201, 228842209, 228988033, 229589413, - 230357761, 231383461, 231405701, 231927781, 232114433, 232460821, 232771501, 233110081, 234869009, 235426913, - 235928071, 237791143, 238001653, 238833421, 240068041, 240371713, 240694513, 240785047, 241505377, 242067841, - 242650717, 242860069, 243583201, 243955141, 244883981, 245006623, 245950561, 246099317, 246282511, 246434761, - 246658441, 247318957, 247321301, 247416101, 249582481, 250436033, 250958401, 250988173, 251528401, 251663837, - 251855893, 252853921, 253610281, 253893397, 255416897, 256831433, 257590661, 258020473, 258043229, 258234401, - 258944401, 259763093, 259765747, 260156101, 260518801, 260736341, 260963389, 261186001, 261703417, 262979501, - 263428181, 264269449, 264384469, 265020001, 265584133, 265735969, 265836161, 266790481, 266925601, 270525737, - 271272569, 271763467, 271826629, 271950829, 273361789, 273480637, 274701913, 274810241, 274919401, 275283401, - 275619961, 276018913, 276131137, 276542401, 276638321, 277787141, 278943061, 279377281, 280885153, 282253141, - 282471853, 282769771, 283900961, 284166877, 284301751, 284736091, 284834299, 285820501, 286316801, 287160301, - 287449091, 287715121, 288099001, 288117721, 288735277, 290643601, 290706781, 290953921, 291088513, 291461633, - 292153681, 292290181, 292433321, 292902481, 293346637, 293847721, 293938261, 295419097, 295743017, 297624961, - 297798961, 298212601, 299367877, 299736181, 301413001, 302635351, 304080001, 307629401, 307694323, 307972801, - 308483209, 309666361, 310474249, 310978027, 311177213, 311411629, 311655829, 311671361, 312408113, 312614021, - 314184487, 315034513, 315351521, 317137969, 317365933, 317641171, 317796119, 319053281, 319374577, 319440769, - 319726177, 320326003, 321324589, 321850849, 322469701, 322941881, 324477697, 325028089, 325352101, 325546873, - 326266051, 326405713, 326469137, 326628721, 326694301, 326695141, 327073601, 327093409, 327398009, 328302901, - 329153653, 329769721, 330198331, 330759617, 331658081, 331934989, 337135501, 337420679, 337665901, 337783981, - 338125537, 338458807, 338914369, 339195097, 339492169, 339794641, 341958121, 341994131, 343017529, 343052833, - 344201441, 344255551, 344776301, 346080391, 348989101, 349752913, 350031973, 350244577, 351058753, 351177769, - 352802803, 352932337, 353815801, 353932801, 354062809, 356604421, 356836819, 357348601, 357872971, 358416577, - 359394751, 359727073, 360145633, 360375181, 360787771, 361307521, 361312337, 362569201, 363170837, 363430637, - 364550761, 365077373, 365231401, 366487201, 366532321, 366652201, 367559501, 367632301, 368016949, 368476501, - 369667561, 371011801, 371611153, 372167101, 373012777, 373533617, 373669453, 373906513, 374346361, 374988661, - 376957153, 377192353, 377334497, 377458849, 377806687, 377869031, 378792649, 379732501, 380137633, 382304161, - 384100001, 385175113, 385319089, 387072661, 388695301, 390609941, 390612221, 391014937, 392679737, 393611653, - 394723177, 396864469, 399156661, 399302581, 399647221, 400385701, 400557109, 401100881, 403095967, 403293313, - 405739681, 405782623, 407737201, 407889161, 409302001, 409458241, 410613809, 410680357, 411618241, 411851389, - 412836689, 413138881, 413429801, 413778817, 414216461, 414368641, 415200361, 415204501, 415476343, 416964241, - 417767201, 417779909, 418044563, 418226581, 418616161, 418617281, 418667401, 419184481, 420607441, 421942951, - 422429041, 422928101, 423384001, 423465001, 424175761, 424411501, 424431541, 425967301, 426174101, 426219649, - 426770437, 426783811, 427294141, 428180191, 428758201, 429135841, 429509837, 430046857, 430381921, 430646401, - 430733701, 432227449, 434042801, 435016187, 435358657, 435993301, 436465501, 437247841, 437462101, 437597101, - 437866087, 439309261, 441354497, 441650591, 441758461, 442050577, 442181291, 442543553, 444660421, 445429693, - 446414621, 446619617, 449501761, 450807481, 450866021, 450872573, 452990401, 453366029, 453967739, 454745773, - 455198563, 457274161, 457320533, 459785089, 460251733, 460585861, 461151121, 461272267, 461329601, 462587329, - 462639409, 462701513, 464012033, 464955857, 465505633, 466290949, 466758181, 467100937, 468410113, 468950021, - 470120257, 470268137, 470644021, 471535373, 471664513, 472814413, 473581057, 474892741, 474970501, 474983881, - 475723849, 478614067, 479962009, 480668347, 481153501, 481239361, 482488393, 482824669, 482921297, 483006889, - 483029821, 483945601, 484200289, 486063001, 486902929, 487896601, 488104681, 488169289, 488585521, 488656981, - 489994201, 490950461, 491738801, 493108481, 494288677, 495909871, 496109729, 496560349, 497148599, 497285713, - 498662561, 498706651, 498905189, 500747293, 501172241, 501472333, 502686713, 504870241, 505473263, 505532773, - 505798213, 506349421, 507142567, 507323521, 508606771, 509302873, 509551201, 510925609, 511098521, 511215521, - 511611673, 512330281, 514738981, 516045197, 516259657, 516764063, 517662001, 518216201, 518548801, 521501473, - 522390109, 522758233, 523756711, 526067821, 526359289, 526686889, 528013333, 528043753, 528220117, 530630701, - 531095029, 531681281, 532126801, 532758241, 532800133, 533429881, 534782293, 535252867, 535428577, 535517581, - 536003333, 536114197, 536342419, 536870911, 540207097, 540621181, 540654409, 540680141, 542497201, 542536457, - 544861633, 545550433, 545622401, 546102481, 546117301, 546322201, 548080513, 548989561, 549308761, 550132741, - 550230409, 550635373, 550853137, 551313001, 552573793, 553027201, 554487121, 554599051, 554964001, 555321007, - 555465601, 556001377, 556069849, 556095433, 556114609, 557165209, 558235109, 558900821, 558977761, 561448487, - 562367821, 563298061, 563947141, 564298489, 564689381, 565664761, 565707061, 567358513, 567596401, 568902001, - 568967221, 569332177, 569495809, 570941881, 572123521, 572228929, 572430769, 572567353, 572936869, 573817861, - 573862021, 574998841, 575326033, 576724219, 577210181, 577352641, 577613261, 579606301, 579956653, 581618143, - 582389641, 582799951, 585261637, 586706821, 587343541, 588049001, 591242653, 591822001, 592467451, 592468777, - 593682169, 593728489, 595405201, 595590841, 597537361, 597717121, 599135767, 599945293, 600893921, 601606487, - 602379181, 604584221, 605454917, 605961049, 606872449, 607148653, 607750681, 608421637, 608917753, 609361567, - 609813781, 611097401, 611374453, 611770513, 611812321, 611817421, 612006253, 613849601, 614742241, 615361183, - 615760133, 615895897, 616280897, 617087701, 619239457, 619365121, 619480601, 620169409, 620544961, 620755537, - 621769669, 622137601, 623735953, 624303241, 624732421, 625060801, 625482001, 626717471, 627886657, 628868467, - 629134081, 630496621, 630622753, 630811513, 631767943, 631974613, 633289807, 635155291, 635291077, 635319361, - 636287653, 636337073, 636936697, 638502913, 638837761, 639305921, 639807781, 640650931, 640977373, 643036321, - 643316461, 643552909, 644004817, 644453633, 644457551, 644731357, 644900257, 645556481, 648056449, 648328801, - 651011329, 651064681, 651151801, 651514753, 652469641, 653235841, 653260633, 655264369, 657732349, 659526601, - 659846021, 660095641, 660754117, 661122881, 661207177, 662134201, 663760681, 665462081, 668498321, 670976641, - 670987021, 671716921, 672103001, 672108193, 673778827, 675260477, 676359391, 678481693, 680983817, 681019921, - 681124207, 681303241, 682528687, 683316001, 683362681, 684350833, 686059921, 687741401, 689537441, 690035713, - 690562601, 691131349, 692535637, 693456521, 694116893, 696042901, 696321949, 696998251, 697821857, 698192041, - 698819711, 702683101, 705303457, 705351583, 706728377, 707691601, 709409993, 710382401, 710617861, 710721001, - 714490481, 717096641, 717653129, 717831211, 720767521, 722955773, 724160251, 724969087, 725508241, 731276521, - 732805681, 734166217, 736668013, 739444021, 739576801, 740988151, 741182401, 741214237, 742017181, 742550401, - 744500641, 745493761, 745745461, 746331041, 747406801, 748638001, 749172821, 749640161, 750632137, 751226401, - 751705597, 752186593, 753233717, 753574537, 753594001, 754020361, 754874257, 756205633, 756271909, 756980137, - 758581651, 758687581, 758901701, 759252367, 759266621, 759638881, 762699649, 763907741, 764033999, 764240611, - 765378241, 766303693, 766823797, 770201221, 770909107, 770937931, 771043201, 771337891, 772495777, 773131927, - 773807401, 775368901, 775896181, 776443769, 777218989, 781471001, 782823281, 784450393, 784777393, 784783477, - 784966297, 787085857, 787209277, 788046901, 788931361, 789082001, 790453049, 791118043, 792144161, 792145729, - 794201333, 794399041, 794937601, 795064909, 796072003, 796200901, 796560703, 797418997, 797834017, 799162561, - 799630753, 799898833, 799916101, 801093011, 801227269, 801866647, 804978721, 805505957, 805771501, 807115753, - 807218413, 808214161, 809790881, 810023881, 810455101, 811110301, 811478533, 811607777, 811730923, 815430533, - 815796413, 816024161, 816215401, 816549121, 817832329, 818401321, 819466201, 819743233, 822018961, 822531841, - 824389441, 826004467, 829512001, 830664451, 831933901, 832048447, 832127489, 832169857, 833610751, 837766217, - 839268139, 839280691, 839908217, 840749761, 841217653, 841660961, 842785841, 842824981, 842960981, 843161887, - 844545271, 845376533, 846961321, 848090377, 848755969, 849548671, 852432769, 854094781, 854868257, 855734401, - 857100421, 857902861, 858687103, 859096477, 860334301, 862082677, 862678081, 863196181, 863609113, 863984881, - 865242841, 867022747, 867110501, 867638201, 868088341, 868111597, 868691401, 870985223, 871157233, 871195561, - 871908481, 876850801, 877542481, 878492941, 878940833, 879995689, 880870513, 880922657, 883276549, 884304037, - 884952001, 886180429, 887795221, 888868441, 892740853, 893692819, 894264337, 896901461, 897087361, 897283213, - 899019353, 900736411, 901848301, 902566501, 903108821, 903390643, 905040953, 907378669, 907670501, 907711561, - 908005249, 910202509, 910867481, 911484421, 914348737, 914906539, 920375821, 920696653, 921858631, 922845241, - 923437213, 926756881, 927106561, 927877001, 929159941, 930530701, 932148253, 933729421, 935794081, 936421141, - 937675393, 938376181, 939947009, 940123801, 941056273, 941734657, 943271569, 944832533, 946034057, 946787377, - 947878081, 949317217, 949697233, 952893881, 954924013, 957600541, 957631249, 958131157, 958735681, 960269377, - 960946321, 962442001, 962489557, 962523169, 964412837, 965501857, 967266451, 967287751, 967790401, 968283247, - 968413217, 968751241, 969528337, 970586713, 971975071, 974113601, 974471243, 974774401, 975576281, 976396961, - 977483449, 979363153, 980056507, 980725201, 981484561, 983456377, 984133441, 984252001, 985052881, 985075681, - 987842101, 994133479, 995586373, 995650921, 997836841, 998489017, 998590601, 998596741, 998724481, 999828727, - 1002261781, 1003062061, 1005402133, 1005833971, 1006800829, 1008777001, 1008839999, 1009025263, 1009140161, 1011319501, - 1011333061, 1011570457, 1011909271, 1012438391, 1013833153, 1015339441, 1015626151, 1017748057, 1020515761, 1021281301, - 1022336611, 1024041853, 1024123501, 1024605121, 1025035129, 1026738161, 1027744453, 1028494429, 1034252929, 1034958601, - 1040234231, 1049584313, 1050102901, 1050535501, 1054999441, 1055009117, 1056121453, 1057426651, 1063212481, 1065508321, - 1065602281, 1066972301, 1069388497, 1070639389, 1070941987, 1071512749, 1071643249, 1072898711, 1073159281, 1073288581, - 1073484823, 1075100041, 1077133397, 1078467589, 1081798061, 1082472553, 1084241341, 1084444481, 1090858081, 1093150081, - 1093352833, 1093526353, 1094042321, 1097416321, 1098743563, 1100624857, 1101623381, 1101673501, 1102573501, 1102750013, - 1104194521, 1105038871, 1106529761, 1106580817, 1106595493, 1107138961, 1108135381, 1109304913, 1110582947, 1111205873, - 1111939201, 1112671603, 1114277221, 1116379301, 1117202557, 1117785881, 1117828001, 1117890019, 1119412321, 1120076281, - 1120981021, 1121176981, 1123406047, 1123625501, 1123727617, 1124396521, 1125038377, 1127040769, 1130933429, 1134367777, - 1138289041, 1138607233, 1139137057, 1140573601, 1142466151, 1147434289, 1148578201, 1150229761, 1151670001, 1153164097, - 1153440289, 1154343961, 1154691409, 1154987209, 1155939709, 1156761911, 1156993373, 1157839381, 1159421509, 1160844821, - 1163098249, 1163227759, 1164218641, 1165717129, 1166475601, 1166598217, 1168221121, 1168256953, 1168492417, 1173229201, - 1173545533, 1174300093, 1180970407, 1181566219, 1183338241, 1184554801, 1186325981, 1187235193, 1191153937, 1191216133, - 1192314817, 1192412033, 1192903531, 1193229577, 1193557093, 1195524181, 1196852273, 1198650961, 1198880261, 1200456577, - 1200778753, 1202142061, 1204205449, 1205606533, 1205772499, 1209998077, 1210393801, 1210562701, 1210653541, 1213619761, - 1217181061, 1217823517, 1217924159, 1219816261, 1219858921, 1220114377, 1221127013, 1222861271, 1223531677, 1223941657, - 1225128829, 1226230297, 1226855293, 1227220801, 1229491063, 1229751667, 1230446653, 1231362793, 1232445677, 1234125721, - 1234646533, 1235188597, 1235864033, 1236313501, 1236442421, 1238825569, 1242171349, 1242858317, 1249166881, 1249785941, - 1250656621, 1252236421, 1254277909, 1255665613, 1257102001, 1258903981, 1260332137, 1263293281, 1264145401, 1265477791, - 1266003461, 1266273793, 1266425101, 1267345081, 1269295201, 1269835201, 1270193401, 1270489621, 1270667353, 1272558739, - 1272866167, 1282447477, 1282568741, 1285636801, 1286298133, 1286298263, 1296613501, 1297443913, 1299072721, 1299784141, - 1299963601, 1301509249, 1301926081, 1302745481, 1306836001, 1307004641, 1307520469, 1307823661, 1308758533, 1308998741, - 1309723213, 1309983901, 1310329567, 1311255661, 1311616153, 1312332001, 1312573123, 1313396221, 1315858381, 1316169541, - 1318126321, 1318717531, 1319978701, 1319992181, 1320793813, 1321058213, 1323668917, 1325172421, 1325329297, 1328256247, - 1329174601, 1329431689, 1331973329, 1341010577, 1341926401, 1343575381, 1344597577, 1344975721, 1345514101, 1345523401, - 1347387361, 1348964401, 1350685001, 1351126261, 1352453257, 1353051517, 1356241321, 1356328121, 1357459183, 1362463807, - 1362515701, 1362742561, 1365662917, 1366587661, 1366608377, 1368769681, 1371908137, 1372681861, 1375322101, 1376799577, - 1378646179, 1379464633, 1382453333, 1383283129, 1385656829, 1386705433, 1388972353, 1389353941, 1389975149, 1391890033, - 1393851553, 1394640941, 1394746081, 1394942473, 1397357851, 1398883201, 1400859847, 1401840833, 1404008369, 1404253369, - 1406826241, 1406851249, 1409372779, 1413803197, 1414154827, 1414529533, 1415969101, 1417986901, 1421475031, 1424503849, - 1425860101, 1426319563, 1426534201, 1427771089, 1428966001, 1432354901, 1435091377, 1438648993, 1440231941, 1440922891, - 1441139641, 1441678411, 1442945689, 1443388481, 1443742273, 1446298309, 1446434677, 1446818651, 1448921633, 1451635201, - 1454282449, 1454445413, 1456527461, 1457378449, 1461307717, 1463065501, 1463178817, 1463992661, 1464568381, 1465908193, - 1465945417, 1468540477, 1468824787, 1469059481, 1469960377, 1470080501, 1470650851, 1471628401, 1472221921, 1473580001, - 1477289941, 1481626513, 1482274513, 1482876673, 1483873861, 1483918801, 1485061471, 1486564301, 1493114149, 1495190699, - 1497221281, 1497965713, 1499971457, 1499989177, 1500142001, 1501165097, 1502171117, 1502403121, 1503240559, 1503705601, - 1504139521, 1504832033, 1507746241, 1509156013, 1510870241, 1511558533, 1515175087, 1515785041, 1517039371, 1518014689, - 1518290707, 1520190341, 1521221473, 1522302121, 1526732803, 1529648231, 1529819971, 1530495289, 1532419099, 1532569681, - 1532755369, 1533343261, 1534063081, 1535020133, 1536112001, 1536251047, 1536883357, 1537433899, 1537641691, 1538012449, - 1539583921, 1539804001, 1540454761, 1540550413, 1541047813, 1541849761, 1541955409, 1544145121, 1545019813, 1545177581, - 1546106773, 1546340401, 1546508057, 1547140841, 1547543161, 1547712601, 1550924873, 1554270481, 1557118081, 1560312001, - 1560620041, 1561800833, 1565893201, 1566594551, 1567830241, 1568916311, 1574362441, 1574601601, 1577983489, 1578009401, - 1580449201, 1581576641, 1581714481, 1582783777, 1583230241, 1583658649, 1586436193, 1587650401, 1590394313, 1593706201, - 1595647351, 1595887921, 1598197201, 1602517949, 1603765021, 1603810561, 1603994701, 1609916491, 1609935913, 1612121473, - 1614508267, 1617795181, 1617921667, 1619447741, 1620646177, 1627103521, 1627898401, 1628692201, 1630062253, 1630307617, - 1631314609, 1632286673, 1632513601, 1633044241, 1636185601, 1637434657, 1637436457, 1637930893, 1638294661, 1639351981, - 1639846391, 1641971701, 1642814653, 1644637051, 1645413001, 1647225529, 1648076041, 1649430889, 1650265549, 1650682153, - 1654940509, 1655660761, 1656229921, 1656280033, 1656917377, 1659009601, 1661202113, 1668037621, 1668926629, 1669893661, - 1671603667, 1671714241, 1672125131, 1674091141, 1674658133, 1675978193, 1678274581, 1679130641, 1680901381, 1683174533, - 1685433413, 1686001861, 1687248001, 1691745821, 1692605041, 1694128129, 1695158921, 1696893101, 1698707377, 1699279441, - 1700250049, 1709909293, 1710753001, 1712392321, 1714322377, 1716160321, 1716714793, 1716774481, 1718013133, 1718088301, - 1719197621, 1721061497, 1721986313, 1722007169, 1722685777, 1725675451, 1726372441, 1731048937, 1731995497, 1732924001, - 1734059291, 1734285601, 1735071913, 1736481601, 1738687469, 1740214841, 1742288881, 1742815621, 1743166441, 1744605097, - 1746692641, 1746721681, 1749124829, 1750412161, 1754818561, 1757148121, 1760014561, 1766984389, 1767234613, 1769091241, - 1769267761, 1770236893, 1771303801, 1772267281, 1773582977, 1776439261, 1776820033, 1779649381, 1779892577, 1784306273, - 1784638309, 1785843547, 1786005521, 1787934881, 1790023861, 1791426787, 1792442737, 1792588813, 1794814103, 1801558201, - 1801774081, 1802510669, 1803768091, 1804906517, 1805947313, 1809888967, 1816408273, 1817067169, 1819829749, 1820306953, - 1821514633, 1828682101, 1828887061, 1831258601, 1835114401, 1837156049, 1837599769, 1839568981, 1841034961, 1841099261, - 1841479501, 1844028961, 1846171781, 1847811673, 1849964117, 1850233897, 1850598961, 1852496761, 1853926777, 1854084649, - 1854940231, 1856689453, 1857221281, 1858098497, 1858197961, 1860373241, 1861026133, 1861880689, 1862880401, 1866409861, - 1867906721, 1868682241, 1871987041, 1872937057, 1873177693, 1874634721, 1874849929, 1878691753, 1879111697, 1879623157, - 1879775501, 1883509633, 1883785681, 1885915841, 1894909141, 1894955311, 1897700113, 1899081757, 1899525601, 1900687381, - 1903447841, 1904658913, 1905958891, 1908088001, 1909566073, 1910134309, 1911197947, 1912950241, 1914303841, 1915391521, - 1916987593, 1917397637, 1920301951, 1921309633, 1922092567, 1922687293, 1923224689, 1923311317, 1923845801, 1924201501, - 1925042737, 1928903971, 1929862849, 1930403333, 1930447501, 1930534453, 1930915169, 1934350351, 1938264241, 1940048881, - 1943951041, 1944125633, 1945042181, 1950987193, 1952513369, 1952968753, 1957705177, 1959659857, 1960708261, 1963149553, - 1965007601, 1968002149, 1970065681, 1974474049, 1977257441, 1982123893, 1982826961, 1988071801, 1988713189, 1988835713, - 1988965861, 1989192277, 1991063449, 1995784961, 1995830761, 1996231189, 1996339649, 1997844157, 1998780001, 1999053601, - 1999111801, 1999743661, 2004299641, 2007646961, 2013554869, 2013834961, 2016481477, 2017021333, 2017509601, 2019564769, - 2021392369, 2021884343, 2027675701, 2028279793, 2028631361, 2028812399, 2029830409, 2030600833, 2036224321, 2043173273, - 2049293401, 2050617713, 2052149221, 2054711381, 2055634561, 2057267941, 2057835781, 2058072041, 2059739221, 2062612033, - 2068867841, 2070739441, 2072624761, 2076192007, 2081039297, 2081551753, 2082146617, 2083034113, 2083997441, 2085453649, - 2085882661, 2086645009, 2093300401, 2095627153, 2096046457, 2097317377, 2100292841, 2101470541, 2101744837, 2104994449, - 2106147457, 2107148761, 2114643217, 2115769633, 2115986557, 2116483027, 2116541221, 2117031263, 2117555641, 2118621097, - 2120096161, 2123601751, 2124078653, 2124691213, 2127197489, 2128104001, 2129304997, 2130134533, 2131004737, 2131811501, - 2140699681, 2140771609, 2141340833, 2144961253, 2147418113, 2147429509, 2152627801, 2154446641, 2155416251, 2156151313, - 2164282177, 2168431201, 2170282969, 2172155819, 2173499329, 2173540951, 2173579801, 2175126601, 2175406201, 2175646177, - 2177374321, 2177645557, 2178082901, 2178939221, 2180221201, 2182281601, 2182802689, 2185362233, 2187717761, 2193980881, - 2199617701, 2200115713, 2201924341, 2202101761, 2202205897, 2203649197, 2203856497, 2206095589, 2210578759, 2213431729, - 2216960929, 2217879901, 2219072017, 2224252801, 2229468697, 2231332357, 2233031701, 2240507821, 2241880033, 2241982009, - 2244932281, 2245519981, 2246762899, 2248354153, 2251732033, 2254314241, 2254757077, 2256197761, 2256748777, 2256751837, - 2262861901, 2269307587, 2274584089, 2283289681, 2284416181, 2289251669, 2289624793, 2290316377, 2290910257, 2291205461, - 2292068143, 2295209281, 2296995121, 2299190401, 2300628601, 2300795353, 2301745249, 2304120001, 2308966661, 2309241601, - 2309405617, 2311558021, 2311575001, 2315137261, 2320527613, 2323147201, 2324867399, 2329584217, 2330569541, 2331181621, - 2335341601, 2338157597, 2338728001, 2340460487, 2345907961, 2347597981, 2352371251, 2354453561, 2355230749, 2355320101, - 2355622721, 2355649921, 2355735089, 2358534361, 2360261989, 2370771181, 2370928337, 2371350101, 2372976563, 2374232977, - 2375415841, 2377166401, 2378309041, 2381782597, 2382678101, 2383164577, 2385574201, 2389072321, 2389544977, 2393708761, - 2394311233, 2398393661, 2404912501, 2411128441, 2412172153, 2412675721, 2413973071, 2422296241, 2423401681, 2425249601, - 2428648967, 2428870753, 2428986913, 2429407961, 2430697513, 2431136401, 2431144801, 2432761633, 2432860273, 2433791593, - 2434964321, 2434974433, 2435091221, 2436691321, 2437907779, 2438778413, 2442050353, 2442454561, 2443708961, 2444950561, - 2448039497, 2448374689, 2453473049, 2454285751, 2456536681, 2457846161, 2463713281, 2471205361, 2473120961, 2473189441, - 2473823353, 2474308069, 2474676949, 2476283239, 2477814193, 2478643907, 2480147521, 2480343553, 2482435981, 2482682131, - 2484408301, 2486017249, 2488420801, 2488591117, 2492480233, 2494660033, 2494984321, 2495834329, 2499327041, 2501012599, - 2501771329, 2502525637, 2504008609, 2506529257, 2506733189, 2507121037, 2508178843, 2513230891, 2516684801, 2519297089, - 2525070241, 2526566041, 2528291341, 2529410281, 2529827821, 2529854713, 2530351561, 2532630787, 2533465661, 2533797017, - 2535516173, 2537105761, 2539406281, 2539736257, 2540469901, 2541660367, 2542479481, 2544590161, 2545934077, 2548051801, - 2550139253, 2550780277, 2551365769, 2552418761, 2553272929, 2555391481, 2561945401, 2564536201, 2565186137, 2570087521, - 2571180247, 2575060949, 2575737361, 2577345541, 2582092189, 2582246701, 2582952769, 2583322381, 2584460701, 2588054401, - 2588582089, 2590663681, 2593065721, 2595276353, 2597289241, 2597294701, 2598933481, 2600611861, 2602343521, 2602378721, - 2604465013, 2604803701, 2611122229, 2611461529, 2613382201, 2614688801, 2616180821, 2617563031, 2621080741, 2621977627, - 2622993661, 2624549929, 2625903601, 2626783921, 2627284987, 2630643401, 2632605049, 2634284801, 2634804481, 2634820813, - 2638067881, 2639099233, 2642159809, 2642582251, 2646751249, 2646790033, 2648662777, 2649907201, 2650820329, 2651507713, - 2654716321, 2656494271, 2658630913, 2658696301, 2659265701, 2668095181, 2668469431, 2670972949, 2672605657, 2672651521, - 2676053333, 2677147201, 2677821121, 2678785621, 2681041843, 2682823681, 2683742491, 2684284441, 2687655169, 2688124001, - 2689427281, 2690408533, 2690867401, 2693739751, 2695115473, 2700818017, 2700891839, 2701878941, 2704957909, 2706863833, - 2707661501, 2716157989, 2716275007, 2717428033, 2719319513, 2721666817, 2721721939, 2723859001, 2725357249, 2733156029, - 2736316301, 2738184697, 2740336561, 2744329909, 2746021741, 2753333227, 2753538001, 2759392633, 2765323397, 2766006253, - 2767672189, 2769080161, 2769602333, 2774295577, 2777887297, 2778304273, 2779477741, 2781117721, 2781226477, 2786028337, - 2787998641, 2789218909, 2800352011, 2805762961, 2809635901, 2812672981, 2814748201, 2823570433, 2824256377, 2824804693, - 2824854913, 2828205397, 2832384133, 2832743713, 2837697773, 2837917633, 2840634109, 2840871041, 2841190381, 2847894377, - 2848466281, 2848722131, 2855046421, 2855071801, 2855512909, 2862066481, 2865483601, 2866005139, 2866527841, 2870377309, - 2871536561, 2872527733, 2872948321, 2874382853, 2877769501, 2881429741, 2882370481, 2885594497, 2887955533, 2890316801, - 2890414873, 2892426029, 2894667781, 2895004927, 2899294889, 2903776129, 2915953633, 2916247819, 2918295451, 2920691161, - 2923042141, 2924158001, 2929062533, 2929106753, 2930831641, 2931708097, 2932327549, 2936227603, 2936958181, 2941174897, - 2941343633, 2944555681, 2944677961, 2945208001, 2945549881, 2951136343, 2956724317, 2957320351, 2965700233, 2967053953, - 2968206601, 2974506841, 2975377429, 2976930001, 2978766341, 2980689601, 2986025677, 2987414977, 2990152901, 2993462713, - 2993495041, 2994098281, 2994415201, 2998202353, 2998919873, 3000688381, 3001561441, 3002647829, 3004443679, 3009628301, - 3011421841, 3014101261, 3015502181, 3016957381, 3017444761, 3018147217, 3018576689, 3019916461, 3025350343, 3026575553, - 3028586471, 3030393901, 3033332641, 3034402681, 3034817209, 3035375047, 3036079729, 3037295801, 3037781251, 3038880473, - 3039681457, 3041984353, 3042630533, 3048159841, 3050190163, 3056100623, 3056160929, 3057886591, 3058670677, 3059397793, - 3063685633, 3065998717, 3076505209, 3077122133, 3079496551, 3082054697, 3082068013, 3083053387, 3083537689, 3083884651, - 3088408429, 3089013313, 3091019777, 3094763851, 3099670657, 3103800701, 3112974481, 3114125071, 3115667521, 3120445697, - 3122287981, 3129914881, 3133899409, 3135040133, 3143282221, 3145410761, 3150972917, 3156599161, 3156643141, 3157579861, - 3163106953, 3166504273, 3167442721, 3170262409, 3172658653, 3175204531, 3175255717, 3178375201, 3181356263, 3181391641, - 3182606857, 3182655361, 3182891401, 3185472001, 3187035113, 3187421077, 3187939921, 3196397821, 3196431829, 3197565001, - 3197632441, 3197911001, 3197911741, 3199164901, 3205663921, 3207297773, 3208902491, 3212465437, 3215031751, 3217412881, - 3219808411, 3221580281, 3222693421, 3224143441, 3225081473, 3227082823, 3227209057, 3229131137, 3233558021, 3237992101, - 3242533897, 3248236309, 3250348417, 3250700737, 3252148621, 3257334541, 3258647809, 3258892801, 3261114601, 3263097641, - 3263568901, 3263626957, 3264820001, 3265122451, 3267417677, 3268506541, 3268841941, 3270933121, 3271999249, 3272030401, - 3272702497, 3274264033, 3275671969, 3276075709, 3277047649, 3278640289, 3280067129, 3282974857, 3287174129, 3288757249, - 3295362727, 3296403601, 3299246833, 3302322241, 3304307341, 3305829073, 3306686659, 3306957593, 3310858777, 3312489577, - 3312536569, 3313196881, 3315139717, 3320669437, 3323308501, 3323590463, 3323829169, 3328354801, 3332800021, 3334350781, - 3340214413, 3342005633, 3344191241, 3346172189, 3347908801, 3349218881, 3350993969, 3352091557, 3355382857, 3355953001, - 3357417181, 3359737921, 3360511981, 3369139201, 3371024521, 3371452921, 3371693063, 3372667121, 3373086601, 3381052177, - 3381901921, 3385842877, 3386603221, 3387014401, 3387487351, 3389030261, 3395091311, 3399205591, 3399890413, 3402234749, - 3407609221, 3407772817, 3407952169, 3408135121, 3409339393, 3411250081, 3411574801, 3411829693, 3412575097, 3415379701, - 3415832137, 3417522841, 3420143941, 3421845001, 3423222757, 3423580481, 3427050673, 3428133103, 3429457921, 3429982081, - 3430804297, 3432695921, 3432997537, 3433458073, 3434575327, 3435973837, 3440195713, 3443704261, 3449768513, 3450717901, - 3453900913, 3458257741, 3461861761, 3463907761, 3464236901, 3466158361, 3470716657, 3474335437, 3480174001, 3482161261, - 3485747521, 3489958697, 3491763493, 3492178873, 3492883081, 3493262761, 3497607433, 3504132113, 3512030497, 3512291021, - 3512369857, 3513604657, 3516565057, 3519318721, 3524086333, 3525088961, 3529119361, 3529864391, 3532687201, 3533662129, - 3533856913, 3538213381, 3542303047, 3543203333, 3548378341, 3549286001, 3549988261, 3552158521, 3553567057, 3557646401, - 3562963973, 3563340457, 3566428301, 3574891757, 3582711841, 3583249921, 3583604161, 3584800801, 3586833253, 3587553971, - 3589937261, 3590409439, 3593276353, 3594110081, 3596491907, 3596815169, 3598772761, 3602006101, 3605151241, 3611571121, - 3612298321, 3612825221, 3614770573, 3616574081, 3620631169, 3628526287, 3630596257, 3631828481, 3632452741, 3635993089, - 3649116277, 3649965281, 3650158849, 3651572609, 3656355841, 3658730893, 3662387977, 3662503093, 3663084541, 3668926801, - 3669587533, 3672754633, 3677180797, 3679657997, 3682471321, 3685647701, 3685775741, 3692307161, 3695628133, 3697278427, - 3700801861, 3705582073, 3705623281, 3708123301, 3708905341, 3709626961, 3712887289, 3713287801, 3713448769, 3718226401, - 3721486081, 3723410161, 3723699373, 3725016749, 3727828501, 3729097633, 3733761739, 3736293461, 3745192001, 3746101189, - 3749383681, 3751554581, 3751782737, 3754680403, 3756668401, 3759781369, 3760622689, 3760896133, 3762110881, 3767640601, - 3773061337, 3774337201, 3784123501, 3787491457, 3798040471, 3798626833, 3799111681, 3800084401, 3805699501, 3807112123, - 3807308269, 3807749821, 3809018947, 3813919453, 3817561777, 3817706621, 3821233121, 3827035237, 3832807681, 3833208961, - 3842941741, 3846174151, 3846532801, 3847106803, 3850058689, 3852800033, 3863326897, 3865604023, 3867183937, 3874471147, - 3874523017, 3875096893, 3875965417, 3886515361, 3886643801, 3887423437, 3887635753, 3891892421, 3891919417, 3894053311, - 3896079281, 3897241129, 3897869201, 3898906129, 3900327241, 3903711841, 3905533721, 3905876501, 3907577521, 3907752241, - 3912174421, 3914880337, 3914923211, 3915467341, 3915604421, 3915921241, 3918227437, 3922321561, 3926912669, 3929293061, - 3934940833, 3935864017, 3936123601, 3945165841, 3947233201, 3947383201, 3953408801, 3953949421, 3955572001, 3958597301, - 3958930441, 3959578801, 3960728641, 3962037061, 3966350203, 3967343161, 3971095301, 3973556837, 3979485931, 3982017601, - 3987528793, 3987960913, 3991124341, 3992697997, 3997536427, 4005660961, 4007365741, 4011996871, 4015548769, 4017684529, - 4018283501, 4020144133, 4026822577, 4027012021, 4027518961, 4028465873, 4028771849, 4031223841, 4034969401, 4034993269, - 4035498409, 4036395581, 4042538497, 4044601751, 4044884689, 4048493983, 4053267217, 4054039841, 4057195309, 4058433931, - 4059776533, 4060942381, 4061009971, 4064633821, 4067039461, 4067887501, 4068671881, 4071644893, 4075241633, 4075721921, - 4076009857, 4079665633, 4079682361, 4083376067, 4085074909, 4088147617, 4088838913, 4092929149, 4098258707, 4099180801, - 4100934241, 4103745689, 4105691393, 4108970251, 4109461709, 4109711581, 4110320663, 4113013141, 4115891893, 4117058221, - 4117447441, 4121286907, 4127050621, 4129914673, 4133928761, 4135847101, 4136916001, 4137262541, 4138838401, 4139015987, - 4150174393, 4155375349, 4157008813, 4162880401, 4166032873, 4183664101, 4185636781, 4186561633, 4187360341, 4191864013, - 4192060699, 4195843037, 4196323561, 4204344601, 4206006229, 4206295433, 4212105409, 4215885697, 4218900001, 4220122321, - 4232966251, 4234224601, 4237212061, 4243744201, 4244022301, 4244663651, 4247990917, 4250920459, 4251904273, 4255695013, - 4257003353, 4261352869, 4271267333, 4275011401, 4277526901, 4278305651, 4282867213, 4285148981, 4293088801, 4294901761, - } - - primes16 = [65536]byte{ - 2, 1, 1, 2, 1, 2, 1, 4, 3, 2, // 0-9 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 10-19 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 20-29 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 30-39 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 40-49 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 50-59 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 60-69 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 70-79 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 80-89 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 90-99 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 100-109 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 110-119 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 120-129 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 130-139 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 140-149 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 150-159 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 160-169 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 170-179 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 180-189 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 190-199 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 200-209 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 210-219 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 220-229 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 230-239 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 240-249 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 250-259 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 260-269 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 270-279 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 280-289 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 290-299 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 300-309 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 310-319 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 320-329 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 330-339 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 340-349 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 350-359 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 360-369 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 370-379 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 380-389 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 390-399 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 400-409 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 410-419 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 420-429 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 430-439 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 440-449 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 450-459 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 460-469 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 470-479 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 480-489 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 490-499 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 500-509 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 510-519 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 520-529 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 530-539 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 540-549 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 550-559 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 560-569 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 570-579 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 580-589 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 590-599 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 600-609 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 610-619 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 620-629 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 630-639 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 640-649 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 650-659 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 660-669 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 670-679 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 680-689 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 690-699 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 700-709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 710-719 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 720-729 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 730-739 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 740-749 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 750-759 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 760-769 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 770-779 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 780-789 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 790-799 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 800-809 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 810-819 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 820-829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 830-839 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 840-849 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 850-859 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 860-869 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 870-879 - 1, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 880-889 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 890-899 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 900-909 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 910-919 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 920-929 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 930-939 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 940-949 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 950-959 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 960-969 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 970-979 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 980-989 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 990-999 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 1000-1009 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 1010-1019 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1020-1029 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 1030-1039 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 1040-1049 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1050-1059 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 1060-1069 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 1070-1079 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 1080-1089 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 1090-1099 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 1100-1109 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 1110-1119 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 1120-1129 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 1130-1139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1140-1149 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 1150-1159 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 1160-1169 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1170-1179 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 1180-1189 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 1190-1199 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 1200-1209 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 1210-1219 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 1220-1229 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 1230-1239 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 1240-1249 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 1250-1259 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 1260-1269 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 1270-1279 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 1280-1289 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 1290-1299 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 1300-1309 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 1310-1319 - 1, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 1320-1329 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 1330-1339 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 1340-1349 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1350-1359 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 1360-1369 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 1370-1379 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 1380-1389 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 1390-1399 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 1400-1409 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 1410-1419 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 1420-1429 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 1430-1439 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 1440-1449 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 1450-1459 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1460-1469 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1470-1479 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 1480-1489 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 1490-1499 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1500-1509 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 1510-1519 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 1520-1529 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 1530-1539 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 1540-1549 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 1550-1559 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 1560-1569 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 1570-1579 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 1580-1589 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 1590-1599 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 1600-1609 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 1610-1619 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 1620-1629 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 1630-1639 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 1640-1649 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 1650-1659 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 24, // 1660-1669 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 1670-1679 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 1680-1689 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 1690-1699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 1700-1709 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1710-1719 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 1720-1729 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 1730-1739 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 1740-1749 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 1750-1759 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 1760-1769 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 1770-1779 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 1780-1789 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1790-1799 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1800-1809 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 1810-1819 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 1820-1829 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 1830-1839 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 1840-1849 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1850-1859 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 1860-1869 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 1870-1879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 1880-1889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1890-1899 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 1900-1909 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 1910-1919 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 1920-1929 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 1930-1939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 1940-1949 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 1950-1959 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 1960-1969 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 1970-1979 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 1980-1989 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 1990-1999 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 2000-2009 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 2010-2019 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 2020-2029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 2030-2039 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 2040-2049 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 2050-2059 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 2060-2069 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 2070-2079 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 2080-2089 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 2090-2099 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 2100-2109 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 2110-2119 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 2120-2129 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 2130-2139 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 2140-2149 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 2150-2159 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 2160-2169 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 2170-2179 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 2180-2189 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 2190-2199 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 2200-2209 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 2210-2219 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 2220-2229 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 2230-2239 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 2240-2249 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 2250-2259 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 2260-2269 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 2270-2279 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 2280-2289 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 2290-2299 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 2300-2309 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 2310-2319 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 2320-2329 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 2330-2339 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 2340-2349 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 2350-2359 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 2360-2369 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 2370-2379 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 2380-2389 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 2390-2399 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 2400-2409 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 2410-2419 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 2420-2429 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 2430-2439 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 2440-2449 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 2450-2459 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 2460-2469 - 3, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 2470-2479 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 2480-2489 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 2490-2499 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 2500-2509 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 2510-2519 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 2520-2529 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 2530-2539 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 2540-2549 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 2550-2559 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 2560-2569 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 2570-2579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 2580-2589 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 2590-2599 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 2600-2609 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 2610-2619 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 2620-2629 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 2630-2639 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 2640-2649 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 2650-2659 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 2660-2669 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 2670-2679 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 2680-2689 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 2690-2699 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 2700-2709 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 2710-2719 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 2720-2729 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 2730-2739 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 2740-2749 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 2750-2759 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 2760-2769 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 2770-2779 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 2780-2789 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 2790-2799 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 2800-2809 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 2810-2819 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 2820-2829 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 2830-2839 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 2840-2849 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 2850-2859 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 2860-2869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 2870-2879 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 2880-2889 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 2890-2899 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 2900-2909 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 2910-2919 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 2920-2929 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 2930-2939 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 2940-2949 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 2950-2959 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 2960-2969 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 2970-2979 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 2980-2989 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 2990-2999 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3000-3009 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 3010-3019 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 3020-3029 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 3030-3039 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 3040-3049 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3050-3059 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 3060-3069 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 3070-3079 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 20, // 3080-3089 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 3090-3099 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 3100-3109 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 3110-3119 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 3120-3129 - 7, 6, 5, 4, 3, 2, 1, 26, 25, 24, // 3130-3139 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 3140-3149 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 3150-3159 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 3160-3169 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3170-3179 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 3180-3189 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 3190-3199 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 3200-3209 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 3210-3219 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 3220-3229 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 3230-3239 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3240-3249 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 3250-3259 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3260-3269 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 3270-3279 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 3280-3289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 3290-3299 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 3300-3309 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 3310-3319 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 3320-3329 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 3330-3339 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 3340-3349 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 3350-3359 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3360-3369 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 3370-3379 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 3380-3389 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 3390-3399 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 3400-3409 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 3410-3419 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 3420-3429 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 3430-3439 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 3440-3449 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 3450-3459 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 22, // 3460-3469 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 3470-3479 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3480-3489 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 3490-3499 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3500-3509 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 3510-3519 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 3520-3529 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 3530-3539 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 3540-3549 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 3550-3559 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3560-3569 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3570-3579 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 3580-3589 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 3590-3599 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 3600-3609 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 3610-3619 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 3620-3629 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 3630-3639 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 3640-3649 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 3650-3659 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3660-3669 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 3670-3679 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3680-3689 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 3690-3699 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 3700-3709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 3710-3719 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 3720-3729 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 3730-3739 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 3740-3749 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3750-3759 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 3760-3769 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 3770-3779 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 3780-3789 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 3790-3799 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 3800-3809 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3810-3819 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 3820-3829 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 3830-3839 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 3840-3849 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 3850-3859 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 3860-3869 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 3870-3879 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 3880-3889 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 3890-3899 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 3900-3909 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 3910-3919 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 3920-3929 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 3930-3939 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 3940-3949 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 3950-3959 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 3960-3969 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 3970-3979 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 3980-3989 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 3990-3999 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 4000-4009 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 4010-4019 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 4020-4029 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 4030-4039 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 4040-4049 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 4050-4059 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 4060-4069 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 4070-4079 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4080-4089 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 4090-4099 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4100-4109 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 4110-4119 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 4120-4129 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 4130-4139 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 4140-4149 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 18, // 4150-4159 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 4160-4169 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 4170-4179 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 4180-4189 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4190-4199 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4200-4209 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 4210-4219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 4220-4229 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4230-4239 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 4240-4249 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 4250-4259 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4260-4269 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 4270-4279 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 4280-4289 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 4290-4299 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 4300-4309 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 4310-4319 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 4320-4329 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 4330-4339 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 4340-4349 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 4350-4359 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 4360-4369 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 4370-4379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4380-4389 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 4390-4399 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 4400-4409 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4410-4419 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 4420-4429 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4430-4439 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 4440-4449 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 4450-4459 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 4460-4469 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4470-4479 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 4480-4489 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 4490-4499 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 4500-4509 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 4510-4519 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 4520-4529 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 4530-4539 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 4540-4549 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4550-4559 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 4560-4569 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 4570-4579 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 4580-4589 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 4590-4599 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 4600-4609 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4610-4619 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 4620-4629 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 4630-4639 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 4640-4649 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 4650-4659 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 4660-4669 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 4670-4679 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4680-4689 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 4690-4699 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 4700-4709 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4710-4719 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 4720-4729 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 4730-4739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4740-4749 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 4750-4759 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 4760-4769 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 4770-4779 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 4780-4789 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 4790-4799 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 4800-4809 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 4810-4819 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4820-4829 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 4830-4839 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 4840-4849 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4850-4859 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4860-4869 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 4870-4879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 4880-4889 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 4890-4899 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 4900-4909 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 4910-4919 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 4920-4929 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 4930-4939 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 4940-4949 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 4950-4959 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 4960-4969 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 4970-4979 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 4980-4989 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 4990-4999 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 5000-5009 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5010-5019 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 5020-5029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 5030-5039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5040-5049 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 5050-5059 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 5060-5069 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 5070-5079 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 5080-5089 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 5090-5099 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 5100-5109 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 28, // 5110-5119 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 5120-5129 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 5130-5139 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 5140-5149 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 5150-5159 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 5160-5169 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 5170-5179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 5180-5189 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 5190-5199 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 5200-5209 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 5210-5219 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 5220-5229 - 1, 2, 1, 4, 3, 2, 1, 24, 23, 22, // 5230-5239 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 5240-5249 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5250-5259 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 5260-5269 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 5270-5279 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 5280-5289 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 5290-5299 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 5300-5309 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 5310-5319 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 5320-5329 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 5330-5339 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 5340-5349 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 5350-5359 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 5360-5369 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5370-5379 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 5380-5389 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 5390-5399 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 5400-5409 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 5410-5419 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5420-5429 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 5430-5439 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 5440-5449 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 5450-5459 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5460-5469 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 5470-5479 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 5480-5489 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5490-5499 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 5500-5509 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 5510-5519 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 5520-5529 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 5530-5539 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 5540-5549 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 5550-5559 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 5560-5569 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 5570-5579 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5580-5589 - 1, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 5590-5599 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 5600-5609 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 5610-5619 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 5620-5629 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 5630-5639 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 5640-5649 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 5650-5659 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 5660-5669 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 5670-5679 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 5680-5689 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 5690-5699 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5700-5709 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 5710-5719 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 5720-5729 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 5730-5739 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 30, // 5740-5749 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 5750-5759 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 5760-5769 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 5770-5779 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 5780-5789 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5790-5799 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 5800-5809 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 5810-5819 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 5820-5829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 5830-5839 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 5840-5849 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 5850-5859 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 5860-5869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 5870-5879 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 5880-5889 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 5890-5899 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 5900-5909 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 5910-5919 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 5920-5929 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 5930-5939 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 5940-5949 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 5950-5959 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 5960-5969 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 5970-5979 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 5980-5989 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 5990-5999 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 6000-6009 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 6010-6019 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 6020-6029 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 6030-6039 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 6040-6049 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 6050-6059 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 6060-6069 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 6070-6079 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 6080-6089 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 6090-6099 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 6100-6109 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 6110-6119 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 6120-6129 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 6130-6139 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 6140-6149 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 6150-6159 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 6160-6169 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 6170-6179 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 6180-6189 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 6190-6199 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 6200-6209 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 6210-6219 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 6220-6229 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 6230-6239 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 6240-6249 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 6250-6259 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 6260-6269 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 6270-6279 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 6280-6289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 6290-6299 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 6300-6309 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 6310-6319 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 6320-6329 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 6330-6339 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 6340-6349 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 6350-6359 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 6360-6369 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 6370-6379 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 6380-6389 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 6390-6399 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 6400-6409 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 6410-6419 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 6420-6429 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 6430-6439 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 6440-6449 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 6450-6459 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 6460-6469 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 6470-6479 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 6480-6489 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 6490-6499 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 6500-6509 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 6510-6519 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 6520-6529 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 6530-6539 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 6540-6549 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 6550-6559 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 6560-6569 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 6570-6579 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 6580-6589 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 6590-6599 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 6600-6609 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 6610-6619 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 6620-6629 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 6630-6639 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 6640-6649 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 6650-6659 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 6660-6669 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 6670-6679 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 6680-6689 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 6690-6699 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 6700-6709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 6710-6719 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 6720-6729 - 3, 2, 1, 4, 3, 2, 1, 24, 23, 22, // 6730-6739 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 6740-6749 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 6750-6759 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 6760-6769 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 6770-6779 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 6780-6789 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 6790-6799 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 6800-6809 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 6810-6819 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 6820-6829 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 6830-6839 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 6840-6849 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 6850-6859 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 6860-6869 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 6870-6879 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 6880-6889 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 6890-6899 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 6900-6909 - 1, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 6910-6919 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 6920-6929 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 6930-6939 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 6940-6949 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 6950-6959 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 6960-6969 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 6970-6979 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 6980-6989 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 6990-6999 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7000-7009 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 7010-7019 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 7020-7029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 7030-7039 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 7040-7049 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 7050-7059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 7060-7069 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 7070-7079 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 7080-7089 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7090-7099 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 7100-7109 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7110-7119 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 7120-7129 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 7130-7139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7140-7149 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 7150-7159 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 7160-7169 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 7170-7179 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 7180-7189 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 7190-7199 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 7200-7209 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 7210-7219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 7220-7229 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 7230-7239 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 7240-7249 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 7250-7259 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 7260-7269 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7270-7279 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 7280-7289 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 7290-7299 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 7300-7309 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7310-7319 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7320-7329 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 7330-7339 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 7340-7349 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 7350-7359 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 7360-7369 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 7370-7379 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7380-7389 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 7390-7399 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7400-7409 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 7410-7419 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7420-7429 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 7430-7439 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7440-7449 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 7450-7459 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 7460-7469 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 7470-7479 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 7480-7489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 7490-7499 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 7500-7509 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 7510-7519 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 7520-7529 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 7530-7539 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 7540-7549 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 7550-7559 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7560-7569 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 7570-7579 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 7580-7589 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7590-7599 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 7600-7609 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7610-7619 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 7620-7629 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 7630-7639 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 20, // 7640-7649 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 7650-7659 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 7660-7669 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 7670-7679 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 7680-7689 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 7690-7699 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 7700-7709 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 7710-7719 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 7720-7729 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7730-7739 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7740-7749 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 30, // 7750-7759 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 7760-7769 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 7770-7779 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 7780-7789 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 7790-7799 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 7800-7809 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 7810-7819 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 7820-7829 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7830-7839 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7840-7849 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 7850-7859 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 7860-7869 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 7870-7879 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 7880-7889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 7890-7899 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 7900-7909 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 7910-7919 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 7920-7929 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 7930-7939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 7940-7949 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7950-7959 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 7960-7969 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 7970-7979 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 7980-7989 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 7990-7999 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 8000-8009 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 8010-8019 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 8020-8029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 8030-8039 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8040-8049 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 8050-8059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 8060-8069 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8070-8079 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 8080-8089 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 8090-8099 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8100-8109 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 8110-8119 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 8120-8129 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 8130-8139 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 8140-8149 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8150-8159 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 8160-8169 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 8170-8179 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8180-8189 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 8190-8199 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 8200-8209 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 8210-8219 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8220-8229 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 8230-8239 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 8240-8249 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8250-8259 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 8260-8269 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 8270-8279 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 8280-8289 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 8290-8299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8300-8309 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 8310-8319 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 8320-8329 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 8330-8339 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8340-8349 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 8350-8359 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 8360-8369 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 8370-8379 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 30, // 8380-8389 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 8390-8399 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 8400-8409 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 8410-8419 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 8420-8429 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8430-8439 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 8440-8449 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8450-8459 - 1, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 8460-8469 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 8470-8479 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 8480-8489 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8490-8499 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8500-8509 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 8510-8519 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 8520-8529 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 8530-8539 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 8540-8549 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8550-8559 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 8560-8569 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 8570-8579 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 8580-8589 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 8590-8599 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 8600-8609 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8610-8619 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 8620-8629 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8630-8639 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 8640-8649 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8650-8659 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 8660-8669 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 8670-8679 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 8680-8689 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 8690-8699 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 8700-8709 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 8710-8719 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8720-8729 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 8730-8739 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 8740-8749 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 8750-8759 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 8760-8769 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 8770-8779 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 8780-8789 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8790-8799 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 8800-8809 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 8810-8819 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8820-8829 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 8830-8839 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 8840-8849 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8850-8859 - 1, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 8860-8869 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 8870-8879 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 8880-8889 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 8890-8899 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 8900-8909 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8910-8919 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 8920-8929 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 8930-8939 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 8940-8949 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 8950-8959 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 8960-8969 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 8970-8979 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 8980-8989 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 8990-8999 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 9000-9009 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 9010-9019 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 9020-9029 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9030-9039 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 9040-9049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 9050-9059 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 9060-9069 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 9070-9079 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9080-9089 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 9090-9099 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 9100-9109 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 9110-9119 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 9120-9129 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 9130-9139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9140-9149 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 9150-9159 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 9160-9169 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 9170-9179 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 9180-9189 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 9190-9199 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 9200-9209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9210-9219 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 9220-9229 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 9230-9239 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 9240-9249 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 9250-9259 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 9260-9269 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 9270-9279 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 9280-9289 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 9290-9299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9300-9309 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 9310-9319 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 9320-9329 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 9330-9339 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 9340-9349 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 9350-9359 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9360-9369 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 9370-9379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9380-9389 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 9390-9399 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 9400-9409 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 9410-9419 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9420-9429 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 22, // 9430-9439 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 9440-9449 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9450-9459 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 9460-9469 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 9470-9479 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9480-9489 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 9490-9499 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9500-9509 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9510-9519 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 9520-9529 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 9530-9539 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 9540-9549 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 9550-9559 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 9560-9569 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 9570-9579 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 9580-9589 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9590-9599 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 9600-9609 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 9610-9619 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 9620-9629 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 9630-9639 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 9640-9649 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9650-9659 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 9660-9669 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 9670-9679 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 9680-9689 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 9690-9699 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 9700-9709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 9710-9719 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 9720-9729 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 9730-9739 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 9740-9749 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 9750-9759 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 9760-9769 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9770-9779 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 9780-9789 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 9790-9799 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 9800-9809 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 9810-9819 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 9820-9829 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 9830-9839 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9840-9849 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 9850-9859 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9860-9869 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 9870-9879 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 9880-9889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9890-9899 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 9900-9909 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 9910-9919 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 9920-9929 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 9930-9939 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 9940-9949 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 9950-9959 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 9960-9969 - 3, 2, 1, 34, 33, 32, 31, 30, 29, 28, // 9970-9979 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 9980-9989 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 9990-9999 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 28, // 10000-10009 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 10010-10019 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 10020-10029 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 10030-10039 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 10040-10049 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10050-10059 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 10060-10069 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 10070-10079 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10080-10089 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 10090-10099 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 10100-10109 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 10110-10119 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10120-10129 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 10130-10139 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10140-10149 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 10150-10159 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 10160-10169 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 10170-10179 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10180-10189 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 10190-10199 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10200-10209 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10210-10219 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 10220-10229 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10230-10239 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 10240-10249 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 10250-10259 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 10260-10269 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 10270-10279 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 10280-10289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10290-10299 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 10300-10309 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 10310-10319 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10320-10329 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 10330-10339 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 10340-10349 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 10350-10359 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 10360-10369 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 10370-10379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10380-10389 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 28, // 10390-10399 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 10400-10409 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 10410-10419 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 10420-10429 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 10430-10439 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10440-10449 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 10450-10459 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 10460-10469 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 10470-10479 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 10480-10489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 10490-10499 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10500-10509 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 10510-10519 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 10520-10529 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 10530-10539 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 10540-10549 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 10550-10559 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 10560-10569 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 10570-10579 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 10580-10589 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 10590-10599 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 10600-10609 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 10610-10619 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 10620-10629 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 10630-10639 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10640-10649 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 10650-10659 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 10660-10669 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 10670-10679 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 10680-10689 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 10690-10699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 10700-10709 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10710-10719 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 10720-10729 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 10730-10739 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10740-10749 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 10750-10759 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10760-10769 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10770-10779 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 10780-10789 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 32, // 10790-10799 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 10800-10809 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 10810-10819 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 10820-10829 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 10830-10839 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 10840-10849 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 10850-10859 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 10860-10869 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10870-10879 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 10880-10889 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10890-10899 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 28, // 10900-10909 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 10910-10919 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 10920-10929 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 10930-10939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 10940-10949 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 10950-10959 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 10960-10969 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 10970-10979 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 10980-10989 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 10990-10999 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 11000-11009 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11010-11019 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 11020-11029 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11030-11039 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 11040-11049 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 11050-11059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 11060-11069 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11070-11079 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 11080-11089 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 11090-11099 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11100-11109 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 11110-11119 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 11120-11129 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 11130-11139 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 11140-11149 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 11150-11159 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 11160-11169 - 1, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 11170-11179 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11180-11189 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 11190-11199 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11200-11209 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 11210-11219 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 11220-11229 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 11230-11239 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 11240-11249 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 11250-11259 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11260-11269 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 11270-11279 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 11280-11289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 11290-11299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 11300-11309 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 11310-11319 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 11320-11329 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 11330-11339 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 11340-11349 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 11350-11359 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 11360-11369 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11370-11379 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 11380-11389 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 11390-11399 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 11400-11409 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11410-11419 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 11420-11429 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 11430-11439 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 11440-11449 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11450-11459 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 11460-11469 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11470-11479 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 11480-11489 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 11490-11499 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 11500-11509 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 11510-11519 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 11520-11529 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 11530-11539 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 11540-11549 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 11550-11559 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 11560-11569 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 11570-11579 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 11580-11589 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 11590-11599 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11600-11609 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 11610-11619 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11620-11629 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 11630-11639 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11640-11649 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 11650-11659 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11660-11669 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 11670-11679 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 11680-11689 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 11690-11699 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11700-11709 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 11710-11719 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 11720-11729 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11730-11739 - 3, 2, 1, 34, 33, 32, 31, 30, 29, 28, // 11740-11749 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 11750-11759 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11760-11769 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 11770-11779 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 11780-11789 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 11790-11799 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 11800-11809 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 11810-11819 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 11820-11829 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 24, // 11830-11839 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 11840-11849 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11850-11859 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 11860-11869 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11870-11879 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 11880-11889 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 11890-11899 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 11900-11909 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11910-11919 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 11920-11929 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 11930-11939 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 11940-11949 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 11950-11959 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 11960-11969 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 11970-11979 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 11980-11989 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 11990-11999 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 12000-12009 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 12010-12019 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 12020-12029 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 12030-12039 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 12040-12049 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 12050-12059 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12060-12069 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 12070-12079 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 12080-12089 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 12090-12099 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 12100-12109 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 24, // 12110-12119 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 12120-12129 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 12130-12139 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 12140-12149 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 12150-12159 - 1, 2, 1, 34, 33, 32, 31, 30, 29, 28, // 12160-12169 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 12170-12179 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 12180-12189 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 12190-12199 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 12200-12209 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 12210-12219 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 12220-12229 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 12230-12239 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12240-12249 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 12250-12259 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 12260-12269 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 12270-12279 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 12280-12289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12290-12299 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 12300-12309 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 12310-12319 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 12320-12329 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 12330-12339 - 3, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 12340-12349 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 12350-12359 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 12360-12369 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 12370-12379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12380-12389 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12390-12399 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 12400-12409 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 12410-12419 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 12420-12429 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 12430-12439 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12440-12449 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 12450-12459 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 12460-12469 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 12470-12479 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 12480-12489 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 12490-12499 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 12500-12509 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 12510-12519 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 12520-12529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 12530-12539 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 12540-12549 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 12550-12559 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 12560-12569 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 12570-12579 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 12580-12589 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12590-12599 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12600-12609 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 12610-12619 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 12620-12629 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 12630-12639 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 12640-12649 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 12650-12659 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12660-12669 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 12670-12679 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 12680-12689 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 12690-12699 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 12700-12709 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 12710-12719 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 12720-12729 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 12730-12739 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 12740-12749 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 12750-12759 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 12760-12769 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12770-12779 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12780-12789 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 12790-12799 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 12800-12809 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12810-12819 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 12820-12829 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12830-12839 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 12840-12849 - 3, 2, 1, 36, 35, 34, 33, 32, 31, 30, // 12850-12859 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 12860-12869 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 12870-12879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 12880-12889 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 12890-12899 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 12900-12909 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 12910-12919 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 12920-12929 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12930-12939 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 12940-12949 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 12950-12959 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 12960-12969 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 12970-12979 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 12980-12989 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 12990-12999 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 24, // 13000-13009 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 13010-13019 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 13020-13029 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 13030-13039 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 13040-13049 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 13050-13059 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 13060-13069 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 13070-13079 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 13080-13089 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 13090-13099 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 13100-13109 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13110-13119 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 13120-13129 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 13130-13139 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 13140-13149 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 13150-13159 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 13160-13169 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 13170-13179 - 3, 2, 1, 4, 3, 2, 1, 30, 29, 28, // 13180-13189 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 13190-13199 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 13200-13209 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 13210-13219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 13220-13229 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13230-13239 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 13240-13249 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 13250-13259 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 13260-13269 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 13270-13279 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13280-13289 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 13290-13299 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 13300-13309 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 13310-13319 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 13320-13329 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 28, // 13330-13339 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 13340-13349 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 13350-13359 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 13360-13369 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13370-13379 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 13380-13389 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 13390-13399 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13400-13409 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 13410-13419 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 13420-13429 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13430-13439 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13440-13449 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 13450-13459 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 13460-13469 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 13470-13479 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 13480-13489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 13490-13499 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 13500-13509 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 13510-13519 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 13520-13529 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 13530-13539 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 13540-13549 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 13550-13559 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 13560-13569 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 13570-13579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13580-13589 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 13590-13599 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 13600-13609 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 13610-13619 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 13620-13629 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 13630-13639 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 13640-13649 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 13650-13659 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 13660-13669 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 13670-13679 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 13680-13689 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 13690-13699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 13700-13709 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13710-13719 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 13720-13729 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 13730-13739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13740-13749 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 13750-13759 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 13760-13769 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13770-13779 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 13780-13789 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 13790-13799 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 13800-13809 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 13810-13819 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 13820-13829 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13830-13839 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 13840-13849 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 13850-13859 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 13860-13869 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 13870-13879 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 13880-13889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13890-13899 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 13900-13909 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 13910-13919 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 13920-13929 - 1, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 13930-13939 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 13940-13949 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 13950-13959 - 3, 2, 1, 4, 3, 2, 1, 30, 29, 28, // 13960-13969 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 13970-13979 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 13980-13989 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 13990-13999 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 14000-14009 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 14010-14019 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 14020-14029 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 14030-14039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14040-14049 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 14050-14059 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14060-14069 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14070-14079 - 1, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 14080-14089 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 14090-14099 - 7, 6, 5, 4, 3, 2, 1, 36, 35, 34, // 14100-14109 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 14110-14119 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 14120-14129 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14130-14139 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 14140-14149 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 14150-14159 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14160-14169 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 14170-14179 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 14180-14189 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 14190-14199 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 14200-14209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14210-14219 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 14220-14229 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14230-14239 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 14240-14249 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 14250-14259 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 14260-14269 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14270-14279 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14280-14289 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 14290-14299 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 14300-14309 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14310-14319 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 14320-14329 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14330-14339 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 14340-14349 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 14350-14359 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 14360-14369 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 14370-14379 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 14380-14389 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14390-14399 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 14400-14409 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 14410-14419 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 14420-14429 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 14430-14439 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 14440-14449 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14450-14459 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 14460-14469 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 14470-14479 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 14480-14489 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14490-14499 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 14500-14509 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 14510-14519 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14520-14529 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 14530-14539 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 14540-14549 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 14550-14559 - 1, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 14560-14569 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 14570-14579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14580-14589 - 1, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 14590-14599 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 14600-14609 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 14610-14619 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 14620-14629 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 14630-14639 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14640-14649 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 14650-14659 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 14660-14669 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14670-14679 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 14680-14689 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 14690-14699 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14700-14709 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 14710-14719 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 14720-14729 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 14730-14739 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 14740-14749 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 14750-14759 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 14760-14769 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 14770-14779 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 14780-14789 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 14790-14799 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14800-14809 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 14810-14819 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 14820-14829 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14830-14839 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 14840-14849 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 14850-14859 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 14860-14869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 14870-14879 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 14880-14889 - 1, 6, 5, 4, 3, 2, 1, 26, 25, 24, // 14890-14899 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 14900-14909 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14910-14919 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 14920-14929 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 14930-14939 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 14940-14949 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 14950-14959 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 14960-14969 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 14970-14979 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 14980-14989 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 14990-14999 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 15000-15009 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 15010-15019 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15020-15029 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 15030-15039 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 15040-15049 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 15050-15059 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 15060-15069 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 15070-15079 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 15080-15089 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15090-15099 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 15100-15109 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15110-15119 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15120-15129 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 15130-15139 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 15140-15149 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15150-15159 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 15160-15169 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 15170-15179 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 15180-15189 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 15190-15199 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 15200-15209 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 15210-15219 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 15220-15229 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 15230-15239 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 15240-15249 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 15250-15259 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 15260-15269 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 15270-15279 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 15280-15289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 15290-15299 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 15300-15309 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 15310-15319 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 15320-15329 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 15330-15339 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 15340-15349 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 15350-15359 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 15360-15369 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 15370-15379 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 15380-15389 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15390-15399 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 15400-15409 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 15410-15419 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 15420-15429 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 15430-15439 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 15440-15449 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15450-15459 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 15460-15469 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 15470-15479 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 15480-15489 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 15490-15499 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15500-15509 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 15510-15519 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 15520-15529 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15530-15539 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15540-15549 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 15550-15559 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 15560-15569 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15570-15579 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 15580-15589 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15590-15599 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 15600-15609 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 15610-15619 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 15620-15629 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15630-15639 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 15640-15649 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15650-15659 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 15660-15669 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 15670-15679 - 3, 2, 1, 44, 43, 42, 41, 40, 39, 38, // 15680-15689 - 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 15690-15699 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 15700-15709 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 15710-15719 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 15720-15729 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 15730-15739 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 15740-15749 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15750-15759 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 15760-15769 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 15770-15779 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 15780-15789 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 15790-15799 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 15800-15809 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 15810-15819 - 3, 2, 1, 36, 35, 34, 33, 32, 31, 30, // 15820-15829 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 15830-15839 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 15840-15849 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 15850-15859 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 15860-15869 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 15870-15879 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 15880-15889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15890-15899 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 15900-15909 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 15910-15919 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 15920-15929 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 15930-15939 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 15940-15949 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 15950-15959 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15960-15969 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 15970-15979 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15980-15989 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 15990-15999 - 1, 6, 5, 4, 3, 2, 1, 26, 25, 24, // 16000-16009 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 16010-16019 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 16020-16029 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 16030-16039 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 16040-16049 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 16050-16059 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 16060-16069 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 16070-16079 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 16080-16089 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 16090-16099 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 16100-16109 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 16110-16119 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 16120-16129 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 16130-16139 - 1, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 16140-16149 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 16150-16159 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 16160-16169 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 16170-16179 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 16180-16189 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 16190-16199 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 16200-16209 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 16210-16219 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 16220-16229 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 16230-16239 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 16240-16249 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 16250-16259 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 16260-16269 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 16270-16279 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 16280-16289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16290-16299 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 16300-16309 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 16310-16319 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 16320-16329 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 16330-16339 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 16340-16349 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16350-16359 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 16360-16369 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16370-16379 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 16380-16389 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 16390-16399 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16400-16409 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 16410-16419 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 16420-16429 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 16430-16439 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 16440-16449 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 16450-16459 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 16460-16469 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 16470-16479 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 16480-16489 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 16490-16499 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 16500-16509 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 16510-16519 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 16520-16529 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 16530-16539 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 16540-16549 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 16550-16559 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 16560-16569 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 16570-16579 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 16580-16589 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 16590-16599 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 16600-16609 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 16610-16619 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16620-16629 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 16630-16639 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 16640-16649 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 16650-16659 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 16660-16669 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 16670-16679 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16680-16689 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 16690-16699 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 16700-16709 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 16710-16719 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 16720-16729 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16730-16739 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 16740-16749 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 16750-16759 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 16760-16769 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 16770-16779 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 16780-16789 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 16790-16799 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16800-16809 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 16810-16819 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 16820-16829 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 16830-16839 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 16840-16849 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 16850-16859 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16860-16869 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 16870-16879 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 16880-16889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16890-16899 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 16900-16909 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 16910-16919 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 16920-16929 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 16930-16939 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 16940-16949 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 16950-16959 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 16960-16969 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 16970-16979 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 16980-16989 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 16990-16999 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17000-17009 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17010-17019 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 17020-17029 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 17030-17039 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 17040-17049 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 17050-17059 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17060-17069 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 17070-17079 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 17080-17089 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 17090-17099 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 17100-17109 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 17110-17119 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 17120-17129 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 17130-17139 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 17140-17149 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 17150-17159 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 17160-17169 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 17170-17179 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 17180-17189 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 17190-17199 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 22, // 17200-17209 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 17210-17219 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17220-17229 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 17230-17239 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17240-17249 - 7, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 17250-17259 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 17260-17269 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 17270-17279 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17280-17289 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 17290-17299 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17300-17309 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 17310-17319 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 17320-17329 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 17330-17339 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17340-17349 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 17350-17359 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17360-17369 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 17370-17379 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 17380-17389 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 17390-17399 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17400-17409 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 17410-17419 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17420-17429 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 17430-17439 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 17440-17449 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17450-17459 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 17460-17469 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 17470-17479 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 17480-17489 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 17490-17499 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 17500-17509 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 17510-17519 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 17520-17529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 17530-17539 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17540-17549 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 17550-17559 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 17560-17569 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 17570-17579 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17580-17589 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 17590-17599 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 17600-17609 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 17610-17619 - 3, 2, 1, 4, 3, 2, 1, 30, 29, 28, // 17620-17629 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 17630-17639 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17640-17649 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 17650-17659 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 17660-17669 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17670-17679 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 17680-17689 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17690-17699 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 17700-17709 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 17710-17719 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 17720-17729 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 17730-17739 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 17740-17749 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17750-17759 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 17760-17769 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 17770-17779 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 17780-17789 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17790-17799 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 17800-17809 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17810-17819 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 17820-17829 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 17830-17839 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17840-17849 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 17850-17859 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 17860-17869 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17870-17879 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17880-17889 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 17890-17899 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 17900-17909 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17910-17919 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 17920-17929 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 17930-17939 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 17940-17949 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 17950-17959 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 17960-17969 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 17970-17979 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 24, // 17980-17989 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 17990-17999 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18000-18009 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 18010-18019 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 18020-18029 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18030-18039 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 18040-18049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 18050-18059 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 18060-18069 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 18070-18079 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 18080-18089 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 18090-18099 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 18100-18109 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 18110-18119 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 18120-18129 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 18130-18139 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 20, // 18140-18149 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 18150-18159 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 18160-18169 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18170-18179 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18180-18189 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 18190-18199 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18200-18209 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 18210-18219 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 18220-18229 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 18230-18239 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18240-18249 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 18250-18259 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 18260-18269 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 18270-18279 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 18280-18289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18290-18299 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 18300-18309 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 18310-18319 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 18320-18329 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18330-18339 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18340-18349 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 18350-18359 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 18360-18369 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 18370-18379 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 18380-18389 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 18390-18399 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18400-18409 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 18410-18419 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 18420-18429 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 18430-18439 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 18440-18449 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 18450-18459 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 18460-18469 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18470-18479 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18480-18489 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 18490-18499 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 18500-18509 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 18510-18519 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 18520-18529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 18530-18539 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18540-18549 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 18550-18559 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 18560-18569 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18570-18579 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 18580-18589 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 18590-18599 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 18600-18609 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 18610-18619 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 18620-18629 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 18630-18639 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 18640-18649 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18650-18659 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18660-18669 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 18670-18679 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18680-18689 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18690-18699 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18700-18709 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 18710-18719 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18720-18729 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18730-18739 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 18740-18749 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 18750-18759 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18760-18769 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 18770-18779 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 18780-18789 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 18790-18799 - 3, 2, 1, 36, 35, 34, 33, 32, 31, 30, // 18800-18809 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 18810-18819 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 18820-18829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 18830-18839 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 18840-18849 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 18850-18859 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, // 18860-18869 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 18870-18879 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 18880-18889 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 18890-18899 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18900-18909 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 28, // 18910-18919 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 18920-18929 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 18930-18939 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 18940-18949 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 18950-18959 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 18960-18969 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 18970-18979 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 18980-18989 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 18990-18999 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 19000-19009 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 19010-19019 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19020-19029 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 19030-19039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19040-19049 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 19050-19059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 19060-19069 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 19070-19079 - 1, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 19080-19089 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 19090-19099 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 19100-19109 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19110-19119 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 19120-19129 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 19130-19139 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 19140-19149 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 19150-19159 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 19160-19169 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19170-19179 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 19180-19189 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 19190-19199 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 19200-19209 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 19210-19219 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19220-19229 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 19230-19239 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 19240-19249 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 19250-19259 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 19260-19269 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 19270-19279 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 19280-19289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19290-19299 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 19300-19309 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 19310-19319 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 19320-19329 - 3, 2, 1, 40, 39, 38, 37, 36, 35, 34, // 19330-19339 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 19340-19349 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 19350-19359 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 19360-19369 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 19370-19379 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 19380-19389 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 19390-19399 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 19400-19409 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 19410-19419 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 19420-19429 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 19430-19439 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 19440-19449 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 19450-19459 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 19460-19469 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 19470-19479 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 19480-19489 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19490-19499 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 19500-19509 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 19510-19519 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19520-19529 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19530-19539 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 19540-19549 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 19550-19559 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19560-19569 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 19570-19579 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 19580-19589 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 19590-19599 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 52, // 19600-19609 - 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, // 19610-19619 - 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 19620-19629 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 19630-19639 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 19640-19649 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19650-19659 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 19660-19669 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19670-19679 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 19680-19689 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 19690-19699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 19700-19709 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 19710-19719 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 19720-19729 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 19730-19739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19740-19749 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 19750-19759 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 19760-19769 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 19770-19779 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 19780-19789 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 19790-19799 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 19800-19809 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 19810-19819 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 19820-19829 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19830-19839 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 19840-19849 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 19850-19859 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 19860-19869 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 19870-19879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 19880-19889 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 19890-19899 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 19900-19909 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 19910-19919 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 19920-19929 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 19930-19939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 19940-19949 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19950-19959 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 19960-19969 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 19970-19979 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 19980-19989 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 19990-19999 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20000-20009 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20010-20019 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 20020-20029 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 20030-20039 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 20040-20049 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20050-20059 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 20060-20069 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 20070-20079 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 20080-20089 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20090-20099 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 20100-20109 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 20110-20119 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 20120-20129 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20130-20139 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 20140-20149 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20150-20159 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20160-20169 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 20170-20179 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 20180-20189 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20190-20199 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 20200-20209 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 20210-20219 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20220-20229 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 20230-20239 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 20240-20249 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20250-20259 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 20260-20269 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 20270-20279 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 20280-20289 - 7, 6, 5, 4, 3, 2, 1, 26, 25, 24, // 20290-20299 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 20300-20309 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20310-20319 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 20320-20329 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 20330-20339 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 20340-20349 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 20350-20359 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 20360-20369 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 20370-20379 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 20380-20389 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 20390-20399 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 20400-20409 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 20410-20419 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20420-20429 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20430-20439 - 1, 2, 1, 34, 33, 32, 31, 30, 29, 28, // 20440-20449 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 20450-20459 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 20460-20469 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 20470-20479 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 20480-20489 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 20490-20499 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 20500-20509 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20510-20519 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20520-20529 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 20530-20539 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 20540-20549 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20550-20559 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 20560-20569 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 20570-20579 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20580-20589 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 20590-20599 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20600-20609 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 20610-20619 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 20620-20629 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 20630-20639 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 20640-20649 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20650-20659 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 20660-20669 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20670-20679 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20680-20689 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 20690-20699 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 20700-20709 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 20710-20719 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20720-20729 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20730-20739 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 20740-20749 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 20750-20759 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20760-20769 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 20770-20779 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 20780-20789 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 20790-20799 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 40, // 20800-20809 - 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 20810-20819 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 20820-20829 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 20830-20839 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 20840-20849 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 20850-20859 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 20860-20869 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 20870-20879 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 20880-20889 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 20890-20899 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 20900-20909 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20910-20919 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 20920-20929 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 20930-20939 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 20940-20949 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 20950-20959 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 20960-20969 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20970-20979 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 20980-20989 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 20990-20999 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21000-21009 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 21010-21019 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 21020-21029 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 21030-21039 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 21040-21049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 21050-21059 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 21060-21069 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 21070-21079 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 21080-21089 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21090-21099 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 21100-21109 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21110-21119 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 21120-21129 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 21130-21139 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 21140-21149 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 21150-21159 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 21160-21169 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 21170-21179 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 21180-21189 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 21190-21199 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21200-21209 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21210-21219 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 21220-21229 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 21230-21239 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 21240-21249 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 21250-21259 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 21260-21269 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 21270-21279 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 21280-21289 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 21290-21299 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 21300-21309 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 21310-21319 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 21320-21329 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21330-21339 - 1, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 21340-21349 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 21350-21359 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 21360-21369 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 21370-21379 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 21380-21389 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 21390-21399 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 21400-21409 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 21410-21419 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 21420-21429 - 3, 2, 1, 34, 33, 32, 31, 30, 29, 28, // 21430-21439 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 21440-21449 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 21450-21459 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 21460-21469 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21470-21479 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 21480-21489 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 21490-21499 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 21500-21509 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 21510-21519 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 28, // 21520-21529 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 21530-21539 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 21540-21549 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 21550-21559 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 21560-21569 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 21570-21579 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 21580-21589 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 21590-21599 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21600-21609 - 1, 2, 1, 4, 3, 2, 1, 30, 29, 28, // 21610-21619 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 21620-21629 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 21630-21639 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 21640-21649 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21650-21659 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 21660-21669 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 21670-21679 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 21680-21689 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21690-21699 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 21700-21709 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 21710-21719 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 21720-21729 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 21730-21739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21740-21749 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 21750-21759 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 21760-21769 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 21770-21779 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 21780-21789 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 21790-21799 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 21800-21809 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 21810-21819 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 21820-21829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 21830-21839 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21840-21849 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 21850-21859 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 21860-21869 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21870-21879 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 21880-21889 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 21890-21899 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21900-21909 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 21910-21919 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 21920-21929 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 21930-21939 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 21940-21949 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21950-21959 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 21960-21969 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 21970-21979 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 21980-21989 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 21990-21999 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 22000-22009 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 22010-22019 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 22020-22029 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 22030-22039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22040-22049 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 22050-22059 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 22060-22069 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 22070-22079 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22080-22089 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 22090-22099 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 22100-22109 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 22110-22119 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 22120-22129 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 22130-22139 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 22140-22149 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 22150-22159 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22160-22169 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 22170-22179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 22180-22189 - 3, 2, 1, 36, 35, 34, 33, 32, 31, 30, // 22190-22199 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 22200-22209 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 22210-22219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 22220-22229 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 22230-22239 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 22240-22249 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 22250-22259 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22260-22269 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 22270-22279 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 22280-22289 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 22290-22299 - 3, 2, 1, 4, 3, 2, 1, 36, 35, 34, // 22300-22309 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 22310-22319 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 22320-22329 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 22330-22339 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 22340-22349 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 22350-22359 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 22360-22369 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22370-22379 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22380-22389 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 22390-22399 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 22400-22409 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 22410-22419 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 22420-22429 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 22430-22439 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 22440-22449 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 22450-22459 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 22460-22469 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22470-22479 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 22480-22489 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22490-22499 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22500-22509 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 22510-22519 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22520-22529 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22530-22539 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 22540-22549 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 22550-22559 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 22560-22569 - 1, 2, 1, 40, 39, 38, 37, 36, 35, 34, // 22570-22579 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 22580-22589 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 22590-22599 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 22600-22609 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 22610-22619 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 22620-22629 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 22630-22639 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 22640-22649 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 22650-22659 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 22660-22669 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 22670-22679 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22680-22689 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 22690-22699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 22700-22709 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 22710-22719 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 22720-22729 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 22730-22739 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22740-22749 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 22750-22759 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 22760-22769 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 22770-22779 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 22780-22789 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 22790-22799 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 22800-22809 - 1, 6, 5, 4, 3, 2, 1, 36, 35, 34, // 22810-22819 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 22820-22829 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 22830-22839 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 22840-22849 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 22850-22859 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22860-22869 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 22870-22879 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 22880-22889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22890-22899 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 22900-22909 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22910-22919 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 22920-22929 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 22930-22939 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 22940-22949 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 22950-22959 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 22960-22969 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 22970-22979 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 22980-22989 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 22990-22999 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 23000-23009 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 23010-23019 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 23020-23029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 23030-23039 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 23040-23049 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 23050-23059 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 23060-23069 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23070-23079 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 23080-23089 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 23090-23099 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 23100-23109 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 23110-23119 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23120-23129 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 23130-23139 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 23140-23149 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 23150-23159 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 23160-23169 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 23170-23179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 23180-23189 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 23190-23199 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 23200-23209 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 23210-23219 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 23220-23229 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 23230-23239 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23240-23249 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 23250-23259 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 23260-23269 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 23270-23279 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23280-23289 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 23290-23299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23300-23309 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23310-23319 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 23320-23329 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 23330-23339 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 23340-23349 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 23350-23359 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 23360-23369 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 23370-23379 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 23380-23389 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 23390-23399 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 23400-23409 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 23410-23419 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23420-23429 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 23430-23439 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 23440-23449 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 23450-23459 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 23460-23469 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 23470-23479 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 23480-23489 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 23490-23499 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 23500-23509 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 23510-23519 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23520-23529 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 23530-23539 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 23540-23549 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 23550-23559 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 23560-23569 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23570-23579 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 23580-23589 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 23590-23599 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 23600-23609 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 23610-23619 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 23620-23629 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 23630-23639 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 23640-23649 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 23650-23659 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 23660-23669 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 23670-23679 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 30, // 23680-23689 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 23690-23699 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 23700-23709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 23710-23719 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 23720-23729 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23730-23739 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 23740-23749 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 23750-23759 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 23760-23769 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 23770-23779 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 23780-23789 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23790-23799 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 23800-23809 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 23810-23819 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 23820-23829 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 23830-23839 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 23840-23849 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 23850-23859 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 23860-23869 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 23870-23879 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 23880-23889 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 23890-23899 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 23900-23909 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 23910-23919 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 28, // 23920-23929 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 23930-23939 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 23940-23949 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 23950-23959 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 23960-23969 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 23970-23979 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 23980-23989 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 23990-23999 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 24000-24009 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 24010-24019 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 24020-24029 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 24030-24039 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 24040-24049 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24050-24059 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24060-24069 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 24070-24079 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 24080-24089 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 24090-24099 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 24100-24109 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 24110-24119 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 24120-24129 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 24130-24139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24140-24149 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 24150-24159 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 24160-24169 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 24170-24179 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 24180-24189 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 24190-24199 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 24200-24209 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 24210-24219 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 24220-24229 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 24230-24239 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 24240-24249 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 24250-24259 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 24260-24269 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24270-24279 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 24280-24289 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 24290-24299 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 24300-24309 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 24310-24319 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 24320-24329 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 24330-24339 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 24340-24349 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 24350-24359 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24360-24369 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 24370-24379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24380-24389 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 24390-24399 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 24400-24409 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 24410-24419 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 24420-24429 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 24430-24439 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 24440-24449 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 24450-24459 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 24460-24469 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 24470-24479 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 24480-24489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 24490-24499 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 24500-24509 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 24510-24519 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 24520-24529 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 24530-24539 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 24540-24549 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 24550-24559 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24560-24569 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 24570-24579 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 24580-24589 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 24590-24599 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24600-24609 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 24610-24619 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 24620-24629 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 24630-24639 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 24640-24649 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 24650-24659 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24660-24669 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 24670-24679 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 24680-24689 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 24690-24699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 24700-24709 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 24710-24719 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 24720-24729 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 24730-24739 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 24740-24749 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 24750-24759 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 24760-24769 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24770-24779 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 24780-24789 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 24790-24799 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 24800-24809 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24810-24819 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 24820-24829 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 24830-24839 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 24840-24849 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 24850-24859 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 24860-24869 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 24870-24879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 24880-24889 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 24890-24899 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 24900-24909 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 24910-24919 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 24920-24929 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 24930-24939 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 24940-24949 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 24950-24959 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 24960-24969 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 24970-24979 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 24980-24989 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 24990-24999 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25000-25009 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 25010-25019 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25020-25029 - 1, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 25030-25039 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 25040-25049 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 25050-25059 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25060-25069 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 25070-25079 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 25080-25089 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 25090-25099 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25100-25109 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 25110-25119 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 25120-25129 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 25130-25139 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 25140-25149 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 25150-25159 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 25160-25169 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25170-25179 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 30, // 25180-25189 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 25190-25199 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 25200-25209 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 25210-25219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 25220-25229 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 25230-25239 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 25240-25249 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 25250-25259 - 1, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 25260-25269 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 25270-25279 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 25280-25289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25290-25299 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 25300-25309 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25310-25319 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 25320-25329 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 25330-25339 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 25340-25349 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 25350-25359 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 25360-25369 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 25370-25379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25380-25389 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 25390-25399 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 25400-25409 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25410-25419 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 25420-25429 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 25430-25439 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 25440-25449 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 25450-25459 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 25460-25469 - 1, 52, 51, 50, 49, 48, 47, 46, 45, 44, // 25470-25479 - 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 25480-25489 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 25490-25499 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 25500-25509 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25510-25519 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 25520-25529 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 25530-25539 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 25540-25549 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25550-25559 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 25560-25569 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 25570-25579 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 25580-25589 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25590-25599 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 25600-25609 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25610-25619 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25620-25629 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 25630-25639 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 25640-25649 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 25650-25659 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 25660-25669 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 25670-25679 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25680-25689 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 25690-25699 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 25700-25709 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 25710-25719 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25720-25729 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 25730-25739 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 25740-25749 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 25750-25759 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 25760-25769 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 25770-25779 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25780-25789 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 25790-25799 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 25800-25809 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 25810-25819 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 25820-25829 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25830-25839 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 25840-25849 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 25850-25859 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 25860-25869 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 25870-25879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 25880-25889 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 25890-25899 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 25900-25909 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 25910-25919 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25920-25929 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 25930-25939 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 25940-25949 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 25950-25959 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 25960-25969 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 25970-25979 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 25980-25989 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 25990-25999 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 26000-26009 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 26010-26019 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 26020-26029 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26030-26039 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 26040-26049 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 26050-26059 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 26060-26069 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 26070-26079 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 26080-26089 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 26090-26099 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 26100-26109 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 26110-26119 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 26120-26129 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26130-26139 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 26140-26149 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 26150-26159 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26160-26169 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 26170-26179 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 26180-26189 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 26190-26199 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 26200-26209 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 26210-26219 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 26220-26229 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 26230-26239 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 26240-26249 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26250-26259 - 1, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 26260-26269 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 26270-26279 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 26280-26289 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 26290-26299 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 26300-26309 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 26310-26319 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 26320-26329 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 26330-26339 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 26340-26349 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 26350-26359 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26360-26369 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 26370-26379 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 26380-26389 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 26390-26399 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 26400-26409 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 26410-26419 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 26420-26429 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 26430-26439 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 26440-26449 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 26450-26459 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 26460-26469 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 26470-26479 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 26480-26489 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 26490-26499 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 26500-26509 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 26510-26519 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 26520-26529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 26530-26539 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 26540-26549 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 26550-26559 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 26560-26569 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 26570-26579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26580-26589 - 1, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 26590-26599 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 26600-26609 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 26610-26619 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 26620-26629 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 26630-26639 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 26640-26649 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 26650-26659 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 26660-26669 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26670-26679 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 26680-26689 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 26690-26699 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26700-26709 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 26710-26719 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 26720-26729 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 26730-26739 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 26740-26749 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 26750-26759 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 26760-26769 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 26770-26779 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 26780-26789 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26790-26799 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 26800-26809 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 26810-26819 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 26820-26829 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 26830-26839 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 26840-26849 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26850-26859 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 26860-26869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 26870-26879 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26880-26889 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 26890-26899 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 26900-26909 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26910-26919 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 26920-26929 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 26930-26939 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 26940-26949 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 26950-26959 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 26960-26969 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 26970-26979 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 26980-26989 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 26990-26999 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27000-27009 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 27010-27019 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27020-27029 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 27030-27039 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 27040-27049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 27050-27059 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 27060-27069 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 27070-27079 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27080-27089 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 27090-27099 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 18, // 27100-27109 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 27110-27119 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 27120-27129 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 27130-27139 - 3, 2, 1, 36, 35, 34, 33, 32, 31, 30, // 27140-27149 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 27150-27159 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 27160-27169 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 27170-27179 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27180-27189 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 27190-27199 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27200-27209 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 27210-27219 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 27220-27229 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 27230-27239 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 27240-27249 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 27250-27259 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27260-27269 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 27270-27279 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 27280-27289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, // 27290-27299 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 27300-27309 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 27310-27319 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 27320-27329 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 27330-27339 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 27340-27349 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27350-27359 - 1, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 27360-27369 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 27370-27379 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 27380-27389 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 27390-27399 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 27400-27409 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 27410-27419 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 27420-27429 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 27430-27439 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 27440-27449 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 27450-27459 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 27460-27469 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 27470-27479 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 27480-27489 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 27490-27499 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 27500-27509 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 27510-27519 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 27520-27529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 27530-27539 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27540-27549 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 27550-27559 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 27560-27569 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27570-27579 - 1, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 27580-27589 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 27590-27599 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27600-27609 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 27610-27619 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27620-27629 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 27630-27639 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 27640-27649 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 27650-27659 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 27660-27669 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 27670-27679 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 27680-27689 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 27690-27699 - 1, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 27700-27709 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 27710-27719 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 27720-27729 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 27730-27739 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 27740-27749 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 27750-27759 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 27760-27769 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 27770-27779 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27780-27789 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 27790-27799 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 27800-27809 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 27810-27819 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 27820-27829 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 27830-27839 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 27840-27849 - 1, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 27850-27859 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 27860-27869 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 27870-27879 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 27880-27889 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 27890-27899 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 27900-27909 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 27910-27919 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 27920-27929 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 27930-27939 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 27940-27949 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 27950-27959 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 27960-27969 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 27970-27979 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 27980-27989 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 27990-27999 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 28000-28009 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 28010-28019 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 28020-28029 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 28030-28039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28040-28049 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 28050-28059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 28060-28069 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28070-28079 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 28080-28089 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 28090-28099 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 28100-28109 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 28110-28119 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 28120-28129 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 28130-28139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28140-28149 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 28150-28159 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 28160-28169 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28170-28179 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 28180-28189 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28190-28199 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28200-28209 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 28210-28219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 48, // 28220-28229 - 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, // 28230-28239 - 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 28240-28249 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 28250-28259 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 28260-28269 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 28270-28279 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 28280-28289 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 28290-28299 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 28300-28309 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, // 28310-28319 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 28320-28329 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 28330-28339 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 28340-28349 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 28350-28359 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 28360-28369 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 28370-28379 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 28380-28389 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 28390-28399 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 28400-28409 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 28410-28419 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 28420-28429 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 28430-28439 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 28440-28449 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 28450-28459 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 28460-28469 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 28470-28479 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 28480-28489 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 28490-28499 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 28500-28509 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 28510-28519 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 28520-28529 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 28530-28539 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 28540-28549 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 28550-28559 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28560-28569 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 28570-28579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28580-28589 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 28590-28599 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 28600-28609 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 28610-28619 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 28620-28629 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 28630-28639 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 28640-28649 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 28650-28659 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 28660-28669 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 28670-28679 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 28680-28689 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 28690-28699 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 28700-28709 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 28710-28719 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 28720-28729 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 28730-28739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28740-28749 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 28750-28759 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28760-28769 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 28770-28779 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 28780-28789 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 28790-28799 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 28800-28809 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 28810-28819 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 28820-28829 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 28830-28839 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 28840-28849 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 28850-28859 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 28860-28869 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 28870-28879 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 28880-28889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28890-28899 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 28900-28909 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28910-28919 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 28920-28929 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 28930-28939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 28940-28949 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 28950-28959 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 28960-28969 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, // 28970-28979 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 28980-28989 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 28990-28999 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 29000-29009 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 29010-29019 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 29020-29029 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 29030-29039 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 29040-29049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 29050-29059 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 29060-29069 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 29070-29079 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 29080-29089 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29090-29099 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 29100-29109 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29110-29119 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 29120-29129 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 29130-29139 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 29140-29149 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 29150-29159 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 29160-29169 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 29170-29179 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29180-29189 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29190-29199 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 29200-29209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29210-29219 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29220-29229 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29230-29239 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 29240-29249 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 29250-29259 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 29260-29269 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 29270-29279 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 29280-29289 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 29290-29299 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 29300-29309 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 29310-29319 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 29320-29329 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 29330-29339 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 29340-29349 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29350-29359 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 29360-29369 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29370-29379 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 29380-29389 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 29390-29399 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29400-29409 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29410-29419 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 29420-29429 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 29430-29439 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 29440-29449 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 29450-29459 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29460-29469 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 29470-29479 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 29480-29489 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29490-29499 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 29500-29509 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 29510-29519 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 29520-29529 - 1, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 29530-29539 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 29540-29549 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 29550-29559 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 29560-29569 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 29570-29579 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 29580-29589 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 29590-29599 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29600-29609 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 29610-29619 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 29620-29629 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 29630-29639 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 29640-29649 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29650-29659 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 29660-29669 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29670-29679 - 3, 2, 1, 34, 33, 32, 31, 30, 29, 28, // 29680-29689 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 29690-29699 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 29700-29709 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 29710-29719 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 29720-29729 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29730-29739 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29740-29749 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 29750-29759 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 29760-29769 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 29770-29779 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 29780-29789 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29790-29799 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 29800-29809 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 29810-29819 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29820-29829 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 29830-29839 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 29840-29849 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29850-29859 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 29860-29869 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 29870-29879 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 29880-29889 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 29890-29899 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 29900-29909 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 29910-29919 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 29920-29929 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 29930-29939 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 29940-29949 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 29950-29959 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 29960-29969 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 29970-29979 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 29980-29989 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 29990-29999 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30000-30009 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 30010-30019 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 30020-30029 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 30030-30039 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 30040-30049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 30050-30059 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30060-30069 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 30070-30079 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 30080-30089 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 30090-30099 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 30100-30109 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 30110-30119 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 30120-30129 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 22, // 30130-30139 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 30140-30149 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30150-30159 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 30160-30169 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30170-30179 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 30180-30189 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 30190-30199 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 30200-30209 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 30210-30219 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 30220-30229 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30230-30239 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 30240-30249 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 30250-30259 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 30260-30269 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 30270-30279 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 30280-30289 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 30290-30299 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 30300-30309 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 30310-30319 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 30320-30329 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30330-30339 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 30340-30349 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 30350-30359 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 30360-30369 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 30370-30379 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 30380-30389 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 30390-30399 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 30400-30409 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 30410-30419 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 30420-30429 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 30430-30439 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 30440-30449 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 30450-30459 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 30460-30469 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 30470-30479 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30480-30489 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 30490-30499 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 30500-30509 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 30510-30519 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 30520-30529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 30530-30539 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 30540-30549 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 18, // 30550-30559 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 30560-30569 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 30570-30579 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 30580-30589 - 3, 2, 1, 38, 37, 36, 35, 34, 33, 32, // 30590-30599 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 30600-30609 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 30610-30619 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30620-30629 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 30630-30639 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 30640-30649 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30650-30659 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30660-30669 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 30670-30679 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 30680-30689 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 30690-30699 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 30700-30709 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 30710-30719 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 30720-30729 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 30730-30739 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 30740-30749 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 30750-30759 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 30760-30769 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 30770-30779 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 30780-30789 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 30790-30799 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 30800-30809 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 30810-30819 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 30820-30829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 30830-30839 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30840-30849 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 30850-30859 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 30860-30869 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30870-30879 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 30880-30889 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 30890-30899 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30900-30909 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 30910-30919 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30920-30929 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 30930-30939 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 30940-30949 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 30950-30959 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 30960-30969 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 30970-30979 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 30980-30989 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 30990-30999 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 31000-31009 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 31010-31019 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 31020-31029 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 31030-31039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31040-31049 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 31050-31059 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 31060-31069 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 31070-31079 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31080-31089 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 31090-31099 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 31100-31109 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31110-31119 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 31120-31129 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 31130-31139 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 31140-31149 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 31150-31159 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31160-31169 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 31170-31179 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 31180-31189 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 31190-31199 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 31200-31209 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 31210-31219 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 31220-31229 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 31230-31239 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 31240-31249 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 31250-31259 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 31260-31269 - 1, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 31270-31279 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 31280-31289 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31290-31299 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 31300-31309 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 31310-31319 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 31320-31329 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 31330-31339 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31340-31349 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 31350-31359 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 31360-31369 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 31370-31379 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 31380-31389 - 1, 2, 1, 4, 3, 2, 1, 72, 71, 70, // 31390-31399 - 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, // 31400-31409 - 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, // 31410-31419 - 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, // 31420-31429 - 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 31430-31439 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 31440-31449 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 31450-31459 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 31460-31469 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 31470-31479 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 31480-31489 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 31490-31499 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31500-31509 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 31510-31519 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31520-31529 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31530-31539 - 1, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 31540-31549 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31550-31559 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 31560-31569 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 31570-31579 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 31580-31589 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31590-31599 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 31600-31609 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31610-31619 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 31620-31629 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 31630-31639 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 31640-31649 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 31650-31659 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 31660-31669 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31670-31679 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 31680-31689 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 31690-31699 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 31700-31709 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31710-31719 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 31720-31729 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31730-31739 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31740-31749 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 31750-31759 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 31760-31769 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 31770-31779 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 31780-31789 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 31790-31799 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31800-31809 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 31810-31819 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 31820-31829 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31830-31839 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 31840-31849 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 31850-31859 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 31860-31869 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 31870-31879 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 31880-31889 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31890-31899 - 7, 6, 5, 4, 3, 2, 1, 50, 49, 48, // 31900-31909 - 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, // 31910-31919 - 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 31920-31929 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 31930-31939 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 31940-31949 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 31950-31959 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 31960-31969 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 31970-31979 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 31980-31989 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 31990-31999 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 32000-32009 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 32010-32019 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 32020-32029 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 32030-32039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32040-32049 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 32050-32059 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 32060-32069 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 32070-32079 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 32080-32089 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 32090-32099 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 32100-32109 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 32110-32119 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 32120-32129 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32130-32139 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 32140-32149 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 32150-32159 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 32160-32169 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 32170-32179 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 32180-32189 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 32190-32199 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 32200-32209 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 32210-32219 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 32220-32229 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 32230-32239 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32240-32249 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 32250-32259 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 32260-32269 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 32270-32279 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 32280-32289 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 32290-32299 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 32300-32309 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32310-32319 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 32320-32329 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32330-32339 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 32340-32349 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 32350-32359 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 32360-32369 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 32370-32379 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 32380-32389 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32390-32399 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32400-32409 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 32410-32419 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 32420-32429 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32430-32439 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 32440-32449 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 32450-32459 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 32460-32469 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 32470-32479 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32480-32489 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 32490-32499 - 3, 2, 1, 4, 3, 2, 1, 24, 23, 22, // 32500-32509 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 32510-32519 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32520-32529 - 1, 2, 1, 4, 3, 2, 1, 24, 23, 22, // 32530-32539 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 32540-32549 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32550-32559 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 32560-32569 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 32570-32579 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 32580-32589 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 32590-32599 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 32600-32609 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32610-32619 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 32620-32629 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 32630-32639 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 32640-32649 - 3, 2, 1, 34, 33, 32, 31, 30, 29, 28, // 32650-32659 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 32660-32669 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 32670-32679 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 32680-32689 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 32690-32699 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 32700-32709 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 30, // 32710-32719 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 32720-32729 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 32730-32739 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 32740-32749 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 32750-32759 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32760-32769 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 32770-32779 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 32780-32789 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 32790-32799 - 1, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 32800-32809 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 32810-32819 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 32820-32829 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 32830-32839 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 32840-32849 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 32850-32859 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 32860-32869 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 32870-32879 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 32880-32889 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 32890-32899 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 32900-32909 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 32910-32919 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 32920-32929 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 32930-32939 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 32940-32949 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 32950-32959 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 32960-32969 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 32970-32979 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 32980-32989 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 32990-32999 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 33000-33009 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 33010-33019 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 33020-33029 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 33030-33039 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 33040-33049 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 33050-33059 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33060-33069 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 33070-33079 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 33080-33089 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 33090-33099 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 33100-33109 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 30, // 33110-33119 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 33120-33129 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 33130-33139 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 33140-33149 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33150-33159 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 33160-33169 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 33170-33179 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33180-33189 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 33190-33199 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 33200-33209 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 33210-33219 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 33220-33229 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 33230-33239 - 7, 6, 5, 4, 3, 2, 1, 40, 39, 38, // 33240-33249 - 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 33250-33259 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 33260-33269 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 33270-33279 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 33280-33289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33290-33299 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33300-33309 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 33310-33319 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 33320-33329 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 33330-33339 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 33340-33349 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 33350-33359 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 33360-33369 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 33370-33379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33380-33389 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 33390-33399 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 33400-33409 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 33410-33419 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 33420-33429 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 33430-33439 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 33440-33449 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 33450-33459 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 33460-33469 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 33470-33479 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 33480-33489 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 33490-33499 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 33500-33509 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33510-33519 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 33520-33529 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 33530-33539 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 33540-33549 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 33550-33559 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 33560-33569 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 33570-33579 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 33580-33589 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 33590-33599 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 33600-33609 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 33610-33619 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 33620-33629 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 33630-33639 - 1, 6, 5, 4, 3, 2, 1, 32, 31, 30, // 33640-33649 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 33650-33659 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 33660-33669 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 33670-33679 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 33680-33689 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 33690-33699 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 33700-33709 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 33710-33719 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 33720-33729 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 33730-33739 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 33740-33749 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 33750-33759 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 33760-33769 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 33770-33779 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33780-33789 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 33790-33799 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 33800-33809 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 33810-33819 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 33820-33829 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 33830-33839 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33840-33849 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 33850-33859 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 33860-33869 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 33870-33879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 33880-33889 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 33890-33899 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33900-33909 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 33910-33919 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 33920-33929 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 33930-33939 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 33940-33949 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 33950-33959 - 1, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 33960-33969 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 33970-33979 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 33980-33989 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 33990-33999 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 34000-34009 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 34010-34019 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34020-34029 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 34030-34039 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 34040-34049 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 34050-34059 - 1, 62, 61, 60, 59, 58, 57, 56, 55, 54, // 34060-34069 - 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, // 34070-34079 - 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 34080-34089 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 34090-34099 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 34100-34109 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 34110-34119 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 34120-34129 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34130-34139 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 34140-34149 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 34150-34159 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34160-34169 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 34170-34179 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 34180-34189 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 34190-34199 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34200-34209 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 34210-34219 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34220-34229 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 34230-34239 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 34240-34249 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 34250-34259 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 34260-34269 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 34270-34279 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 34280-34289 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 34290-34299 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 34300-34309 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 34310-34319 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 34320-34329 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 34330-34339 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34340-34349 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34350-34359 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 34360-34369 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34370-34379 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 34380-34389 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 34390-34399 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 34400-34409 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34410-34419 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 34420-34429 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 34430-34439 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 34440-34449 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 34450-34459 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 34460-34469 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 34470-34479 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 34480-34489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 34490-34499 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34500-34509 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 34510-34519 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 34520-34529 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 34530-34539 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 34, // 34540-34549 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 34550-34559 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 34560-34569 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 34570-34579 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 34580-34589 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 34590-34599 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 34600-34609 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 34610-34619 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34620-34629 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 34630-34639 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 34640-34649 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 34650-34659 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 34660-34669 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 34670-34679 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 34680-34689 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 34690-34699 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 34700-34709 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34710-34719 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 34720-34729 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 34730-34739 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 34740-34749 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 34750-34759 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 34760-34769 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34770-34779 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 34780-34789 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 34790-34799 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 34800-34809 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 34810-34819 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 34820-34829 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34830-34839 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 22, // 34840-34849 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 34850-34859 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34860-34869 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 34870-34879 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 34880-34889 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 34890-34899 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 34900-34909 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 20, // 34910-34919 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 34920-34929 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 34930-34939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 34940-34949 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34950-34959 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 34960-34969 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 34970-34979 - 1, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 34980-34989 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 34990-34999 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 35000-35009 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 35010-35019 - 3, 2, 1, 4, 3, 2, 1, 24, 23, 22, // 35020-35029 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 35030-35039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35040-35049 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 35050-35059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 35060-35069 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35070-35079 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 35080-35089 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 35090-35099 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 35100-35109 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 35110-35119 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 35120-35129 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35130-35139 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 35140-35149 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 35150-35159 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35160-35169 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 35170-35179 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 35180-35189 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35190-35199 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 35200-35209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35210-35219 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 35220-35229 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 35230-35239 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35240-35249 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 35250-35259 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 35260-35269 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 35270-35279 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35280-35289 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 35290-35299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35300-35309 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 35310-35319 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 35320-35329 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 35330-35339 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 35340-35349 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 35350-35359 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 35360-35369 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35370-35379 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 35380-35389 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 35390-35399 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 35400-35409 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 35410-35419 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 35420-35429 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 35430-35439 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 35440-35449 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35450-35459 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 35460-35469 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 35470-35479 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35480-35489 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 35490-35499 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 35500-35509 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35510-35519 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 35520-35529 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 35530-35539 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 35540-35549 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 35550-35559 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 35560-35569 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 35570-35579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35580-35589 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 35590-35599 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 35600-35609 - 7, 6, 5, 4, 3, 2, 1, 54, 53, 52, // 35610-35619 - 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, // 35620-35629 - 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 35630-35639 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 35640-35649 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 35650-35659 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35660-35669 - 1, 6, 5, 4, 3, 2, 1, 52, 51, 50, // 35670-35679 - 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, // 35680-35689 - 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 35690-35699 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 35700-35709 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 35710-35719 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 35720-35729 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 35730-35739 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 35740-35749 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 35750-35759 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35760-35769 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 35770-35779 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 35780-35789 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 35790-35799 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 35800-35809 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 35810-35819 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35820-35829 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 35830-35839 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35840-35849 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 35850-35859 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 35860-35869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 35870-35879 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 35880-35889 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 35890-35899 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35900-35909 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 35910-35919 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 35920-35929 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 35930-35939 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 35940-35949 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 35950-35959 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 35960-35969 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 35970-35979 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 35980-35989 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 35990-35999 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 36000-36009 - 1, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 36010-36019 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 36020-36029 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 36030-36039 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 36040-36049 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36050-36059 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 36060-36069 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 36070-36079 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 36080-36089 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 36090-36099 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 36100-36109 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 36110-36119 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36120-36129 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 36130-36139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36140-36149 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36150-36159 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 36160-36169 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 36170-36179 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 36180-36189 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 36190-36199 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 36200-36209 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 36210-36219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 36220-36229 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36230-36239 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36240-36249 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36250-36259 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 36260-36269 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 36270-36279 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36280-36289 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 36290-36299 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 36300-36309 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 36310-36319 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 36320-36329 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36330-36339 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 36340-36349 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 36350-36359 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36360-36369 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 36370-36379 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 44, // 36380-36389 - 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 36390-36399 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 36400-36409 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 36410-36419 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36420-36429 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 36430-36439 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36440-36449 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 36450-36459 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 36460-36469 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 36470-36479 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36480-36489 - 3, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 36490-36499 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 36500-36509 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36510-36519 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 36520-36529 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36530-36539 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36540-36549 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 36550-36559 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 36560-36569 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36570-36579 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 36580-36589 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 36590-36599 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 36600-36609 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 36610-36619 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 36620-36629 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 36630-36639 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 36640-36649 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 36650-36659 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36660-36669 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 36670-36679 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 36680-36689 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 36690-36699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 36700-36709 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 36710-36719 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 36720-36729 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 36730-36739 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 36740-36749 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36750-36759 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 36760-36769 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 36770-36779 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 36780-36789 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 36790-36799 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 36800-36809 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36810-36819 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36820-36829 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 36830-36839 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 36840-36849 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 36850-36859 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 36860-36869 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 36870-36879 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 36880-36889 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 36890-36899 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36900-36909 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 36910-36919 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 36920-36929 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36930-36939 - 3, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 36940-36949 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 36950-36959 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 36960-36969 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 36970-36979 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 36980-36989 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 36990-36999 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 37000-37009 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 37010-37019 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 37020-37029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 37030-37039 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 37040-37049 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 37050-37059 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 37060-37069 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37070-37079 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 37080-37089 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 37090-37099 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37100-37109 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 37110-37119 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 37120-37129 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 37130-37139 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 37140-37149 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 37150-37159 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37160-37169 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37170-37179 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 37180-37189 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 37190-37199 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37200-37209 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 37210-37219 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 37220-37229 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 37230-37239 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 37240-37249 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 37250-37259 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 37260-37269 - 3, 2, 1, 4, 3, 2, 1, 30, 29, 28, // 37270-37279 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 37280-37289 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37290-37299 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 37300-37309 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 37310-37319 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37320-37329 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 37330-37339 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37340-37349 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 37350-37359 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 37360-37369 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 37370-37379 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37380-37389 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 37390-37399 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 37400-37409 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 37410-37419 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 37420-37429 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37430-37439 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 37440-37449 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 37450-37459 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 37460-37469 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 37470-37479 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 37480-37489 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 37490-37499 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 37500-37509 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 37510-37519 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 37520-37529 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 37530-37539 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 37540-37549 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37550-37559 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 37560-37569 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 37570-37579 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 37580-37589 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37590-37599 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 37600-37609 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 37610-37619 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 37620-37629 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 37630-37639 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 37640-37649 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 37650-37659 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 37660-37669 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 37670-37679 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37680-37689 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 37690-37699 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37700-37709 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 37710-37719 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 37720-37729 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37730-37739 - 7, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 37740-37749 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 37750-37759 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 37760-37769 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37770-37779 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 37780-37789 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 37790-37799 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37800-37809 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 37810-37819 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37820-37829 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37830-37839 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 37840-37849 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 37850-37859 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37860-37869 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 37870-37879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 37880-37889 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 37890-37899 - 7, 6, 5, 4, 3, 2, 1, 44, 43, 42, // 37900-37909 - 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 37910-37919 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 37920-37929 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 37930-37939 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 37940-37949 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 37950-37959 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 37960-37969 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 37970-37979 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 37980-37989 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 37990-37999 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38000-38009 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 38010-38019 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 38020-38029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 38030-38039 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 38040-38049 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 38050-38059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 38060-38069 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38070-38079 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 38080-38089 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 38090-38099 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38100-38109 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 30, // 38110-38119 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 38120-38129 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 38130-38139 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 38140-38149 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 38150-38159 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 38160-38169 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 38170-38179 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 38180-38189 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 38190-38199 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 38200-38209 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 38210-38219 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38220-38229 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 38230-38239 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 38240-38249 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38250-38259 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38260-38269 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 38270-38279 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 38280-38289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 38290-38299 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 38300-38309 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 38310-38319 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 38320-38329 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 38330-38339 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38340-38349 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 38350-38359 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38360-38369 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 38370-38379 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38380-38389 - 3, 2, 1, 38, 37, 36, 35, 34, 33, 32, // 38390-38399 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 38400-38409 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 38410-38419 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38420-38429 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 38430-38439 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 38440-38449 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 38450-38459 - 1, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 38460-38469 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 38470-38479 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 38480-38489 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38490-38499 - 1, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 38500-38509 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 38510-38519 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 38520-38529 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38530-38539 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 38540-38549 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 38550-38559 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 24, // 38560-38569 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 38570-38579 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38580-38589 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 38590-38599 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 38600-38609 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 38610-38619 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 38620-38629 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 38630-38639 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38640-38649 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 38650-38659 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 38660-38669 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 38670-38679 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38680-38689 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 38690-38699 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 38700-38709 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 38710-38719 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 38720-38729 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 38730-38739 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 38740-38749 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 38750-38759 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 38760-38769 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38770-38779 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 38780-38789 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38790-38799 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 38800-38809 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38810-38819 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38820-38829 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 38830-38839 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38840-38849 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38850-38859 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 38860-38869 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 38870-38879 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38880-38889 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38890-38899 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 38900-38909 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 38910-38919 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 38920-38929 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 38930-38939 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38940-38949 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 38950-38959 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 38960-38969 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 38970-38979 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 38980-38989 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 38990-38999 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 39000-39009 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 39010-39019 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 39020-39029 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39030-39039 - 1, 2, 1, 4, 3, 2, 1, 32, 31, 30, // 39040-39049 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 39050-39059 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 39060-39069 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 39070-39079 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 39080-39089 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 39090-39099 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 39100-39109 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 39110-39119 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 39120-39129 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 39130-39139 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 39140-39149 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 39150-39159 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 39160-39169 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39170-39179 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39180-39189 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 39190-39199 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 39200-39209 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 39210-39219 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 39220-39229 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 39230-39239 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39240-39249 - 1, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 39250-39259 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 39260-39269 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 39270-39279 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 39280-39289 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 39290-39299 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 39300-39309 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 39310-39319 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 39320-39329 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39330-39339 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 39340-39349 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 39350-39359 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 39360-39369 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 39370-39379 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 39380-39389 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 39390-39399 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 39400-39409 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 39410-39419 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 39420-39429 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 39430-39439 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 39440-39449 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39450-39459 - 1, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 39460-39469 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 39470-39479 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 39480-39489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 39490-39499 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 39500-39509 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39510-39519 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 39520-39529 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39530-39539 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39540-39549 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 39550-39559 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 39560-39569 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39570-39579 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 39580-39589 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 39590-39599 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 39600-39609 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 39610-39619 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 39620-39629 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 39630-39639 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 39640-39649 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 39650-39659 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 39660-39669 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 39670-39679 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 39680-39689 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 39690-39699 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 39700-39709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 39710-39719 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 39720-39729 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 39730-39739 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 39740-39749 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39750-39759 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 39760-39769 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 39770-39779 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39780-39789 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 39790-39799 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 39800-39809 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39810-39819 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 39820-39829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 39830-39839 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 39840-39849 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 39850-39859 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 39860-39869 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 39870-39879 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 39880-39889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39890-39899 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 39900-39909 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 39910-39919 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 39920-39929 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 39930-39939 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 39940-39949 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 39950-39959 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 39960-39969 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 39970-39979 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 20, // 39980-39989 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 39990-39999 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 40000-40009 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 40010-40019 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 40020-40029 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 24, // 40030-40039 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 40040-40049 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40050-40059 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 40060-40069 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 40070-40079 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 40080-40089 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 40090-40099 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 40100-40109 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40110-40119 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 22, // 40120-40129 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 40130-40139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 40140-40149 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 40150-40159 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 40160-40169 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 40170-40179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 40180-40189 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 40190-40199 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40200-40209 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 40210-40219 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 40220-40229 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 40230-40239 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40240-40249 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 40250-40259 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 40260-40269 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 40270-40279 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 54, // 40280-40289 - 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, // 40290-40299 - 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 40300-40309 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 40310-40319 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 40320-40329 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40330-40339 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 40340-40349 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 40350-40359 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 40360-40369 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 40370-40379 - 7, 6, 5, 4, 3, 2, 1, 36, 35, 34, // 40380-40389 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 40390-40399 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 40400-40409 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40410-40419 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 40420-40429 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 40430-40439 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 40440-40449 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 40450-40459 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 40460-40469 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40470-40479 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 40480-40489 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 40490-40499 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 40500-40509 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 40510-40519 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 40520-40529 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40530-40539 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 40540-40549 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 40550-40559 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 40560-40569 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 40570-40579 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 40580-40589 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 40590-40599 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 40600-40609 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 40610-40619 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 40620-40629 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 54, // 40630-40639 - 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, // 40640-40649 - 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 40650-40659 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 40660-40669 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 40670-40679 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40680-40689 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 40690-40699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, // 40700-40709 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 40710-40719 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 40720-40729 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 40730-40739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 40740-40749 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 40750-40759 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 40760-40769 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 40770-40779 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 40780-40789 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 40790-40799 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40800-40809 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 40810-40819 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 40820-40829 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 40830-40839 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 40840-40849 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 40850-40859 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 40860-40869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 40870-40879 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 40880-40889 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 40890-40899 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 40900-40909 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 40910-40919 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 40920-40929 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 40930-40939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 40940-40949 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 40950-40959 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40960-40969 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 40970-40979 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 40980-40989 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 40990-40999 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41000-41009 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 41010-41019 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 41020-41029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 41030-41039 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 41040-41049 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 41050-41059 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 41060-41069 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 41070-41079 - 1, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 41080-41089 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 41090-41099 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 41100-41109 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 41110-41119 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41120-41129 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41130-41139 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 41140-41149 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41150-41159 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 41160-41169 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 41170-41179 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 41180-41189 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41190-41199 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 41200-41209 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 41210-41219 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 41220-41229 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 41230-41239 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 41240-41249 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 41250-41259 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 41260-41269 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41270-41279 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 41280-41289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 34, // 41290-41299 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 41300-41309 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 41310-41319 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 41320-41329 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 41330-41339 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41340-41349 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 41350-41359 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 41360-41369 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41370-41379 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 41380-41389 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 41390-41399 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41400-41409 - 1, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 41410-41419 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 41420-41429 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 41430-41439 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 41440-41449 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 41450-41459 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 41460-41469 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 41470-41479 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41480-41489 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 41490-41499 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 41500-41509 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 41510-41519 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 41520-41529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 41530-41539 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 30, // 41540-41549 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 41550-41559 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 41560-41569 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 41570-41579 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 41580-41589 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 41590-41599 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 41600-41609 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 41610-41619 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 41620-41629 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41630-41639 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 41640-41649 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 41650-41659 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 41660-41669 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41670-41679 - 1, 6, 5, 4, 3, 2, 1, 32, 31, 30, // 41680-41689 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 41690-41699 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 41700-41709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 41710-41719 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 41720-41729 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 41730-41739 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 41740-41749 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 41750-41759 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41760-41769 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 41770-41779 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 41780-41789 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41790-41799 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 41800-41809 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 41810-41819 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 41820-41829 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 41830-41839 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 41840-41849 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 41850-41859 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 41860-41869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 41870-41879 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 41880-41889 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 41890-41899 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 41900-41909 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 41910-41919 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 41920-41929 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41930-41939 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 41940-41949 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 41950-41959 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 41960-41969 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 41970-41979 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 41980-41989 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 41990-41999 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 42000-42009 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 42010-42019 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 42020-42029 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 42030-42039 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 42040-42049 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42050-42059 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42060-42069 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 42070-42079 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 42080-42089 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42090-42099 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 42100-42109 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 42110-42119 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42120-42129 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 42130-42139 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 42140-42149 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 42150-42159 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 42160-42169 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 42170-42179 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 42180-42189 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 42190-42199 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 42200-42209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42210-42219 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 42220-42229 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 42230-42239 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 42240-42249 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 42250-42259 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 42260-42269 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42270-42279 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 42280-42289 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 42290-42299 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 42300-42309 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 42310-42319 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 42320-42329 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 42330-42339 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 42340-42349 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 42350-42359 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 42360-42369 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 42370-42379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42380-42389 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 42390-42399 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 24, // 42400-42409 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 42410-42419 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 42420-42429 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 42430-42439 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 42440-42449 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 42450-42459 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 42460-42469 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 42470-42479 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 42480-42489 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 42490-42499 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 42500-42509 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 42510-42519 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 42520-42529 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 42530-42539 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 42540-42549 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 42550-42559 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 42560-42569 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 42570-42579 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 42580-42589 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 42590-42599 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42600-42609 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 42610-42619 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 42620-42629 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42630-42639 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 42640-42649 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 42650-42659 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 42660-42669 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 42670-42679 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 42680-42689 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 42690-42699 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 42700-42709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 42710-42719 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 42720-42729 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 42730-42739 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 42740-42749 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 42750-42759 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 42760-42769 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 42770-42779 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 42780-42789 - 3, 2, 1, 4, 3, 2, 1, 24, 23, 22, // 42790-42799 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 42800-42809 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 42810-42819 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 42820-42829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 42830-42839 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 42840-42849 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 42850-42859 - 3, 2, 1, 36, 35, 34, 33, 32, 31, 30, // 42860-42869 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 42870-42879 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 42880-42889 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 42890-42899 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 42900-42909 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 42910-42919 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 42920-42929 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 42930-42939 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 42940-42949 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 42950-42959 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 42960-42969 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 42970-42979 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 42980-42989 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 42990-42999 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 43000-43009 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 43010-43019 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 43020-43029 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 43030-43039 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 43040-43049 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43050-43059 - 3, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 43060-43069 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 43070-43079 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43080-43089 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 43090-43099 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 43100-43109 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 43110-43119 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43120-43129 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 43130-43139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43140-43149 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 43150-43159 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 43160-43169 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 43170-43179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 43180-43189 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43190-43199 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 43200-43209 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43210-43219 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 43220-43229 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 43230-43239 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 43240-43249 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43250-43259 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43260-43269 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43270-43279 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 43280-43289 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 43290-43299 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43300-43309 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 43310-43319 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43320-43329 - 1, 60, 59, 58, 57, 56, 55, 54, 53, 52, // 43330-43339 - 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, // 43340-43349 - 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 43350-43359 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 43360-43369 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 43370-43379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43380-43389 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 43390-43399 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 43400-43409 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 43410-43419 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 43420-43429 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43430-43439 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43440-43449 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 43450-43459 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 43460-43469 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43470-43479 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 43480-43489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 43490-43499 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 43500-43509 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 43510-43519 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 43520-43529 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43530-43539 - 1, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 43540-43549 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 43550-43559 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43560-43569 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 43570-43579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43580-43589 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 43590-43599 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 43600-43609 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 43610-43619 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 43620-43629 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 43630-43639 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 43640-43649 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43650-43659 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 43660-43669 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 43670-43679 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43680-43689 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 43690-43699 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43700-43709 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 43710-43719 - 1, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 43720-43729 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 43730-43739 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43740-43749 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 43750-43759 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 43760-43769 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 43770-43779 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 43780-43789 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 43790-43799 - 1, 52, 51, 50, 49, 48, 47, 46, 45, 44, // 43800-43809 - 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 43810-43819 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 43820-43829 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 43830-43839 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43840-43849 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 43850-43859 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 43860-43869 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 43870-43879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 43880-43889 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 43890-43899 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43900-43909 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 43910-43919 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 43920-43929 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 43930-43939 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 43940-43949 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 43950-43959 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 43960-43969 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 43970-43979 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 43980-43989 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 43990-43999 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 44000-44009 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 44010-44019 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 44020-44029 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44030-44039 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 44040-44049 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 44050-44059 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44060-44069 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 44070-44079 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 44080-44089 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44090-44099 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44100-44109 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 44110-44119 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 44120-44129 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 44130-44139 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 44140-44149 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 44150-44159 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44160-44169 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 44170-44179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 44180-44189 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44190-44199 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 44200-44209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44210-44219 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 44220-44229 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 44230-44239 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 44240-44249 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 44250-44259 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 44260-44269 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 44270-44279 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 44280-44289 - 3, 2, 1, 58, 57, 56, 55, 54, 53, 52, // 44290-44299 - 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, // 44300-44309 - 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 44310-44319 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 44320-44329 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 44330-44339 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44340-44349 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 44350-44359 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44360-44369 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44370-44379 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 28, // 44380-44389 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 44390-44399 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 44400-44409 - 7, 6, 5, 4, 3, 2, 1, 32, 31, 30, // 44410-44419 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 44420-44429 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 44430-44439 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 44440-44449 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 44450-44459 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 44460-44469 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 44470-44479 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 44480-44489 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 44490-44499 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 44500-44509 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 44510-44519 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44520-44529 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 44530-44539 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 44540-44549 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 44550-44559 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 44560-44569 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 44570-44579 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 44580-44589 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 44590-44599 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 44600-44609 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 44610-44619 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 44620-44629 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 44630-44639 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 44640-44649 - 1, 6, 5, 4, 3, 2, 1, 26, 25, 24, // 44650-44659 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 44660-44669 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 44670-44679 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 44680-44689 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 44690-44699 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44700-44709 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 44710-44719 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 44720-44729 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44730-44739 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 44740-44749 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 44750-44759 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 44760-44769 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 44770-44779 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 44780-44789 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 44790-44799 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 44800-44809 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 44810-44819 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 44820-44829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 44830-44839 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 44840-44849 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 44850-44859 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 44860-44869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 44870-44879 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 44880-44889 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 44890-44899 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 44900-44909 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 44910-44919 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 44920-44929 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 44930-44939 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 44940-44949 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 44950-44959 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 44960-44969 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 44970-44979 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 44980-44989 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 44990-44999 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 45000-45009 - 3, 2, 1, 40, 39, 38, 37, 36, 35, 34, // 45010-45019 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 45020-45029 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 45030-45039 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 45040-45049 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 45050-45059 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 45060-45069 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 45070-45079 - 3, 2, 1, 36, 35, 34, 33, 32, 31, 30, // 45080-45089 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 45090-45099 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 45100-45109 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 45110-45119 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 45120-45129 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 45130-45139 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 45140-45149 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45150-45159 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 45160-45169 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 45170-45179 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45180-45189 - 1, 6, 5, 4, 3, 2, 1, 36, 35, 34, // 45190-45199 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 45200-45209 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 45210-45219 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 45220-45229 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 45230-45239 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 45240-45249 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 45250-45259 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 45260-45269 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45270-45279 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 45280-45289 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 45290-45299 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 45300-45309 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 45310-45319 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 45320-45329 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 45330-45339 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 45340-45349 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45350-45359 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 45360-45369 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 45370-45379 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 45380-45389 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 45390-45399 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 45400-45409 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 45410-45419 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 45420-45429 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 42, // 45430-45439 - 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 45440-45449 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 45450-45459 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 45460-45469 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45470-45479 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45480-45489 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 45490-45499 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 45500-45509 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 45510-45519 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 45520-45529 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 45530-45539 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 45540-45549 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 45550-45559 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 45560-45569 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 45570-45579 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 45580-45589 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 45590-45599 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 45600-45609 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 45610-45619 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45620-45629 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45630-45639 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 45640-45649 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 45650-45659 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 45660-45669 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 45670-45679 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45680-45689 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 45690-45699 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 45700-45709 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 45710-45719 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 45720-45729 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 45730-45739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45740-45749 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 45750-45759 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 45760-45769 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 38, // 45770-45779 - 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 45780-45789 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 45790-45799 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 45800-45809 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 45810-45819 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 45820-45829 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 45830-45839 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 45840-45849 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 45850-45859 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 45860-45869 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 45870-45879 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 45880-45889 - 3, 2, 1, 50, 49, 48, 47, 46, 45, 44, // 45890-45899 - 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 45900-45909 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 45910-45919 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 45920-45929 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 45930-45939 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 45940-45949 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 45950-45959 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 45960-45969 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 45970-45979 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 32, // 45980-45989 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 45990-45999 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 46000-46009 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46010-46019 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 46020-46029 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 46030-46039 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 46040-46049 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46050-46059 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46060-46069 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 46070-46079 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46080-46089 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 46090-46099 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 46100-46109 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 46110-46119 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46120-46129 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 46130-46139 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 46140-46149 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 46150-46159 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46160-46169 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46170-46179 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 46180-46189 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 46190-46199 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 46200-46209 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 46210-46219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 46220-46229 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 46230-46239 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 46240-46249 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46250-46259 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46260-46269 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 46270-46279 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 46280-46289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46290-46299 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 46300-46309 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 46310-46319 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 46320-46329 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 46330-46339 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 46340-46349 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 46350-46359 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 46360-46369 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46370-46379 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 46380-46389 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 46390-46399 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46400-46409 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 46410-46419 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 46420-46429 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 46430-46439 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 46440-46449 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 46450-46459 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46460-46469 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 46470-46479 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 46480-46489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 46490-46499 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 46500-46509 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46510-46519 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 46520-46529 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 46530-46539 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 46540-46549 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 46550-46559 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 46560-46569 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 46570-46579 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 46580-46589 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46590-46599 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 46600-46609 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 46610-46619 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46620-46629 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 46630-46639 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 46640-46649 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46650-46659 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 46660-46669 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 46670-46679 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 46680-46689 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46690-46699 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 46700-46709 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46710-46719 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 46720-46729 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 46730-46739 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 46740-46749 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 46750-46759 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 46760-46769 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 46770-46779 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 46780-46789 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 46790-46799 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 46800-46809 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 46810-46819 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 46820-46829 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 46830-46839 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46840-46849 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 46850-46859 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 46860-46869 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 46870-46879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 46880-46889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 46890-46899 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 46900-46909 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 46910-46919 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46920-46929 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 46930-46939 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 46940-46949 - 7, 6, 5, 4, 3, 2, 1, 36, 35, 34, // 46950-46959 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 46960-46969 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 46970-46979 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 46980-46989 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 46990-46999 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 47000-47009 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 47010-47019 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 47020-47029 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47030-47039 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47040-47049 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 28, // 47050-47059 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 47060-47069 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 47070-47079 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 47080-47089 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 47090-47099 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47100-47109 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 47110-47119 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 47120-47129 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 47130-47139 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 47140-47149 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47150-47159 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 47160-47169 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 47170-47179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 47180-47189 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 47190-47199 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 47200-47209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47210-47219 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 47220-47229 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 47230-47239 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47240-47249 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 47250-47259 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 47260-47269 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 47270-47279 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 47280-47289 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 47290-47299 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 47300-47309 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 47310-47319 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 47320-47329 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 47330-47339 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47340-47349 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 47350-47359 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 47360-47369 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47370-47379 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 47380-47389 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 47390-47399 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 47400-47409 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 47410-47419 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47420-47429 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47430-47439 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 47440-47449 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 32, // 47450-47459 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 47460-47469 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 47470-47479 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47480-47489 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 47490-47499 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 47500-47509 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 47510-47519 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 47520-47529 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 47530-47539 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 47540-47549 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 47550-47559 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 47560-47569 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47570-47579 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47580-47589 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 47590-47599 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 47600-47609 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 47610-47619 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 47620-47629 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 47630-47639 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 47640-47649 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 22, // 47650-47659 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 47660-47669 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47670-47679 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 47680-47689 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 47690-47699 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47700-47709 - 1, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 47710-47719 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 47720-47729 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 47730-47739 - 1, 2, 1, 34, 33, 32, 31, 30, 29, 28, // 47740-47749 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 47750-47759 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 47760-47769 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 47770-47779 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47780-47789 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 47790-47799 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 47800-47809 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 47810-47819 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 47820-47829 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 47830-47839 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 47840-47849 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 47850-47859 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 47860-47869 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 47870-47879 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 47880-47889 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 47890-47899 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 47900-47909 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 47910-47919 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 47920-47929 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 47930-47939 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 47940-47949 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 47950-47959 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 47960-47969 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 47970-47979 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 47980-47989 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 47990-47999 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 48000-48009 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 48010-48019 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 20, // 48020-48029 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 48030-48039 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 48040-48049 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 48050-48059 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48060-48069 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 48070-48079 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48080-48089 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 48090-48099 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 48100-48109 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 48110-48119 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48120-48129 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 48130-48139 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 48140-48149 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 48150-48159 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 48160-48169 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 48170-48179 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 48180-48189 - 3, 2, 1, 4, 3, 2, 1, 24, 23, 22, // 48190-48199 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 48200-48209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48210-48219 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 48220-48229 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 48230-48239 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 48240-48249 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 48250-48259 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48260-48269 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48270-48279 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 48280-48289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 48290-48299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48300-48309 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 48310-48319 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 48320-48329 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 48330-48339 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48340-48349 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 48350-48359 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48360-48369 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48370-48379 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 48380-48389 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 48390-48399 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 48400-48409 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 48410-48419 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 48420-48429 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 48430-48439 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 48440-48449 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48450-48459 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 48460-48469 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 48470-48479 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 48480-48489 - 1, 6, 5, 4, 3, 2, 1, 26, 25, 24, // 48490-48499 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 48500-48509 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48510-48519 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 48520-48529 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 48530-48539 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 48540-48549 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48550-48559 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 48560-48569 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 48570-48579 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 48580-48589 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 48590-48599 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48600-48609 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 48610-48619 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 48620-48629 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 48630-48639 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 48640-48649 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48650-48659 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48660-48669 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 52, // 48670-48679 - 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, // 48680-48689 - 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 48690-48699 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 48700-48709 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 48710-48719 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48720-48729 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 48730-48739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 48740-48749 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 48750-48759 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 48760-48769 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 48770-48779 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 48780-48789 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 48790-48799 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 48800-48809 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 48810-48819 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 48820-48829 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 48830-48839 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 48840-48849 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 48850-48859 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 48860-48869 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48870-48879 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 48880-48889 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 48890-48899 - 7, 6, 5, 4, 3, 2, 1, 40, 39, 38, // 48900-48909 - 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 48910-48919 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 48920-48929 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 48930-48939 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 48940-48949 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 48950-48959 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48960-48969 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 48970-48979 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 48980-48989 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 48990-48999 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 49000-49009 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 49010-49019 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49020-49029 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 49030-49039 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 49040-49049 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 49050-49059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 49060-49069 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49070-49079 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 49080-49089 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49090-49099 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 49100-49109 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 49110-49119 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 49120-49129 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 49130-49139 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 49140-49149 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 49150-49159 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 49160-49169 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 49170-49179 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49180-49189 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 49190-49199 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 49200-49209 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49210-49219 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 49220-49229 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 49230-49239 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49240-49249 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 49250-49259 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 49260-49269 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 49270-49279 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 49280-49289 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 49290-49299 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 49300-49309 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 49310-49319 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49320-49329 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 24, // 49330-49339 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 49340-49349 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49350-49359 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 22, // 49360-49369 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 49370-49379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49380-49389 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 49390-49399 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 49400-49409 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 49410-49419 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 49420-49429 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 49430-49439 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49440-49449 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 49450-49459 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 49460-49469 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 49470-49479 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 49480-49489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 49490-49499 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 49500-49509 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49510-49519 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 49520-49529 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 49530-49539 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 49540-49549 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 38, // 49550-49559 - 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 49560-49569 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 49570-49579 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 49580-49589 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 49590-49599 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 49600-49609 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 49610-49619 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 49620-49629 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 24, // 49630-49639 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 49640-49649 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49650-49659 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 49660-49669 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49670-49679 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 49680-49689 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 49690-49699 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49700-49709 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 49710-49719 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 49720-49729 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 49730-49739 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 49740-49749 - 7, 6, 5, 4, 3, 2, 1, 26, 25, 24, // 49750-49759 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 49760-49769 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49770-49779 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 49780-49789 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49790-49799 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 49800-49809 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49810-49819 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 49820-49829 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 49830-49839 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 49840-49849 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 49850-49859 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49860-49869 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 49870-49879 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49880-49889 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 49890-49899 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 49900-49909 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 49910-49919 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 49920-49929 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 49930-49939 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 49940-49949 - 7, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 49950-49959 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 49960-49969 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 49970-49979 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 49980-49989 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 49990-49999 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 50000-50009 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50010-50019 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 50020-50029 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 50030-50039 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 50040-50049 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 50050-50059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 50060-50069 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 50070-50079 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 50080-50089 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 50090-50099 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50100-50109 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 50110-50119 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 50120-50129 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 50130-50139 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 50140-50149 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 50150-50159 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 50160-50169 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 50170-50179 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 50180-50189 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 50190-50199 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 50200-50209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50210-50219 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 50220-50229 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 50230-50239 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 50240-50249 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50250-50259 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 50260-50269 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 50270-50279 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 50280-50289 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 50290-50299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50300-50309 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50310-50319 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 50320-50329 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 50330-50339 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 50340-50349 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 50350-50359 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 50360-50369 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 50370-50379 - 3, 2, 1, 4, 3, 2, 1, 24, 23, 22, // 50380-50389 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 50390-50399 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50400-50409 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 50410-50419 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 50420-50429 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50430-50439 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 50440-50449 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 50450-50459 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 50460-50469 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 50470-50479 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 50480-50489 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 50490-50499 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 50500-50509 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 50510-50519 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 50520-50529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 50530-50539 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 50540-50549 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 50550-50559 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 50560-50569 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50570-50579 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 50580-50589 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 28, // 50590-50599 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 50600-50609 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 50610-50619 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 50620-50629 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 50630-50639 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 50640-50649 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 50650-50659 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50660-50669 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 50670-50679 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 50680-50689 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 50690-50699 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 50700-50709 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 50710-50719 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 50720-50729 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50730-50739 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 50740-50749 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 50750-50759 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 50760-50769 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 50770-50779 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 32, // 50780-50789 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 50790-50799 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 50800-50809 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50810-50819 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 50820-50829 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 50830-50839 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 50840-50849 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 50850-50859 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 50860-50869 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 50870-50879 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50880-50889 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 50890-50899 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 50900-50909 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 50910-50919 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 50920-50929 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 50930-50939 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 50940-50949 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 50950-50959 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 50960-50969 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 50970-50979 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 50980-50989 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 50990-50999 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 51000-51009 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 51010-51019 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51020-51029 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51030-51039 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 51040-51049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 51050-51059 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51060-51069 - 1, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 51070-51079 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 51080-51089 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 51090-51099 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 51100-51109 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 51110-51119 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51120-51129 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 51130-51139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51140-51149 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 51150-51159 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 51160-51169 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 51170-51179 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51180-51189 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 51190-51199 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 51200-51209 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 51210-51219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 51220-51229 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 51230-51239 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 51240-51249 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 51250-51259 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 51260-51269 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51270-51279 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 51280-51289 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 51290-51299 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 51300-51309 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 51310-51319 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 51320-51329 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51330-51339 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 12, // 51340-51349 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51350-51359 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 51360-51369 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51370-51379 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 51380-51389 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 51390-51399 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 51400-51409 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 51410-51419 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 51420-51429 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 51430-51439 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 51440-51449 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51450-51459 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51460-51469 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 51470-51479 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 51480-51489 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51490-51499 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 51500-51509 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 51510-51519 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 51520-51529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 51530-51539 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51540-51549 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51550-51559 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 51560-51569 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 51570-51579 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51580-51589 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 51590-51599 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 51600-51609 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 51610-51619 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51620-51629 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 51630-51639 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 51640-51649 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 51650-51659 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51660-51669 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 51670-51679 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 51680-51689 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 51690-51699 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51700-51709 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 51710-51719 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 51720-51729 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 51730-51739 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 51740-51749 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 51750-51759 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 51760-51769 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 51770-51779 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 51780-51789 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 51790-51799 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 51800-51809 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 51810-51819 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 51820-51829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 51830-51839 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51840-51849 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 51850-51859 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 51860-51869 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 51870-51879 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 51880-51889 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 51890-51899 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 51900-51909 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 51910-51919 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 51920-51929 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51930-51939 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 51940-51949 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 51950-51959 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51960-51969 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 51970-51979 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 51980-51989 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 51990-51999 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 52000-52009 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52010-52019 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 52020-52029 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 52030-52039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52040-52049 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 52050-52059 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 52060-52069 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52070-52079 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 52080-52089 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 52090-52099 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 52100-52109 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52110-52119 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 52120-52129 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 52130-52139 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 52140-52149 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 52150-52159 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 52160-52169 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 52170-52179 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 52180-52189 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52190-52199 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 52200-52209 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 52210-52219 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 52220-52229 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 52230-52239 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 52240-52249 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 52250-52259 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 52260-52269 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 52270-52279 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 52280-52289 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52290-52299 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 52300-52309 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 52310-52319 - 1, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 52320-52329 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 52330-52339 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 52340-52349 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52350-52359 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 52360-52369 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 52370-52379 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 52380-52389 - 1, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 52390-52399 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 52400-52409 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 52410-52419 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 52420-52429 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 52430-52439 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 52440-52449 - 3, 2, 1, 4, 3, 2, 1, 32, 31, 30, // 52450-52459 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 52460-52469 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 52470-52479 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 52480-52489 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52490-52499 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52500-52509 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 52510-52519 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 52520-52529 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52530-52539 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 52540-52549 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 52550-52559 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 52560-52569 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 52570-52579 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 52580-52589 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 52590-52599 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 52600-52609 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 52610-52619 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 52620-52629 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 28, // 52630-52639 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 52640-52649 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 52650-52659 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 52660-52669 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 52670-52679 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52680-52689 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 52690-52699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 52700-52709 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52710-52719 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 52720-52729 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 52730-52739 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 52740-52749 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 52750-52759 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 52760-52769 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 52770-52779 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 52780-52789 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 52790-52799 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 52800-52809 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 52810-52819 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 52820-52829 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 52830-52839 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 52840-52849 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 52850-52859 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 52860-52869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 52870-52879 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 52880-52889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52890-52899 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 52900-52909 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 52910-52919 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 52920-52929 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 52930-52939 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 52940-52949 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 52950-52959 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 52960-52969 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 52970-52979 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 52980-52989 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 52990-52999 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 53000-53009 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 53010-53019 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 53020-53029 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 53030-53039 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 53040-53049 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 53050-53059 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 53060-53069 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 53070-53079 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 53080-53089 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 53090-53099 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 53100-53109 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 53110-53119 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 53120-53129 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 53130-53139 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 53140-53149 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53150-53159 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53160-53169 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 53170-53179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 53180-53189 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 53190-53199 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 53200-53209 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 53210-53219 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53220-53229 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 28, // 53230-53239 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 53240-53249 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 53250-53259 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 53260-53269 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 53270-53279 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 53280-53289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 53290-53299 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 53300-53309 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 53310-53319 - 3, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 53320-53329 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 53330-53339 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 53340-53349 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 53350-53359 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 53360-53369 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 53370-53379 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 53380-53389 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53390-53399 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 53400-53409 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 53410-53419 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 53420-53429 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 53430-53439 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 53440-53449 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 53450-53459 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 53460-53469 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 53470-53479 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 53480-53489 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 53490-53499 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 53500-53509 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 53510-53519 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 53520-53529 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 53530-53539 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 53540-53549 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 53550-53559 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 53560-53569 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 53570-53579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53580-53589 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 53590-53599 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 53600-53609 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 53610-53619 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 53620-53629 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 53630-53639 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 53640-53649 - 3, 2, 1, 4, 3, 2, 1, 24, 23, 22, // 53650-53659 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 53660-53669 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53670-53679 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 53680-53689 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 53690-53699 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 53700-53709 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 53710-53719 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53720-53729 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 53730-53739 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 53740-53749 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 53750-53759 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 53760-53769 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 53770-53779 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 53780-53789 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 53790-53799 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 53800-53809 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 53810-53819 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53820-53829 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 53830-53839 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 53840-53849 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 53850-53859 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 53860-53869 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53870-53879 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 53880-53889 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 53890-53899 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 53900-53909 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 53910-53919 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 53920-53929 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 53930-53939 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 53940-53949 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 28, // 53950-53959 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 53960-53969 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 53970-53979 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 53980-53989 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 53990-53999 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54000-54009 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 54010-54019 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 54020-54029 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 54030-54039 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 54040-54049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 54050-54059 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 54060-54069 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 54070-54079 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 54080-54089 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54090-54099 - 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 54100-54109 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54110-54119 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 54120-54129 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 54130-54139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54140-54149 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 54150-54159 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 54160-54169 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54170-54179 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 54180-54189 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 54190-54199 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 54200-54209 - 7, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 54210-54219 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 54220-54229 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 54230-54239 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54240-54249 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 54250-54259 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 54260-54269 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 54270-54279 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 54280-54289 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 54290-54299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54300-54309 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 54310-54319 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 54320-54329 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 54330-54339 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 54340-54349 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54350-54359 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 54360-54369 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 54370-54379 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 54380-54389 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54390-54399 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 54400-54409 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 54410-54419 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 54420-54429 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 54430-54439 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 20, // 54440-54449 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 54450-54459 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 54460-54469 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 54470-54479 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 54480-54489 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 54490-54499 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 54500-54509 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 54510-54519 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 54520-54529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 54530-54539 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 54540-54549 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 54550-54559 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 54560-54569 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 54570-54579 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 54580-54589 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54590-54599 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 54600-54609 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 54610-54619 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 54620-54629 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 54630-54639 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 54640-54649 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 54650-54659 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 54660-54669 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 30, // 54670-54679 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 54680-54689 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 54690-54699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 54700-54709 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 54710-54719 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 54720-54729 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 54730-54739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54740-54749 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 54750-54759 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 54760-54769 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 54770-54779 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 54780-54789 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, // 54790-54799 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 54800-54809 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 54810-54819 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 54820-54829 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 54830-54839 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54840-54849 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 54850-54859 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 54860-54869 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 54870-54879 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 54880-54889 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 54890-54899 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 54900-54909 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 54910-54919 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 54920-54929 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54930-54939 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 54940-54949 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 54950-54959 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 54960-54969 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 54970-54979 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 54980-54989 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 54990-54999 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 55000-55009 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55010-55019 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 55020-55029 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 55030-55039 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 55040-55049 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 55050-55059 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 55060-55069 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 24, // 55070-55079 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 55080-55089 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 55090-55099 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 55100-55109 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 55110-55119 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 55120-55129 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 55130-55139 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 55140-55149 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 55150-55159 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 55160-55169 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 55170-55179 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 55180-55189 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55190-55199 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 55200-55209 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 55210-55219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 55220-55229 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 55230-55239 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 55240-55249 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 32, // 55250-55259 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 55260-55269 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 55270-55279 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55280-55289 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 55290-55299 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 55300-55309 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 55310-55319 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55320-55329 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 55330-55339 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 55340-55349 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 55350-55359 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 55360-55369 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 55370-55379 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 55380-55389 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 55390-55399 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55400-55409 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 55410-55419 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 55420-55429 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 55430-55439 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 55440-55449 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 55450-55459 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 55460-55469 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 55470-55479 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 55480-55489 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55490-55499 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55500-55509 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 55510-55519 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 55520-55529 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55530-55539 - 1, 6, 5, 4, 3, 2, 1, 32, 31, 30, // 55540-55549 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 55550-55559 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 55560-55569 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 55570-55579 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 55580-55589 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 55590-55599 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 55600-55609 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 55610-55619 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55620-55629 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 55630-55639 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 55640-55649 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55650-55659 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 55660-55669 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 55670-55679 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55680-55689 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 55690-55699 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55700-55709 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 55710-55719 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 55720-55729 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 55730-55739 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 55740-55749 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 55750-55759 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 55760-55769 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 55770-55779 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 55780-55789 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 55790-55799 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 55800-55809 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 55810-55819 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 55820-55829 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 55830-55839 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 55840-55849 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 55850-55859 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55860-55869 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 55870-55879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 55880-55889 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 55890-55899 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 55900-55909 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 55910-55919 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 55920-55929 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 55930-55939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 55940-55949 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 55950-55959 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 55960-55969 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 55970-55979 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 55980-55989 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 55990-55999 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 30, // 56000-56009 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 56010-56019 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 56020-56029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 56030-56039 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 56040-56049 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 56050-56059 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 56060-56069 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56070-56079 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 56080-56089 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 56090-56099 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 56100-56109 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 56110-56119 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 56120-56129 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 56130-56139 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 56140-56149 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 56150-56159 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 56160-56169 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 56170-56179 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 56180-56189 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 56190-56199 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 28, // 56200-56209 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 56210-56219 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 56220-56229 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 56230-56239 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 56240-56249 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 56250-56259 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 30, // 56260-56269 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 56270-56279 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 56280-56289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 56290-56299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56300-56309 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 56310-56319 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 56320-56329 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 56330-56339 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 56340-56349 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 56350-56359 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 56360-56369 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 56370-56379 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 56380-56389 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 56390-56399 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 56400-56409 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 56410-56419 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56420-56429 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 56430-56439 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 56440-56449 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 56450-56459 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 56460-56469 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 56470-56479 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 56480-56489 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56490-56499 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 56500-56509 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 56510-56519 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 56520-56529 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 56530-56539 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 56540-56549 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 56550-56559 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 56560-56569 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 56570-56579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56580-56589 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 56590-56599 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56600-56609 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 56610-56619 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 56620-56629 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 56630-56639 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 56640-56649 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 56650-56659 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 56660-56669 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56670-56679 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 56680-56689 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56690-56699 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56700-56709 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 56710-56719 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56720-56729 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 56730-56739 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 56740-56749 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 56750-56759 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 56760-56769 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 56770-56779 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 56780-56789 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 56790-56799 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 56800-56809 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 56810-56819 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 56820-56829 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 56830-56839 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 56840-56849 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 56850-56859 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 56860-56869 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 56870-56879 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56880-56889 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 56890-56899 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 56900-56909 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56910-56919 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 56920-56929 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56930-56939 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 56940-56949 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 56950-56959 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 56960-56969 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 56970-56979 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 56980-56989 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 38, // 56990-56999 - 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 57000-57009 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 57010-57019 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57020-57029 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 57030-57039 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 57040-57049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 57050-57059 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 57060-57069 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 57070-57079 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 57080-57089 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 57090-57099 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 57100-57109 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 57110-57119 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57120-57129 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 57130-57139 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 57140-57149 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 57150-57159 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 57160-57169 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 57170-57179 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57180-57189 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 57190-57199 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 57200-57209 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57210-57219 - 1, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 57220-57229 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57230-57239 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57240-57249 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 57250-57259 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 57260-57269 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 57270-57279 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 57280-57289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57290-57299 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 57300-57309 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 57310-57319 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 57320-57329 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57330-57339 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 57340-57349 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57350-57359 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 57360-57369 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 57370-57379 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 57380-57389 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 57390-57399 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 57400-57409 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 57410-57419 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 57420-57429 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 57430-57439 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57440-57449 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 57450-57459 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 57460-57469 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57470-57479 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 57480-57489 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 57490-57499 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 57500-57509 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57510-57519 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 28, // 57520-57529 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 57530-57539 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57540-57549 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 57550-57559 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57560-57569 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57570-57579 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 57580-57589 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 57590-57599 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 57600-57609 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 57610-57619 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57620-57629 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 57630-57639 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 57640-57649 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 57650-57659 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 57660-57669 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 57670-57679 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 57680-57689 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 57690-57699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 57700-57709 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 57710-57719 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 57720-57729 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 57730-57739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57740-57749 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 57750-57759 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 57760-57769 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 57770-57779 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 57780-57789 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 57790-57799 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 20, // 57800-57809 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 57810-57819 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 57820-57829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 57830-57839 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 57840-57849 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 57850-57859 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 57860-57869 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57870-57879 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 57880-57889 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 57890-57899 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 57900-57909 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 57910-57919 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 57920-57929 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 57930-57939 - 3, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 57940-57949 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 57950-57959 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 57960-57969 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 57970-57979 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 57980-57989 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 57990-57999 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 58000-58009 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 58010-58019 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 58020-58029 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 58030-58039 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 58040-58049 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 58050-58059 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 58060-58069 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 58070-58079 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 58080-58089 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 58090-58099 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 58100-58109 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 58110-58119 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 58120-58129 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58130-58139 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 58140-58149 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 58150-58159 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 58160-58169 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 58170-58179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 58180-58189 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 58190-58199 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 58200-58209 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 58210-58219 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 58220-58229 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 58230-58239 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 58240-58249 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 58250-58259 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 58260-58269 - 1, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 58270-58279 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 58280-58289 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 58290-58299 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 58300-58309 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 58310-58319 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58320-58329 - 7, 6, 5, 4, 3, 2, 1, 26, 25, 24, // 58330-58339 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 58340-58349 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 58350-58359 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 10, // 58360-58369 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 58370-58379 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 58380-58389 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 58390-58399 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 58400-58409 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 58410-58419 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 58420-58429 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 58430-58439 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 58440-58449 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 58450-58459 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58460-58469 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 58470-58479 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 58480-58489 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 58490-58499 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 58500-58509 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 58510-58519 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58520-58529 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 58530-58539 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 58540-58549 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58550-58559 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 58560-58569 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 58570-58579 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 58580-58589 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 58590-58599 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 58600-58609 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 58610-58619 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 58620-58629 - 1, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 58630-58639 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58640-58649 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 58650-58659 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 58660-58669 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 58670-58679 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 58680-58689 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 58690-58699 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 58700-58709 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58710-58719 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 58720-58729 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 58730-58739 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58740-58749 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 58750-58759 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 58760-58769 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58770-58779 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 42, // 58780-58789 - 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 58790-58799 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 58800-58809 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 58810-58819 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 58820-58829 - 1, 58, 57, 56, 55, 54, 53, 52, 51, 50, // 58830-58839 - 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, // 58840-58849 - 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 58850-58859 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 58860-58869 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 58870-58879 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 58880-58889 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 58890-58899 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 58900-58909 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 58910-58919 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 58920-58929 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 58930-58939 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 58940-58949 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 58950-58959 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 58960-58969 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 58970-58979 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 58980-58989 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 58990-58999 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 59000-59009 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59010-59019 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 59020-59029 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 59030-59039 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59040-59049 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 59050-59059 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 59060-59069 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 59070-59079 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 59080-59089 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 59090-59099 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 59100-59109 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 59110-59119 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 59120-59129 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59130-59139 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 59140-59149 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 59150-59159 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 59160-59169 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 59170-59179 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 59180-59189 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 59190-59199 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 59200-59209 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 59210-59219 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 59220-59229 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 59230-59239 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 59240-59249 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 59250-59259 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 59260-59269 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 59270-59279 - 1, 52, 51, 50, 49, 48, 47, 46, 45, 44, // 59280-59289 - 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, // 59290-59299 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 59300-59309 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 59310-59319 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 59320-59329 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 59330-59339 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59340-59349 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 59350-59359 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 59360-59369 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 59370-59379 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 59380-59389 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 59390-59399 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 59400-59409 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 59410-59419 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 59420-59429 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59430-59439 - 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 59440-59449 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 59450-59459 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 59460-59469 - 1, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 59470-59479 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 59480-59489 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 59490-59499 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 59500-59509 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 59510-59519 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 59520-59529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 59530-59539 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 59540-59549 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 59550-59559 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 59560-59569 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59570-59579 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 59580-59589 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 59590-59599 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59600-59609 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 59610-59619 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 22, // 59620-59629 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 59630-59639 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59640-59649 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 59650-59659 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 59660-59669 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 59670-59679 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 59680-59689 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 59690-59699 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 59700-59709 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 59710-59719 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 59720-59729 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 59730-59739 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 59740-59749 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 59750-59759 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59760-59769 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 59770-59779 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59780-59789 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 59790-59799 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 59800-59809 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 59810-59819 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 59820-59829 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 59830-59839 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 59840-59849 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 59850-59859 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 59860-59869 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 59870-59879 - 7, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 59880-59889 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 59890-59899 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 59900-59909 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59910-59919 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 59920-59929 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 59930-59939 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59940-59949 - 1, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 59950-59959 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59960-59969 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 59970-59979 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 59980-59989 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 59990-59999 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 60000-60009 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 60010-60019 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 60020-60029 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 60030-60039 - 1, 36, 35, 34, 33, 32, 31, 30, 29, 28, // 60040-60049 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 60050-60059 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 60060-60069 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 60070-60079 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 60080-60089 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60090-60099 - 1, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 60100-60109 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 60110-60119 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 60120-60129 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 60130-60139 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 60140-60149 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60150-60159 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 40, // 60160-60169 - 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 60170-60179 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 60180-60189 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 60190-60199 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 60200-60209 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 60210-60219 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 60220-60229 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 60230-60239 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60240-60249 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 60250-60259 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60260-60269 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 60270-60279 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 60280-60289 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 60290-60299 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 60300-60309 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 60310-60319 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60320-60329 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 60330-60339 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 60340-60349 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 60350-60359 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 60360-60369 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 60370-60379 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 60380-60389 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 60390-60399 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 60400-60409 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 60410-60419 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 60420-60429 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 60430-60439 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 60440-60449 - 7, 6, 5, 4, 3, 2, 1, 36, 35, 34, // 60450-60459 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 60460-60469 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 60470-60479 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 60480-60489 - 3, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 60490-60499 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 60500-60509 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60510-60519 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 60520-60529 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 50, // 60530-60539 - 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, // 60540-60549 - 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 60550-60559 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 60560-60569 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 60570-60579 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 60580-60589 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60590-60599 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 60600-60609 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 60610-60619 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 60620-60629 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 60630-60639 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 60640-60649 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 60650-60659 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 60660-60669 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 60670-60679 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 60680-60689 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 60690-60699 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 60700-60709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 60710-60719 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 60720-60729 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 60730-60739 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 60740-60749 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 60750-60759 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 60760-60769 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 60770-60779 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 60780-60789 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 60790-60799 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60800-60809 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60810-60819 - 1, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 60820-60829 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 60830-60839 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 60840-60849 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 60850-60859 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 60860-60869 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 60870-60879 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 60880-60889 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 60890-60899 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 60900-60909 - 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, // 60910-60919 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 60920-60929 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 60930-60939 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 60940-60949 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 60950-60959 - 1, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 60960-60969 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 60970-60979 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 60980-60989 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 60990-60999 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 61000-61009 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 61010-61019 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 61020-61029 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61030-61039 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 61040-61049 - 1, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 61050-61059 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 61060-61069 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 61070-61079 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61080-61089 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 22, // 61090-61099 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 61100-61109 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61110-61119 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 61120-61129 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61130-61139 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61140-61149 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 61150-61159 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 42, // 61160-61169 - 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, // 61170-61179 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 61180-61189 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 61190-61199 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61200-61209 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61210-61219 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 61220-61229 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 61230-61239 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61240-61249 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 61250-61259 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 61260-61269 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61270-61279 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 61280-61289 - 1, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 61290-61299 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 61300-61309 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 61310-61319 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61320-61329 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 61330-61339 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 61340-61349 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 61350-61359 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 61360-61369 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 61370-61379 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 61380-61389 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61390-61399 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 8, // 61400-61409 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 61410-61419 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 61420-61429 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61430-61439 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 61440-61449 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61450-61459 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 61460-61469 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61470-61479 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 61480-61489 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 61490-61499 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 61500-61509 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 24, // 61510-61519 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 61520-61529 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61530-61539 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 61540-61549 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 2, // 61550-61559 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 61560-61569 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61570-61579 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 61580-61589 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61590-61599 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 61600-61609 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 61610-61619 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 61620-61629 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 61630-61639 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 61640-61649 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 61650-61659 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 61660-61669 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 61670-61679 - 1, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 61680-61689 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61690-61699 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 61700-61709 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 61710-61719 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 61720-61729 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 61730-61739 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61740-61749 - 1, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 61750-61759 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 61760-61769 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61770-61779 - 1, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 61780-61789 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 61790-61799 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61800-61809 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 61810-61819 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 61820-61829 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 61830-61839 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 61840-61849 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61850-61859 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61860-61869 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 30, // 61870-61879 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 61880-61889 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 61890-61899 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 61900-61909 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 61910-61919 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 61920-61929 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 61930-61939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 61940-61949 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 61950-61959 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 61960-61969 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 61970-61979 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 61980-61989 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 61990-61999 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 62000-62009 - 1, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 62010-62019 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 62020-62029 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 62030-62039 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 62040-62049 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 62050-62059 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62060-62069 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62070-62079 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 62080-62089 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 62090-62099 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 62100-62109 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 62110-62119 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 62120-62129 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 62130-62139 - 1, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 62140-62149 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 62150-62159 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62160-62169 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 62170-62179 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 62180-62189 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62190-62199 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 62200-62209 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 62210-62219 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62220-62229 - 3, 2, 1, 40, 39, 38, 37, 36, 35, 34, // 62230-62239 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 62240-62249 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 62250-62259 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62260-62269 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 62270-62279 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 62280-62289 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 62290-62299 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 62300-62309 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62310-62319 - 3, 2, 1, 4, 3, 2, 1, 20, 19, 18, // 62320-62329 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 62330-62339 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 62340-62349 - 1, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 62350-62359 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 62360-62369 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62370-62379 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 62380-62389 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62390-62399 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 62400-62409 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 62410-62419 - 3, 2, 1, 36, 35, 34, 33, 32, 31, 30, // 62420-62429 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 62430-62439 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 62440-62449 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 62450-62459 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 62460-62469 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 62470-62479 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 62480-62489 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 62490-62499 - 1, 6, 5, 4, 3, 2, 1, 26, 25, 24, // 62500-62509 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 62510-62519 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62520-62529 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 62530-62539 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 62540-62549 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62550-62559 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 62560-62569 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62570-62579 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62580-62589 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 62590-62599 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 62600-62609 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 62610-62619 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 62620-62629 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 62630-62639 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62640-62649 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 24, // 62650-62659 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 62660-62669 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62670-62679 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 62680-62689 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62690-62699 - 1, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 62700-62709 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62710-62719 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 62720-62729 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62730-62739 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 62740-62749 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 62750-62759 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 62760-62769 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 62770-62779 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62780-62789 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62790-62799 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 62800-62809 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 62810-62819 - 7, 6, 5, 4, 3, 2, 1, 24, 23, 22, // 62820-62829 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 62830-62839 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62840-62849 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62850-62859 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 62860-62869 - 3, 2, 1, 24, 23, 22, 21, 20, 19, 18, // 62870-62879 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 62880-62889 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 62890-62899 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 62900-62909 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62910-62919 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 62920-62929 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, // 62930-62939 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 62940-62949 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 62950-62959 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 62960-62969 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 62970-62979 - 1, 2, 1, 4, 3, 2, 1, 2, 1, 40, // 62980-62989 - 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, // 62990-62999 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 63000-63009 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 63010-63019 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 63020-63029 - 1, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 63030-63039 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 63040-63049 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 63050-63059 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 63060-63069 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 18, // 63070-63079 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 63080-63089 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 63090-63099 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 63100-63109 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 63110-63119 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 63120-63129 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 63130-63139 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, // 63140-63149 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 63150-63159 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 63160-63169 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 63170-63179 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 63180-63189 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 63190-63199 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 63200-63209 - 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 63210-63219 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 63220-63229 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 63230-63239 - 1, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 63240-63249 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 63250-63259 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 63260-63269 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 63270-63279 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 63280-63289 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, // 63290-63299 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 63300-63309 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 63310-63319 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 63320-63329 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 63330-63339 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 63340-63349 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 63350-63359 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 63360-63369 - 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 63370-63379 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 63380-63389 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 63390-63399 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 63400-63409 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 63410-63419 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 63420-63429 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 63430-63439 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 63440-63449 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 63450-63459 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 63460-63469 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 63470-63479 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 63480-63489 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 22, // 63490-63499 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 63500-63509 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 63510-63519 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 63520-63529 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 63530-63539 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 63540-63549 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 63550-63559 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 63560-63569 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 63570-63579 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 63580-63589 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 63590-63599 - 1, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 63600-63609 - 1, 6, 5, 4, 3, 2, 1, 12, 11, 10, // 63610-63619 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 63620-63629 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 63630-63639 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 10, // 63640-63649 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 63650-63659 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 63660-63669 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 63670-63679 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 63680-63689 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 63690-63699 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 63700-63709 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 63710-63719 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 63720-63729 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 63730-63739 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 63740-63749 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 63750-63759 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 63760-63769 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 63770-63779 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 63780-63789 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 63790-63799 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 63800-63809 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 63810-63819 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 63820-63829 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 63830-63839 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 63840-63849 - 3, 2, 1, 4, 3, 2, 1, 6, 5, 4, // 63850-63859 - 3, 2, 1, 38, 37, 36, 35, 34, 33, 32, // 63860-63869 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 63870-63879 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 63880-63889 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 63890-63899 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 63900-63909 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 63910-63919 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, // 63920-63929 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 63930-63939 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 28, // 63940-63949 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 63950-63959 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 63960-63969 - 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 63970-63979 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 63980-63989 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 63990-63999 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 64000-64009 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 14, // 64010-64019 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64020-64029 - 3, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 64030-64039 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 64040-64049 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64050-64059 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 64060-64069 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64070-64079 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64080-64089 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 64090-64099 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 64100-64109 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64110-64119 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 64120-64129 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 64130-64139 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64140-64149 - 1, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 64150-64159 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64160-64169 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 64170-64179 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 28, // 64180-64189 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 64190-64199 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 64200-64209 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 64210-64219 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 64220-64229 - 1, 6, 5, 4, 3, 2, 1, 34, 33, 32, // 64230-64239 - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, // 64240-64249 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 64250-64259 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64260-64269 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 64270-64279 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 64280-64289 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64290-64299 - 1, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 64300-64309 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 64310-64319 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 64320-64329 - 3, 2, 1, 40, 39, 38, 37, 36, 35, 34, // 64330-64339 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 64340-64349 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 64350-64359 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64360-64369 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 64370-64379 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 64380-64389 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 64390-64399 - 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 64400-64409 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 64410-64419 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64420-64429 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 64430-64439 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64440-64449 - 1, 2, 1, 30, 29, 28, 27, 26, 25, 24, // 64450-64459 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 64460-64469 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64470-64479 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 10, // 64480-64489 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 64490-64499 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64500-64509 - 3, 2, 1, 40, 39, 38, 37, 36, 35, 34, // 64510-64519 - 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, // 64520-64529 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 64530-64539 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64540-64549 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 64550-64559 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 64560-64569 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 64570-64579 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64580-64589 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64590-64599 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 64600-64609 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 64610-64619 - 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 64620-64629 - 3, 2, 1, 28, 27, 26, 25, 24, 23, 22, // 64630-64639 - 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, // 64640-64649 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64650-64659 - 1, 2, 1, 4, 3, 2, 1, 12, 11, 10, // 64660-64669 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 64670-64679 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64680-64689 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 64690-64699 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, // 64700-64709 - 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, // 64710-64719 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 64720-64729 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 64730-64739 - 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, // 64740-64749 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 64750-64759 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 64760-64769 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64770-64779 - 1, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 64780-64789 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 64790-64799 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64800-64809 - 1, 6, 5, 4, 3, 2, 1, 32, 31, 30, // 64810-64819 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 64820-64829 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 64830-64839 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 64840-64849 - 3, 2, 1, 18, 17, 16, 15, 14, 13, 12, // 64850-64859 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64860-64869 - 1, 6, 5, 4, 3, 2, 1, 2, 1, 12, // 64870-64879 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64880-64889 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64890-64899 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 64900-64909 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 64910-64919 - 1, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 64920-64929 - 7, 6, 5, 4, 3, 2, 1, 14, 13, 12, // 64930-64939 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 64940-64949 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 64950-64959 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 28, // 64960-64969 - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, // 64970-64979 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 64980-64989 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 64990-64999 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 65000-65009 - 1, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 65010-65019 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 4, // 65020-65029 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 65030-65039 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 65040-65049 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 65050-65059 - 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, // 65060-65069 - 1, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 65070-65079 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, // 65080-65089 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 65090-65099 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 65100-65109 - 1, 8, 7, 6, 5, 4, 3, 2, 1, 4, // 65110-65119 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 12, // 65120-65129 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 65130-65139 - 1, 6, 5, 4, 3, 2, 1, 20, 19, 18, // 65140-65149 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 65150-65159 - 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, // 65160-65169 - 1, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 65170-65179 - 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, // 65180-65189 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 65190-65199 - 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, // 65200-65209 - 3, 2, 1, 26, 25, 24, 23, 22, 21, 20, // 65210-65219 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 65220-65229 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 65230-65239 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 65240-65249 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 65250-65259 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 18, // 65260-65269 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 65270-65279 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 65280-65289 - 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, // 65290-65299 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, // 65300-65309 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 65310-65319 - 3, 2, 1, 4, 3, 2, 1, 26, 25, 24, // 65320-65329 - 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, // 65330-65339 - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 65340-65349 - 3, 2, 1, 4, 3, 2, 1, 14, 13, 12, // 65350-65359 - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 65360-65369 - 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, // 65370-65379 - 1, 12, 11, 10, 9, 8, 7, 6, 5, 4, // 65380-65389 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 65390-65399 - 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, // 65400-65409 - 3, 2, 1, 6, 5, 4, 3, 2, 1, 4, // 65410-65419 - 3, 2, 1, 14, 13, 12, 11, 10, 9, 8, // 65420-65429 - 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, // 65430-65439 - 7, 6, 5, 4, 3, 2, 1, 2, 1, 30, // 65440-65449 - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, // 65450-65459 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 65460-65469 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 18, // 65470-65479 - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, // 65480-65489 - 7, 6, 5, 4, 3, 2, 1, 22, 21, 20, // 65490-65499 - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, // 65500-65509 - 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, // 65510-65519 - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 65520-65529 - 0, 0, 0, 0, 0, 0, - } - - lohi [256]struct{ lo, hi int } -) - -func init() { - for i, v := range liars { - blk := v >> 24 - x := &lohi[blk] - if x.lo == 0 || i < x.lo { - x.lo = i - } - if i > x.hi { - x.hi = i - } - } -} diff --git a/vendor/github.com/cznic/mathutil/test_deps.go b/vendor/github.com/cznic/mathutil/test_deps.go deleted file mode 100644 index 40054dcad..000000000 --- a/vendor/github.com/cznic/mathutil/test_deps.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2014 The mathutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mathutil - -// Pull test dependencies too. -// Enables easy 'go test X' after 'go get X' -import ( -// nothing yet -) diff --git a/vendor/github.com/cznic/ql/LICENSE b/vendor/github.com/cznic/ql/LICENSE deleted file mode 100644 index 0d10c02b9..000000000 --- a/vendor/github.com/cznic/ql/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014 The ql Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/ql/blob.go b/vendor/github.com/cznic/ql/blob.go deleted file mode 100644 index 2005b52c7..000000000 --- a/vendor/github.com/cznic/ql/blob.go +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "bytes" - "encoding/gob" - "math/big" - "sync" - "time" -) - -const shortBlob = 256 // bytes - -var ( - gobInitDuration = time.Duration(278) - gobInitInt = big.NewInt(42) - gobInitRat = big.NewRat(355, 113) - gobInitTime time.Time -) - -func init() { - var err error - if gobInitTime, err = time.ParseInLocation( - "Jan 2, 2006 at 3:04pm (MST)", - "Jul 9, 2012 at 5:02am (CEST)", - time.FixedZone("XYZ", 1234), - ); err != nil { - panic(err) - } - newGobCoder() -} - -type gobCoder struct { - buf bytes.Buffer - dec *gob.Decoder - enc *gob.Encoder - mu sync.Mutex -} - -func newGobCoder() (g *gobCoder) { - g = &gobCoder{} - g.enc = gob.NewEncoder(&g.buf) - if err := g.enc.Encode(gobInitInt); err != nil { - panic(err) - } - - if err := g.enc.Encode(gobInitRat); err != nil { - panic(err) - } - - if err := g.enc.Encode(gobInitTime); err != nil { - panic(err) - } - - if err := g.enc.Encode(gobInitDuration); err != nil { - panic(err) - } - - g.dec = gob.NewDecoder(&g.buf) - i := big.NewInt(0) - if err := g.dec.Decode(i); err != nil { - panic(err) - } - - r := big.NewRat(3, 5) - if err := g.dec.Decode(r); err != nil { - panic(err) - } - - t := time.Now() - if err := g.dec.Decode(&t); err != nil { - panic(err) - } - - var d time.Duration - if err := g.dec.Decode(&d); err != nil { - panic(err) - } - - return -} - -func isBlobType(v interface{}) (bool, Type) { - switch v.(type) { - case []byte: - return true, Blob - case *big.Int: - return true, BigInt - case *big.Rat: - return true, BigRat - case time.Time: - return true, Time - case time.Duration: - return true, Duration - default: - return false, -1 - } -} - -func (g *gobCoder) encode(v interface{}) (b []byte, err error) { - g.mu.Lock() - defer g.mu.Unlock() - - g.buf.Reset() - switch x := v.(type) { - case []byte: - return x, nil - case *big.Int: - err = g.enc.Encode(x) - case *big.Rat: - err = g.enc.Encode(x) - case time.Time: - err = g.enc.Encode(x) - case time.Duration: - err = g.enc.Encode(int64(x)) - default: - panic("internal error 002") - } - b = g.buf.Bytes() - return -} - -func (g *gobCoder) decode(b []byte, typ int) (v interface{}, err error) { - g.mu.Lock() - defer g.mu.Unlock() - - g.buf.Reset() - g.buf.Write(b) - switch typ { - case qBlob: - return b, nil - case qBigInt: - x := big.NewInt(0) - err = g.dec.Decode(&x) - v = x - case qBigRat: - x := big.NewRat(1, 1) - err = g.dec.Decode(&x) - v = x - case qTime: - var x time.Time - err = g.dec.Decode(&x) - v = x - case qDuration: - var x int64 - err = g.dec.Decode(&x) - v = time.Duration(x) - default: - panic("internal error 003") - } - return -} diff --git a/vendor/github.com/cznic/ql/btree.go b/vendor/github.com/cznic/ql/btree.go deleted file mode 100644 index 299a5b530..000000000 --- a/vendor/github.com/cznic/ql/btree.go +++ /dev/null @@ -1,723 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "io" -) - -const ( - kx = 128 //DONE benchmark tune this number if using custom key/value type(s). - kd = 64 //DONE benchmark tune this number if using custom key/value type(s). -) - -type ( - // cmp compares a and b. Return value is: - // - // < 0 if a < b - // 0 if a == b - // > 0 if a > b - // - cmp func(a, b []interface{}) int - - d struct { // data page - c int - d [2*kd + 1]de - n *d - p *d - } - - de struct { // d element - k []interface{} - v []interface{} - } - - enumerator struct { - err error - hit bool - i int - k []interface{} - q *d - t *tree - ver int64 - } - - // tree is a B+tree. - tree struct { - c int - cmp cmp - first *d - last *d - r interface{} - ver int64 - } - - xe struct { // x element - ch interface{} - sep *d - } - - x struct { // index page - c int - x [2*kx + 2]xe - } -) - -var ( // R/O zero values - zd d - zde de - zx x - zxe xe -) - -func clr(q interface{}) { - switch z := q.(type) { - case *x: - for i := 0; i <= z.c; i++ { // Ch0 Sep0 ... Chn-1 Sepn-1 Chn - clr(z.x[i].ch) - } - *z = zx // GC - case *d: - *z = zd // GC - } -} - -// -------------------------------------------------------------------------- x - -func newX(ch0 interface{}) *x { - r := &x{} - r.x[0].ch = ch0 - return r -} - -func (q *x) extract(i int) { - q.c-- - if i < q.c { - copy(q.x[i:], q.x[i+1:q.c+1]) - q.x[q.c].ch = q.x[q.c+1].ch - q.x[q.c].sep = nil // GC - q.x[q.c+1] = zxe // GC - } -} - -func (q *x) insert(i int, d *d, ch interface{}) *x { - c := q.c - if i < c { - q.x[c+1].ch = q.x[c].ch - copy(q.x[i+2:], q.x[i+1:c]) - q.x[i+1].sep = q.x[i].sep - } - c++ - q.c = c - q.x[i].sep = d - q.x[i+1].ch = ch - return q -} - -func (q *x) siblings(i int) (l, r *d) { - if i >= 0 { - if i > 0 { - l = q.x[i-1].ch.(*d) - } - if i < q.c { - r = q.x[i+1].ch.(*d) - } - } - return -} - -// -------------------------------------------------------------------------- d - -func (l *d) mvL(r *d, c int) { - copy(l.d[l.c:], r.d[:c]) - copy(r.d[:], r.d[c:r.c]) - l.c += c - r.c -= c -} - -func (l *d) mvR(r *d, c int) { - copy(r.d[c:], r.d[:r.c]) - copy(r.d[:c], l.d[l.c-c:]) - r.c += c - l.c -= c -} - -// ----------------------------------------------------------------------- tree - -// treeNew returns a newly created, empty tree. The compare function is used -// for key collation. -func treeNew(cmp cmp) *tree { - return &tree{cmp: cmp} -} - -// Clear removes all K/V pairs from the tree. -func (t *tree) Clear() { - if t.r == nil { - return - } - - clr(t.r) - t.c, t.first, t.last, t.r = 0, nil, nil, nil - t.ver++ -} - -func (t *tree) cat(p *x, q, r *d, pi int) { - t.ver++ - q.mvL(r, r.c) - if r.n != nil { - r.n.p = q - } else { - t.last = q - } - q.n = r.n - if p.c > 1 { - p.extract(pi) - p.x[pi].ch = q - } else { - t.r = q - } -} - -func (t *tree) catX(p, q, r *x, pi int) { - t.ver++ - q.x[q.c].sep = p.x[pi].sep - copy(q.x[q.c+1:], r.x[:r.c]) - q.c += r.c + 1 - q.x[q.c].ch = r.x[r.c].ch - if p.c > 1 { - p.c-- - pc := p.c - if pi < pc { - p.x[pi].sep = p.x[pi+1].sep - copy(p.x[pi+1:], p.x[pi+2:pc+1]) - p.x[pc].ch = p.x[pc+1].ch - p.x[pc].sep = nil // GC - p.x[pc+1].ch = nil // GC - } - return - } - - t.r = q -} - -//Delete removes the k's KV pair, if it exists, in which case Delete returns -//true. -func (t *tree) Delete(k []interface{}) (ok bool) { - pi := -1 - var p *x - q := t.r - if q == nil { - return - } - - for { - var i int - i, ok = t.find(q, k) - if ok { - switch z := q.(type) { - case *x: - dp := z.x[i].sep - switch { - case dp.c > kd: - t.extract(dp, 0) - default: - if z.c < kx && q != t.r { - t.underflowX(p, &z, pi, &i) - } - pi = i + 1 - p = z - q = z.x[pi].ch - ok = false - continue - } - case *d: - t.extract(z, i) - if z.c >= kd { - return - } - - if q != t.r { - t.underflow(p, z, pi) - } else if t.c == 0 { - t.Clear() - } - } - return - } - - switch z := q.(type) { - case *x: - if z.c < kx && q != t.r { - t.underflowX(p, &z, pi, &i) - } - pi = i - p = z - q = z.x[i].ch - case *d: - return - } - } -} - -func (t *tree) extract(q *d, i int) { // (r []interface{}) { - t.ver++ - //r = q.d[i].v // prepared for Extract - q.c-- - if i < q.c { - copy(q.d[i:], q.d[i+1:q.c+1]) - } - q.d[q.c] = zde // GC - t.c-- -} - -func (t *tree) find(q interface{}, k []interface{}) (i int, ok bool) { - var mk []interface{} - l := 0 - switch z := q.(type) { - case *x: - h := z.c - 1 - for l <= h { - m := (l + h) >> 1 - mk = z.x[m].sep.d[0].k - switch cmp := t.cmp(k, mk); { - case cmp > 0: - l = m + 1 - case cmp == 0: - return m, true - default: - h = m - 1 - } - } - case *d: - h := z.c - 1 - for l <= h { - m := (l + h) >> 1 - mk = z.d[m].k - switch cmp := t.cmp(k, mk); { - case cmp > 0: - l = m + 1 - case cmp == 0: - return m, true - default: - h = m - 1 - } - } - } - return l, false -} - -// First returns the first item of the tree in the key collating order, or -// (nil, nil) if the tree is empty. -func (t *tree) First() (k []interface{}, v []interface{}) { - if q := t.first; q != nil { - q := &q.d[0] - k, v = q.k, q.v - } - return -} - -// Get returns the value associated with k and true if it exists. Otherwise Get -// returns (nil, false). -func (t *tree) Get(k []interface{}) (v []interface{}, ok bool) { - q := t.r - if q == nil { - return - } - - for { - var i int - if i, ok = t.find(q, k); ok { - switch z := q.(type) { - case *x: - return z.x[i].sep.d[0].v, true - case *d: - return z.d[i].v, true - } - } - switch z := q.(type) { - case *x: - q = z.x[i].ch - default: - return - } - } -} - -func (t *tree) insert(q *d, i int, k []interface{}, v []interface{}) *d { - t.ver++ - c := q.c - if i < c { - copy(q.d[i+1:], q.d[i:c]) - } - c++ - q.c = c - q.d[i].k, q.d[i].v = k, v - t.c++ - return q -} - -// Last returns the last item of the tree in the key collating order, or (nil, -// nil) if the tree is empty. -func (t *tree) Last() (k []interface{}, v []interface{}) { - if q := t.last; q != nil { - q := &q.d[q.c-1] - k, v = q.k, q.v - } - return -} - -// Len returns the number of items in the tree. -func (t *tree) Len() int { - return t.c -} - -func (t *tree) overflow(p *x, q *d, pi, i int, k []interface{}, v []interface{}) { - t.ver++ - l, r := p.siblings(pi) - - if l != nil && l.c < 2*kd && i > 0 { - l.mvL(q, 1) - t.insert(q, i-1, k, v) - return - } - - if r != nil && r.c < 2*kd { - if i < 2*kd { - q.mvR(r, 1) - t.insert(q, i, k, v) - } else { - t.insert(r, 0, k, v) - } - return - } - - t.split(p, q, pi, i, k, v) -} - -// Seek returns an enumerator positioned on a an item such that k >= item's -// key. ok reports if k == item.key The enumerator's position is possibly -// after the last item in the tree. -func (t *tree) Seek(k []interface{}) (e *enumerator, ok bool) { - q := t.r - if q == nil { - e = &enumerator{nil, false, 0, k, nil, t, t.ver} - return - } - - for { - var i int - if i, ok = t.find(q, k); ok { - switch z := q.(type) { - case *x: - e = &enumerator{nil, ok, 0, k, z.x[i].sep, t, t.ver} - return - case *d: - e = &enumerator{nil, ok, i, k, z, t, t.ver} - return - } - } - switch z := q.(type) { - case *x: - q = z.x[i].ch - case *d: - e = &enumerator{nil, ok, i, k, z, t, t.ver} - return - } - } -} - -// SeekFirst returns an enumerator positioned on the first KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returned and e will be nil. -func (t *tree) SeekFirst() (e *enumerator, err error) { - q := t.first - if q == nil { - return nil, io.EOF - } - - return &enumerator{nil, true, 0, q.d[0].k, q, t, t.ver}, nil -} - -// SeekLast returns an enumerator positioned on the last KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returned and e will be nil. -func (t *tree) SeekLast() (e *enumerator, err error) { - q := t.last - if q == nil { - return nil, io.EOF - } - - return &enumerator{nil, true, q.c - 1, q.d[q.c-1].k, q, t, t.ver}, nil -} - -// Set sets the value associated with k. -func (t *tree) Set(k []interface{}, v []interface{}) { - pi := -1 - var p *x - q := t.r - if q != nil { - for { - i, ok := t.find(q, k) - if ok { - switch z := q.(type) { - case *x: - z.x[i].sep.d[0].v = v - case *d: - z.d[i].v = v - } - return - } - - switch z := q.(type) { - case *x: - if z.c > 2*kx { - t.splitX(p, &z, pi, &i) - } - pi = i - p = z - q = z.x[i].ch - case *d: - switch { - case z.c < 2*kd: - t.insert(z, i, k, v) - default: - t.overflow(p, z, pi, i, k, v) - } - return - } - } - } - - z := t.insert(&d{}, 0, k, v) - t.r, t.first, t.last = z, z, z -} - -func (t *tree) split(p *x, q *d, pi, i int, k []interface{}, v []interface{}) { - t.ver++ - r := &d{} - if q.n != nil { - r.n = q.n - r.n.p = r - } else { - t.last = r - } - q.n = r - r.p = q - - copy(r.d[:], q.d[kd:2*kd]) - for i := range q.d[kd:] { - q.d[kd+i] = zde - } - q.c = kd - r.c = kd - if pi >= 0 { - p.insert(pi, r, r) - } else { - t.r = newX(q).insert(0, r, r) - } - if i > kd { - t.insert(r, i-kd, k, v) - return - } - - t.insert(q, i, k, v) -} - -func (t *tree) splitX(p *x, pp **x, pi int, i *int) { - t.ver++ - q := *pp - r := &x{} - copy(r.x[:], q.x[kx+1:]) - q.c = kx - r.c = kx - if pi >= 0 { - p.insert(pi, q.x[kx].sep, r) - } else { - t.r = newX(q).insert(0, q.x[kx].sep, r) - } - q.x[kx].sep = nil - for i := range q.x[kx+1:] { - q.x[kx+i+1] = zxe - } - if *i > kx { - *pp = r - *i -= kx + 1 - } -} - -func (t *tree) underflow(p *x, q *d, pi int) { - t.ver++ - l, r := p.siblings(pi) - - if l != nil && l.c+q.c >= 2*kd { - l.mvR(q, 1) - } else if r != nil && q.c+r.c >= 2*kd { - q.mvL(r, 1) - r.d[r.c] = zde // GC - } else if l != nil { - t.cat(p, l, q, pi-1) - } else { - t.cat(p, q, r, pi) - } -} - -func (t *tree) underflowX(p *x, pp **x, pi int, i *int) { - t.ver++ - var l, r *x - q := *pp - - if pi >= 0 { - if pi > 0 { - l = p.x[pi-1].ch.(*x) - } - if pi < p.c { - r = p.x[pi+1].ch.(*x) - } - } - - if l != nil && l.c > kx { - q.x[q.c+1].ch = q.x[q.c].ch - copy(q.x[1:], q.x[:q.c]) - q.x[0].ch = l.x[l.c].ch - q.x[0].sep = p.x[pi-1].sep - q.c++ - *i++ - l.c-- - p.x[pi-1].sep = l.x[l.c].sep - return - } - - if r != nil && r.c > kx { - q.x[q.c].sep = p.x[pi].sep - q.c++ - q.x[q.c].ch = r.x[0].ch - p.x[pi].sep = r.x[0].sep - copy(r.x[:], r.x[1:r.c]) - r.c-- - rc := r.c - r.x[rc].ch = r.x[rc+1].ch - r.x[rc].sep = nil - r.x[rc+1].ch = nil - return - } - - if l != nil { - *i += l.c + 1 - t.catX(p, l, q, pi-1) - *pp = l - return - } - - t.catX(p, q, r, pi) -} - -// ----------------------------------------------------------------- enumerator - -// Next returns the currently enumerated item, if it exists and moves to the -// next item in the key collation order. If there is no item to return, err == -// io.EOF is returned. -func (e *enumerator) Next() (k []interface{}, v []interface{}, err error) { - if err = e.err; err != nil { - return - } - - if e.ver != e.t.ver { - f, hit := e.t.Seek(e.k) - if !e.hit && hit { - if err = f.next(); err != nil { - return - } - } - - *e = *f - } - if e.q == nil { - e.err, err = io.EOF, io.EOF - return - } - - if e.i >= e.q.c { - if err = e.next(); err != nil { - return - } - } - - i := e.q.d[e.i] - k, v = i.k, i.v - e.k, e.hit = k, false - e.next() - return -} - -func (e *enumerator) next() error { - if e.q == nil { - e.err = io.EOF - return io.EOF - } - - switch { - case e.i < e.q.c-1: - e.i++ - default: - if e.q, e.i = e.q.n, 0; e.q == nil { - e.err = io.EOF - } - } - return e.err -} - -// Prev returns the currently enumerated item, if it exists and moves to the -// previous item in the key collation order. If there is no item to return, err -// == io.EOF is returned. -func (e *enumerator) Prev() (k []interface{}, v []interface{}, err error) { - if err = e.err; err != nil { - return - } - - if e.ver != e.t.ver { - f, hit := e.t.Seek(e.k) - if !e.hit && hit { - if err = f.prev(); err != nil { - return - } - } - - *e = *f - } - if e.q == nil { - e.err, err = io.EOF, io.EOF - return - } - - if e.i >= e.q.c { - if err = e.next(); err != nil { - return - } - } - - i := e.q.d[e.i] - k, v = i.k, i.v - e.k, e.hit = k, false - e.prev() - return -} - -func (e *enumerator) prev() error { - if e.q == nil { - e.err = io.EOF - return io.EOF - } - - switch { - case e.i > 0: - e.i-- - default: - if e.q = e.q.p; e.q == nil { - e.err = io.EOF - break - } - - e.i = e.q.c - 1 - } - return e.err -} diff --git a/vendor/github.com/cznic/ql/builtin.go b/vendor/github.com/cznic/ql/builtin.go deleted file mode 100644 index a7e6be791..000000000 --- a/vendor/github.com/cznic/ql/builtin.go +++ /dev/null @@ -1,1012 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "fmt" - "math/rand" - "reflect" - "strconv" - "strings" - "time" -) - -//TODO agg bigint, bigrat, time, duration - -var builtin = map[string]struct { - f func([]interface{}, map[interface{}]interface{}) (interface{}, error) - minArgs int - maxArgs int - isStatic bool - isAggregate bool -}{ - "__testBlob": {builtinTestBlob, 1, 1, true, false}, - "__testString": {builtinTestString, 1, 1, true, false}, - "avg": {builtinAvg, 1, 1, false, true}, - "complex": {builtinComplex, 2, 2, true, false}, - "contains": {builtinContains, 2, 2, true, false}, - "count": {builtinCount, 0, 1, false, true}, - "date": {builtinDate, 8, 8, true, false}, - "day": {builtinDay, 1, 1, true, false}, - "formatTime": {builtinFormatTime, 2, 2, true, false}, - "formatFloat": {builtinFormatFloat, 1, 4, true, false}, - "formatInt": {builtinFormatInt, 1, 2, true, false}, - "hasPrefix": {builtinHasPrefix, 2, 2, true, false}, - "hasSuffix": {builtinHasSuffix, 2, 2, true, false}, - "hour": {builtinHour, 1, 1, true, false}, - "hours": {builtinHours, 1, 1, true, false}, - "id": {builtinID, 0, 1, false, false}, - "imag": {builtinImag, 1, 1, true, false}, - "len": {builtinLen, 1, 1, true, false}, - "max": {builtinMax, 1, 1, false, true}, - "min": {builtinMin, 1, 1, false, true}, - "minute": {builtinMinute, 1, 1, true, false}, - "minutes": {builtinMinutes, 1, 1, true, false}, - "month": {builtinMonth, 1, 1, true, false}, - "nanosecond": {builtinNanosecond, 1, 1, true, false}, - "nanoseconds": {builtinNanoseconds, 1, 1, true, false}, - "now": {builtinNow, 0, 0, false, false}, - "parseTime": {builtinParseTime, 2, 2, true, false}, - "real": {builtinReal, 1, 1, true, false}, - "second": {builtinSecond, 1, 1, true, false}, - "seconds": {builtinSeconds, 1, 1, true, false}, - "since": {builtinSince, 1, 1, false, false}, - "sleep": {builtinSleep, 1, 1, false, false}, - "sum": {builtinSum, 1, 1, false, true}, - "timeIn": {builtinTimeIn, 2, 2, true, false}, - "weekday": {builtinWeekday, 1, 1, true, false}, - "year": {builtinYear, 1, 1, true, false}, - "yearDay": {builtinYearday, 1, 1, true, false}, -} - -func badNArgs(min int, s string, arg []interface{}) error { - a := []string{} - for _, v := range arg { - a = append(a, fmt.Sprintf("%v", v)) - } - switch len(arg) < min { - case true: - return fmt.Errorf("missing argument to %s(%s)", s, strings.Join(a, ", ")) - default: //case false: - return fmt.Errorf("too many arguments to %s(%s)", s, strings.Join(a, ", ")) - } -} - -func invArg(arg interface{}, s string) error { - return fmt.Errorf("invalid argument %v (type %T) for %s", arg, arg, s) -} - -func builtinTestBlob(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - n, err := intExpr(arg[0]) - if err != nil { - return nil, err - } - - rng := rand.New(rand.NewSource(n)) - b := make([]byte, n) - for i := range b { - b[i] = byte(rng.Int()) - } - return b, nil -} - -func builtinTestString(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - n, err := intExpr(arg[0]) - if err != nil { - return nil, err - } - - rng := rand.New(rand.NewSource(n)) - b := make([]byte, n) - for i := range b { - b[i] = byte(rng.Int()) - } - return string(b), nil -} - -func builtinAvg(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - type avg struct { - sum interface{} - n uint64 - } - - if _, ok := ctx["$agg0"]; ok { - return - } - - fn := ctx["$fn"] - if _, ok := ctx["$agg"]; ok { - data, ok := ctx[fn].(avg) - if !ok { - return - } - - switch x := data.sum.(type) { - case complex64: - return complex64(complex128(x) / complex(float64(data.n), 0)), nil - case complex128: - return complex64(x / complex(float64(data.n), 0)), nil - case float32: - return float32(float64(x) / float64(data.n)), nil - case float64: - return x / float64(data.n), nil - case int8: - return int8(int64(x) / int64(data.n)), nil - case int16: - return int16(int64(x) / int64(data.n)), nil - case int32: - return int32(int64(x) / int64(data.n)), nil - case int64: - return x / int64(data.n), nil - case uint8: - return uint8(uint64(x) / data.n), nil - case uint16: - return uint16(uint64(x) / data.n), nil - case uint32: - return uint32(uint64(x) / data.n), nil - case uint64: - return x / data.n, nil - } - - } - - data, _ := ctx[fn].(avg) - y := arg[0] - if y == nil { - return - } - - switch x := data.sum.(type) { - case nil: - switch y := y.(type) { - case float32, float64, int8, int16, int32, int64, uint8, uint16, uint32, uint64: - data = avg{y, 0} - default: - return nil, fmt.Errorf("avg: cannot accept %v (value if type %T)", y, y) - } - case complex64: - data.sum = x + y.(complex64) - case complex128: - data.sum = x + y.(complex128) - case float32: - data.sum = x + y.(float32) - case float64: - data.sum = x + y.(float64) - case int8: - data.sum = x + y.(int8) - case int16: - data.sum = x + y.(int16) - case int32: - data.sum = x + y.(int32) - case int64: - data.sum = x + y.(int64) - case uint8: - data.sum = x + y.(uint8) - case uint16: - data.sum = x + y.(uint16) - case uint32: - data.sum = x + y.(uint32) - case uint64: - data.sum = x + y.(uint64) - } - data.n++ - ctx[fn] = data - return -} - -func builtinComplex(arg []interface{}, _ map[interface{}]interface{}) (v interface{}, err error) { - re, im := arg[0], arg[1] - if re == nil || im == nil { - return nil, nil - } - - re, im = coerce(re, im) - if reflect.TypeOf(re) != reflect.TypeOf(im) { - return nil, fmt.Errorf("complex(%T(%#v), %T(%#v)): invalid types", re, re, im, im) - } - - switch re := re.(type) { - case idealFloat: - return idealComplex(complex(float64(re), float64(im.(idealFloat)))), nil - case idealInt: - return idealComplex(complex(float64(re), float64(im.(idealInt)))), nil - case idealRune: - return idealComplex(complex(float64(re), float64(im.(idealRune)))), nil - case idealUint: - return idealComplex(complex(float64(re), float64(im.(idealUint)))), nil - case float32: - return complex(re, im.(float32)), nil - case float64: - return complex(re, im.(float64)), nil - case int8: - return complex(float64(re), float64(im.(int8))), nil - case int16: - return complex(float64(re), float64(im.(int16))), nil - case int32: - return complex(float64(re), float64(im.(int32))), nil - case int64: - return complex(float64(re), float64(im.(int64))), nil - case uint8: - return complex(float64(re), float64(im.(uint8))), nil - case uint16: - return complex(float64(re), float64(im.(uint16))), nil - case uint32: - return complex(float64(re), float64(im.(uint32))), nil - case uint64: - return complex(float64(re), float64(im.(uint64))), nil - default: - return nil, invArg(re, "complex") - } -} - -func builtinContains(arg []interface{}, _ map[interface{}]interface{}) (v interface{}, err error) { - switch s := arg[0].(type) { - case nil: - return nil, nil - case string: - switch chars := arg[1].(type) { - case nil: - return nil, nil - case string: - return strings.Contains(s, chars), nil - default: - return nil, invArg(chars, "string") - } - default: - return nil, invArg(s, "string") - } -} - -func builtinCount(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - if _, ok := ctx["$agg0"]; ok { - return int64(0), nil - } - - fn := ctx["$fn"] - if _, ok := ctx["$agg"]; ok { - return ctx[fn].(int64), nil - } - - n, _ := ctx[fn].(int64) - switch len(arg) { - case 0: - n++ - case 1: - if arg[0] != nil { - n++ - } - default: - panic("internal error 067") - } - ctx[fn] = n - return -} - -func builtinDate(arg []interface{}, _ map[interface{}]interface{}) (v interface{}, err error) { - for i, v := range arg { - switch i { - case 7: - switch x := v.(type) { - case string: - default: - return nil, invArg(x, "date") - } - default: - switch x := v.(type) { - case int64: - case idealInt: - arg[i] = int64(x) - default: - return nil, invArg(x, "date") - } - } - } - - sloc := arg[7].(string) - loc := time.Local - switch sloc { - case "local": - default: - loc, err = time.LoadLocation(sloc) - if err != nil { - return - } - } - - return time.Date( - int(arg[0].(int64)), - time.Month(arg[1].(int64)), - int(arg[2].(int64)), - int(arg[3].(int64)), - int(arg[4].(int64)), - int(arg[5].(int64)), - int(arg[6].(int64)), - loc, - ), nil -} - -func builtinLen(arg []interface{}, _ map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case string: - return int64(len(x)), nil - default: - return nil, invArg(x, "len") - } -} - -func builtinDay(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return int64(x.Day()), nil - default: - return nil, invArg(x, "day") - } -} - -func builtinFormatTime(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - switch y := arg[1].(type) { - case nil: - return nil, nil - case string: - return x.Format(y), nil - default: - return nil, invArg(y, "formatTime") - } - default: - return nil, invArg(x, "formatTime") - } -} - -func builtinFormatFloat(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - var val float64 - var fmt byte = 'g' - - prec := -1 - bitSize := 64 - - switch x := arg[0].(type) { - case nil: - return nil, nil - case float32: - val = float64(x) - bitSize = 32 - case float64: - val = x - default: - return nil, invArg(x, "formatFloat") - } - - switch len(arg) { - case 4: - arg3 := coerce1(arg[3], int64(0)) - switch y := arg3.(type) { - case nil: - return nil, nil - case int64: - bitSize = int(y) - default: - return nil, invArg(y, "formatFloat") - } - fallthrough - case 3: - arg2 := coerce1(arg[2], int64(0)) - switch y := arg2.(type) { - case nil: - return nil, nil - case int64: - prec = int(y) - default: - return nil, invArg(y, "formatFloat") - } - fallthrough - case 2: - arg1 := coerce1(arg[1], byte(0)) - switch y := arg1.(type) { - case nil: - return nil, nil - case byte: - fmt = y - default: - return nil, invArg(y, "formatFloat") - } - } - - return strconv.FormatFloat(val, fmt, prec, bitSize), nil -} - -func builtinFormatInt(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - var intVal int64 - var uintVal uint64 - - uintType := false - base := 10 - - switch x := arg[0].(type) { - case nil: - return nil, nil - case int8: - intVal = int64(x) - case int16: - intVal = int64(x) - case int32: - intVal = int64(x) - case int64: - intVal = x - case uint8: - uintType = true - uintVal = uint64(x) - case uint16: - uintType = true - uintVal = uint64(x) - case uint32: - uintType = true - uintVal = uint64(x) - case uint64: - uintType = true - uintVal = x - default: - return nil, invArg(x, "formatInt") - } - - switch len(arg) { - case 2: - arg1 := coerce1(arg[1], int64(0)) - switch y := arg1.(type) { - case nil: - return nil, nil - case int64: - base = int(y) - default: - return nil, invArg(y, "formatInt") - } - } - - if uintType { - return strconv.FormatUint(uintVal, base), nil - } - - return strconv.FormatInt(intVal, base), nil -} - -func builtinHasPrefix(arg []interface{}, _ map[interface{}]interface{}) (v interface{}, err error) { - switch s := arg[0].(type) { - case nil: - return nil, nil - case string: - switch prefix := arg[1].(type) { - case nil: - return nil, nil - case string: - return strings.HasPrefix(s, prefix), nil - default: - return nil, invArg(prefix, "string") - } - default: - return nil, invArg(s, "string") - } -} - -func builtinHasSuffix(arg []interface{}, _ map[interface{}]interface{}) (v interface{}, err error) { - switch s := arg[0].(type) { - case nil: - return nil, nil - case string: - switch suffix := arg[1].(type) { - case nil: - return nil, nil - case string: - return strings.HasSuffix(s, suffix), nil - default: - return nil, invArg(suffix, "string") - } - default: - return nil, invArg(s, "string") - } -} - -func builtinHour(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return int64(x.Hour()), nil - default: - return nil, invArg(x, "hour") - } -} - -func builtinHours(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Duration: - return x.Hours(), nil - default: - return nil, invArg(x, "hours") - } -} - -func builtinID(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := ctx["$id"].(type) { - case map[string]interface{}: - if len(arg) == 0 { - return nil, nil - } - - tab := arg[0].(*ident) - id, ok := x[tab.s] - if !ok { - return nil, fmt.Errorf("value not available: id(%s)", tab) - } - - if _, ok := id.(int64); ok { - return id, nil - } - - return nil, fmt.Errorf("value not available: id(%s)", tab) - case int64: - return x, nil - default: - return nil, nil - } -} - -func builtinImag(arg []interface{}, _ map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case idealComplex: - return imag(x), nil - case complex64: - return imag(x), nil - case complex128: - return imag(x), nil - default: - return nil, invArg(x, "imag") - } -} - -func builtinMax(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - if _, ok := ctx["$agg0"]; ok { - return - } - - fn := ctx["$fn"] - if _, ok := ctx["$agg"]; ok { - if v, ok = ctx[fn]; ok { - return - } - - return nil, nil - } - - max := ctx[fn] - y := arg[0] - if y == nil { - return - } - switch x := max.(type) { - case nil: - switch y := y.(type) { - case float32, float64, string, int8, int16, int32, int64, uint8, uint16, uint32, uint64, time.Time: - max = y - default: - return nil, fmt.Errorf("max: cannot accept %v (value if type %T)", y, y) - } - case float32: - if y := y.(float32); y > x { - max = y - } - case float64: - if y := y.(float64); y > x { - max = y - } - case string: - if y := y.(string); y > x { - max = y - } - case int8: - if y := y.(int8); y > x { - max = y - } - case int16: - if y := y.(int16); y > x { - max = y - } - case int32: - if y := y.(int32); y > x { - max = y - } - case int64: - if y := y.(int64); y > x { - max = y - } - case uint8: - if y := y.(uint8); y > x { - max = y - } - case uint16: - if y := y.(uint16); y > x { - max = y - } - case uint32: - if y := y.(uint32); y > x { - max = y - } - case uint64: - if y := y.(uint64); y > x { - max = y - } - case time.Time: - if y := y.(time.Time); y.After(x) { - max = y - } - } - ctx[fn] = max - return -} - -func builtinMin(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - if _, ok := ctx["$agg0"]; ok { - return - } - - fn := ctx["$fn"] - if _, ok := ctx["$agg"]; ok { - if v, ok = ctx[fn]; ok { - return - } - - return nil, nil - } - - min := ctx[fn] - y := arg[0] - if y == nil { - return - } - switch x := min.(type) { - case nil: - switch y := y.(type) { - case float32, float64, string, int8, int16, int32, int64, uint8, uint16, uint32, uint64, time.Time: - min = y - default: - return nil, fmt.Errorf("min: cannot accept %v (value if type %T)", y, y) - } - case float32: - if y := y.(float32); y < x { - min = y - } - case float64: - if y := y.(float64); y < x { - min = y - } - case string: - if y := y.(string); y < x { - min = y - } - case int8: - if y := y.(int8); y < x { - min = y - } - case int16: - if y := y.(int16); y < x { - min = y - } - case int32: - if y := y.(int32); y < x { - min = y - } - case int64: - if y := y.(int64); y < x { - min = y - } - case uint8: - if y := y.(uint8); y < x { - min = y - } - case uint16: - if y := y.(uint16); y < x { - min = y - } - case uint32: - if y := y.(uint32); y < x { - min = y - } - case uint64: - if y := y.(uint64); y < x { - min = y - } - case time.Time: - if y := y.(time.Time); y.Before(x) { - min = y - } - } - ctx[fn] = min - return -} - -func builtinMinute(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return int64(x.Minute()), nil - default: - return nil, invArg(x, "minute") - } -} - -func builtinMinutes(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Duration: - return x.Minutes(), nil - default: - return nil, invArg(x, "minutes") - } -} - -func builtinMonth(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return int64(x.Month()), nil - default: - return nil, invArg(x, "month") - } -} - -func builtinNanosecond(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return int64(x.Nanosecond()), nil - default: - return nil, invArg(x, "nanosecond") - } -} - -func builtinNanoseconds(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Duration: - return x.Nanoseconds(), nil - default: - return nil, invArg(x, "nanoseconds") - } -} - -func builtinNow(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - return time.Now(), nil -} - -func builtinParseTime(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - var a [2]string - for i, v := range arg { - switch x := v.(type) { - case nil: - return nil, nil - case string: - a[i] = x - default: - return nil, invArg(x, "parseTime") - } - } - - t, err := time.Parse(a[0], a[1]) - if err != nil { - return nil, err - } - - ls := t.Location().String() - if ls == "UTC" { - return t, nil - } - - l, err := time.LoadLocation(ls) - if err != nil { - return t, nil - } - - return time.ParseInLocation(a[0], a[1], l) -} - -func builtinReal(arg []interface{}, _ map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case idealComplex: - return real(x), nil - case complex64: - return real(x), nil - case complex128: - return real(x), nil - default: - return nil, invArg(x, "real") - } -} - -func builtinSecond(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return int64(x.Second()), nil - default: - return nil, invArg(x, "second") - } -} - -func builtinSeconds(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Duration: - return x.Seconds(), nil - default: - return nil, invArg(x, "seconds") - } -} - -func builtinSince(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return time.Since(x), nil - default: - return nil, invArg(x, "since") - } -} - -func builtinSleep(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Duration: - time.Sleep(x) - return nil, nil - case idealInt: - v := time.Second * time.Duration(int64(x)) - time.Sleep(v) - return nil, nil - case int64: - v := time.Second * time.Duration(x) - time.Sleep(v) - return nil, nil - default: - return nil, invArg(x, "sleep") - } -} - -func builtinSum(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - if _, ok := ctx["$agg0"]; ok { - return - } - - fn := ctx["$fn"] - if _, ok := ctx["$agg"]; ok { - if v, ok = ctx[fn]; ok { - return - } - - return nil, nil - } - - sum := ctx[fn] - y := arg[0] - if y == nil { - return - } - switch x := sum.(type) { - case nil: - switch y := y.(type) { - case complex64, complex128, float32, float64, int8, int16, int32, int64, uint8, uint16, uint32, uint64: - sum = y - default: - return nil, fmt.Errorf("sum: cannot accept %v (value if type %T)", y, y) - } - case complex64: - sum = x + y.(complex64) - case complex128: - sum = x + y.(complex128) - case float32: - sum = x + y.(float32) - case float64: - sum = x + y.(float64) - case int8: - sum = x + y.(int8) - case int16: - sum = x + y.(int16) - case int32: - sum = x + y.(int32) - case int64: - sum = x + y.(int64) - case uint8: - sum = x + y.(uint8) - case uint16: - sum = x + y.(uint16) - case uint32: - sum = x + y.(uint32) - case uint64: - sum = x + y.(uint64) - } - ctx[fn] = sum - return -} - -func builtinTimeIn(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - switch y := arg[1].(type) { - case nil: - return nil, nil - case string: - loc := time.Local - switch y { - case "local": - default: - loc, err = time.LoadLocation(y) - if err != nil { - return - } - } - - return x.In(loc), nil - default: - return nil, invArg(x, "timeIn") - } - default: - return nil, invArg(x, "timeIn") - } -} - -func builtinWeekday(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return int64(x.Weekday()), nil - default: - return nil, invArg(x, "weekday") - } -} - -func builtinYear(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return int64(x.Year()), nil - default: - return nil, invArg(x, "year") - } -} - -func builtinYearday(arg []interface{}, ctx map[interface{}]interface{}) (v interface{}, err error) { - switch x := arg[0].(type) { - case nil: - return nil, nil - case time.Time: - return int64(x.YearDay()), nil - default: - return nil, invArg(x, "yearDay") - } -} diff --git a/vendor/github.com/cznic/ql/coerce.go b/vendor/github.com/cznic/ql/coerce.go deleted file mode 100644 index 292913538..000000000 --- a/vendor/github.com/cznic/ql/coerce.go +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright 2013 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// CAUTION: This file was generated automatically by -// -// $ go run helper/helper.go -o coerce.go -// -// DO NOT EDIT! - -package ql - -import ( - "math" - "math/big" - "reflect" - "time" -) - -func coerce(a, b interface{}) (x, y interface{}) { - if reflect.TypeOf(a) == reflect.TypeOf(b) { - return a, b - } - - switch a.(type) { - case idealComplex, idealFloat, idealInt, idealRune, idealUint: - switch b.(type) { - case idealComplex, idealFloat, idealInt, idealRune, idealUint: - x, y = coerce1(a, b), b - if reflect.TypeOf(x) == reflect.TypeOf(y) { - return - } - - return a, coerce1(b, a) - default: - return coerce1(a, b), b - } - default: - switch b.(type) { - case idealComplex, idealFloat, idealInt, idealRune, idealUint: - return a, coerce1(b, a) - default: - return a, b - } - } -} - -func coerce1(inVal, otherVal interface{}) (coercedInVal interface{}) { - coercedInVal = inVal - if otherVal == nil { - return - } - - switch x := inVal.(type) { - case nil: - return - case idealComplex: - switch otherVal.(type) { - //case idealComplex: - //case idealFloat: - //case idealInt: - //case idealRune: - //case idealUint: - //case bool: - case complex64: - return complex64(x) - case complex128: - return complex128(x) - //case float32: - //case float64: - //case int8: - //case int16: - //case int32: - //case int64: - //case string: - //case uint8: - //case uint16: - //case uint32: - //case uint64: - //case *big.Int: - //case *big.Rat: - //case time.Time: - //case time.Duration: - } - case idealFloat: - switch otherVal.(type) { - case idealComplex: - return idealComplex(complex(float64(x), 0)) - case idealFloat: - return idealFloat(float64(x)) - //case idealInt: - //case idealRune: - //case idealUint: - //case bool: - case complex64: - return complex(float32(x), 0) - case complex128: - return complex(float64(x), 0) - case float32: - return float32(float64(x)) - case float64: - return float64(x) - //case int8: - //case int16: - //case int32: - //case int64: - //case string: - //case uint8: - //case uint16: - //case uint32: - //case uint64: - //case *big.Int: - case *big.Rat: - return big.NewRat(1, 1).SetFloat64(float64(x)) - //case time.Time: - //case time.Duration: - } - case idealInt: - switch otherVal.(type) { - case idealComplex: - return idealComplex(complex(float64(x), 0)) - case idealFloat: - return idealFloat(int64(x)) - case idealInt: - return idealInt(int64(x)) - //case idealRune: - case idealUint: - if x >= 0 { - return idealUint(int64(x)) - } - //case bool: - case complex64: - return complex(float32(x), 0) - case complex128: - return complex(float64(x), 0) - case float32: - return float32(int64(x)) - case float64: - return float64(int64(x)) - case int8: - if x >= math.MinInt8 && x <= math.MaxInt8 { - return int8(int64(x)) - } - case int16: - if x >= math.MinInt16 && x <= math.MaxInt16 { - return int16(int64(x)) - } - case int32: - if x >= math.MinInt32 && x <= math.MaxInt32 { - return int32(int64(x)) - } - case int64: - return int64(x) - //case string: - case uint8: - if x >= 0 && x <= math.MaxUint8 { - return uint8(int64(x)) - } - case uint16: - if x >= 0 && x <= math.MaxUint16 { - return uint16(int64(x)) - } - case uint32: - if x >= 0 && x <= math.MaxUint32 { - return uint32(int64(x)) - } - case uint64: - if x >= 0 { - return uint64(int64(x)) - } - case *big.Int: - return big.NewInt(int64(x)) - case *big.Rat: - return big.NewRat(1, 1).SetInt64(int64(x)) - //case time.Time: - case time.Duration: - return time.Duration(int64(x)) - } - case idealRune: - switch otherVal.(type) { - case idealComplex: - return idealComplex(complex(float64(x), 0)) - case idealFloat: - return idealFloat(int64(x)) - case idealInt: - return idealInt(int64(x)) - case idealRune: - return idealRune(int64(x)) - case idealUint: - return idealUint(int64(x)) - //case bool: - case complex64: - return complex(float32(x), 0) - case complex128: - return complex(float64(x), 0) - case float32: - return float32(int64(x)) - case float64: - return float64(int64(x)) - case int8: - return int8(int64(x)) - case int16: - return int16(int64(x)) - case int32: - return int32(int64(x)) - case int64: - return int64(x) - //case string: - case uint8: - return uint8(int64(x)) - case uint16: - return uint16(int64(x)) - case uint32: - return uint32(int64(x)) - case uint64: - return uint64(int64(x)) - case *big.Int: - return big.NewInt(int64(x)) - case *big.Rat: - return big.NewRat(1, 1).SetInt64(int64(x)) - //case time.Time: - case time.Duration: - return time.Duration(int64(x)) - } - case idealUint: - switch otherVal.(type) { - case idealComplex: - return idealComplex(complex(float64(x), 0)) - case idealFloat: - return idealFloat(uint64(x)) - case idealInt: - if x <= math.MaxInt64 { - return idealInt(int64(x)) - } - //case idealRune: - case idealUint: - return idealUint(uint64(x)) - //case bool: - case complex64: - return complex(float32(x), 0) - case complex128: - return complex(float64(x), 0) - case float32: - return float32(uint64(x)) - case float64: - return float64(uint64(x)) - case int8: - if x <= math.MaxInt8 { - return int8(int64(x)) - } - case int16: - if x <= math.MaxInt16 { - return int16(int64(x)) - } - case int32: - if x <= math.MaxInt32 { - return int32(int64(x)) - } - case int64: - if x <= math.MaxInt64 { - return int64(x) - } - //case string: - case uint8: - if x >= 0 && x <= math.MaxUint8 { - return uint8(int64(x)) - } - case uint16: - if x >= 0 && x <= math.MaxUint16 { - return uint16(int64(x)) - } - case uint32: - if x >= 0 && x <= math.MaxUint32 { - return uint32(int64(x)) - } - case uint64: - return uint64(x) - case *big.Int: - return big.NewInt(0).SetUint64(uint64(x)) - case *big.Rat: - return big.NewRat(1, 1).SetInt(big.NewInt(0).SetUint64(uint64(x))) - //case time.Time: - case time.Duration: - if x <= math.MaxInt64 { - return time.Duration(int64(x)) - } - } - } - return -} diff --git a/vendor/github.com/cznic/ql/design/doc.go b/vendor/github.com/cznic/ql/design/doc.go deleted file mode 100644 index 7d9a627f8..000000000 --- a/vendor/github.com/cznic/ql/design/doc.go +++ /dev/null @@ -1,298 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* - -Package design describes some of the data structures used in QL. - -Handles - -A handle is a 7 byte "pointer" to a block in the DB[0]. - -Scalar encoding - -Encoding of so called "scalars" provided by [1]. Unless specified otherwise, -all values discussed below are scalars, encoded scalars or encoding of scalar -arrays. - -Database root - -DB root is a 1-scalar found at a fixed handle (#1). - - +---+------+--------+-----------------------+ - | # | Name | Type | Description | - +---+------+--------+-----------------------+ - | 0 | head | handle | First table meta data | - +---+------+--------+-----------------------+ - -Head is the head of a single linked list of table of meta data. It's zero if -there are no tables in the DB. - -Table meta data - -Table meta data are a 6-scalar. - - +---+---------+--------+--------------------------+ - | # | Name | Type | Description | - +---+---------+--------+--------------------------+ - | 0 | next | handle | Next table meta data. | - | 1 | scols | string | Column defintitions | - | 2 | hhead | handle | -> head -> first record | - | 3 | name | string | Table name | - | 4 | indices | string | Index definitions | - | 5 | hxroots | handle | Index B+Trees roots list | - +---+---------+--------+--------------------------+ - -Fields #4 and #5 are optional for backward compatibility with existing -databases. OTOH, forward compatibility will not work. Once any indices are -created using a newer QL version the older versions of QL, expecting only 4 -fields of meta data will not be able to use the DB. That's the intended -behavior because the older versions of QL cannot update the indexes, which can -break queries runned by the newer QL version which expect indices to be always -actualized on any table-with-indices mutation. - -The handle of the next table meta data is in the field #0 (next). If there is -no next table meta data, the field is zero. Names and types of table columns -are stored in field #1 (scols). A single field is described by concatenating a -type tag and the column name. The type tags are - - bool 'b' - complex64 'c' - complex128 'd' - float32 'f' - float64 'g', alias float - int8 'i' - int16 'j' - int32 'k' - int64 'l', alias int - string 's' - uint8 'u', alias byte - uint16 'v' - uint32 'w' - uint64 'x', alias uint - bigInt 'I' - bigRat 'R' - blob 'B' - duration 'D' - time 'T' - -The scols value is the above described encoded fields joined using "|". For -example - - CREATE TABLE t (Foo bool, Bar string, Baz float); - -This statement adds a table meta data with scols - - "bFool|sBar|gBaz" - -Columns can be dropped from a table - - ALTER TABLE t DROP COLUMN Bar; - -This "erases" the field info in scols, so the value becomes - - "bFool||gBaz" - -Colums can be added to a table - - ALTER TABLE t ADD Count uint; - -New fields are always added to the end of scols - - "bFool||gBaz|xCount" - -Index of a field in strings.Split(scols, "|") is the index of the field in a -table record. The above discussed rules for column dropping and column adding -allow for schema evolution without a need to reshape any existing table data. -Dropped columns are left where they are and new records insert nil in their -place. The encoded nil is one byte. Added columns, when not present in -preexisting records are returned as nil values. If the overhead of dropped -columns becomes an issue and there's time/space and memory enough to move the -records of a table around: - - BEGIN TRANSACTION; - CREATE TABLE new (column definitions); - INSERT INTO new SELECT * FROM old; - DROP TABLE old; - CREATE TABLE old (column definitions); - INSERT INTO old SELECT * FROM new; - DROP TABLE new; - END TRANSACTION; - -This is not very time/space effective and for Big Data it can cause an OOM -because transactions are limited by memory resources available to the process. -Perhaps a method and/or QL statement to do this in-place should be added -(MAYBE consider adopting MySQL's OPTIMIZE TABLE syntax). - -Field #2 (hhead) is a handle to a head of table records, i.e. not a handle to -the first record in the table. It is thus always non zero even for a table -having no records. The reason for this "double pointer" schema is to enable -adding (linking) a new record by updating a single value of the (hhead pointing -to) head. - - tableMeta.hhead -> head -> firstTableRecord - -The table name is stored in field #3 (name). - -Indices - -Consider an index named N, indexing column named C. The encoding of this -particular index is a string "N". is a string "n" for non unique -indices and "u" for unique indices. There is this index information for the -index possibly indexing the record id() and for all other columns of scols. -Where the column is not indexed, the index info is an empty string. Infos for -all indexes are joined with "|". For example - - BEGIN TRANSACTION; - CREATE TABLE t (Foo int, Bar bool, Baz string); - CREATE INDEX X ON t (Baz); - CREATE UNIQUE INDEX Y ON t (Foo); - COMMIT; - -The values of fields #1 and #4 for the above are - - scols: "lFoo|bBar|sBaz" - indices: "|uY||nX" - -Aligning properly the "|" split parts - - id col #0 col#1 col#2 - +----------+----+--------+--------+--------+ - | scols: | | "lFoo" | "bBar" | "sBaz" | - +----------+----+--------+--------+--------+ - | indices: | "" | "uY" | "" | "nX" | - +----------+----+--------+--------+--------+ - -shows that the record id() is not indexed for this table while the columns Foo -and Baz are. - -Note that there cannot be two differently named indexes for the same column and -it's intended. The indices are B+Trees[2]. The list of handles to their roots -is pointed to by hxroots with zeros for non indexed columns. For the previous -example - - tableMeta.hxroots -> {0, y, 0, x} - -where x is the root of the B+Tree for the X index and y is the root of the -B+Tree for the Y index. If there would be an index for id(), its B+Tree root -will be present where the first zero is. Similarly to hhead, hxroots is never -zero, even when there are no indices for a table. - -Table record - -A table record is an N-scalar. - - +-----+------------+--------+-------------------------------+ - | # | Name | Type | Description | - +-----+------------+--------+-------------------------------+ - | 0 | next | handle | Next record or zero. | - | 1 | id | int64 | Automatically assigned unique | - | | | | value obtainable by id(). | - | 2 | field #0 | scalar | First field of the record. | - | 3 | field #1 | scalar | Second field of the record. | - ... - | N-1 | field #N-2 | scalar | Last field of the record. | - +-----+------------+--------+-------------------------------+ - -The linked "ordering" of table records has no semantics and it doesn't have to -correlate to the order of how the records were added to the table. In fact, an -efficient way of the linking leads to "ordering" which is actually reversed wrt -the insertion order. - -Non unique index - -The composite key of the B+Tree is {indexed values, record handle}. The B+Tree -value is not used. - - B+Tree key B+Tree value - +----------------+---------------+ +--------------+ - | Indexed Values | Record Handle | -> | not used | - +----------------+---------------+ +--------------+ - -Unique index - -If the indexed values are all NULL then the composite B+Tree key is {nil, -record handle} and the B+Tree value is not used. - - B+Tree key B+Tree value - +------+-----------------+ +--------------+ - | NULL | Record Handle | -> | not used | - +------+-----------------+ +--------------+ - -If the indexed values are not all NULL then key of the B+Tree key are the indexed -values and the B+Tree value is the record handle. - - B+Tree key B+Tree value - +----------------+ +---------------+ - | Indexed Values | -> | Record Handle | - +----------------+ +---------------+ - -Non scalar types - -Scalar types of [1] are bool, complex*, float*, int*, uint*, string and []byte -types. All other types are "blob-like". - - QL type Go type - ----------------------------- - blob []byte - bigint big.Int - bigrat big.Rat - time time.Time - duration time.Duration - -Memory back-end stores the Go type directly. File back-end must resort to -encode all of the above as (tagged) []byte due to the lack of more types -supported natively by lldb. NULL values of blob-like types are encoded as nil -(gbNull in lldb/gb.go), exactly the same as the already existing QL types are. - -Blob encoding - -The values of the blob-like types are first encoded into a []byte slice: - - +-----------------------+-------------------+ - | blob | raw | - | bigint, bigrat, time | gob encoded | - | duration | gob encoded int64 | - +-----------------------+-------------------+ - -The gob encoding is "differential" wrt an initial encoding of all of the -blob-like type. IOW, the initial type descriptors which gob encoding must write -out are stripped off and "resupplied" on decoding transparently. See also -blob.go. If the length of the resulting slice is <= shortBlob, the first and -only chunk is the scalar encoding of - - - []interface{}{typeTag, slice}. // initial (and last) chunk - -The length of slice can be zero (for blob("")). If the resulting slice is long -(> shortBlob), the first chunk comes from encoding - - []interface{}{typeTag, nextHandle, firstPart}. // initial, but not final chunk - -In this case len(firstPart) <= shortBlob. Second and other chunks: If the chunk -is the last one, src is - - []interface{lastPart}. // overflow chunk (last) - -In this case len(lastPart) <= 64kB. If the chunk is not the last one, src is - - []interface{}{nextHandle, part}. // overflow chunk (not last) - -In this case len(part) == 64kB. - -Links - -Referenced from above: - - [0]: http://godoc.org/github.com/cznic/lldb#hdr-Block_handles - [1]: http://godoc.org/github.com/cznic/lldb#EncodeScalars - [2]: http://godoc.org/github.com/cznic/lldb#BTree - -Rationale - -While these notes might be useful to anyone looking at QL sources, the -specifically intended reader is my future self. - -*/ -package design diff --git a/vendor/github.com/cznic/ql/doc.go b/vendor/github.com/cznic/ql/doc.go deleted file mode 100644 index 1f697e3db..000000000 --- a/vendor/github.com/cznic/ql/doc.go +++ /dev/null @@ -1,2652 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//MAYBE set operations -//MAYBE +=, -=, ... - -//TODO verify there's a graceful failure for a 2G+ blob on a 32 bit machine. - -// Package ql implements a pure Go embedded SQL database engine. -// -// QL is a member of the SQL family of languages. It is less complex and less -// powerful than SQL (whichever specification SQL is considered to be). -// -// Change list -// -// 2017-01-10: Release v1.1.0 fixes some bugs and adds a configurable WAL -// headroom. -// -// https://github.com/cznic/ql/issues/140 -// -// 2016-07-29: Release v1.0.6 enables alternatively using = instead of == for -// equality operation. -// -// https://github.com/cznic/ql/issues/131 -// -// 2016-07-11: Release v1.0.5 undoes vendoring of lldb. QL now uses stable lldb -// (github.com/cznic/lldb). -// -// https://github.com/cznic/ql/issues/128 -// -// 2016-07-06: Release v1.0.4 fixes a panic when closing the WAL file. -// -// https://github.com/cznic/ql/pull/127 -// -// 2016-04-03: Release v1.0.3 fixes a data race. -// -// https://github.com/cznic/ql/issues/126 -// -// 2016-03-23: Release v1.0.2 vendors github.com/cznic/exp/lldb and -// github.com/camlistore/go4/lock. -// -// 2016-03-17: Release v1.0.1 adjusts for latest goyacc. Parser error messages -// are improved and changed, but their exact form is not considered a API -// change. -// -// 2016-03-05: The current version has been tagged v1.0.0. -// -// 2015-06-15: To improve compatibility with other SQL implementations, the -// count built-in aggregate function now accepts * as its argument. -// -// 2015-05-29: The execution planner was rewritten from scratch. It should use -// indices in all places where they were used before plus in some additional -// situations. It is possible to investigate the plan using the newly added -// EXPLAIN statement. The QL tool is handy for such analysis. If the planner -// would have used an index, but no such exists, the plan includes hints in -// form of copy/paste ready CREATE INDEX statements. -// -// The planner is still quite simple and a lot of work on it is yet ahead. You -// can help this process by filling an issue with a schema and query which -// fails to use an index or indices when it should, in your opinion. Bonus -// points for including output of `ql 'explain '`. -// -// 2015-05-09: The grammar of the CREATE INDEX statement now accepts an -// expression list instead of a single expression, which was further limited to -// just a column name or the built-in id(). As a side effect, composite -// indices are now functional. However, the values in the expression-list style -// index are not yet used by other statements or the statement/query planner. -// The composite index is useful while having UNIQUE clause to check for -// semantically duplicate rows before they get added to the table or when such -// a row is mutated using the UPDATE statement and the expression-list style -// index tuple of the row is thus recomputed. -// -// 2015-05-02: The Schema field of table __Table now correctly reflects any -// column constraints and/or defaults. Also, the (*DB).Info method now has that -// information provided in new ColumInfo fields NotNull, Constraint and -// Default. -// -// 2015-04-20: Added support for {LEFT,RIGHT,FULL} [OUTER] JOIN. -// -// 2015-04-18: Column definitions can now have constraints and defaults. -// Details are discussed in the "Constraints and defaults" chapter below the -// CREATE TABLE statement documentation. -// -// 2015-03-06: New built-in functions formatFloat and formatInt. Thanks -// urandom! (https://github.com/urandom) -// -// 2015-02-16: IN predicate now accepts a SELECT statement. See the updated -// "Predicates" section. -// -// 2015-01-17: Logical operators || and && have now alternative spellings: OR -// and AND (case insensitive). AND was a keyword before, but OR is a new one. -// This can possibly break existing queries. For the record, it's a good idea -// to not use any name appearing in, for example, [7] in your queries as the -// list of QL's keywords may expand for gaining better compatibility with -// existing SQL "standards". -// -// 2015-01-12: ACID guarantees were tightened at the cost of performance in -// some cases. The write collecting window mechanism, a formerly used -// implementation detail, was removed. Inserting rows one by one in a -// transaction is now slow. I mean very slow. Try to avoid inserting single -// rows in a transaction. Instead, whenever possible, perform batch updates of -// tens to, say thousands of rows in a single transaction. See also: -// http://www.sqlite.org/faq.html#q19, the discussed synchronization principles -// involved are the same as for QL, modulo minor details. -// -// Note: A side effect is that closing a DB before exiting an application, both -// for the Go API and through database/sql driver, is no more required, -// strictly speaking. Beware that exiting an application while there is an open -// (uncommitted) transaction in progress means losing the transaction data. -// However, the DB will not become corrupted because of not closing it. Nor -// that was the case before, but formerly failing to close a DB could have -// resulted in losing the data of the last transaction. -// -// 2014-09-21: id() now optionally accepts a single argument - a table name. -// -// 2014-09-01: Added the DB.Flush() method and the LIKE pattern matching -// predicate. -// -// 2014-08-08: The built in functions max and min now accept also time values. -// Thanks opennota! (https://github.com/opennota) -// -// 2014-06-05: RecordSet interface extended by new methods FirstRow and Rows. -// -// 2014-06-02: Indices on id() are now used by SELECT statements. -// -// 2014-05-07: Introduction of Marshal, Schema, Unmarshal. -// -// 2014-04-15: -// -// Added optional IF NOT EXISTS clause to CREATE INDEX and optional IF EXISTS -// clause to DROP INDEX. -// -// 2014-04-12: -// -// The column Unique in the virtual table __Index was renamed to IsUnique -// because the old name is a keyword. Unfortunately, this is a breaking change, -// sorry. -// -// 2014-04-11: Introduction of LIMIT, OFFSET. -// -// 2014-04-10: Introduction of query rewriting. -// -// 2014-04-07: Introduction of indices. -// -// Building non CGO QL -// -// QL imports zappy[8], a block-based compressor, which speeds up its -// performance by using a C version of the compression/decompression -// algorithms. If a CGO-free (pure Go) version of QL, or an app using QL, is -// required, please include 'purego' in the -tags option of go -// {build,get,install}. For example: -// -// $ go get -tags purego github.com/cznic/ql -// -// If zappy was installed before installing QL, it might be necessary to -// rebuild zappy first (or rebuild QL with all its dependencies using the -a -// option): -// -// $ touch "$GOPATH"/src/github.com/cznic/zappy/*.go -// $ go install -tags purego github.com/cznic/zappy -// $ go install github.com/cznic/ql -// -// Notation -// -// The syntax is specified using Extended Backus-Naur Form (EBNF) -// -// Production = production_name "=" [ Expression ] "." . -// Expression = Alternative { "|" Alternative } . -// Alternative = Term { Term } . -// Term = production_name | token [ "…" token ] | Group | Option | Repetition . -// Group = "(" Expression ")" . -// Option = "[" Expression "]" . -// Repetition = "{" Expression "}" . -// Productions are expressions constructed from terms and the following operators, in increasing precedence -// -// | alternation -// () grouping -// [] option (0 or 1 times) -// {} repetition (0 to n times) -// -// Lower-case production names are used to identify lexical tokens. -// Non-terminals are in CamelCase. Lexical tokens are enclosed in double quotes -// "" or back quotes ``. -// -// The form a … b represents the set of characters from a through b as -// alternatives. The horizontal ellipsis … is also used elsewhere in the spec -// to informally denote various enumerations or code snippets that are not -// further specified. -// -// QL source code representation -// -// QL source code is Unicode text encoded in UTF-8. The text is not -// canonicalized, so a single accented code point is distinct from the same -// character constructed from combining an accent and a letter; those are -// treated as two code points. For simplicity, this document will use the -// unqualified term character to refer to a Unicode code point in the source -// text. -// -// Each code point is distinct; for instance, upper and lower case letters are -// different characters. -// -// Implementation restriction: For compatibility with other tools, the parser -// may disallow the NUL character (U+0000) in the statement. -// -// Implementation restriction: A byte order mark is disallowed anywhere in QL -// statements. -// -// Characters -// -// The following terms are used to denote specific character classes -// -// newline = . // the Unicode code point U+000A -// unicode_char = . // an arbitrary Unicode code point except newline -// ascii_letter = "a" … "z" | "A" … "Z" . -// unicode_letter = . // Unicode category L. -// unicode_digit = . // Unocode category D. -// -// Letters and digits -// -// The underscore character _ (U+005F) is considered a letter. -// -// letter = ascii_letter | unicode_letter | "_" . -// decimal_digit = "0" … "9" . -// octal_digit = "0" … "7" . -// hex_digit = "0" … "9" | "A" … "F" | "a" … "f" . -// -// Lexical elements -// -// Lexical elements are comments, tokens, identifiers, keywords, operators and -// delimiters, integer, floating-point, imaginary, rune and string literals and -// QL parameters. -// -// Comments -// -// There are three forms of comments -// -// Line comments start with the character sequence // or -- and stop at the end -// of the line. A line comment acts like a space. -// -// General comments start with the character sequence /* and continue through -// the character sequence */. A general comment acts like a space. -// -// Comments do not nest. -// -// Tokens -// -// Tokens form the vocabulary of QL. There are four classes: identifiers, -// keywords, operators and delimiters, and literals. White space, formed from -// spaces (U+0020), horizontal tabs (U+0009), carriage returns (U+000D), and -// newlines (U+000A), is ignored except as it separates tokens that would -// otherwise combine into a single token. -// -// Semicolons -// -// The formal grammar uses semicolons ";" as separators of QL statements. A -// single QL statement or the last QL statement in a list of statements can -// have an optional semicolon terminator. (Actually a separator from the -// following empty statement.) -// -// Identifiers -// -// Identifiers name entities such as tables or record set columns. An -// identifier is a sequence of one or more letters and digits. The first -// character in an identifier must be a letter. -// -// identifier = letter { letter | decimal_digit | unicode_digit } . -// -// For example -// -// price -// _tmp42 -// Sales -// -// No identifiers are predeclared, however note that no keyword can be used as -// an identifier. Identifiers starting with two underscores are used for meta -// data virtual tables names. For forward compatibility, users should generally -// avoid using any identifiers starting with two underscores. For example -// -// __Column -// __Column2 -// __Index -// __Table -// -// Keywords -// -// The following keywords are reserved and may not be used as identifiers. -// -// ADD complex128 FROM LEFT string -// ALTER complex64 FULL LIKE TABLE -// AND CREATE GROUP LIMIT time -// AS DEFAULT IF NOT TRANSACTION -// ASC DELETE IN NULL true -// BEGIN DESC INDEX OFFSET TRUNCATE -// BETWEEN DISTINCT INSERT ON uint -// bigint DROP int OR uint16 -// bigrat duration int16 ORDER uint32 -// blob EXISTS int32 OUTER uint64 -// bool EXPLAIN int64 RIGHT uint8 -// BY false int8 ROLLBACK UNIQUE -// byte float INTO rune UPDATE -// COLUMN float32 IS SELECT VALUES -// COMMIT float64 JOIN SET WHERE -// -// Keywords are not case sensitive. -// -// Operators and Delimiters -// -// The following character sequences represent operators, delimiters, and other -// special tokens -// -// + & && == != ( ) -// - | || < <= [ ] -// * ^ > >= , ; -// / << = . -// % >> ! -// &^ -// -// Operators consisting of more than one character are referred to by names in -// the rest of the documentation -// -// andand = "&&" . -// andnot = "&^" . -// lsh = "<<" . -// le = "<=" . -// eq = "==" | "=" . -// ge = ">=" . -// neq = "!=" . -// oror = "||" . -// rsh = ">>" . -// -// Integer literals -// -// An integer literal is a sequence of digits representing an integer constant. -// An optional prefix sets a non-decimal base: 0 for octal, 0x or 0X for -// hexadecimal. In hexadecimal literals, letters a-f and A-F represent values -// 10 through 15. -// -// int_lit = decimal_lit | octal_lit | hex_lit . -// decimal_lit = ( "1" … "9" ) { decimal_digit } . -// octal_lit = "0" { octal_digit } . -// hex_lit = "0" ( "x" | "X" ) hex_digit { hex_digit } . -// -// For example -// -// 42 -// 0600 -// 0xBadFace -// 1701411834604692 -// -// Floating-point literals -// -// A floating-point literal is a decimal representation of a floating-point -// constant. It has an integer part, a decimal point, a fractional part, and an -// exponent part. The integer and fractional part comprise decimal digits; the -// exponent part is an e or E followed by an optionally signed decimal -// exponent. One of the integer part or the fractional part may be elided; one -// of the decimal point or the exponent may be elided. -// -// float_lit = decimals "." [ decimals ] [ exponent ] | -// decimals exponent | -// "." decimals [ exponent ] . -// decimals = decimal_digit { decimal_digit } . -// exponent = ( "e" | "E" ) [ "+" | "-" ] decimals . -// -// For example -// -// 0. -// 72.40 -// 072.40 // == 72.40 -// 2.71828 -// 1.e+0 -// 6.67428e-11 -// 1E6 -// .25 -// .12345E+5 -// -// Imaginary literals -// -// An imaginary literal is a decimal representation of the imaginary part of a -// complex constant. It consists of a floating-point literal or decimal integer -// followed by the lower-case letter i. -// -// imaginary_lit = (decimals | float_lit) "i" . -// -// For example -// -// 0i -// 011i // == 11i -// 0.i -// 2.71828i -// 1.e+0i -// 6.67428e-11i -// 1E6i -// .25i -// .12345E+5i -// -// Rune literals -// -// A rune literal represents a rune constant, an integer value identifying a -// Unicode code point. A rune literal is expressed as one or more characters -// enclosed in single quotes. Within the quotes, any character may appear -// except single quote and newline. A single quoted character represents the -// Unicode value of the character itself, while multi-character sequences -// beginning with a backslash encode values in various formats. -// -// The simplest form represents the single character within the quotes; since -// QL statements are Unicode characters encoded in UTF-8, multiple -// UTF-8-encoded bytes may represent a single integer value. For instance, the -// literal 'a' holds a single byte representing a literal a, Unicode U+0061, -// value 0x61, while 'ä' holds two bytes (0xc3 0xa4) representing a literal -// a-dieresis, U+00E4, value 0xe4. -// -// Several backslash escapes allow arbitrary values to be encoded as ASCII -// text. There are four ways to represent the integer value as a numeric -// constant: \x followed by exactly two hexadecimal digits; \u followed by -// exactly four hexadecimal digits; \U followed by exactly eight hexadecimal -// digits, and a plain backslash \ followed by exactly three octal digits. In -// each case the value of the literal is the value represented by the digits in -// the corresponding base. -// -// Although these representations all result in an integer, they have different -// valid ranges. Octal escapes must represent a value between 0 and 255 -// inclusive. Hexadecimal escapes satisfy this condition by construction. The -// escapes \u and \U represent Unicode code points so within them some values -// are illegal, in particular those above 0x10FFFF and surrogate halves. -// -// After a backslash, certain single-character escapes represent special -// values -// -// \a U+0007 alert or bell -// \b U+0008 backspace -// \f U+000C form feed -// \n U+000A line feed or newline -// \r U+000D carriage return -// \t U+0009 horizontal tab -// \v U+000b vertical tab -// \\ U+005c backslash -// \' U+0027 single quote (valid escape only within rune literals) -// \" U+0022 double quote (valid escape only within string literals) -// -// All other sequences starting with a backslash are illegal inside rune -// literals. -// -// rune_lit = "'" ( unicode_value | byte_value ) "'" . -// unicode_value = unicode_char | little_u_value | big_u_value | escaped_char . -// byte_value = octal_byte_value | hex_byte_value . -// octal_byte_value = `\` octal_digit octal_digit octal_digit . -// hex_byte_value = `\` "x" hex_digit hex_digit . -// little_u_value = `\` "u" hex_digit hex_digit hex_digit hex_digit . -// big_u_value = `\` "U" hex_digit hex_digit hex_digit hex_digit -// hex_digit hex_digit hex_digit hex_digit . -// escaped_char = `\` ( "a" | "b" | "f" | "n" | "r" | "t" | "v" | `\` | "'" | `"` ) . -// -// For example -// -// 'a' -// 'ä' -// '本' -// '\t' -// '\000' -// '\007' -// '\377' -// '\x07' -// '\xff' -// '\u12e4' -// '\U00101234' -// 'aa' // illegal: too many characters -// '\xa' // illegal: too few hexadecimal digits -// '\0' // illegal: too few octal digits -// '\uDFFF' // illegal: surrogate half -// '\U00110000' // illegal: invalid Unicode code point -// -// String literals -// -// A string literal represents a string constant obtained from concatenating a -// sequence of characters. There are two forms: raw string literals and -// interpreted string literals. -// -// Raw string literals are character sequences between back quotes ``. Within -// the quotes, any character is legal except back quote. The value of a raw -// string literal is the string composed of the uninterpreted (implicitly -// UTF-8-encoded) characters between the quotes; in particular, backslashes -// have no special meaning and the string may contain newlines. Carriage -// returns inside raw string literals are discarded from the raw string value. -// -// Interpreted string literals are character sequences between double quotes -// "". The text between the quotes, which may not contain newlines, forms the -// value of the literal, with backslash escapes interpreted as they are in rune -// literals (except that \' is illegal and \" is legal), with the same -// restrictions. The three-digit octal (\nnn) and two-digit hexadecimal (\xnn) -// escapes represent individual bytes of the resulting string; all other -// escapes represent the (possibly multi-byte) UTF-8 encoding of individual -// characters. Thus inside a string literal \377 and \xFF represent a single -// byte of value 0xFF=255, while ÿ, \u00FF, \U000000FF and \xc3\xbf represent -// the two bytes 0xc3 0xbf of the UTF-8 encoding of character U+00FF. -// -// string_lit = raw_string_lit | interpreted_string_lit . -// raw_string_lit = "`" { unicode_char | newline } "`" . -// interpreted_string_lit = `"` { unicode_value | byte_value } `"` . -// -// For example -// -// `abc` // same as "abc" -// `\n -// \n` // same as "\\n\n\\n" -// "\n" -// "" -// "Hello, world!\n" -// "日本語" -// "\u65e5本\U00008a9e" -// "\xff\u00FF" -// "\uD800" // illegal: surrogate half -// "\U00110000" // illegal: invalid Unicode code point -// -// These examples all represent the same string -// -// "日本語" // UTF-8 input text -// `日本語` // UTF-8 input text as a raw literal -// "\u65e5\u672c\u8a9e" // the explicit Unicode code points -// "\U000065e5\U0000672c\U00008a9e" // the explicit Unicode code points -// "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" // the explicit UTF-8 bytes -// -// If the statement source represents a character as two code points, such as a -// combining form involving an accent and a letter, the result will be an error -// if placed in a rune literal (it is not a single code point), and will appear -// as two code points if placed in a string literal. -// -// QL parameters -// -// Literals are assigned their values from the respective text representation -// at "compile" (parse) time. QL parameters provide the same functionality as -// literals, but their value is assigned at execution time from an expression -// list passed to DB.Run or DB.Execute. Using '?' or '$' is completely -// equivalent. -// -// ql_parameter = ( "?" | "$" ) "1" … "9" { "0" … "9" } . -// -// For example -// -// SELECT DepartmentID -// FROM department -// WHERE DepartmentID == ?1 -// ORDER BY DepartmentName; -// -// SELECT employee.LastName -// FROM department, employee -// WHERE department.DepartmentID == $1 && employee.LastName > $2 -// ORDER BY DepartmentID; -// -// Constants -// -// Keywords 'false' and 'true' (not case sensitive) represent the two possible -// constant values of type bool (also not case sensitive). -// -// Keyword 'NULL' (not case sensitive) represents an untyped constant which is -// assignable to any type. NULL is distinct from any other value of any type. -// -// Types -// -// A type determines the set of values and operations specific to values of -// that type. A type is specified by a type name. -// -// Type = "bigint" // http://golang.org/pkg/math/big/#Int -// | "bigrat" // http://golang.org/pkg/math/big/#Rat -// | "blob" // []byte -// | "bool" -// | "byte" // alias for uint8 -// | "complex128" -// | "complex64" -// | "duration" // http://golang.org/pkg/time/#Duration -// | "float" // alias for float64 -// | "float32" -// | "float64" -// | "int" // alias for int64 -// | "int16" -// | "int32" -// | "int64" -// | "int8" -// | "rune" // alias for int32 -// | "string" -// | "time" // http://golang.org/pkg/time/#Time -// | "uint" // alias for uint64 -// | "uint16" -// | "uint32" -// | "uint64" -// | "uint8" . -// -// Named instances of the boolean, numeric, and string types are keywords. The -// names are not case sensitive. -// -// Note: The blob type is exchanged between the back end and the API as []byte. -// On 32 bit platforms this limits the size which the implementation can handle -// to 2G. -// -// Boolean types -// -// A boolean type represents the set of Boolean truth values denoted by the -// predeclared constants true and false. The predeclared boolean type is bool. -// -// Duration type -// -// A duration type represents the elapsed time between two instants as an int64 -// nanosecond count. The representation limits the largest representable -// duration to approximately 290 years. -// -// Numeric types -// -// A numeric type represents sets of integer or floating-point values. The -// predeclared architecture-independent numeric types are -// -// uint8 the set of all unsigned 8-bit integers (0 to 255) -// uint16 the set of all unsigned 16-bit integers (0 to 65535) -// uint32 the set of all unsigned 32-bit integers (0 to 4294967295) -// uint64 the set of all unsigned 64-bit integers (0 to 18446744073709551615) -// -// int8 the set of all signed 8-bit integers (-128 to 127) -// int16 the set of all signed 16-bit integers (-32768 to 32767) -// int32 the set of all signed 32-bit integers (-2147483648 to 2147483647) -// int64 the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807) -// duration the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807) -// bigint the set of all integers -// -// bigrat the set of all rational numbers -// -// float32 the set of all IEEE-754 32-bit floating-point numbers -// float64 the set of all IEEE-754 64-bit floating-point numbers -// -// complex64 the set of all complex numbers with float32 real and imaginary parts -// complex128 the set of all complex numbers with float64 real and imaginary parts -// -// byte alias for uint8 -// float alias for float64 -// int alias for int64 -// rune alias for int32 -// uint alias for uint64 -// -// The value of an n-bit integer is n bits wide and represented using two's -// complement arithmetic. -// -// Conversions are required when different numeric types are mixed in an -// expression or assignment. -// -// String types -// -// A string type represents the set of string values. A string value is a -// (possibly empty) sequence of bytes. The case insensitive keyword for the -// string type is 'string'. -// -// The length of a string (its size in bytes) can be discovered using the -// built-in function len. -// -// Time types -// -// A time type represents an instant in time with nanosecond precision. Each -// time has associated with it a location, consulted when computing the -// presentation form of the time. -// -// Predeclared functions -// -// The following functions are implicitly declared -// -// avg complex contains count date -// day formatTime formatFloat formatInt -// hasPrefix hasSuffix hour hours id -// imag len max min minute -// minutes month nanosecond nanoseconds now -// parseTime real second seconds since -// sum timeIn weekday year yearDay -// -// Expressions -// -// An expression specifies the computation of a value by applying operators and -// functions to operands. -// -// Operands -// -// Operands denote the elementary values in an expression. An operand may be a -// literal, a (possibly qualified) identifier denoting a constant or a function -// or a table/record set column, or a parenthesized expression. -// -// Operand = Literal | QualifiedIdent | "(" Expression ")" . -// Literal = "FALSE" | "NULL" | "TRUE" -// | float_lit | imaginary_lit | int_lit | rune_lit | string_lit -// | ql_parameter . -// -// Qualified identifiers -// -// A qualified identifier is an identifier qualified with a table/record set -// name prefix. -// -// QualifiedIdent = identifier [ "." identifier ] . -// -// For example -// -// invoice.Num // might denote column 'Num' from table 'invoice' -// -// Primary expressions -// -// Primary expression are the operands for unary and binary expressions. -// -// PrimaryExpression = Operand -// | Conversion -// | PrimaryExpression Index -// | PrimaryExpression Slice -// | PrimaryExpression Call . -// -// Call = "(" [ "*" | ExpressionList ] ")" . // * only in count(*). -// Index = "[" Expression "]" . -// Slice = "[" [ Expression ] ":" [ Expression ] "]" . -// -// For example -// -// x -// 2 -// (s + ".txt") -// f(3.1415, true) -// s[i : j + 1] -// -// Index expressions -// -// A primary expression of the form -// -// s[x] -// -// denotes the element of a string indexed by x. Its type is byte. The value x -// is called the index. The following rules apply -// -// - The index x must be of integer type except bigint or duration; it is in -// range if 0 <= x < len(s), otherwise it is out of range. -// -// - A constant index must be non-negative and representable by a value of type -// int. -// -// - A constant index must be in range if the string a is a literal. -// -// - If x is out of range at run time, a run-time error occurs. -// -// - s[x] is the byte at index x and the type of s[x] is byte. -// -// If s is NULL or x is NULL then the result is NULL. -// -// Otherwise s[x] is illegal. -// -// Slices -// -// For a string, the primary expression -// -// s[low : high] -// -// constructs a substring. The indices low and high select which elements -// appear in the result. The result has indices starting at 0 and length equal -// to high - low. -// -// For convenience, any of the indices may be omitted. A missing low index -// defaults to zero; a missing high index defaults to the length of the sliced -// operand -// -// s[2:] // same s[2 : len(s)] -// s[:3] // same as s[0 : 3] -// s[:] // same as s[0 : len(s)] -// -// The indices low and high are in range if 0 <= low <= high <= len(a), -// otherwise they are out of range. A constant index must be non-negative and -// representable by a value of type int. If both indices are constant, they -// must satisfy low <= high. If the indices are out of range at run time, a -// run-time error occurs. -// -// Integer values of type bigint or duration cannot be used as indices. -// -// If s is NULL the result is NULL. If low or high is not omitted and is NULL -// then the result is NULL. -// -// Calls -// -// Given an identifier f denoting a predeclared function, -// -// f(a1, a2, … an) -// -// calls f with arguments a1, a2, … an. Arguments are evaluated before the -// function is called. The type of the expression is the result type of f. -// -// complex(x, y) -// len(name) -// -// In a function call, the function value and arguments are evaluated in the -// usual order. After they are evaluated, the parameters of the call are passed -// by value to the function and the called function begins execution. The -// return value of the function is passed by value when the function returns. -// -// Calling an undefined function causes a compile-time error. -// -// Operators -// -// Operators combine operands into expressions. -// -// Expression = Term { ( oror | "OR" ) Term } . -// -// ExpressionList = Expression { "," Expression } [ "," ]. -// Factor = PrimaryFactor { ( ge | ">" | le | "<" | neq | eq | "LIKE" ) PrimaryFactor } [ Predicate ] . -// PrimaryFactor = PrimaryTerm { ( "^" | "|" | "-" | "+" ) PrimaryTerm } . -// PrimaryTerm = UnaryExpr { ( andnot | "&" | lsh | rsh | "%" | "/" | "*" ) UnaryExpr } . -// Term = Factor { ( andand | "AND" ) Factor } . -// UnaryExpr = [ "^" | "!" | "-" | "+" ] PrimaryExpression . -// -// Comparisons are discussed elsewhere. For other binary operators, the operand -// types must be identical unless the operation involves shifts or untyped -// constants. For operations involving constants only, see the section on -// constant expressions. -// -// Except for shift operations, if one operand is an untyped constant and the -// other operand is not, the constant is converted to the type of the other -// operand. -// -// The right operand in a shift expression must have unsigned integer type or -// be an untyped constant that can be converted to unsigned integer type. If -// the left operand of a non-constant shift expression is an untyped constant, -// the type of the constant is what it would be if the shift expression were -// replaced by its left operand alone. -// -// Pattern matching -// -// Expressions of the form -// -// expr1 LIKE expr2 -// -// yield a boolean value true if expr2, a regular expression, matches expr1 -// (see also [6]). Both expression must be of type string. If any one of the -// expressions is NULL the result is NULL. -// -// Predicates -// -// Predicates are special form expressions having a boolean result type. -// -// Expressions of the form -// -// expr IN ( expr1, expr2, expr3, ... ) // case A -// -// expr NOT IN ( expr1, expr2, expr3, ... ) // case B -// -// are equivalent, including NULL handling, to -// -// expr == expr1 || expr == expr2 || expr == expr3 || ... // case A -// -// expr != expr1 && expr != expr2 && expr != expr3 && ... // case B -// -// The types of involved expressions must be comparable as defined in -// "Comparison operators". -// -// Another form of the IN predicate creates the expression list from a result -// of a SelectStmt. -// -// DELETE FROM t WHERE id() IN (SELECT id_t FROM u WHERE inactive_days > 365) -// -// The SelectStmt must select only one column. The produced expression list is -// resource limited by the memory available to the process. NULL values -// produced by the SelectStmt are ignored, but if all records of the SelectStmt -// are NULL the predicate yields NULL. The select statement is evaluated only -// once. If the type of expr is not the same as the type of the field returned -// by the SelectStmt then the set operation yields false. The type of the -// column returned by the SelectStmt must be one of the simple (non blob-like) -// types: -// -// bool -// byte // alias uint8 -// complex128 -// complex64 -// float // alias float64 -// float32 -// float64 -// int // alias int64 -// int16 -// int32 -// int64 -// int8 -// rune // alias int32 -// string -// uint // alias uint64 -// uint16 -// uint32 -// uint64 -// uint8 -// -// Expressions of the form -// -// expr BETWEEN low AND high // case A -// -// expr NOT BETWEEN low AND high // case B -// -// are equivalent, including NULL handling, to -// -// expr >= low && expr <= high // case A -// -// expr < low || expr > high // case B -// -// The types of involved expressions must be ordered as defined in "Comparison -// operators". -// -// Predicate = ( -// [ "NOT" ] ( -// "IN" "(" ExpressionList ")" -// | "IN" "(" SelectStmt [ ";" ] ")" -// | "BETWEEN" PrimaryFactor "AND" PrimaryFactor -// ) -// | "IS" [ "NOT" ] "NULL" -// ). -// -// Expressions of the form -// -// expr IS NULL // case A -// -// expr IS NOT NULL // case B -// -// yield a boolean value true if expr does not have a specific type (case A) or -// if expr has a specific type (case B). In other cases the result is a boolean -// value false. -// -// Operator precedence -// -// Unary operators have the highest precedence. -// -// There are five precedence levels for binary operators. Multiplication -// operators bind strongest, followed by addition operators, comparison -// operators, && (logical AND), and finally || (logical OR) -// -// Precedence Operator -// 5 * / % << >> & &^ -// 4 + - | ^ -// 3 == != < <= > >= -// 2 && -// 1 || -// -// Binary operators of the same precedence associate from left to right. For -// instance, x / y * z is the same as (x / y) * z. -// -// +x -// 23 + 3*x[i] -// x <= f() -// ^a >> b -// f() || g() -// x == y+1 && z > 0 -// -// Note that the operator precedence is reflected explicitly by the grammar. -// -// Arithmetic operators -// -// Arithmetic operators apply to numeric values and yield a result of the same -// type as the first operand. The four standard arithmetic operators (+, -, *, -// /) apply to integer, rational, floating-point, and complex types; + also -// applies to strings; +,- also applies to times. All other arithmetic -// operators apply to integers only. -// -// + sum integers, rationals, floats, complex values, strings -// - difference integers, rationals, floats, complex values, times -// * product integers, rationals, floats, complex values -// / quotient integers, rationals, floats, complex values -// % remainder integers -// -// & bitwise AND integers -// | bitwise OR integers -// ^ bitwise XOR integers -// &^ bit clear (AND NOT) integers -// -// << left shift integer << unsigned integer -// >> right shift integer >> unsigned integer -// -// Strings can be concatenated using the + operator -// -// "hi" + string(c) + " and good bye" -// -// String addition creates a new string by concatenating the operands. -// -// A value of type duration can be added to or subtracted from a value of type time. -// -// now() + duration("1h") // time after 1 hour from now -// duration("1h") + now() // time after 1 hour from now -// now() - duration("1h") // time before 1 hour from now -// duration("1h") - now() // illegal, negative times do not exist -// -// Times can subtracted from each other producing a value of type duration. -// -// now() - t0 // elapsed time since t0 -// now() + now() // illegal, operator + not defined for times -// -// For two integer values x and y, the integer quotient q = x / y and remainder -// r = x % y satisfy the following relationships -// -// x = q*y + r and |r| < |y| -// -// with x / y truncated towards zero ("truncated division"). -// -// x y x / y x % y -// 5 3 1 2 -// -5 3 -1 -2 -// 5 -3 -1 2 -// -5 -3 1 -2 -// -// As an exception to this rule, if the dividend x is the most negative value -// for the int type of x, the quotient q = x / -1 is equal to x (and r = 0). -// -// x, q -// int8 -128 -// int16 -32768 -// int32 -2147483648 -// int64 -9223372036854775808 -// -// If the divisor is a constant expression, it must not be zero. If the divisor -// is zero at run time, a run-time error occurs. If the dividend is -// non-negative and the divisor is a constant power of 2, the division may be -// replaced by a right shift, and computing the remainder may be replaced by a -// bitwise AND operation -// -// x x / 4 x % 4 x >> 2 x & 3 -// 11 2 3 2 3 -// -11 -2 -3 -3 1 -// -// The shift operators shift the left operand by the shift count specified by -// the right operand. They implement arithmetic shifts if the left operand is a -// signed integer and logical shifts if it is an unsigned integer. There is no -// upper limit on the shift count. Shifts behave as if the left operand is -// shifted n times by 1 for a shift count of n. As a result, x << 1 is the same -// as x*2 and x >> 1 is the same as x/2 but truncated towards negative -// infinity. -// -// For integer operands, the unary operators +, -, and ^ are defined as follows -// -// +x is 0 + x -// -x negation is 0 - x -// ^x bitwise complement is m ^ x with m = "all bits set to 1" for unsigned x -// and m = -1 for signed x -// -// For floating-point and complex numbers, +x is the same as x, while -x is the -// negation of x. The result of a floating-point or complex division by zero is -// not specified beyond the IEEE-754 standard; whether a run-time error occurs -// is implementation-specific. -// -// Whenever any operand of any arithmetic operation, unary or binary, is NULL, -// as well as in the case of the string concatenating operation, the result is -// NULL. -// -// 42*NULL // the result is NULL -// NULL/x // the result is NULL -// "foo"+NULL // the result is NULL -// -// Integer overflow -// -// For unsigned integer values, the operations +, -, *, and << are computed -// modulo 2n, where n is the bit width of the unsigned integer's type. Loosely -// speaking, these unsigned integer operations discard high bits upon overflow, -// and expressions may rely on ``wrap around''. -// -// For signed integers with a finite bit width, the operations +, -, *, and << -// may legally overflow and the resulting value exists and is deterministically -// defined by the signed integer representation, the operation, and its -// operands. No exception is raised as a result of overflow. An evaluator may -// not optimize an expression under the assumption that overflow does not -// occur. For instance, it may not assume that x < x + 1 is always true. -// -// Integers of type bigint and rationals do not overflow but their handling is -// limited by the memory resources available to the program. -// -// Comparison operators -// -// Comparison operators compare two operands and yield a boolean value. -// -// == equal -// != not equal -// < less -// <= less or equal -// > greater -// >= greater or equal -// -// In any comparison, the first operand must be of same type as is the second -// operand, or vice versa. -// -// The equality operators == and != apply to operands that are comparable. The -// ordering operators <, <=, >, and >= apply to operands that are ordered. -// These terms and the result of the comparisons are defined as follows -// -// - Boolean values are comparable. Two boolean values are equal if they are -// either both true or both false. -// -// - Complex values are comparable. Two complex values u and v are equal if -// both real(u) == real(v) and imag(u) == imag(v). -// -// - Integer values are comparable and ordered, in the usual way. Note that -// durations are integers. -// -// - Floating point values are comparable and ordered, as defined by the -// IEEE-754 standard. -// -// - Rational values are comparable and ordered, in the usual way. -// -// - String and Blob values are comparable and ordered, lexically byte-wise. -// -// - Time values are comparable and ordered. -// -// Whenever any operand of any comparison operation is NULL, the result is -// NULL. -// -// Note that slices are always of type string. -// -// Logical operators -// -// Logical operators apply to boolean values and yield a boolean result. The -// right operand is evaluated conditionally. -// -// && conditional AND p && q is "if p then q else false" -// || conditional OR p || q is "if p then true else q" -// ! NOT !p is "not p" -// -// The truth tables for logical operations with NULL values -// -// +-------+-------+---------+---------+ -// | p | q | p || q | p && q | -// +-------+-------+---------+---------+ -// | true | true | *true | true | -// | true | false | *true | false | -// | true | NULL | *true | NULL | -// | false | true | true | *false | -// | false | false | false | *false | -// | false | NULL | NULL | *false | -// | NULL | true | true | NULL | -// | NULL | false | NULL | false | -// | NULL | NULL | NULL | NULL | -// +-------+-------+---------+---------+ -// * indicates q is not evaluated. -// -// +-------+-------+ -// | p | !p | -// +-------+-------+ -// | true | false | -// | false | true | -// | NULL | NULL | -// +-------+-------+ -// -// Conversions -// -// Conversions are expressions of the form T(x) where T is a type and x is an -// expression that can be converted to type T. -// -// Conversion = Type "(" Expression ")" . -// -// A constant value x can be converted to type T in any of these cases: -// -// - x is representable by a value of type T. -// -// - x is a floating-point constant, T is a floating-point type, and x is -// representable by a value of type T after rounding using IEEE 754 -// round-to-even rules. The constant T(x) is the rounded value. -// -// - x is an integer constant and T is a string type. The same rule as for -// non-constant x applies in this case. -// -// Converting a constant yields a typed constant as result. -// -// float32(2.718281828) // 2.718281828 of type float32 -// complex128(1) // 1.0 + 0.0i of type complex128 -// float32(0.49999999) // 0.5 of type float32 -// string('x') // "x" of type string -// string(0x266c) // "♬" of type string -// "foo" + "bar" // "foobar" -// int(1.2) // illegal: 1.2 cannot be represented as an int -// string(65.0) // illegal: 65.0 is not an integer constant -// -// A non-constant value x can be converted to type T in any of these cases: -// -// - x has type T. -// -// - x's type and T are both integer or floating point types. -// -// - x's type and T are both complex types. -// -// - x is an integer, except bigint or duration, and T is a string type. -// -// Specific rules apply to (non-constant) conversions between numeric types or -// to and from a string type. These conversions may change the representation -// of x and incur a run-time cost. All other conversions only change the type -// but not the representation of x. -// -// A conversion of NULL to any type yields NULL. -// -// Conversions between numeric types -// -// For the conversion of non-constant numeric values, the following rules -// apply -// -// 1. When converting between integer types, if the value is a signed integer, -// it is sign extended to implicit infinite precision; otherwise it is zero -// extended. It is then truncated to fit in the result type's size. For -// example, if v == uint16(0x10F0), then uint32(int8(v)) == 0xFFFFFFF0. The -// conversion always yields a valid value; there is no indication of overflow. -// -// 2. When converting a floating-point number to an integer, the fraction is -// discarded (truncation towards zero). -// -// 3. When converting an integer or floating-point number to a floating-point -// type, or a complex number to another complex type, the result value is -// rounded to the precision specified by the destination type. For instance, -// the value of a variable x of type float32 may be stored using additional -// precision beyond that of an IEEE-754 32-bit number, but float32(x) -// represents the result of rounding x's value to 32-bit precision. Similarly, -// x + 0.1 may use more than 32 bits of precision, but float32(x + 0.1) does -// not. -// -// In all non-constant conversions involving floating-point or complex values, -// if the result type cannot represent the value the conversion succeeds but -// the result value is implementation-dependent. -// -// Conversions to and from a string type -// -// 1. Converting a signed or unsigned integer value to a string type yields a -// string containing the UTF-8 representation of the integer. Values outside -// the range of valid Unicode code points are converted to "\uFFFD". -// -// string('a') // "a" -// string(-1) // "\ufffd" == "\xef\xbf\xbd" -// string(0xf8) // "\u00f8" == "ø" == "\xc3\xb8" -// string(0x65e5) // "\u65e5" == "日" == "\xe6\x97\xa5" -// -// 2. Converting a blob to a string type yields a string whose successive bytes -// are the elements of the blob. -// -// string(b /* []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'} */) // "hellø" -// string(b /* []byte{} */) // "" -// string(b /* []byte(nil) */) // "" -// -// 3. Converting a value of a string type to a blob yields a blob whose -// successive elements are the bytes of the string. -// -// blob("hellø") // []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'} -// blob("") // []byte{} -// -// 4. Converting a value of a bigint type to a string yields a string -// containing the decimal decimal representation of the integer. -// -// string(M9) // "2305843009213693951" -// -// 5. Converting a value of a string type to a bigint yields a bigint value -// containing the integer represented by the string value. A prefix of “0x” or -// “0X” selects base 16; the “0” prefix selects base 8, and a “0b” or “0B” -// prefix selects base 2. Otherwise the value is interpreted in base 10. An -// error occurs if the string value is not in any valid format. -// -// bigint("2305843009213693951") // M9 -// bigint("0x1ffffffffffffffffffffff") // M10 == 2^89-1 -// -// 6. Converting a value of a rational type to a string yields a string -// containing the decimal decimal representation of the rational in the form -// "a/b" (even if b == 1). -// -// string(bigrat(355)/bigrat(113)) // "355/113" -// -// 7. Converting a value of a string type to a bigrat yields a bigrat value -// containing the rational represented by the string value. The string can be -// given as a fraction "a/b" or as a floating-point number optionally followed -// by an exponent. An error occurs if the string value is not in any valid -// format. -// -// bigrat("1.2e-34") -// bigrat("355/113") -// -// 8. Converting a value of a duration type to a string returns a string -// representing the duration in the form "72h3m0.5s". Leading zero units are -// omitted. As a special case, durations less than one second format using a -// smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading -// digit is non-zero. The zero duration formats as 0, with no unit. -// -// string(elapsed) // "1h", for example -// -// 9. Converting a string value to a duration yields a duration represented by -// the string. A duration string is a possibly signed sequence of decimal -// numbers, each with optional fraction and a unit suffix, such as "300ms", -// "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", -// "m", "h". -// -// duration("1m") // http://golang.org/pkg/time/#Minute -// -// 10. Converting a time value to a string returns the time formatted using the -// format string -// -// "2006-01-02 15:04:05.999999999 -0700 MST" -// -// Order of evaluation -// -// When evaluating the operands of an expression or of function calls, -// operations are evaluated in lexical left-to-right order. -// -// For example, in the evaluation of -// -// g(h(), i()+x[j()], c) -// -// the function calls and evaluation of c happen in the order h(), i(), j(), c. -// -// Floating-point operations within a single expression are evaluated according -// to the associativity of the operators. Explicit parentheses affect the -// evaluation by overriding the default associativity. In the expression x + (y -// + z) the addition y + z is performed before adding x. -// -// Statements -// -// Statements control execution. -// -// Statement = EmptyStmt | AlterTableStmt | BeginTransactionStmt | CommitStmt -// | CreateIndexStmt | CreateTableStmt | DeleteFromStmt | DropIndexStmt -// | DropTableStmt | InsertIntoStmt | RollbackStmt | SelectStmt -// | TruncateTableStmt | UpdateStmt | ExplainStmt. -// -// StatementList = Statement { ";" Statement } . -// -// Empty statements -// -// The empty statement does nothing. -// -// EmptyStmt = . -// -// ALTER TABLE -// -// Alter table statements modify existing tables. With the ADD clause it adds -// a new column to the table. The column must not exist. With the DROP clause -// it removes an existing column from a table. The column must exist and it -// must be not the only (last) column of the table. IOW, there cannot be a -// table with no columns. -// -// AlterTableStmt = "ALTER" "TABLE" TableName ( "ADD" ColumnDef | "DROP" "COLUMN" ColumnName ) . -// -// For example -// -// BEGIN TRANSACTION; -// ALTER TABLE Stock ADD Qty int; -// ALTER TABLE Income DROP COLUMN Taxes; -// COMMIT; -// -// When adding a column to a table with existing data, the constraint clause of -// the ColumnDef cannot be used. Adding a constrained column to an empty table -// is fine. -// -// BEGIN TRANSACTION -// -// Begin transactions statements introduce a new transaction level. Every -// transaction level must be eventually balanced by exactly one of COMMIT or -// ROLLBACK statements. Note that when a transaction is roll-backed because of -// a statement failure then no explicit balancing of the respective BEGIN -// TRANSACTION is statement is required nor permitted. -// -// Failure to properly balance any opened transaction level may cause dead -// locks and/or lose of data updated in the uppermost opened but never properly -// closed transaction level. -// -// BeginTransactionStmt = "BEGIN" "TRANSACTION" . -// -// For example -// -// BEGIN TRANSACTION; -// INSERT INTO foo VALUES (42, 3.14); -// INSERT INTO foo VALUES (-1, 2.78); -// COMMIT; -// -// Mandatory transactions -// -// A database cannot be updated (mutated) outside of a transaction. Statements -// requiring a transaction -// -// ALTER TABLE -// COMMIT -// CREATE INDEX -// CREATE TABLE -// DELETE FROM -// DROP INDEX -// DROP TABLE -// INSERT INTO -// ROLLBACK -// TRUNCATE TABLE -// UPDATE -// -// A database is effectively read only outside of a transaction. Statements not -// requiring a transaction -// -// BEGIN TRANSACTION -// SELECT FROM -// -// COMMIT -// -// The commit statement closes the innermost transaction nesting level. If -// that's the outermost level then the updates to the DB made by the -// transaction are atomically made persistent. -// -// CommitStmt = "COMMIT" . -// -// For example -// -// BEGIN TRANSACTION; -// INSERT INTO AccountA (Amount) VALUES ($1); -// INSERT INTO AccountB (Amount) VALUES (-$1); -// COMMIT; -// -// CREATE INDEX -// -// Create index statements create new indices. Index is a named projection of -// ordered values of a table column to the respective records. As a special -// case the id() of the record can be indexed. Index name must not be the same -// as any of the existing tables and it also cannot be the same as of any -// column name of the table the index is on. -// -// CreateIndexStmt = "CREATE" [ "UNIQUE" ] "INDEX" [ "IF" "NOT" "EXISTS" ] -// IndexName "ON" TableName "(" ExpressionList ")" . -// -// For example -// -// BEGIN TRANSACTION; -// CREATE TABLE Orders (CustomerID int, Date time); -// CREATE INDEX OrdersID ON Orders (id()); -// CREATE INDEX OrdersDate ON Orders (Date); -// CREATE TABLE Items (OrderID int, ProductID int, Qty int); -// CREATE INDEX ItemsOrderID ON Items (OrderID); -// COMMIT; -// -// Now certain SELECT statements may use the indices to speed up joins and/or -// to speed up record set filtering when the WHERE clause is used; or the -// indices might be used to improve the performance when the ORDER BY clause is -// present. -// -// The UNIQUE modifier requires the indexed values tuple to be index-wise -// unique or have all values NULL. -// -// The optional IF NOT EXISTS clause makes the statement a no operation if the -// index already exists. -// -// Simple index -// -// A simple index consists of only one expression which must be either a column -// name or the built-in id(). -// -// Expression list index -// -// A more complex and more general index is one that consists of more than one -// expression or its single expression does not qualify as a simple index. In -// this case the type of all expressions in the list must be one of the non -// blob-like types. -// -// Note: Blob-like types are blob, bigint, bigrat, time and duration. -// -// CREATE TABLE -// -// Create table statements create new tables. A column definition declares the -// column name and type. Table names and column names are case sensitive. -// Neither a table or an index of the same name may exist in the DB. -// -// CreateTableStmt = "CREATE" "TABLE" [ "IF" "NOT" "EXISTS" ] TableName -// "(" ColumnDef { "," ColumnDef } [ "," ] ")" . -// -// ColumnDef = ColumnName Type [ "NOT" "NULL" | Expression ] [ "DEFAULT" Expression ] . -// ColumnName = identifier . -// TableName = identifier . -// -// For example -// -// BEGIN TRANSACTION; -// CREATE TABLE department ( -// DepartmentID int, -// DepartmentName string, -// ); -// CREATE TABLE employee ( -// LastName string, -// DepartmentID int, -// ); -// COMMIT; -// -// The optional IF NOT EXISTS clause makes the statement a no operation if the -// table already exists. -// -// The optional constraint clause has two forms. The first one is found in many -// SQL dialects. -// -// BEGIN TRANSACTION; -// CREATE TABLE department ( -// DepartmentID int, -// DepartmentName string NOT NULL, -// ); -// COMMIT; -// -// This form prevents the data in column DepartmentName to be NULL. -// -// The second form allows an arbitrary boolean expression to be used to -// validate the column. If the value of the expression is true then the -// validation succeeded. If the value of the expression is false or NULL then -// the validation fails. If the value of the expression is not of type bool an -// error occurs. -// -// BEGIN TRANSACTION; -// CREATE TABLE department ( -// DepartmentID int, -// DepartmentName string DepartmentName IN ("HQ", "R/D", "Lab", "HR"), -// ); -// COMMIT; -// -// BEGIN TRANSACTION; -// CREATE TABLE t ( -// TimeStamp time TimeStamp < now() && since(TimeStamp) < duration("10s"), -// Event string Event != "" && Event like "[0-9]+:[ \t]+.*", -// ); -// COMMIT; -// -// The optional DEFAULT clause is an expression which, if present, is -// substituted instead of a NULL value when the colum is assigned a value. -// -// BEGIN TRANSACTION; -// CREATE TABLE department ( -// DepartmentID int, -// DepartmentName string DepartmentName IN ("HQ", "R/D", "Lab", "HR") DEFAULT "HQ", -// ); -// COMMIT; -// -// Note that the constraint and/or default expressions may refer to other -// columns by name: -// -// BEGIN TRANSACTION; -// CREATE TABLE t ( -// a int, -// b int b > a && b < c DEFAULT (a+c)/2, -// c int, -// ); -// COMMIT; -// -// -// Constraints and defaults -// -// When a table row is inserted by the INSERT INTO statement or when a table -// row is updated by the UPDATE statement, the order of operations is as -// follows: -// -// 1. The new values of the affected columns are set and the values of all the -// row columns become the named values which can be referred to in default -// expressions evaluated in step 2. -// -// 2. If any row column value is NULL and the DEFAULT clause is present in the -// column's definition, the default expression is evaluated and its value is -// set as the respective column value. -// -// 3. The values, potentially updated, of row columns become the named values -// which can be referred to in constraint expressions evaluated during step 4. -// -// 4. All row columns which definition has the constraint clause present will -// have that constraint checked. If any constraint violation is detected, the -// overall operation fails and no changes to the table are made. -// -// DELETE FROM -// -// Delete from statements remove rows from a table, which must exist. -// -// DeleteFromStmt = "DELETE" "FROM" TableName [ WhereClause ] . -// -// For example -// -// BEGIN TRANSACTION; -// DELETE FROM DepartmentID -// WHERE DepartmentName == "Ponies"; -// COMMIT; -// -// If the WHERE clause is not present then all rows are removed and the -// statement is equivalent to the TRUNCATE TABLE statement. -// -// DROP INDEX -// -// Drop index statements remove indices from the DB. The index must exist. -// -// DropIndexStmt = "DROP" "INDEX" [ "IF" "EXISTS" ] IndexName . -// IndexName = identifier . -// -// For example -// -// BEGIN TRANSACTION; -// DROP INDEX ItemsOrderID; -// COMMIT; -// -// The optional IF EXISTS clause makes the statement a no operation if the -// index does not exist. -// -// DROP TABLE -// -// Drop table statements remove tables from the DB. The table must exist. -// -// DropTableStmt = "DROP" "TABLE" [ "IF" "EXISTS" ] TableName . -// -// For example -// -// BEGIN TRANSACTION; -// DROP TABLE Inventory; -// COMMIT; -// -// The optional IF EXISTS clause makes the statement a no operation if the -// table does not exist. -// -// INSERT INTO -// -// Insert into statements insert new rows into tables. New rows come from -// literal data, if using the VALUES clause, or are a result of select -// statement. In the later case the select statement is fully evaluated before -// the insertion of any rows is performed, allowing to insert values calculated -// from the same table rows are to be inserted into. If the ColumnNameList part -// is omitted then the number of values inserted in the row must be the same as -// are columns in the table. If the ColumnNameList part is present then the -// number of values per row must be same as the same number of column names. -// All other columns of the record are set to NULL. The type of the value -// assigned to a column must be the same as is the column's type or the value -// must be NULL. -// -// InsertIntoStmt = "INSERT" "INTO" TableName [ "(" ColumnNameList ")" ] ( Values | SelectStmt ) . -// -// ColumnNameList = ColumnName { "," ColumnName } [ "," ] . -// Values = "VALUES" "(" ExpressionList ")" { "," "(" ExpressionList ")" } [ "," ] . -// -// For example -// -// BEGIN TRANSACTION; -// INSERT INTO department (DepartmentID) VALUES (42); -// -// INSERT INTO department ( -// DepartmentName, -// DepartmentID, -// ) -// VALUES ( -// "R&D", -// 42, -// ); -// -// INSERT INTO department VALUES -// (42, "R&D"), -// (17, "Sales"), -// ; -// COMMIT; -// -// BEGIN TRANSACTION; -// INSERT INTO department (DepartmentName, DepartmentID) -// SELECT DepartmentName+"/headquarters", DepartmentID+1000 -// FROM department; -// COMMIT; -// -// If any of the columns of the table were defined using the optional -// constraints clause or the optional defaults clause then those are processed -// on a per row basis. The details are discussed in the "Constraints and -// defaults" chapter below the CREATE TABLE statement documentation. -// -// Explain statement -// -// Explain statement produces a recordset consisting of lines of text which -// describe the execution plan of a statement, if any. -// -// ExplainStmt = "EXPLAIN" Statement . -// -// For example, the QL tool treats the explain statement specially and outputs -// the joined lines: -// -// $ ql 'create table t(i int); create table u(j int)' -// $ ql 'explain select * from t, u where t.i > 42 && u.j < 314' -// ┌Compute Cartesian product of -// │ ┌Iterate all rows of table "t" -// │ └Output field names ["i"] -// │ ┌Iterate all rows of table "u" -// │ └Output field names ["j"] -// └Output field names ["t.i" "u.j"] -// ┌Filter on t.i > 42 && u.j < 314 -// │Possibly useful indices -// │CREATE INDEX xt_i ON t(i); -// │CREATE INDEX xu_j ON u(j); -// └Output field names ["t.i" "u.j"] -// $ ql 'CREATE INDEX xt_i ON t(i); CREATE INDEX xu_j ON u(j);' -// $ ql 'explain select * from t, u where t.i > 42 && u.j < 314' -// ┌Compute Cartesian product of -// │ ┌Iterate all rows of table "t" using index "xt_i" where i > 42 -// │ └Output field names ["i"] -// │ ┌Iterate all rows of table "u" using index "xu_j" where j < 314 -// │ └Output field names ["j"] -// └Output field names ["t.i" "u.j"] -// $ ql 'explain select * from t where i > 12 and i between 10 and 20 and i < 42' -// ┌Iterate all rows of table "t" using index "xt_i" where i > 12 && i <= 20 -// └Output field names ["i"] -// $ -// -// The explanation may aid in uderstanding how a statement/query would be -// executed and if indices are used as expected - or which indices may possibly -// improve the statement performance. The create index statements above were -// directly copy/pasted in the terminal from the suggestions provided by the -// filter recordset pipeline part returned by the explain statement. -// -// If the statement has nothing special in its plan, the result is the original -// statement. -// -// $ ql 'explain delete from t where 42 < i' -// DELETE FROM t WHERE i > 42; -// $ -// -// To get an explanation of the select statement of the IN predicate, use the EXPLAIN -// statement with that particular select statement. -// -// $ ql 'explain select * from t where i in (select j from u where j > 0)' -// ┌Iterate all rows of table "t" -// └Output field names ["i"] -// ┌Filter on i IN (SELECT j FROM u WHERE j > 0;) -// └Output field names ["i"] -// $ ql 'explain select j from u where j > 0' -// ┌Iterate all rows of table "u" using index "xu_j" where j > 0 -// └Output field names ["j"] -// $ -// -// ROLLBACK -// -// The rollback statement closes the innermost transaction nesting level -// discarding any updates to the DB made by it. If that's the outermost level -// then the effects on the DB are as if the transaction never happened. -// -// RollbackStmt = "ROLLBACK" . -// -// For example -// -// // First statement list -// BEGIN TRANSACTION -// SELECT * INTO tmp FROM foo; -// INSERT INTO tmp SELECT * from bar; -// SELECT * from tmp; -// -// The (temporary) record set from the last statement is returned and can be -// processed by the client. -// -// // Second statement list -// ROLLBACK; -// -// In this case the rollback is the same as 'DROP TABLE tmp;' but it can be a -// more complex operation. -// -// SELECT FROM -// -// Select from statements produce recordsets. The optional DISTINCT modifier -// ensures all rows in the result recordset are unique. Either all of the -// resulting fields are returned ('*') or only those named in FieldList. -// -// RecordSetList is a list of table names or parenthesized select statements, -// optionally (re)named using the AS clause. -// -// The result can be filtered using a WhereClause and orderd by the OrderBy -// clause. -// -// SelectStmt = "SELECT" [ "DISTINCT" ] ( "*" | FieldList ) [ "FROM" RecordSetList ] -// [ JoinClause ] [ WhereClause ] [ GroupByClause ] [ OrderBy ] [ Limit ] [ Offset ]. -// -// JoinClause = ( "LEFT" | "RIGHT" | "FULL" ) [ "OUTER" ] "JOIN" RecordSet "ON" Expression . -// -// RecordSet = ( TableName | "(" SelectStmt [ ";" ] ")" ) [ "AS" identifier ] . -// RecordSetList = RecordSet { "," RecordSet } [ "," ] . -// -// For example -// -// SELECT * FROM Stock; -// -// SELECT DepartmentID -// FROM department -// WHERE DepartmentID == 42 -// ORDER BY DepartmentName; -// -// SELECT employee.LastName -// FROM department, employee -// WHERE department.DepartmentID == employee.DepartmentID -// ORDER BY DepartmentID; -// -// If Recordset is a nested, parenthesized SelectStmt then it must be given a -// name using the AS clause if its field are to be accessible in expressions. -// -// SELECT a.b, c.d -// FROM -// x AS a, -// ( -// SELECT * FROM y; -// ) AS c -// WHERE a.e > c.e; -// -// Fields naming rules -// -// A field is an named expression. Identifiers, not used as a type in -// conversion or a function name in the Call clause, denote names of (other) -// fields, values of which should be used in the expression. -// -// Field = Expression [ "AS" identifier ] . -// -// The expression can be named using the AS clause. If the AS clause is not -// present and the expression consists solely of a field name, then that field -// name is used as the name of the resulting field. Otherwise the field is -// unnamed. -// -// For example -// -// SELECT 314, 42 as AUQLUE, DepartmentID, DepartmentID+1000, LastName as Name from employee; -// // Fields are []string{"", "AUQLUE", "DepartmentID", "", "Name"} -// -// The SELECT statement can optionally enumerate the desired/resulting fields -// in a list. -// -// FieldList = Field { "," Field } [ "," ] . -// -// No two identical field names can appear in the list. -// -// SELECT DepartmentID, LastName, DepartmentID from employee; -// // duplicate field name "DepartmentID" -// -// SELECT DepartmentID, LastName, DepartmentID as ID2 from employee; -// // works -// -// When more than one record set is used in the FROM clause record set list, -// the result record set field names are rewritten to be qualified using -// the record set names. -// -// SELECT * FROM employee, department; -// // Fields are []string{"employee.LastName", "employee.DepartmentID", "department.DepartmentID", "department.DepartmentName" -// -// If a particular record set doesn't have a name, its respective fields became -// unnamed. -// -// SELECT * FROM employee as e, ( SELECT * FROM department); -// // Fields are []string{"e.LastName", "e.DepartmentID", "", "" -// -// SELECT * FROM employee AS e, ( SELECT * FROM department) AS d; -// // Fields are []string{"e.LastName", "e.DepartmentID", "d.DepartmentID", "d.DepartmentName" -// -// Outer joins -// -// The optional JOIN clause, for example -// -// SELECT * -// FROM a -// LEFT OUTER JOIN b ON expr; -// -// is mostly equal to -// -// SELECT * -// FROM a, b -// WHERE expr; -// -// except that the rows from a which, when they appear in the cross join, never -// made expr to evaluate to true, are combined with a virtual row from b, -// containing all nulls, and added to the result set. For the RIGHT JOIN -// variant the discussed rules are used for rows from b not satisfying expr == -// true and the virtual, all-null row "comes" from a. The FULL JOIN adds the -// respective rows which would be otherwise provided by the separate executions -// of the LEFT JOIN and RIGHT JOIN variants. For more thorough OUTER JOIN -// discussion please see the Wikipedia article at [10]. -// -// Recordset ordering -// -// Resultins rows of a SELECT statement can be optionally ordered by the ORDER -// BY clause. Collating proceeds by considering the expressions in the -// expression list left to right until a collating order is determined. Any -// possibly remaining expressions are not evaluated. -// -// OrderBy = "ORDER" "BY" ExpressionList [ "ASC" | "DESC" ] . -// -// All of the expression values must yield an ordered type or NULL. Ordered -// types are defined in "Comparison operators". Collating of elements having a -// NULL value is different compared to what the comparison operators yield in -// expression evaluation (NULL result instead of a boolean value). -// -// Below, T denotes a non NULL value of any QL type. -// -// NULL < T -// -// NULL collates before any non NULL value (is considered smaller than T). -// -// NULL == NULL -// -// Two NULLs have no collating order (are considered equal). -// -// Recordset filtering -// -// The WHERE clause restricts records considered by some statements, like -// SELECT FROM, DELETE FROM, or UPDATE. -// -// expression value consider the record -// ---------------- ------------------- -// true yes -// false or NULL no -// -// It is an error if the expression evaluates to a non null value of non bool -// type. -// -// Another form of the WHERE clause is an existence predicate of a -// parenthesized select statement. The EXISTS form evaluates to true if the -// parenthesized SELECT statement produces a non empty record set. The NOT -// EXISTS form evaluates to true if the parenthesized SELECT statement produces -// an empty record set. The parenthesized SELECT statement is evaluated only -// once (TODO issue #159). -// -// WhereClause = "WHERE" Expression -// | "WHERE" "EXISTS" "(" SelectStmt ")" -// | "WHERE" "NOT" "EXISTS" "(" SelectStmt ")" . -// -// Recordset grouping -// -// The GROUP BY clause is used to project rows having common values into a -// smaller set of rows. -// -// For example -// -// SELECT Country, sum(Qty) FROM Sales GROUP BY Country; -// -// SELECT Country, Product FROM Sales GROUP BY Country, Product; -// -// SELECT DISTINCT Country, Product FROM Sales; -// -// Using the GROUP BY without any aggregate functions in the selected fields is -// in certain cases equal to using the DISTINCT modifier. The last two examples -// above produce the same resultsets. -// -// GroupByClause = "GROUP BY" ColumnNameList . -// -// Skipping records -// -// The optional OFFSET clause allows to ignore first N records. For example -// -// SELECT * FROM t OFFSET 10; -// -// The above will produce only rows 11, 12, ... of the record set, if they -// exist. The value of the expression must a non negative integer, but not -// bigint or duration. -// -// Offset = "OFFSET" Expression . -// -// Limiting the result set size -// -// The optional LIMIT clause allows to ignore all but first N records. For -// example -// -// SELECT * FROM t LIMIT 10; -// -// The above will return at most the first 10 records of the record set. The -// value of the expression must a non negative integer, but not bigint or -// duration. -// -// Limit = "Limit" Expression . -// -// The LIMIT and OFFSET clauses can be combined. For example -// -// SELECT * FROM t LIMIT 5 OFFSET 3; -// -// Considering table t has, say 10 records, the above will produce only records -// 4 - 8. -// -// #1: Ignore 1/3 -// #2: Ignore 2/3 -// #3: Ignore 3/3 -// #4: Return 1/5 -// #5: Return 2/5 -// #6: Return 3/5 -// #7: Return 4/5 -// #8: Return 5/5 -// -// After returning record #8, no more result rows/records are computed. -// -// Select statement evaluation order -// -// 1. The FROM clause is evaluated, producing a Cartesian product of its source -// record sets (tables or nested SELECT statements). -// -// 2. If present, the JOIN cluase is evaluated on the result set of the -// previous evaluation and the recordset specified by the JOIN clause. (... -// JOIN Recordset ON ...) -// -// 3. If present, the WHERE clause is evaluated on the result set of the -// previous evaluation. -// -// 4. If present, the GROUP BY clause is evaluated on the result set of the -// previous evaluation(s). -// -// 5. The SELECT field expressions are evaluated on the result set of the -// previous evaluation(s). -// -// 6. If present, the DISTINCT modifier is evaluated on the result set of the -// previous evaluation(s). -// -// 7. If present, the ORDER BY clause is evaluated on the result set of the -// previous evaluation(s). -// -// 8. If present, the OFFSET clause is evaluated on the result set of the -// previous evaluation(s). The offset expression is evaluated once for the -// first record produced by the previous evaluations. -// -// 9. If present, the LIMIT clause is evaluated on the result set of the -// previous evaluation(s). The limit expression is evaluated once for the first -// record produced by the previous evaluations. -// -// -// TRUNCATE TABLE -// -// Truncate table statements remove all records from a table. The table must -// exist. -// -// TruncateTableStmt = "TRUNCATE" "TABLE" TableName . -// -// For example -// -// BEGIN TRANSACTION -// TRUNCATE TABLE department; -// COMMIT; -// -// UPDATE -// -// Update statements change values of fields in rows of a table. -// -// UpdateStmt = "UPDATE" TableName [ "SET" ] AssignmentList [ WhereClause ] . -// -// AssignmentList = Assignment { "," Assignment } [ "," ] . -// Assignment = ColumnName "=" Expression . -// -// For example -// -// BEGIN TRANSACTION -// UPDATE department -// DepartmentName = DepartmentName + " dpt.", -// DepartmentID = 1000+DepartmentID, -// WHERE DepartmentID < 1000; -// COMMIT; -// -// Note: The SET clause is optional. -// -// If any of the columns of the table were defined using the optional -// constraints clause or the optional defaults clause then those are processed -// on a per row basis. The details are discussed in the "Constraints and -// defaults" chapter below the CREATE TABLE statement documentation. -// -// System Tables -// -// To allow to query for DB meta data, there exist specially named tables, some -// of them being virtual. -// -// Note: Virtual system tables may have fake table-wise unique but meaningless -// and unstable record IDs. Do not apply the built-in id() to any system table. -// -// Tables Table -// -// The table __Table lists all tables in the DB. The schema is -// -// CREATE TABLE __Table (Name string, Schema string); -// -// The Schema column returns the statement to (re)create table Name. This table -// is virtual. -// -// Columns Table -// -// The table __Colum lists all columns of all tables in the DB. The schema is -// -// CREATE TABLE __Column (TableName string, Ordinal int, Name string, Type string); -// -// The Ordinal column defines the 1-based index of the column in the record. -// This table is virtual. -// -// Columns2 Table -// -// The table __Colum2 lists all columns of all tables in the DB which have the -// constraint NOT NULL or which have a constraint expression defined or which -// have a default expression defined. The schema is -// -// CREATE TABLE __Column2 (TableName string, Name string, NotNull bool, ConstraintExpr string, DefaultExpr string) -// -// It's possible to obtain a consolidated recordset for all properties of all -// DB columns using -// -// SELECT -// __Column.TableName, __Column.Ordinal, __Column.Name, __Column.Type, -// __Column2.NotNull, __Column2.ConstraintExpr, __Column2.DefaultExpr, -// FROM __Column -// LEFT JOIN __Column2 -// ON __Column.TableName == __Column2.TableName && __Column.Name == __Column2.Name -// ORDER BY __Column.TableName, __Column.Ordinal; -// -// The Name column is the column name in TableName. -// -// Indices table -// -// The table __Index lists all indices in the DB. The schema is -// -// CREATE TABLE __Index (TableName string, ColumnName string, Name string, IsUnique bool); -// -// The IsUnique columns reflects if the index was created using the optional -// UNIQUE clause. This table is virtual. -// -// Built-in functions -// -// Built-in functions are predeclared. -// -// Average -// -// The built-in aggregate function avg returns the average of values of an -// expression. Avg ignores NULL values, but returns NULL if all values of a -// column are NULL or if avg is applied to an empty record set. -// -// func avg(e numeric) typeof(e) -// -// The column values must be of a numeric type. -// -// SELECT salesperson, avg(sales) FROM salesforce GROUP BY salesperson; -// -// Contains -// -// The built-in function contains returns true if substr is within s. -// -// func contains(s, substr string) bool -// -// If any argument to contains is NULL the result is NULL. -// -// Count -// -// The built-in aggregate function count returns how many times an expression -// has a non NULL values or the number of rows in a record set. Note: count() -// returns 0 for an empty record set. -// -// func count() int // The number of rows in a record set. -// func count(*) int // Equivalent to count(). -// func count(e expression) int // The number of cases where the expression value is not NULL. -// -// For example -// -// SELECT count() FROM department; // # of rows -// -// SELECT count(*) FROM department; // # of rows -// -// SELECT count(DepartmentID) FROM department; // # of records with non NULL field DepartmentID -// -// SELECT count()-count(DepartmentID) FROM department; // # of records with NULL field DepartmentID -// -// SELECT count(foo+bar*3) AS y FROM t; // # of cases where 'foo+bar*3' is non NULL -// -// Date -// -// Date returns the time corresponding to -// -// yyyy-mm-dd hh:mm:ss + nsec nanoseconds -// -// in the appropriate zone for that time in the given location. -// -// The month, day, hour, min, sec, and nsec values may be outside their usual -// ranges and will be normalized during the conversion. For example, October 32 -// converts to November 1. -// -// A daylight savings time transition skips or repeats times. For example, in -// the United States, March 13, 2011 2:15am never occurred, while November 6, -// 2011 1:15am occurred twice. In such cases, the choice of time zone, and -// therefore the time, is not well-defined. Date returns a time that is correct -// in one of the two zones involved in the transition, but it does not -// guarantee which. -// -// func date(year, month, day, hour, min, sec, nsec int, loc string) time -// -// A location maps time instants to the zone in use at that time. Typically, -// the location represents the collection of time offsets in use in a -// geographical area, such as "CEST" and "CET" for central Europe. "local" -// represents the system's local time zone. "UTC" represents Universal -// Coordinated Time (UTC). -// -// The month specifies a month of the year (January = 1, ...). -// -// If any argument to date is NULL the result is NULL. -// -// Day -// -// The built-in function day returns the day of the month specified by t. -// -// func day(t time) int -// -// If the argument to day is NULL the result is NULL. -// -// Format time -// -// The built-in function formatTime returns a textual representation of the -// time value formatted according to layout, which defines the format by -// showing how the reference time, -// -// Mon Jan 2 15:04:05 -0700 MST 2006 -// -// would be displayed if it were the value; it serves as an example of the -// desired output. The same display rules will then be applied to the time -// value. -// -// func formatTime(t time, layout string) string -// -// If any argument to formatTime is NULL the result is NULL. -// -// NOTE: The string value of the time zone, like "CET" or "ACDT", is dependent -// on the time zone of the machine the function is run on. For example, if the -// t value is in "CET", but the machine is in "ACDT", instead of "CET" the -// result is "+0100". This is the same what Go (time.Time).String() returns and -// in fact formatTime directly calls t.String(). -// -// formatTime(date(2006, 1, 2, 15, 4, 5, 999999999, "CET")) -// -// returns -// -// 2006-01-02 15:04:05.999999999 +0100 CET -// -// on a machine in the CET time zone, but may return -// -// 2006-01-02 15:04:05.999999999 +0100 +0100 -// -// on a machine in the ACDT zone. The time value is in both cases the same so -// its ordering and comparing is correct. Only the display value can differ. -// -// Format numbers -// -// The built-in functions formatFloat and formatInt format numbers -// to strings using go's number format functions in the `strconv` package. For -// all three functions, only the first argument is mandatory. The default values -// of the rest are shown in the examples. If the first argument is NULL, the -// result is NULL. -// -// formatFloat(43.2[, 'g', -1, 64]) string -// -// returns -// -// "43.2" -// -// formatInt(-42[, 10]) string -// -// returns -// -// "-42" -// -// formatInt(uint32(42)[, 10]) string -// -// returns -// -// "42" -// -// Unlike the `strconv` equivalent, the formatInt function handles all integer -// types, both signed and unsigned. -// -// HasPrefix -// -// The built-in function hasPrefix tests whether the string s begins with prefix. -// -// func hasPrefix(s, prefix string) bool -// -// If any argument to hasPrefix is NULL the result is NULL. -// -// HasSuffix -// -// The built-in function hasSuffix tests whether the string s ends with suffix. -// -// func hasSuffix(s, suffix string) bool -// -// If any argument to hasSuffix is NULL the result is NULL. -// -// Hour -// -// The built-in function hour returns the hour within the day specified by t, -// in the range [0, 23]. -// -// func hour(t time) int -// -// If the argument to hour is NULL the result is NULL. -// -// Hours -// -// The built-in function hours returns the duration as a floating point number -// of hours. -// -// func hours(d duration) float -// -// If the argument to hours is NULL the result is NULL. -// -// Record id -// -// The built-in function id takes zero or one arguments. If no argument is -// provided, id() returns a table-unique automatically assigned numeric -// identifier of type int. Ids of deleted records are not reused unless the DB -// becomes completely empty (has no tables). -// -// func id() int -// -// For example -// -// SELECT id(), LastName -// FROM employee; -// -// If id() without arguments is called for a row which is not a table record -// then the result value is NULL. -// -// For example -// -// SELECT id(), e.LastName, e.DepartmentID, d.DepartmentID -// FROM -// employee AS e, -// department AS d, -// WHERE e.DepartmentID == d.DepartmentID; -// // Will always return NULL in first field. -// -// SELECT e.ID, e.LastName, e.DepartmentID, d.DepartmentID -// FROM -// (SELECT id() AS ID, LastName, DepartmentID FROM employee) AS e, -// department as d, -// WHERE e.DepartmentID == d.DepartmentID; -// // Will work. -// -// If id() has one argument it must be a table name of a table in a cross join. -// -// For example -// -// SELECT * -// FROM foo, bar -// WHERE bar.fooID == id(foo) -// ORDER BY id(foo); -// -// Length -// -// The built-in function len takes a string argument and returns the lentgh of -// the string in bytes. -// -// func len(s string) int -// -// The expression len(s) is constant if s is a string constant. -// -// If the argument to len is NULL the result is NULL. -// -// Maximum -// -// The built-in aggregate function max returns the largest value of an -// expression in a record set. Max ignores NULL values, but returns NULL if -// all values of a column are NULL or if max is applied to an empty record set. -// -// func max(e expression) typeof(e) // The largest value of the expression. -// -// The expression values must be of an ordered type. -// -// For example -// -// SELECT department, max(sales) FROM t GROUP BY department; -// -// Minimum -// -// The built-in aggregate function min returns the smallest value of an -// expression in a record set. Min ignores NULL values, but returns NULL if -// all values of a column are NULL or if min is applied to an empty record set. -// -// func min(e expression) typeof(e) // The smallest value of the expression. -// -// For example -// -// SELECT a, min(b) FROM t GROUP BY a; -// -// The column values must be of an ordered type. -// -// Minute -// -// The built-in function minute returns the minute offset within the hour -// specified by t, in the range [0, 59]. -// -// func minute(t time) int -// -// If the argument to minute is NULL the result is NULL. -// -// Minutes -// -// The built-in function minutes returns the duration as a floating point -// number of minutes. -// -// func minutes(d duration) float -// -// If the argument to minutes is NULL the result is NULL. -// -// Month -// -// The built-in function month returns the month of the year specified by t -// (January = 1, ...). -// -// func month(t time) int -// -// If the argument to month is NULL the result is NULL. -// -// Nanosecond -// -// The built-in function nanosecond returns the nanosecond offset within the -// second specified by t, in the range [0, 999999999]. -// -// func nanosecond(t time) int -// -// If the argument to nanosecond is NULL the result is NULL. -// -// Nanoseconds -// -// The built-in function nanoseconds returns the duration as an integer -// nanosecond count. -// -// func nanoseconds(d duration) float -// -// If the argument to nanoseconds is NULL the result is NULL. -// -// Now -// -// The built-in function now returns the current local time. -// -// func now() time -// -// Parse time -// -// The built-in function parseTime parses a formatted string and returns the -// time value it represents. The layout defines the format by showing how the -// reference time, -// -// Mon Jan 2 15:04:05 -0700 MST 2006 -// -// would be interpreted if it were the value; it serves as an example of the -// input format. The same interpretation will then be made to the input string. -// -// Elements omitted from the value are assumed to be zero or, when zero is -// impossible, one, so parsing "3:04pm" returns the time corresponding to Jan -// 1, year 0, 15:04:00 UTC (note that because the year is 0, this time is -// before the zero Time). Years must be in the range 0000..9999. The day of the -// week is checked for syntax but it is otherwise ignored. -// -// In the absence of a time zone indicator, parseTime returns a time in UTC. -// -// When parsing a time with a zone offset like -0700, if the offset corresponds -// to a time zone used by the current location, then parseTime uses that -// location and zone in the returned time. Otherwise it records the time as -// being in a fabricated location with time fixed at the given zone offset. -// -// When parsing a time with a zone abbreviation like MST, if the zone -// abbreviation has a defined offset in the current location, then that offset -// is used. The zone abbreviation "UTC" is recognized as UTC regardless of -// location. If the zone abbreviation is unknown, Parse records the time as -// being in a fabricated location with the given zone abbreviation and a zero -// offset. This choice means that such a time can be parses and reformatted -// with the same layout losslessly, but the exact instant used in the -// representation will differ by the actual zone offset. To avoid such -// problems, prefer time layouts that use a numeric zone offset. -// -// func parseTime(layout, value string) time -// -// If any argument to parseTime is NULL the result is NULL. -// -// Second -// -// The built-in function second returns the second offset within the minute -// specified by t, in the range [0, 59]. -// -// func second(t time) int -// -// If the argument to second is NULL the result is NULL. -// -// Seconds -// -// The built-in function seconds returns the duration as a floating point -// number of seconds. -// -// func seconds(d duration) float -// -// If the argument to seconds is NULL the result is NULL. -// -// Since -// -// The built-in function since returns the time elapsed since t. It is -// shorthand for now()-t. -// -// func since(t time) duration -// -// If the argument to since is NULL the result is NULL. -// -// Sum -// -// The built-in aggregate function sum returns the sum of values of an -// expression for all rows of a record set. Sum ignores NULL values, but -// returns NULL if all values of a column are NULL or if sum is applied to an -// empty record set. -// -// func sum(e expression) typeof(e) // The sum of the values of the expression. -// -// The column values must be of a numeric type. -// -// SELECT salesperson, sum(sales) FROM salesforce GROUP BY salesperson; -// -// Time in a specific zone -// -// The built-in function timeIn returns t with the location information set to -// loc. For discussion of the loc argument please see date(). -// -// func timeIn(t time, loc string) time -// -// If any argument to timeIn is NULL the result is NULL. -// -// Weekday -// -// The built-in function weekday returns the day of the week specified by t. -// Sunday == 0, Monday == 1, ... -// -// func weekday(t time) int -// -// If the argument to weekday is NULL the result is NULL. -// -// Year -// -// The built-in function year returns the year in which t occurs. -// -// func year(t time) int -// -// If the argument to year is NULL the result is NULL. -// -// Year day -// -// The built-in function yearDay returns the day of the year specified by t, in -// the range [1,365] for non-leap years, and [1,366] in leap years. -// -// func yearDay(t time) int -// -// If the argument to yearDay is NULL the result is NULL. -// -// Manipulating complex numbers -// -// Three functions assemble and disassemble complex numbers. The built-in -// function complex constructs a complex value from a floating-point real and -// imaginary part, while real and imag extract the real and imaginary parts of -// a complex value. -// -// complex(realPart, imaginaryPart floatT) complexT -// real(complexT) floatT -// imag(complexT) floatT -// -// The type of the arguments and return value correspond. For complex, the two -// arguments must be of the same floating-point type and the return type is the -// complex type with the corresponding floating-point constituents: complex64 -// for float32, complex128 for float64. The real and imag functions together -// form the inverse, so for a complex value z, z == complex(real(z), imag(z)). -// -// If the operands of these functions are all constants, the return value is a -// constant. -// -// complex(2, -2) // complex128 -// complex(1.0, -1.4) // complex128 -// float32(math.Cos(math.Pi/2)) // float32 -// complex(5, float32(-x)) // complex64 -// imag(b) // float64 -// real(complex(5, float32(-x))) // float32 -// -// If any argument to any of complex, real, imag functions is NULL the result -// is NULL. -// -// Size guarantees -// -// For the numeric types, the following sizes are guaranteed -// -// type size in bytes -// -// byte, uint8, int8 1 -// uint16, int16 2 -// uint32, int32, float32 4 -// uint, uint64, int, int64, float64, complex64 8 -// complex128 16 -// -// License -// -// Portions of this specification page are modifications based on work[2] -// created and shared by Google[3] and used according to terms described in the -// Creative Commons 3.0 Attribution License[4]. -// -// This specification is licensed under the Creative Commons Attribution 3.0 -// License, and code is licensed under a BSD license[5]. -// -// References -// -// Links from the above documentation -// -// [1]: http://golang.org/ref/spec#Notation -// [2]: http://golang.org/ref/spec -// [3]: http://code.google.com/policies.html -// [4]: http://creativecommons.org/licenses/by/3.0/ -// [5]: http://golang.org/LICENSE -// [6]: http://golang.org/pkg/regexp/#Regexp.MatchString -// [7]: http://developer.mimer.com/validator/sql-reserved-words.tml -// [8]: http://godoc.org/github.com/cznic/zappy -// [9]: http://www.w3schools.com/sql/sql_default.asp -// [10]: http://en.wikipedia.org/wiki/Join_(SQL)#Outer_join -// -// Implementation details -// -// This section is not part of the specification. -// -// Indices -// -// WARNING: The implementation of indices is new and it surely needs more time -// to become mature. -// -// Indices are used currently used only by the WHERE clause. The following -// expression patterns of 'WHERE expression' are recognized and trigger index -// use. -// -// - WHERE c // For bool typed indexed column c -// - WHERE !c // For bool typed indexed column c -// - WHERE c relOp constExpr // For indexed column c -// - WHERE c relOp parameter // For indexed column c -// - WHERE parameter relOp c // For indexed column c -// - WHERE constExpr relOp c // For indexed column c -// -// The relOp is one of the relation operators <, <=, ==, >=, >. For the -// equality operator both operands must be of comparable types. For all other -// operators both operands must be of ordered types. The constant expression is -// a compile time constant expression. Some constant folding is still a TODO. -// Parameter is a QL parameter ($1 etc.). -// -// Query rewriting -// -// Consider tables t and u, both with an indexed field f. The WHERE expression -// doesn't comply with the above simple detected cases. -// -// SELECT * FROM t, u WHERE t.f < x && u.f < y; -// -// However, such query is now automatically rewritten to -// -// SELECT * FROM -// (SELECT * FROM t WHERE f < x), -// (SELECT * FROM u WHERE f < y); -// -// which will use both of the indices. The impact of using the indices can be -// substantial (cf. BenchmarkCrossJoin*) if the resulting rows have low -// "selectivity", ie. only few rows from both tables are selected by the -// respective WHERE filtering. -// -// Note: Existing QL DBs can be used and indices can be added to them. However, -// once any indices are present in the DB, the old QL versions cannot work with -// such DB anymore. -// -// Benchmarks -// -// Running a benchmark with -v (-test.v) outputs information about the scale -// used to report records/s and a brief description of the benchmark. For -// example -// -// $ go test -run NONE -bench 'SelectMem.*1e[23]' -v -// PASS -// BenchmarkSelectMem1kBx1e2 50000 67680 ns/op 1477537.05 MB/s -// --- BENCH: BenchmarkSelectMem1kBx1e2 -// all_test.go:310: -// ============================================================= -// NOTE: All benchmarks report records/s as 1000000 bytes/s. -// ============================================================= -// all_test.go:321: Having a table of 100 records, each of size 1kB, measure the performance of -// SELECT * FROM t; -// -// BenchmarkSelectMem1kBx1e3 5000 634819 ns/op 1575251.01 MB/s -// --- BENCH: BenchmarkSelectMem1kBx1e3 -// all_test.go:321: Having a table of 1000 records, each of size 1kB, measure the performance of -// SELECT * FROM t; -// -// ok github.com/cznic/ql 7.496s -// $ -// -// Running the full suite of benchmarks takes a lot of time. Use the -timeout -// flag to avoid them being killed after the default time limit (10 minutes). -package ql diff --git a/vendor/github.com/cznic/ql/driver.go b/vendor/github.com/cznic/ql/driver.go deleted file mode 100644 index 02518313f..000000000 --- a/vendor/github.com/cznic/ql/driver.go +++ /dev/null @@ -1,593 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// database/sql/driver - -package ql - -import ( - "bytes" - "database/sql" - "database/sql/driver" - "errors" - "fmt" - "io" - "math/big" - "net/url" - "os" - "path/filepath" - "strconv" - "strings" - "sync" - "time" -) - -var ( - _ driver.Conn = (*driverConn)(nil) - _ driver.Driver = (*sqlDriver)(nil) - _ driver.Execer = (*driverConn)(nil) - _ driver.Queryer = (*driverConn)(nil) - _ driver.Result = (*driverResult)(nil) - _ driver.Rows = (*driverRows)(nil) - _ driver.Stmt = (*driverStmt)(nil) - _ driver.Tx = (*driverConn)(nil) - - txBegin = MustCompile("BEGIN TRANSACTION;") - txCommit = MustCompile("COMMIT;") - txRollback = MustCompile("ROLLBACK;") - - errNoResult = errors.New("query statement does not produce a result set (no top level SELECT)") -) - -type errList []error - -func (e *errList) append(err error) { - if err != nil { - *e = append(*e, err) - } -} - -func (e errList) error() error { - if len(e) == 0 { - return nil - } - - return e -} - -func (e errList) Error() string { - a := make([]string, len(e)) - for i, v := range e { - a[i] = v.Error() - } - return strings.Join(a, "\n") -} - -func params(args []driver.Value) []interface{} { - r := make([]interface{}, len(args)) - for i, v := range args { - r[i] = interface{}(v) - } - return r -} - -var ( - fileDriver = &sqlDriver{dbs: map[string]*driverDB{}} - fileDriverOnce sync.Once - memDriver = &sqlDriver{isMem: true, dbs: map[string]*driverDB{}} - memDriverOnce sync.Once -) - -// RegisterDriver registers a QL database/sql/driver[0] named "ql". The name -// parameter of -// -// sql.Open("ql", name) -// -// is interpreted as a path name to a named DB file which will be created if -// not present. The underlying QL database data are persisted on db.Close(). -// RegisterDriver can be safely called multiple times, it'll register the -// driver only once. -// -// The name argument can be optionally prefixed by "file://". In that case the -// prefix is stripped before interpreting it as a file name. -// -// The name argument can be optionally prefixed by "memory://". In that case -// the prefix is stripped before interpreting it as a name of a memory-only, -// volatile DB. -// -// [0]: http://golang.org/pkg/database/sql/driver/ -func RegisterDriver() { - fileDriverOnce.Do(func() { sql.Register("ql", fileDriver) }) -} - -// RegisterMemDriver registers a QL memory database/sql/driver[0] named -// "ql-mem". The name parameter of -// -// sql.Open("ql-mem", name) -// -// is interpreted as an unique memory DB name which will be created if not -// present. The underlying QL memory database data are not persisted on -// db.Close(). RegisterMemDriver can be safely called multiple times, it'll -// register the driver only once. -// -// [0]: http://golang.org/pkg/database/sql/driver/ -func RegisterMemDriver() { - memDriverOnce.Do(func() { sql.Register("ql-mem", memDriver) }) -} - -type driverDB struct { - db *DB - name string - refcount int -} - -func newDriverDB(db *DB, name string) *driverDB { - return &driverDB{db: db, name: name, refcount: 1} -} - -// sqlDriver implements the interface required by database/sql/driver. -type sqlDriver struct { - dbs map[string]*driverDB - isMem bool - mu sync.Mutex -} - -func (d *sqlDriver) lock() func() { - d.mu.Lock() - return d.mu.Unlock -} - -// Open returns a new connection to the database. The name is a string in a -// driver-specific format. -// -// Open may return a cached connection (one previously closed), but doing so is -// unnecessary; the sql package maintains a pool of idle connections for -// efficient re-use. -// -// The returned connection is only used by one goroutine at a time. -// -// The name supported URL parameters: -// -// headroom Size of the WAL headroom. See https://github.com/cznic/ql/issues/140. -func (d *sqlDriver) Open(name string) (driver.Conn, error) { - switch { - case d == fileDriver: - if !strings.Contains(name, "://") && !strings.HasPrefix(name, "file") { - name = "file://" + name - } - case d == memDriver: - if !strings.Contains(name, "://") && !strings.HasPrefix(name, "memory") { - name = "memory://" + name - } - default: - return nil, fmt.Errorf("open: unexpected/unsupported instance of driver.Driver: %p", d) - } - - name = filepath.ToSlash(name) // Ensure / separated URLs on Windows - uri, err := url.Parse(name) - if err != nil { - return nil, err - } - - switch uri.Scheme { - case "file": - // ok - case "memory": - d = memDriver - default: - return nil, fmt.Errorf("open: unexpected/unsupported scheme: %s", uri.Scheme) - } - - name = filepath.Clean(filepath.Join(uri.Host, uri.Path)) - if d == fileDriver && (name == "" || name == "." || name == string(os.PathSeparator)) { - return nil, fmt.Errorf("invalid DB name %q", name) - } - - var headroom int64 - if a := uri.Query()["headroom"]; len(a) != 0 { - if headroom, err = strconv.ParseInt(a[0], 10, 64); err != nil { - return nil, err - } - } - - defer d.lock()() - db := d.dbs[name] - if db == nil { - var err error - var db0 *DB - switch d.isMem { - case true: - db0, err = OpenMem() - default: - db0, err = OpenFile(name, &Options{CanCreate: true, Headroom: headroom}) - } - if err != nil { - return nil, err - } - - db = newDriverDB(db0, name) - d.dbs[name] = db - return newDriverConn(d, db), nil - } - - db.refcount++ - return newDriverConn(d, db), nil -} - -// driverConn is a connection to a database. It is not used concurrently by -// multiple goroutines. -// -// Conn is assumed to be stateful. -type driverConn struct { - ctx *TCtx - db *driverDB - driver *sqlDriver - stop map[*driverStmt]struct{} - tnl int -} - -func newDriverConn(d *sqlDriver, ddb *driverDB) driver.Conn { - r := &driverConn{ - db: ddb, - driver: d, - stop: map[*driverStmt]struct{}{}, - } - return r -} - -// Prepare returns a prepared statement, bound to this connection. -func (c *driverConn) Prepare(query string) (driver.Stmt, error) { - list, err := Compile(query) - if err != nil { - return nil, err - } - - s := &driverStmt{conn: c, stmt: list} - c.stop[s] = struct{}{} - return s, nil -} - -// Close invalidates and potentially stops any current prepared statements and -// transactions, marking this connection as no longer in use. -// -// Because the sql package maintains a free pool of connections and only calls -// Close when there's a surplus of idle connections, it shouldn't be necessary -// for drivers to do their own connection caching. -func (c *driverConn) Close() error { - var err errList - for s := range c.stop { - err.append(s.Close()) - } - defer c.driver.lock()() - dbs, name := c.driver.dbs, c.db.name - v := dbs[name] - v.refcount-- - if v.refcount == 0 { - err.append(c.db.db.Close()) - delete(dbs, name) - } - return err.error() -} - -// Begin starts and returns a new transaction. -func (c *driverConn) Begin() (driver.Tx, error) { - if c.ctx == nil { - c.ctx = NewRWCtx() - } - - if _, _, err := c.db.db.Execute(c.ctx, txBegin); err != nil { - return nil, err - } - - c.tnl++ - return c, nil -} - -func (c *driverConn) Commit() error { - if c.tnl == 0 || c.ctx == nil { - return errCommitNotInTransaction - } - - if _, _, err := c.db.db.Execute(c.ctx, txCommit); err != nil { - return err - } - - c.tnl-- - if c.tnl == 0 { - c.ctx = nil - } - return nil -} - -func (c *driverConn) Rollback() error { - if c.tnl == 0 || c.ctx == nil { - return errRollbackNotInTransaction - } - - if _, _, err := c.db.db.Execute(c.ctx, txRollback); err != nil { - return err - } - - c.tnl-- - if c.tnl == 0 { - c.ctx = nil - } - return nil -} - -// Execer is an optional interface that may be implemented by a Conn. -// -// If a Conn does not implement Execer, the sql package's DB.Exec will first -// prepare a query, execute the statement, and then close the statement. -// -// Exec may return driver.ErrSkip. -func (c *driverConn) Exec(query string, args []driver.Value) (driver.Result, error) { - list, err := Compile(query) - if err != nil { - return nil, err - } - - return driverExec(c.db, c.ctx, list, args) -} - -func driverExec(db *driverDB, ctx *TCtx, list List, args []driver.Value) (driver.Result, error) { - if _, _, err := db.db.Execute(ctx, list, params(args)...); err != nil { - return nil, err - } - - if len(list.l) == 1 { - switch list.l[0].(type) { - case *createTableStmt, *dropTableStmt, *alterTableAddStmt, - *alterTableDropColumnStmt, *truncateTableStmt: - return driver.ResultNoRows, nil - } - } - - r := &driverResult{} - if ctx != nil { - r.lastInsertID, r.rowsAffected = ctx.LastInsertID, ctx.RowsAffected - } - return r, nil -} - -// Queryer is an optional interface that may be implemented by a Conn. -// -// If a Conn does not implement Queryer, the sql package's DB.Query will first -// prepare a query, execute the statement, and then close the statement. -// -// Query may return driver.ErrSkip. -func (c *driverConn) Query(query string, args []driver.Value) (driver.Rows, error) { - list, err := Compile(query) - if err != nil { - return nil, err - } - - return driverQuery(c.db, c.ctx, list, args) -} - -func driverQuery(db *driverDB, ctx *TCtx, list List, args []driver.Value) (driver.Rows, error) { - rss, _, err := db.db.Execute(ctx, list, params(args)...) - if err != nil { - return nil, err - } - - switch n := len(rss); n { - case 0: - return nil, errNoResult - default: - return newDriverMultiRows(rss), nil - } -} - -// driverResult is the result of a query execution. -type driverResult struct { - lastInsertID int64 - rowsAffected int64 -} - -// LastInsertId returns the database's auto-generated ID after, for example, an -// INSERT into a table with primary key. -func (r *driverResult) LastInsertId() (int64, error) { // -golint - return r.lastInsertID, nil -} - -// RowsAffected returns the number of rows affected by the query. -func (r *driverResult) RowsAffected() (int64, error) { - return r.rowsAffected, nil -} - -// driverRows is an iterator over an executed query's results. -type driverRows struct { - rs Recordset - done chan int - rows chan interface{} -} - -func newdriverRows(rs Recordset) *driverRows { - r := &driverRows{ - rs: rs, - done: make(chan int), - rows: make(chan interface{}, 500), - } - go func() { - err := io.EOF - if e := r.rs.Do(false, func(data []interface{}) (bool, error) { - select { - case r.rows <- data: - return true, nil - case <-r.done: - return false, nil - } - }); e != nil { - err = e - } - - select { - case r.rows <- err: - case <-r.done: - } - }() - return r -} - -// Columns returns the names of the columns. The number of columns of the -// result is inferred from the length of the slice. If a particular column -// name isn't known, an empty string should be returned for that entry. -func (r *driverRows) Columns() []string { - f, _ := r.rs.Fields() - return f -} - -// Close closes the rows iterator. -func (r *driverRows) Close() error { - close(r.done) - return nil -} - -// Next is called to populate the next row of data into the provided slice. The -// provided slice will be the same size as the Columns() are wide. -// -// The dest slice may be populated only with a driver Value type, but excluding -// string. All string values must be converted to []byte. -// -// Next should return io.EOF when there are no more rows. -func (r *driverRows) Next(dest []driver.Value) error { - select { - case rx := <-r.rows: - switch x := rx.(type) { - case error: - return x - case []interface{}: - if g, e := len(x), len(dest); g != e { - return fmt.Errorf("field count mismatch: got %d, need %d", g, e) - } - - for i, xi := range x { - switch v := xi.(type) { - case nil, int64, float64, bool, []byte, time.Time: - dest[i] = v - case complex64, complex128, *big.Int, *big.Rat, idealComplex: - var buf bytes.Buffer - fmt.Fprintf(&buf, "%v", v) - dest[i] = buf.Bytes() - case int8: - dest[i] = int64(v) - case int16: - dest[i] = int64(v) - case int32: - dest[i] = int64(v) - case int: - dest[i] = int64(v) - case uint8: - dest[i] = int64(v) - case uint16: - dest[i] = int64(v) - case uint32: - dest[i] = int64(v) - case uint64: - dest[i] = int64(v) - case uint: - dest[i] = int64(v) - case time.Duration: - dest[i] = int64(v) - case string: - dest[i] = []byte(v) - case idealInt: - dest[i] = int64(v) - case idealUint: - dest[i] = int64(v) - case idealFloat: - dest[i] = float64(v) - default: - return fmt.Errorf("internal error 004") - } - } - return nil - default: - return fmt.Errorf("internal error 005") - } - case <-r.done: - return io.EOF - } -} - -type driverMultiRows struct { - rs []Recordset - pos int - active *driverRows -} - -func newDriverMultiRows(rs []Recordset) *driverMultiRows { - return &driverMultiRows{ - rs: rs, - active: newdriverRows(rs[0]), - } -} -func (r *driverMultiRows) Columns() []string { - return r.active.Columns() -} -func (r *driverMultiRows) Close() error { - return r.active.Close() -} - -func (r *driverMultiRows) HasNextResultSet() bool { - return r.pos+1 < len(r.rs) -} -func (r *driverMultiRows) NextResultSet() error { - if r.HasNextResultSet() { - r.active.Close() - r.pos++ - r.active = newdriverRows(r.rs[r.pos]) - return nil - } - return io.EOF -} - -func (r *driverMultiRows) Next(dest []driver.Value) error { - return r.active.Next(dest) -} - -// driverStmt is a prepared statement. It is bound to a driverConn and not used -// by multiple goroutines concurrently. -type driverStmt struct { - conn *driverConn - stmt List -} - -// Close closes the statement. -// -// As of Go 1.1, a Stmt will not be closed if it's in use by any queries. -func (s *driverStmt) Close() error { - delete(s.conn.stop, s) - return nil -} - -// NumInput returns the number of placeholder parameters. -// -// If NumInput returns >= 0, the sql package will sanity check argument counts -// from callers and return errors to the caller before the statement's Exec or -// Query methods are called. -// -// NumInput may also return -1, if the driver doesn't know its number of -// placeholders. In that case, the sql package will not sanity check Exec or -// Query argument counts. -func (s *driverStmt) NumInput() int { - if x := s.stmt; len(x.l) == 1 { - return x.params - } - - return -1 -} - -// Exec executes a query that doesn't return rows, such as an INSERT or UPDATE. -func (s *driverStmt) Exec(args []driver.Value) (driver.Result, error) { - c := s.conn - return driverExec(c.db, c.ctx, s.stmt, args) -} - -// Exec executes a query that may return rows, such as a SELECT. -func (s *driverStmt) Query(args []driver.Value) (driver.Rows, error) { - c := s.conn - return driverQuery(c.db, c.ctx, s.stmt, args) -} diff --git a/vendor/github.com/cznic/ql/driver/driver.go b/vendor/github.com/cznic/ql/driver/driver.go deleted file mode 100644 index 557c70d82..000000000 --- a/vendor/github.com/cznic/ql/driver/driver.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* -Package driver registers a QL sql/driver named "ql" and a memory driver named "ql-mem". - -See also [0], [1] and [3]. - -Usage - -A skeleton program using ql/driver. - - package main - - import ( - "database/sql" - - _ "github.com/cznic/ql/driver" - ) - - func main() { - ... - // Disk file DB - db, err := sql.Open("ql", "ql.db") // [2] - // alternatively - db, err := sql.Open("ql", "file://ql.db") - - // and/or - - // RAM DB - mdb, err := sql.Open("ql-mem", "mem.db") - // alternatively - mdb, err := sql.Open("ql", "memory://mem.db") - if err != nil { - log.Fatal(err) - } - - // Use db/mdb here - ... - } - -This package exports nothing. - -Links - -Referenced from above: - - [0]: http://godoc.org/github.com/cznic/ql - [1]: http://golang.org/pkg/database/sql/ - [2]: http://golang.org/pkg/database/sql/#Open - [3]: http://golang.org/pkg/database/sql/driver -*/ -package driver - -import "github.com/cznic/ql" - -func init() { - ql.RegisterDriver() - ql.RegisterMemDriver() -} diff --git a/vendor/github.com/cznic/ql/driver1.8.go b/vendor/github.com/cznic/ql/driver1.8.go deleted file mode 100644 index 4d178f323..000000000 --- a/vendor/github.com/cznic/ql/driver1.8.go +++ /dev/null @@ -1,140 +0,0 @@ -// +build go1.8 - -package ql - -import ( - "context" - "database/sql/driver" - "fmt" - "strconv" - "strings" -) - -const prefix = "$" - -func (c *driverConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) { - query, vals, err := replaceNamed(query, args) - if err != nil { - return nil, err - } - - return c.Exec(query, vals) -} - -func replaceNamed(query string, args []driver.NamedValue) (string, []driver.Value, error) { - toks, err := tokenize(query) - if err != nil { - return "", nil, err - } - - a := make([]driver.Value, len(args)) - m := map[string]int{} - for _, v := range args { - m[v.Name] = v.Ordinal - a[v.Ordinal-1] = v.Value - } - for i, v := range toks { - if len(v) > 1 && strings.HasPrefix(v, prefix) { - if v[1] >= '1' && v[1] <= '9' { - continue - } - - nm := v[1:] - k, ok := m[nm] - if !ok { - return query, nil, fmt.Errorf("unknown named parameter %s", nm) - } - - toks[i] = fmt.Sprintf("$%d", k) - } - } - return strings.Join(toks, " "), a, nil -} - -func (c *driverConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { - query, vals, err := replaceNamed(query, args) - if err != nil { - return nil, err - } - - return c.Query(query, vals) -} - -func (c *driverConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { - query, err := filterNamedArgs(query) - if err != nil { - return nil, err - } - - return c.Prepare(query) -} - -func filterNamedArgs(query string) (string, error) { - toks, err := tokenize(query) - if err != nil { - return "", err - } - - n := 0 - for _, v := range toks { - if len(v) > 1 && strings.HasPrefix(v, prefix) && v[1] >= '1' && v[1] <= '9' { - m, err := strconv.ParseUint(v[1:], 10, 31) - if err != nil { - return "", err - } - - if int(m) > n { - n = int(m) - } - } - } - for i, v := range toks { - if len(v) > 1 && strings.HasPrefix(v, prefix) { - if v[1] >= '1' && v[1] <= '9' { - continue - } - - n++ - toks[i] = fmt.Sprintf("$%d", n) - } - } - return strings.Join(toks, " "), nil -} - -func (s *driverStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) { - a := make([]driver.Value, len(args)) - for k, v := range args { - a[k] = v.Value - } - return s.Exec(a) -} - -func (s *driverStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) { - a := make([]driver.Value, len(args)) - for k, v := range args { - a[k] = v.Value - } - return s.Query(a) -} - -func tokenize(s string) (r []string, _ error) { - lx, err := newLexer(s) - if err != nil { - return nil, err - } - - var lval yySymType - for lx.Lex(&lval) != 0 { - s := string(lx.TokenBytes(nil)) - if s != "" { - switch s[len(s)-1] { - case '"': - s = "\"" + s - case '`': - s = "`" + s - } - } - r = append(r, s) - } - return r, nil -} diff --git a/vendor/github.com/cznic/ql/errors.go b/vendor/github.com/cznic/ql/errors.go deleted file mode 100644 index 305414f4a..000000000 --- a/vendor/github.com/cznic/ql/errors.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "errors" -) - -var ( - errBeginTransNoCtx = errors.New("BEGIN TRANSACTION: Must use R/W context, have nil") - errCommitNotInTransaction = errors.New("COMMIT: Not in transaction") - errDivByZero = errors.New("division by zero") - errIncompatibleDBFormat = errors.New("incompatible DB format") - errNoDataForHandle = errors.New("read: no data for handle") - errRollbackNotInTransaction = errors.New("ROLLBACK: Not in transaction") -) diff --git a/vendor/github.com/cznic/ql/etc.go b/vendor/github.com/cznic/ql/etc.go deleted file mode 100644 index a4ea697ce..000000000 --- a/vendor/github.com/cznic/ql/etc.go +++ /dev/null @@ -1,2772 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "bytes" - "fmt" - "io" - "math" - "math/big" - "time" -) - -// QL types. -const ( - qBool = 0x62 // 'b' - qComplex64 = 0x63 // 'c' - qComplex128 = 0x64 // 'd' - qFloat32 = 0x66 // 'f' - qFloat64 = 0x67 // 'g', alias float - qInt8 = 0x69 // 'i' - qInt16 = 0x6a // 'j' - qInt32 = 0x6b // 'k' - qInt64 = 0x6c // 'l', alias int - qString = 0x73 // 's' - qUint8 = 0x75 // 'u', alias byte - qUint16 = 0x76 // 'v' - qUint32 = 0x77 // 'w' - qUint64 = 0x78 // 'x', alias uint - - qBigInt = 0x49 // 'I' - qBigRat = 0x52 // 'R' - qBlob = 0x42 // 'B' - qDuration = 0x44 // 'D' - qTime = 0x54 // 'T' -) - -var ( - type2Str = map[int]string{ - qBigInt: "bigint", - qBigRat: "bigrat", - qBlob: "blob", - qBool: "bool", - qComplex128: "complex128", - qComplex64: "complex64", - qDuration: "duration", - qFloat32: "float32", - qFloat64: "float64", - qInt16: "int16", - qInt32: "int32", - qInt64: "int64", - qInt8: "int8", - qString: "string", - qTime: "time", - qUint16: "uint16", - qUint32: "uint32", - qUint64: "uint64", - qUint8: "uint8", - } -) - -func typeStr(typ int) (r string) { - return type2Str[typ] -} - -func noEOF(err error) error { - if err == io.EOF { - err = nil - } - return err -} - -func runErr(err error) error { return fmt.Errorf("run time error: %s", err) } - -func invXOp(s, x interface{}) error { - return fmt.Errorf("invalid operation: %v[%v] (index of type %T)", s, x, x) -} - -func invSOp(s interface{}) error { - return fmt.Errorf("cannot slice %s (type %T)", s, s) -} - -func invNegX(x interface{}) error { - return fmt.Errorf("invalid string index %v (index must be non-negative)", x) -} - -func invNegLO(x interface{}) error { - return fmt.Errorf("invalid LIMIT or OFFSET value %v (must be non-negative)", x) -} - -func invSliceNegX(x interface{}) error { - return fmt.Errorf("invalid slice index %v (index must be non-negative)", x) -} - -func invBoundX(s string, x uint64) error { - return fmt.Errorf("invalid string index %d (out of bounds for %d-byte string)", x, len(s)) -} - -func invSliceBoundX(s string, x uint64) error { - return fmt.Errorf("invalid slice index %d (out of bounds for %d-byte string)", x, len(s)) -} - -func intExpr(x interface{}) (i int64, err error) { - switch x := x.(type) { - case idealInt: - if x < 0 { - return 0, invNegLO(x) - } - - return int64(x), nil - case idealRune: - if x < 0 { - return 0, invNegLO(x) - } - - return int64(x), nil - case idealUint: - if x < 0 { - return 0, invNegLO(x) - } - - return int64(x), nil - case int8: - if x < 0 { - return 0, invNegLO(x) - } - - return int64(x), nil - case int16: - if x < 0 { - return 0, invNegLO(x) - } - - return int64(x), nil - case int32: - if x < 0 { - return 0, invNegLO(x) - } - - return int64(x), nil - case int64: - if x < 0 { - return 0, invNegLO(x) - } - - return x, nil - case uint8: - return int64(x), nil - case uint16: - return int64(x), nil - case uint32: - return int64(x), nil - case uint64: - return int64(x), nil - default: - return 0, fmt.Errorf("non-integer expression: %v (value of type %T)", x, x) - } -} - -func limOffExpr(x interface{}) (i uint64, err error) { - switch x := x.(type) { - case idealInt: - if x < 0 { - return 0, invNegLO(x) - } - - return uint64(x), nil - case idealRune: - if x < 0 { - return 0, invNegLO(x) - } - - return uint64(x), nil - case idealUint: - if x < 0 { - return 0, invNegLO(x) - } - - return uint64(x), nil - case int8: - if x < 0 { - return 0, invNegLO(x) - } - - return uint64(x), nil - case int16: - if x < 0 { - return 0, invNegLO(x) - } - - return uint64(x), nil - case int32: - if x < 0 { - return 0, invNegLO(x) - } - - return uint64(x), nil - case int64: - if x < 0 { - return 0, invNegLO(x) - } - - return uint64(x), nil - case uint8: - return uint64(x), nil - case uint16: - return uint64(x), nil - case uint32: - return uint64(x), nil - case uint64: - return x, nil - default: - return 0, fmt.Errorf("non-integer used in LIMIT or OFFSET: %v (value of type %T)", x, x) - } -} - -func indexExpr(s *string, x interface{}) (i uint64, err error) { - switch x := x.(type) { - case idealFloat: - if x < 0 { - return 0, invNegX(x) - } - - if s != nil && int(x) >= len(*s) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case idealInt: - if x < 0 { - return 0, invNegX(x) - } - - if s != nil && int64(x) >= int64(len(*s)) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case idealRune: - if x < 0 { - return 0, invNegX(x) - } - - if s != nil && int32(x) >= int32(len(*s)) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case idealUint: - if x < 0 { - return 0, invNegX(x) - } - - if s != nil && uint64(x) >= uint64(len(*s)) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case int8: - if x < 0 { - return 0, invNegX(x) - } - - if s != nil && int(x) >= len(*s) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case int16: - if x < 0 { - return 0, invNegX(x) - } - - if s != nil && int(x) >= len(*s) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case int32: - if x < 0 { - return 0, invNegX(x) - } - - if s != nil && int(x) >= len(*s) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case int64: - if x < 0 { - return 0, invNegX(x) - } - - if s != nil && x >= int64(len(*s)) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case uint8: - if s != nil && int(x) >= len(*s) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case uint16: - if s != nil && int(x) >= len(*s) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case uint32: - if s != nil && x >= uint32(len(*s)) { - return 0, invBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case uint64: - if s != nil && x >= uint64(len(*s)) { - return 0, invBoundX(*s, x) - } - - return x, nil - default: - return 0, fmt.Errorf("non-integer string index %v (value of type %T)", x, x) - } -} - -func sliceExpr(s *string, x interface{}, mod int) (i uint64, err error) { - switch x := x.(type) { - case idealFloat: - if x < 0 { - return 0, invSliceNegX(x) - } - - if s != nil && int(x) >= len(*s)+mod { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case idealInt: - if x < 0 { - return 0, invSliceNegX(x) - } - - if s != nil && int64(x) >= int64(len(*s)+mod) { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case idealRune: - if x < 0 { - return 0, invSliceNegX(x) - } - - if s != nil && int32(x) >= int32(len(*s)+mod) { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case idealUint: - if x < 0 { - return 0, invSliceNegX(x) - } - - if s != nil && uint64(x) >= uint64(len(*s)+mod) { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case int8: - if x < 0 { - return 0, invSliceNegX(x) - } - - if s != nil && int(x) >= len(*s)+mod { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case int16: - if x < 0 { - return 0, invSliceNegX(x) - } - - if s != nil && int(x) >= len(*s)+mod { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case int32: - if x < 0 { - return 0, invSliceNegX(x) - } - - if s != nil && int(x) >= len(*s)+mod { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case int64: - if x < 0 { - return 0, invSliceNegX(x) - } - - if s != nil && x >= int64(len(*s)+mod) { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case uint8: - if s != nil && int(x) >= len(*s)+mod { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case uint16: - if s != nil && int(x) >= len(*s)+mod { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case uint32: - if s != nil && x >= uint32(len(*s)+mod) { - return 0, invSliceBoundX(*s, uint64(x)) - } - - return uint64(x), nil - case uint64: - if s != nil && x >= uint64(len(*s)+mod) { - return 0, invSliceBoundX(*s, x) - } - - return x, nil - default: - return 0, fmt.Errorf("invalid slice index %s (type %T)", x, x) - } -} - -type iop int - -func (o iop) String() string { - switch i := int(o); i { - case andand: - return "&&" - case andnot: - return "&^" - case lsh: - return "<<" - case le: - return "<=" - case eq: - return "==" - case ge: - return ">=" - case neq: - return "!=" - case oror: - return "||" - case rsh: - return ">>" - default: - return string(i) - } -} - -func ideal(v interface{}) interface{} { - switch x := v.(type) { - case idealComplex: - return complex128(x) - case idealFloat: - return float64(x) - case idealInt: - return int64(x) - case idealRune: - return int64(x) - case idealUint: - return uint64(x) - default: - return v - } -} - -func eval(v expression, execCtx *execCtx, ctx map[interface{}]interface{}) (y interface{}) { - y, err := expand1(v.eval(execCtx, ctx)) - if err != nil { - panic(err) // panic ok here - } - return -} - -func eval2(a, b expression, execCtx *execCtx, ctx map[interface{}]interface{}) (x, y interface{}) { - return eval(a, execCtx, ctx), eval(b, execCtx, ctx) -} - -func invOp2(x, y interface{}, o int) (interface{}, error) { - return nil, fmt.Errorf("invalid operation: %v %v %v (mismatched types %T and %T)", x, iop(o), y, ideal(x), ideal(y)) -} - -func undOp(x interface{}, o int) (interface{}, error) { - return nil, fmt.Errorf("invalid operation: %v%v (operator %v not defined on %T)", iop(o), x, iop(o), x) -} - -func undOp2(x, y interface{}, o int) (interface{}, error) { - return nil, fmt.Errorf("invalid operation: %v %v %v (operator %v not defined on %T)", x, iop(o), y, iop(o), x) -} - -func invConv(val interface{}, typ int) (interface{}, error) { - return nil, fmt.Errorf("cannot convert %v (type %T) to type %s", val, val, typeStr(typ)) -} - -func truncConv(val interface{}) (interface{}, error) { - return nil, fmt.Errorf("constant %v truncated to integer", val) -} - -func convert(val interface{}, typ int) (v interface{}, err error) { //NTYPE - if val == nil { - return nil, nil - } - - switch typ { - case qBool: - switch x := val.(type) { - //case nil: - //case idealComplex: - //case idealFloat: - //case idealInt: - //case idealRune: - //case idealUint: - case bool: - return x, nil - //case complex64: - //case complex128: - //case float32: - //case float64: - //case int8: - //case int16: - //case int32: - //case int64: - //case string: - //case uint8: - //case uint16: - //case uint32: - //case uint64: - default: - return invConv(val, typ) - } - case qComplex64: - switch x := val.(type) { - //case nil: - case idealComplex: - return complex64(x), nil - case idealFloat: - return complex(float32(x), 0), nil - case idealInt: - return complex(float32(x), 0), nil - case idealRune: - return complex(float32(x), 0), nil - case idealUint: - return complex(float32(x), 0), nil - //case bool: - case complex64: - return x, nil - case complex128: - return complex64(x), nil - //case float32: - //case float64: - //case int8: - //case int16: - //case int32: - //case int64: - //case string: - //case uint8: - //case uint16: - //case uint32: - //case uint64: - default: - return invConv(val, typ) - } - case qComplex128: - switch x := val.(type) { - //case nil: - case idealComplex: - return complex128(x), nil - case idealFloat: - return complex(float64(x), 0), nil - case idealInt: - return complex(float64(x), 0), nil - case idealRune: - return complex(float64(x), 0), nil - case idealUint: - return complex(float64(x), 0), nil - //case bool: - case complex64: - return complex128(x), nil - case complex128: - return x, nil - //case float32: - //case float64: - //case int8: - //case int16: - //case int32: - //case int64: - //case string: - //case uint8: - //case uint16: - //case uint32: - //case uint64: - default: - return invConv(val, typ) - } - case qFloat32: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - return float32(x), nil - case idealInt: - return float32(x), nil - case idealRune: - return float32(x), nil - case idealUint: - return float32(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return x, nil - case float64: - return float32(x), nil - case int8: - return float32(x), nil - case int16: - return float32(x), nil - case int32: - return float32(x), nil - case int64: - return float32(x), nil - //case string: - case uint8: - return float32(x), nil - case uint16: - return float32(x), nil - case uint32: - return float32(x), nil - case uint64: - return float32(x), nil - case *big.Int: - v, _ := big.NewRat(1, 1).SetInt(x).Float64() - return float32(v), nil - case *big.Rat: - v, _ := x.Float64() - return float32(v), nil - case time.Duration: - return float32(x), nil - default: - return invConv(val, typ) - } - case qFloat64: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - return float64(x), nil - case idealInt: - return float64(x), nil - case idealRune: - return float64(x), nil - case idealUint: - return float64(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return float64(x), nil - case float64: - return x, nil - case int8: - return float64(x), nil - case int16: - return float64(x), nil - case int32: - return float64(x), nil - case int64: - return float64(x), nil - //case string: - case uint8: - return float64(x), nil - case uint16: - return float64(x), nil - case uint32: - return float64(x), nil - case uint64: - return float64(x), nil - case *big.Int: - v, _ := big.NewRat(1, 1).SetInt(x).Float64() - return v, nil - case *big.Rat: - v, _ := x.Float64() - return v, nil - case time.Duration: - return float64(x), nil - default: - return invConv(val, typ) - } - case qInt8: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - if _, frac := math.Modf(float64(x)); frac != 0 { - return truncConv(x) - } - - return int8(x), nil - case idealInt: - return int8(x), nil - case idealRune: - return int8(x), nil - case idealUint: - return int8(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return int8(x), nil - case float64: - return int8(x), nil - case int8: - return x, nil - case int16: - return int8(x), nil - case int32: - return int8(x), nil - case int64: - return int8(x), nil - //case string: - case uint8: - return int8(x), nil - case uint16: - return int8(x), nil - case uint32: - return int8(x), nil - case uint64: - return int8(x), nil - case *big.Int: - return int8(x.Int64()), nil - case time.Duration: - return int8(x), nil - default: - return invConv(val, typ) - } - case qInt16: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - if _, frac := math.Modf(float64(x)); frac != 0 { - return truncConv(x) - } - - return int16(x), nil - case idealInt: - return int16(x), nil - case idealRune: - return int16(x), nil - case idealUint: - return int16(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return int16(x), nil - case float64: - return int16(x), nil - case int8: - return int16(x), nil - case int16: - return x, nil - case int32: - return int16(x), nil - case int64: - return int16(x), nil - //case string: - case uint8: - return int16(x), nil - case uint16: - return int16(x), nil - case uint32: - return int16(x), nil - case uint64: - return int16(x), nil - case *big.Int: - return int16(x.Int64()), nil - case time.Duration: - return int16(x), nil - default: - return invConv(val, typ) - } - case qInt32: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - if _, frac := math.Modf(float64(x)); frac != 0 { - return truncConv(x) - } - - return int32(x), nil - case idealInt: - return int32(x), nil - case idealRune: - return int32(x), nil - case idealUint: - return int32(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return int32(x), nil - case float64: - return int32(x), nil - case int8: - return int32(x), nil - case int16: - return int32(x), nil - case int32: - return x, nil - case int64: - return int32(x), nil - //case string: - case uint8: - return int32(x), nil - case uint16: - return int32(x), nil - case uint32: - return int32(x), nil - case uint64: - return int32(x), nil - case *big.Int: - return int32(x.Int64()), nil - case time.Duration: - return int32(x), nil - default: - return invConv(val, typ) - } - case qInt64: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - if _, frac := math.Modf(float64(x)); frac != 0 { - return truncConv(x) - } - - return int64(x), nil - case idealInt: - return int64(x), nil - case idealRune: - return int64(x), nil - case idealUint: - return int64(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return int64(x), nil - case float64: - return int64(x), nil - case int8: - return int64(x), nil - case int16: - return int64(x), nil - case int32: - return int64(x), nil - case int64: - return x, nil - //case string: - case uint8: - return int64(x), nil - case uint16: - return int64(x), nil - case uint32: - return int64(x), nil - case uint64: - return int64(x), nil - case *big.Int: - return x.Int64(), nil - case time.Duration: - return int64(x), nil - default: - return invConv(val, typ) - } - case qString: - switch x := val.(type) { - //case nil: - //case idealComplex: - //case idealFloat: - case idealInt: - return string(x), nil - case idealRune: - return string(x), nil - case idealUint: - return string(x), nil - //case bool: - //case complex64: - //case complex128: - //case float32: - //case float64: - case int8: - return string(x), nil - case int16: - return string(x), nil - case int32: - return string(x), nil - case int64: - return string(x), nil - case string: - return x, nil - case uint8: - return string(x), nil - case uint16: - return string(x), nil - case uint32: - return string(x), nil - case uint64: - return string(x), nil - case []byte: - return string(x), nil - case *big.Int: - return x.String(), nil - case time.Time: - return x.String(), nil - case time.Duration: - return x.String(), nil - default: - return invConv(val, typ) - } - case qUint8: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - if _, frac := math.Modf(float64(x)); frac != 0 { - return truncConv(x) - } - - return uint8(x), nil - case idealInt: - return uint8(x), nil - case idealRune: - return uint8(x), nil - case idealUint: - return uint8(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return uint8(x), nil - case float64: - return uint8(x), nil - case int8: - return uint8(x), nil - case int16: - return uint8(x), nil - case int32: - return uint8(x), nil - case int64: - return uint8(x), nil - //case string: - case uint8: - return x, nil - case uint16: - return uint8(x), nil - case uint32: - return uint8(x), nil - case uint64: - return uint8(x), nil - case *big.Int: - return uint8(x.Int64()), nil - case time.Duration: - return uint8(x), nil - default: - return invConv(val, typ) - } - case qUint16: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - if _, frac := math.Modf(float64(x)); frac != 0 { - return truncConv(x) - } - - return uint16(x), nil - case idealInt: - return uint16(x), nil - case idealRune: - return uint16(x), nil - case idealUint: - return uint16(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return uint16(x), nil - case float64: - return uint16(x), nil - case int8: - return uint16(x), nil - case int16: - return uint16(x), nil - case int32: - return uint16(x), nil - case int64: - return uint16(x), nil - //case string: - case uint8: - return uint16(x), nil - case uint16: - return x, nil - case uint32: - return uint16(x), nil - case uint64: - return uint16(x), nil - case *big.Int: - return uint16(x.Int64()), nil - case time.Duration: - return uint16(x), nil - default: - return invConv(val, typ) - } - case qUint32: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - if _, frac := math.Modf(float64(x)); frac != 0 { - return truncConv(x) - } - - return uint32(x), nil - case idealInt: - return uint32(x), nil - case idealRune: - return uint32(x), nil - case idealUint: - return uint32(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return uint32(x), nil - case float64: - return uint32(x), nil - case int8: - return uint32(x), nil - case int16: - return uint32(x), nil - case int32: - return uint32(x), nil - case int64: - return uint32(x), nil - //case string: - case uint8: - return uint32(x), nil - case uint16: - return uint32(x), nil - case uint32: - return x, nil - case uint64: - return uint32(x), nil - case *big.Int: - return uint32(x.Int64()), nil - case time.Duration: - return uint32(x), nil - default: - return invConv(val, typ) - } - case qUint64: - switch x := val.(type) { - //case nil: - //case idealComplex: - case idealFloat: - if _, frac := math.Modf(float64(x)); frac != 0 { - return truncConv(x) - } - - return uint64(x), nil - case idealInt: - return uint64(x), nil - case idealRune: - return uint64(x), nil - case idealUint: - return uint64(x), nil - //case bool: - //case complex64: - //case complex128: - case float32: - return uint64(x), nil - case float64: - return uint64(x), nil - case int8: - return uint64(x), nil - case int16: - return uint64(x), nil - case int32: - return uint64(x), nil - case int64: - return uint64(x), nil - //case string: - case uint8: - return uint64(x), nil - case uint16: - return uint64(x), nil - case uint32: - return uint64(x), nil - case uint64: - return x, nil - case *big.Int: - return x.Uint64(), nil - case time.Duration: - return uint64(x), nil - default: - return invConv(val, typ) - } - case qBlob: - switch x := val.(type) { - case string: - return []byte(x), nil - case []byte: - return x, nil - default: - return invConv(val, typ) - } - case qBigInt: - switch x := val.(type) { - // case blob - // case bool - //case idealComplex: - case idealFloat: - if _, frac := math.Modf(float64(x)); frac != 0 { - return truncConv(x) - } - - rr := big.NewRat(1, 1).SetFloat64(float64(x)) - ii := big.NewInt(0).Set(rr.Num()) - ii.Quo(ii, rr.Denom()) - return ii, nil - case idealInt: - return big.NewInt(0).SetInt64(int64(x)), nil - case idealRune: - return big.NewInt(0).SetInt64(int64(x)), nil - case idealUint: - return big.NewInt(0).SetUint64(uint64(x)), nil - //case complex64 - //case complex128 - case float32: - rr := big.NewRat(1, 1).SetFloat64(float64(x)) - ii := big.NewInt(0).Set(rr.Num()) - ii.Quo(ii, rr.Denom()) - return ii, nil - case float64: - rr := big.NewRat(1, 1).SetFloat64(x) - ii := big.NewInt(0).Set(rr.Num()) - ii.Quo(ii, rr.Denom()) - return ii, nil - case int8: - return big.NewInt(0).SetInt64(int64(x)), nil - case int16: - return big.NewInt(0).SetInt64(int64(x)), nil - case int32: - return big.NewInt(0).SetInt64(int64(x)), nil - case int64: - return big.NewInt(0).SetInt64(x), nil - case string: - y := big.NewInt(0) - if _, ok := y.SetString(x, 0); !ok { - return invConv(val, typ) - } - - return y, nil - case uint8: - return big.NewInt(0).SetUint64(uint64(x)), nil - case uint16: - return big.NewInt(0).SetUint64(uint64(x)), nil - case uint32: - return big.NewInt(0).SetUint64(uint64(x)), nil - case uint64: - return big.NewInt(0).SetUint64(x), nil - case *big.Int: - return x, nil - case *big.Rat: - ii := big.NewInt(0).Set(x.Num()) - ii.Div(ii, x.Denom()) - return ii, nil - default: - return invConv(val, typ) - } - case qBigRat: - switch x := val.(type) { - // case blob - // case bool - //case idealComplex: - case idealFloat: - return big.NewRat(1, 1).SetFloat64(float64(x)), nil - case idealInt: - return big.NewRat(1, 1).SetInt64(int64(x)), nil - case idealRune: - return big.NewRat(1, 1).SetInt64(int64(x)), nil - case idealUint: - return big.NewRat(1, 1).SetInt(big.NewInt(0).SetUint64(uint64(x))), nil - //case complex64 - //case complex128 - case float32: - return big.NewRat(1, 1).SetFloat64(float64(x)), nil - case float64: - return big.NewRat(1, 1).SetFloat64(x), nil - case int8: - return big.NewRat(1, 1).SetInt64(int64(x)), nil - case int16: - return big.NewRat(1, 1).SetInt64(int64(x)), nil - case int32: - return big.NewRat(1, 1).SetInt64(int64(x)), nil - case int64: - return big.NewRat(1, 1).SetInt64(x), nil - case string: - y := big.NewRat(1, 1) - if _, ok := y.SetString(x); !ok { - return invConv(val, typ) - } - - return y, nil - case uint8: - return big.NewRat(1, 1).SetInt64(int64(x)), nil - case uint16: - return big.NewRat(1, 1).SetInt64(int64(x)), nil - case uint32: - return big.NewRat(1, 1).SetInt64(int64(x)), nil - case uint64: - return big.NewRat(1, 1).SetInt(big.NewInt(0).SetUint64(x)), nil - case *big.Int: - return big.NewRat(1, 1).SetInt(x), nil - case *big.Rat: - return x, nil - default: - return invConv(val, typ) - } - case qDuration: - switch x := val.(type) { - // case blob - // case bool - //case idealComplex: - case idealFloat: - return time.Duration(x), nil - case idealInt: - return time.Duration(x), nil - case idealRune: - return time.Duration(x), nil - case idealUint: - return time.Duration(x), nil - //case complex64 - //case complex128 - case float32: - return time.Duration(x), nil - case float64: - return time.Duration(x), nil - case int8: - return time.Duration(x), nil - case int16: - return time.Duration(x), nil - case int32: - return time.Duration(x), nil - case int64: - return time.Duration(x), nil - case string: - return time.ParseDuration(x) - case uint8: - return time.Duration(x), nil - case uint16: - return time.Duration(x), nil - case uint32: - return time.Duration(x), nil - case uint64: - return time.Duration(x), nil - case *big.Int: - return time.Duration(x.Int64()), nil - case *big.Rat: - f, _ := x.Float64() - return time.Duration(f), nil - case time.Duration: - return x, nil - default: - return invConv(val, typ) - } - case qTime: - switch x := val.(type) { - // case blob - // case bool - //case idealComplex: - //case idealFloat: - //case idealInt: - //case idealRune: - //case idealUint: - //case complex64 - //case complex128 - //case float32: - //case float64: - //case int8: - //case int16: - //case int32: - //case int64: - //case string: - //case uint8: - //case uint16: - //case uint32: - //case uint64: - //case *big.Int: - //case *big.Rat: - //case time.Duration: - case time.Time: - return x, nil - default: - return invConv(val, typ) - } - default: - panic("internal error 006") - } -} - -func invShiftRHS(lhs, rhs interface{}) (interface{}, error) { - return nil, fmt.Errorf("invalid operation: %v << %v (shift count type %T, must be unsigned integer)", lhs, rhs, rhs) -} - -func invTruncInt(v interface{}) error { - return fmt.Errorf("constant %v truncated to integer", v) -} - -func overflow(v interface{}, typ int) error { - return fmt.Errorf("constant %v overflows %s", v, typeStr(typ)) -} - -func typeCheck1(val interface{}, c *col) (interface{}, error) { - rec := []interface{}{val} - c = c.clone() - c.index = 0 - if err := typeCheck(rec, []*col{c}); err != nil { - return nil, err - } - - return rec[0], nil -} - -func typeCheck(rec []interface{}, cols []*col) (err error) { - for _, c := range cols { - i := c.index - if v := rec[i]; !c.typeCheck(v) { - switch v.(type) { - case idealComplex: - y := complex128(v.(idealComplex)) - switch c.typ { - case qBool: - case qComplex64: - rec[i] = complex64(y) - continue - case qComplex128: - rec[i] = y - continue - case qFloat32, qFloat64, qInt8, qInt16, qInt32, qInt64, qUint8, qUint16, qUint32, qUint64: - return fmt.Errorf("constant %v truncated to real", y) - } - case idealFloat: - y := float64(v.(idealFloat)) - switch c.typ { - case qBool: - case qComplex64: - rec[i] = complex(float32(y), 0) - continue - case qComplex128: - rec[i] = complex(y, 0) - continue - case qFloat32: - rec[i] = float32(y) - continue - case qFloat64: - rec[i] = y - continue - case qInt8: - if math.Floor(y) != y { - return invTruncInt(y) - } - - if y < math.MinInt8 || y > math.MaxInt8 { - return overflow(y, c.typ) - } - - rec[i] = int8(y) - continue - case qInt16: - if math.Floor(y) != y { - return invTruncInt(y) - } - - if y < math.MinInt16 || y > math.MaxInt16 { - return overflow(y, c.typ) - } - - rec[i] = int16(y) - continue - case qInt32: - if math.Floor(y) != y { - return invTruncInt(y) - } - - if y < math.MinInt32 || y > math.MaxInt32 { - return overflow(y, c.typ) - } - - rec[i] = int32(y) - continue - case qInt64: - if math.Floor(y) != y { - return invTruncInt(y) - } - - if y < math.MinInt64 || y > math.MaxInt64 { - return overflow(y, c.typ) - } - - rec[i] = int64(y) - continue - case qString: - case qUint8: - if math.Floor(y) != y { - return invTruncInt(y) - } - - if y < 0 || y > math.MaxUint8 { - return overflow(y, c.typ) - } - - rec[i] = uint8(y) - continue - case qUint16: - if math.Floor(y) != y { - return invTruncInt(y) - } - - if y < 0 || y > math.MaxUint16 { - return overflow(y, c.typ) - } - - rec[i] = uint16(y) - continue - case qUint32: - if math.Floor(y) != y { - return invTruncInt(y) - } - - if y < 0 || y > math.MaxUint32 { - return overflow(y, c.typ) - } - - rec[i] = uint32(y) - continue - case qUint64: - if math.Floor(y) != y { - return invTruncInt(y) - } - - if y < 0 || y > math.MaxUint64 { - return overflow(y, c.typ) - } - - rec[i] = uint64(y) - continue - case qBigInt: - if math.Floor(y) != y { - return invTruncInt(y) - } - - rr := big.NewRat(1, 1).SetFloat64(y) - ii := big.NewInt(0) - ii.Set(rr.Num()) - ii.Quo(ii, rr.Denom()) - rec[i] = ii - continue - case qBigRat: - rec[i] = big.NewRat(1, 1).SetFloat64(y) - continue - } - case idealInt: - y := int64(v.(idealInt)) - switch c.typ { - case qBool: - case qComplex64: - rec[i] = complex(float32(y), 0) - continue - case qComplex128: - rec[i] = complex(float64(y), 0) - continue - case qFloat32: - rec[i] = float32(y) - continue - case qFloat64: - rec[i] = float64(y) - continue - case qInt8: - if y < math.MinInt8 || y > math.MaxInt8 { - return overflow(y, c.typ) - } - - rec[i] = int8(y) - continue - case qInt16: - if y < math.MinInt16 || y > math.MaxInt16 { - return overflow(y, c.typ) - } - - rec[i] = int16(y) - continue - case qInt32: - if y < math.MinInt32 || y > math.MaxInt32 { - return overflow(y, c.typ) - } - - rec[i] = int32(y) - continue - case qInt64: - if y < math.MinInt64 || y > math.MaxInt64 { - return overflow(y, c.typ) - } - - rec[i] = y - continue - case qString: - case qUint8: - if y < 0 || y > math.MaxUint8 { - return overflow(y, c.typ) - } - - rec[i] = uint8(y) - continue - case qUint16: - if y < 0 || y > math.MaxUint16 { - return overflow(y, c.typ) - } - - rec[i] = uint16(y) - continue - case qUint32: - if y < 0 || y > math.MaxUint32 { - return overflow(y, c.typ) - } - - rec[i] = uint32(y) - continue - case qUint64: - if y < 0 { - return overflow(y, c.typ) - } - - rec[i] = uint64(y) - continue - case qBigInt: - rec[i] = big.NewInt(y) - continue - case qBigRat: - rec[i] = big.NewRat(1, 1).SetInt64(y) - continue - } - case idealRune: - y := int64(v.(idealRune)) - switch c.typ { - case qBool: - case qComplex64: - rec[i] = complex(float32(y), 0) - continue - case qComplex128: - rec[i] = complex(float64(y), 0) - continue - case qFloat32: - rec[i] = float32(y) - continue - case qFloat64: - rec[i] = float64(y) - continue - case qInt8: - if y < math.MinInt8 || y > math.MaxInt8 { - return overflow(y, c.typ) - } - - rec[i] = int8(y) - continue - case qInt16: - if y < math.MinInt16 || y > math.MaxInt16 { - return overflow(y, c.typ) - } - - rec[i] = int16(y) - continue - case qInt32: - if y < math.MinInt32 || y > math.MaxInt32 { - return overflow(y, c.typ) - } - - rec[i] = int32(y) - continue - case qInt64: - if y < math.MinInt64 || y > math.MaxInt64 { - return overflow(y, c.typ) - } - - rec[i] = y - continue - case qString: - case qUint8: - if y < 0 || y > math.MaxUint8 { - return overflow(y, c.typ) - } - - rec[i] = uint8(y) - continue - case qUint16: - if y < 0 || y > math.MaxUint16 { - return overflow(y, c.typ) - } - - rec[i] = uint16(y) - continue - case qUint32: - if y < 0 { - return overflow(y, c.typ) - } - - rec[i] = uint32(y) - continue - case qUint64: - if y < 0 { - return overflow(y, c.typ) - } - - rec[i] = uint64(y) - continue - case qBigInt: - rec[i] = big.NewInt(y) - continue - case qBigRat: - rec[i] = big.NewRat(1, 1).SetInt64(y) - continue - } - case idealUint: - y := uint64(v.(idealUint)) - switch c.typ { - case qBool: - case qComplex64: - rec[i] = complex(float32(y), 0) - continue - case qComplex128: - rec[i] = complex(float64(y), 0) - continue - case qFloat32: - rec[i] = float32(y) - continue - case qFloat64: - rec[i] = float64(y) - continue - case qInt8: - if y > math.MaxInt8 { - return overflow(y, c.typ) - } - - rec[i] = int8(y) - continue - case qInt16: - if y > math.MaxInt16 { - return overflow(y, c.typ) - } - - rec[i] = int16(y) - continue - case qInt32: - if y > math.MaxInt32 { - return overflow(y, c.typ) - } - - rec[i] = int32(y) - continue - case qInt64: - if y > math.MaxInt64 { - return overflow(y, c.typ) - } - - rec[i] = int64(y) - continue - case qString: - rec[i] = string(y) - continue - case qUint8: - if y > math.MaxUint8 { - return overflow(y, c.typ) - } - - rec[i] = uint8(y) - continue - case qUint16: - if y > math.MaxUint16 { - return overflow(y, c.typ) - } - - rec[i] = uint16(y) - continue - case qUint32: - if y > math.MaxUint32 { - return overflow(y, c.typ) - } - - rec[i] = uint32(y) - continue - case qUint64: - rec[i] = y - continue - case qBigInt: - rec[i] = big.NewInt(0).SetUint64(y) - continue - case qBigRat: - ii := big.NewInt(0).SetUint64(y) - rec[i] = big.NewRat(1, 1).SetInt(ii) - continue - } - } - return fmt.Errorf("cannot use %v (type %T) in assignment to, or comparison with, column %s (type %s)", v, ideal(v), c.name, typeStr(c.typ)) - } - } - return -} - -//TODO collate1 should return errors instead of panicing -func collate1(a, b interface{}) int { - switch x := a.(type) { - case nil: - if b != nil { - return -1 - } - - return 0 - case bool: - switch y := b.(type) { - case nil: - return 1 - case bool: - if !x && y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - default: - // Make bool collate before anything except nil and - // other bool for index seeking first non NULL value. - return -1 - } - case idealComplex: - switch y := b.(type) { - case nil: - return 1 - case idealComplex: - if x == y { - return 0 - } - - if real(x) < real(y) { - return -1 - } - - if real(x) > real(y) { - return 1 - } - - if imag(x) < imag(y) { - return -1 - } - - return 1 - case complex64: - { - x, y := complex64(x), y - if x == y { - return 0 - } - - if real(x) < real(y) { - return -1 - } - - if real(x) > real(y) { - return 1 - } - - if imag(x) < imag(y) { - return -1 - } - - return 1 - } - case complex128: - { - x := complex128(x) - if x == y { - return 0 - } - - if real(x) < real(y) { - return -1 - } - - if real(x) > real(y) { - return 1 - } - - if imag(x) < imag(y) { - return -1 - } - - return 1 - } - default: - panic("internal error 012") - } - case idealUint: - switch y := b.(type) { - case nil: - return 1 - case idealUint: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case uint8: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case uint16: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case uint32: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case uint64: - { - x, y := uint64(x), y - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case uint: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 013") - } - case idealRune: - switch y := b.(type) { - case nil: - return 1 - case idealRune: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case int8: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case int16: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case int32: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case int64: - { - x, y := int64(x), y - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case int: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 014") - } - case idealInt: - switch y := b.(type) { - case nil: - return 1 - case idealInt: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case int8: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case int16: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case int32: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case int64: - { - x, y := int64(x), y - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case int: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 015") - } - case idealFloat: - switch y := b.(type) { - case nil: - return 1 - case idealFloat: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case float32: - { - x, y := float64(x), float64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case float64: - { - x, y := float64(x), y - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 016") - } - case complex64: - switch y := b.(type) { - case nil: - return 1 - case complex64: - if x == y { - return 0 - } - - if real(x) < real(y) { - return -1 - } - - if real(x) > real(y) { - return 1 - } - - if imag(x) < imag(y) { - return -1 - } - - return 1 - case idealComplex: - { - x, y := x, complex64(y) - if x == y { - return 0 - } - - if real(x) < real(y) { - return -1 - } - - if real(x) > real(y) { - return 1 - } - - if imag(x) < imag(y) { - return -1 - } - - return 1 - } - default: - panic("internal error 017") - } - case complex128: - switch y := b.(type) { - case nil: - return 1 - case complex128: - if x == y { - return 0 - } - - if real(x) < real(y) { - return -1 - } - - if real(x) > real(y) { - return 1 - } - - if imag(x) < imag(y) { - return -1 - } - - return 1 - case idealComplex: - { - x, y := x, complex128(y) - if x == y { - return 0 - } - - if real(x) < real(y) { - return -1 - } - - if real(x) > real(y) { - return 1 - } - - if imag(x) < imag(y) { - return -1 - } - - return 1 - } - default: - panic("internal error 018") - } - case float32: - switch y := b.(type) { - case nil: - return 1 - case float32: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealFloat: - { - x, y := x, float32(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 019") - } - case float64: - switch y := b.(type) { - case nil: - return 1 - case float64: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealFloat: - { - x, y := x, float64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 020") - } - case int8: - switch y := b.(type) { - case nil: - return 1 - case int8: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealInt: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 021") - } - case int16: - switch y := b.(type) { - case nil: - return 1 - case int16: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealInt: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 022") - } - case int32: - switch y := b.(type) { - case nil: - return 1 - case int32: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealInt: - { - x, y := int64(x), int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 023") - } - case int64: - switch y := b.(type) { - case nil: - return 1 - case int64: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealInt: - { - x, y := x, int64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 024") - } - case uint8: - switch y := b.(type) { - case nil: - return 1 - case uint8: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealInt: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case idealUint: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 025") - } - case uint16: - switch y := b.(type) { - case nil: - return 1 - case uint16: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealInt: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case idealUint: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 026") - } - case uint32: - switch y := b.(type) { - case nil: - return 1 - case uint32: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealInt: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case idealUint: - { - x, y := uint64(x), uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 027") - } - case uint64: - switch y := b.(type) { - case nil: - return 1 - case uint64: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - case idealInt: - { - x, y := x, uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - case idealUint: - { - x, y := x, uint64(y) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - } - default: - panic("internal error 028") - } - case string: - switch y := b.(type) { - case nil: - return 1 - case string: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - default: - panic("internal error 029") - } - case []byte: - switch y := b.(type) { - case nil: - return 1 - case []byte: - return bytes.Compare(x, y) - default: - panic("internal error 030") - } - case *big.Int: - switch y := b.(type) { - case nil: - return 1 - case *big.Int: - return x.Cmp(y) - case idealInt: - { - y := big.NewInt(int64(y)) - return x.Cmp(y) - } - case idealUint: - { - u := big.NewInt(0) - u.SetUint64(uint64(y)) - return x.Cmp(u) - } - default: - panic("internal error 031") - } - case *big.Rat: - switch y := b.(type) { - case nil: - return 1 - case *big.Rat: - return x.Cmp(y) - case idealInt: - { - y := big.NewRat(int64(y), 1) - return x.Cmp(y) - } - case idealUint: - { - u := big.NewInt(0) - u.SetUint64(uint64(y)) - var y big.Rat - y.SetInt(u) - return x.Cmp(&y) - } - default: - panic("internal error 032") - } - case time.Time: - switch y := b.(type) { - case nil: - return 1 - case time.Time: - if x.Before(y) { - return -1 - } - - if x.Equal(y) { - return 0 - } - - return 1 - default: - panic("internal error 033") - } - case time.Duration: - switch y := b.(type) { - case nil: - return 1 - case time.Duration: - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - default: - panic("internal error 034") - } - case chunk: - switch y := b.(type) { - case nil: - return 1 - case chunk: - a, err := x.expand() - if err != nil { - panic(err) - } - - b, err := y.expand() - if err != nil { - panic(err) - } - - return collate1(a, b) - default: - panic("internal error 035") - } - default: - //dbg("%T(%v) %T(%v)", a, a, b, b) - panic("internal error 036") - } -} - -//TODO collate should return errors from collate1 -func collate(x, y []interface{}) (r int) { - //defer func() { dbg("%v %v -> %v", x, y, r) }() - nx, ny := len(x), len(y) - - switch { - case nx == 0 && ny != 0: - return -1 - case nx == 0 && ny == 0: - return 0 - case nx != 0 && ny == 0: - return 1 - } - - r = 1 - if nx > ny { - x, y, r = y, x, -r - } - - for i, xi := range x { - if c := collate1(xi, y[i]); c != 0 { - return c * r - } - } - - if nx == ny { - return 0 - } - - return -r -} - -var collators = map[bool]func(a, b []interface{}) int{false: collateDesc, true: collate} - -func collateDesc(a, b []interface{}) int { - return -collate(a, b) -} - -func isOrderedType(v interface{}) (y interface{}, r bool, err error) { - //dbg("====") - //dbg("%T(%v)", v, v) - //defer func() { dbg("%T(%v)", y, y) }() - switch x := v.(type) { - case idealFloat, idealInt, idealRune, idealUint, - float32, float64, - int8, int16, int32, int64, - uint8, uint16, uint32, uint64, - string: - return v, true, nil - case *big.Int, *big.Rat, time.Time, time.Duration: - return x, true, nil - case chunk: - if y, err = x.expand(); err != nil { - return - } - - return isOrderedType(y) - } - - return v, false, nil -} - -var isSystemName = map[string]bool{ - "__Column": true, - "__Column2": true, - "__Index": true, - "__Index2": true, - "__Index2_Column": true, - "__Index2_Expr": true, - "__Table": true, -} - -func qnames(l []string) []string { - r := make([]string, len(l)) - for i, v := range l { - r[i] = fmt.Sprintf("%q", v) - } - return r -} diff --git a/vendor/github.com/cznic/ql/expr.go b/vendor/github.com/cznic/ql/expr.go deleted file mode 100644 index 12cb3db60..000000000 --- a/vendor/github.com/cznic/ql/expr.go +++ /dev/null @@ -1,4043 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found pIn the LICENSE file. - -package ql - -import ( - "bytes" - "fmt" - "math/big" - "regexp" - "strings" - "time" -) - -var ( - _ expression = (*binaryOperation)(nil) - _ expression = (*call)(nil) - _ expression = (*conversion)(nil) - _ expression = (*ident)(nil) - _ expression = (*indexOp)(nil) - _ expression = (*isNull)(nil) - _ expression = (*pIn)(nil) - _ expression = (*pLike)(nil) - _ expression = (*parameter)(nil) - _ expression = (*pexpr)(nil) - _ expression = (*slice)(nil) - _ expression = (*unaryOperation)(nil) - _ expression = value{} -) - -type expression interface { - clone(arg []interface{}, unqualify ...string) (expression, error) - eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) - isStatic() bool - String() string -} - -func cloneExpressionList(arg []interface{}, list []expression, unqualify ...string) ([]expression, error) { - r := make([]expression, len(list)) - var err error - for i, v := range list { - if r[i], err = v.clone(arg, unqualify...); err != nil { - return nil, err - } - } - return r, nil -} - -func isConstValue(v interface{}) interface{} { - switch x := v.(type) { - case value: - return x.val - case - idealComplex, - idealFloat, - idealInt, - idealRune, - idealUint: - return v - default: - return nil - } -} - -func isColumnExpression(v expression) (bool, string) { - x, ok := v.(*ident) - if ok { - return true, x.s - } - - c, ok := v.(*call) - if !ok || c.f != "id" || len(c.arg) != 0 { - return false, "" - } - - return true, "id()" -} - -func mentionedColumns0(e expression, q, nq bool, m map[string]struct{}) { - switch x := e.(type) { - case parameter, - value: - // nop - case *binaryOperation: - mentionedColumns0(x.l, q, nq, m) - mentionedColumns0(x.r, q, nq, m) - case *call: - if x.f != "id" { - for _, e := range x.arg { - mentionedColumns0(e, q, nq, m) - } - } - case *conversion: - mentionedColumns0(x.val, q, nq, m) - case *ident: - if q && x.isQualified() { - m[x.s] = struct{}{} - } - if nq && !x.isQualified() { - m[x.s] = struct{}{} - } - case *indexOp: - mentionedColumns0(x.expr, q, nq, m) - mentionedColumns0(x.x, q, nq, m) - case *isNull: - mentionedColumns0(x.expr, q, nq, m) - case *pexpr: - mentionedColumns0(x.expr, q, nq, m) - case *pIn: - mentionedColumns0(x.expr, q, nq, m) - for _, e := range x.list { - mentionedColumns0(e, q, nq, m) - } - case *pLike: - mentionedColumns0(x.expr, q, nq, m) - mentionedColumns0(x.pattern, q, nq, m) - case *slice: - mentionedColumns0(x.expr, q, nq, m) - if y := x.lo; y != nil { - mentionedColumns0(*y, q, nq, m) - } - if y := x.hi; y != nil { - mentionedColumns0(*y, q, nq, m) - } - case *unaryOperation: - mentionedColumns0(x.v, q, nq, m) - default: - panic("internal error 052") - } -} - -func mentionedColumns(e expression) map[string]struct{} { - m := map[string]struct{}{} - mentionedColumns0(e, false, true, m) - return m -} - -func staticExpr(e expression) (expression, error) { - if e.isStatic() { - v, err := e.eval(nil, nil) - if err != nil { - return nil, err - } - - if v == nil { - return value{nil}, nil - } - - return value{v}, nil - } - - return e, nil -} - -type ( - idealComplex complex128 - idealFloat float64 - idealInt int64 - idealRune int32 - idealUint uint64 -) - -type pexpr struct { - expr expression -} - -func (p *pexpr) clone(arg []interface{}, unqualify ...string) (expression, error) { - expr, err := p.expr.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - return &pexpr{expr: expr}, nil -} - -func (p *pexpr) isStatic() bool { return p.expr.isStatic() } - -func (p *pexpr) String() string { - return fmt.Sprintf("(%s)", p.expr) -} - -func (p *pexpr) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - return p.expr.eval(execCtx, ctx) -} - -//DONE newBetween -//LATER like newBetween, check all others have and use new* - -func newBetween(expr, lo, hi interface{}, not bool) (expression, error) { - e, err := staticExpr(expr.(expression)) - if err != nil { - return nil, err - } - - l, err := staticExpr(lo.(expression)) - if err != nil { - return nil, err - } - - h, err := staticExpr(hi.(expression)) - if err != nil { - return nil, err - } - - var a, b expression - op := andand - switch { - case not: // e < l || e > h - op = oror - if a, err = newBinaryOperation('<', e, l); err != nil { - return nil, err - } - - if b, err = newBinaryOperation('>', e, h); err != nil { - return nil, err - } - default: // e >= l && e <= h - if a, err = newBinaryOperation(ge, e, l); err != nil { - return nil, err - } - - if b, err = newBinaryOperation(le, e, h); err != nil { - return nil, err - } - } - - if a, err = staticExpr(a); err != nil { - return nil, err - } - - if b, err = staticExpr(b); err != nil { - return nil, err - } - - ret, err := newBinaryOperation(op, a, b) - if err != nil { - return nil, err - } - - return staticExpr(ret) -} - -type pLike struct { - expr expression - pattern expression - re *regexp.Regexp - sexpr *string -} - -func (p *pLike) clone(arg []interface{}, unqualify ...string) (expression, error) { - expr, err := p.expr.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - pattern, err := p.pattern.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - return &pLike{ - expr: expr, - pattern: pattern, - re: p.re, - sexpr: p.sexpr, - }, nil -} - -func (p *pLike) isStatic() bool { return p.expr.isStatic() && p.pattern.isStatic() } -func (p *pLike) String() string { return fmt.Sprintf("%s LIKE %s", p.expr, p.pattern) } - -func (p *pLike) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - var sexpr string - var ok bool - switch { - case p.sexpr != nil: - sexpr = *p.sexpr - default: - expr, err := expand1(p.expr.eval(execCtx, ctx)) - if err != nil { - return nil, err - } - - if expr == nil { - return nil, nil - } - - sexpr, ok = expr.(string) - if !ok { - return nil, fmt.Errorf("non-string expression in LIKE: %v (value of type %T)", expr, expr) - } - - if p.expr.isStatic() { - p.sexpr = new(string) - *p.sexpr = sexpr - } - } - - re := p.re - if re == nil { - pattern, err := expand1(p.pattern.eval(execCtx, ctx)) - if err != nil { - return nil, err - } - - if pattern == nil { - return nil, nil - } - - spattern, ok := pattern.(string) - if !ok { - return nil, fmt.Errorf("non-string pattern in LIKE: %v (value of type %T)", pattern, pattern) - } - - if re, err = regexp.Compile(spattern); err != nil { - return nil, err - } - - if p.pattern.isStatic() { - p.re = re - } - } - - return re.MatchString(sexpr), nil -} - -type binaryOperation struct { - op int - l, r expression -} - -func newBinaryOperation0(op int, x, y interface{}) (v expression, err error) { - if op == eq { - if l, ok := x.(value); ok { - if b, ok := l.val.(bool); ok { - if b { // true == y: y - return y.(expression), nil - } - - // false == y: !y - return newUnaryOperation('!', y) - } - } - - if r, ok := y.(value); ok { - if b, ok := r.val.(bool); ok { - if b { // x == true: x - return x.(expression), nil - } - - // x == false: !x - return newUnaryOperation('!', x) - } - } - } - - if op == neq { - if l, ok := x.(value); ok { - if b, ok := l.val.(bool); ok { - if b { // true != y: !y - return newUnaryOperation('!', y) - } - - // false != y: y - return y.(expression), nil - } - } - - if r, ok := y.(value); ok { - if b, ok := r.val.(bool); ok { - if b { // x != true: !x - return newUnaryOperation('!', x) - } - - // x != false: x - return x.(expression), nil - } - } - } - - b := binaryOperation{op, x.(expression), y.(expression)} - var lv interface{} - if e := b.l; e.isStatic() { - if lv, err = e.eval(nil, nil); err != nil { - return nil, err - } - - b.l = value{lv} - } - - if e := b.r; e.isStatic() { - v, err := e.eval(nil, nil) - if err != nil { - return nil, err - } - - if v == nil { - return value{nil}, nil - } - - if op == '/' || op == '%' { - rb := binaryOperation{eq, e, value{idealInt(0)}} - val, err := rb.eval(nil, nil) - if err != nil { - return nil, err - } - - if val.(bool) { - return nil, errDivByZero - } - } - - if b.l.isStatic() && lv == nil { - return value{nil}, nil - } - - b.r = value{v} - } - - if !b.isStatic() { - return &b, nil - } - - val, err := b.eval(nil, nil) - return value{val}, err -} - -func newBinaryOperation(op int, x, y interface{}) (v expression, err error) { - expr, err := newBinaryOperation0(op, x, y) - if err != nil { - return nil, err - } - - b, ok := expr.(*binaryOperation) - if !ok { - return expr, nil - } - - if _, ok := b.l.(*ident); ok { - return expr, nil - } - - if c, ok := b.l.(*call); ok && c.f == "id" { - return expr, nil - } - - var r expression - if r, ok = b.r.(*ident); !ok { - r1, ok := b.r.(*call) - if !ok || r1.f != "id" || len(r1.arg) != 0 { - return expr, nil - } - - r = r1 - } - - // Normalize expr relOp indent: ident invRelOp expr - switch b.op { - case '<': - return &binaryOperation{'>', r, b.l}, nil - case le: - return &binaryOperation{ge, r, b.l}, nil - case '>': - return &binaryOperation{'<', r, b.l}, nil - case ge: - return &binaryOperation{le, r, b.l}, nil - case eq, neq: - return &binaryOperation{b.op, r, b.l}, nil - default: - return expr, nil - } -} - -func (o *binaryOperation) isIdentRelOpVal() (bool, string, interface{}, error) { - sid := "" - id, ok := o.l.(*ident) - if !ok { - f, ok := o.l.(*call) - if !ok || f.f != "id" || len(f.arg) != 0 { - return false, "", nil, nil - } - - sid = "id()" - } else { - if id.isQualified() { - return false, "", nil, nil - } - - sid = id.s - } - - if v, ok := o.r.(value); ok { - switch o.op { - case '<', - le, - '>', - ge, - eq, - neq: - return true, sid, v.val, nil - default: - return false, "", nil, nil - } - } - - return false, "", nil, nil -} - -func (o *binaryOperation) clone(arg []interface{}, unqualify ...string) (expression, error) { - l, err := o.l.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - r, err := o.r.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - return newBinaryOperation(o.op, l, r) -} - -func (o *binaryOperation) isStatic() bool { return o.l.isStatic() && o.r.isStatic() } - -func (o *binaryOperation) String() string { - return fmt.Sprintf("%s %s %s", o.l, iop(o.op), o.r) -} - -func (o *binaryOperation) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (r interface{}, err error) { - defer func() { - if e := recover(); e != nil { - switch x := e.(type) { - case error: - r, err = nil, x - default: - r, err = nil, fmt.Errorf("%v", x) - } - } - }() - - switch op := o.op; op { - case andand: - a, err := expand1(o.l.eval(execCtx, ctx)) - if err != nil { - return nil, err - } - - switch x := a.(type) { - case nil: - b, err := expand1(o.r.eval(execCtx, ctx)) - if err != nil { - return nil, err - } - - switch y := b.(type) { - case nil: - return nil, nil - case bool: - if !y { - return false, nil - } - - return nil, nil - default: - return invOp2(x, y, op) - } - case bool: - if !x { - return false, nil - } - - b, err := expand1(o.r.eval(execCtx, ctx)) - if err != nil { - return nil, err - } - - switch y := b.(type) { - case nil: - return nil, nil - case bool: - return y, nil - default: - return invOp2(x, y, op) - } - default: - return undOp(x, op) - } - case oror: - a, err := expand1(o.l.eval(execCtx, ctx)) - if err != nil { - return nil, err - } - - switch x := a.(type) { - case nil: - b, err := expand1(o.r.eval(execCtx, ctx)) - if err != nil { - return nil, err - } - - switch y := b.(type) { - case nil: - return nil, nil - case bool: - if y { - return y, nil - } - - return nil, nil - default: - return invOp2(x, y, op) - } - case bool: - if x { - return x, nil - } - - b, err := expand1(o.r.eval(execCtx, ctx)) - if err != nil { - return nil, err - } - - switch y := b.(type) { - case nil: - return nil, nil - case bool: - return y, nil - default: - return invOp2(x, y, op) - } - default: - return undOp(x, op) - } - case '>': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - switch y := b.(type) { - case idealFloat: - return x > y, nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return x > y, nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return x > y, nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return x > y, nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - switch y := b.(type) { - case float32: - return x > y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x > y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x > y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x > y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x > y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x > y, nil - default: - return invOp2(x, y, op) - } - case string: - switch y := b.(type) { - case string: - return x > y, nil - default: - return invOp2(x, y, op) - } - case uint8: - switch y := b.(type) { - case uint8: - return x > y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x > y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x > y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x > y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - return x.Cmp(y) > 0, nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - return x.Cmp(y) > 0, nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x > y, nil - default: - return invOp2(x, y, op) - } - case time.Time: - switch y := b.(type) { - case time.Time: - return x.After(y), nil - default: - return invOp2(x, y, op) - } - case []byte: - switch y := b.(type) { - case []byte: - return bytes.Equal(x, y), nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case '<': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - switch y := b.(type) { - case idealFloat: - return x < y, nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return x < y, nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return x < y, nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return x < y, nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - switch y := b.(type) { - case float32: - return x < y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x < y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x < y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x < y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x < y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x < y, nil - default: - return invOp2(x, y, op) - } - case string: - switch y := b.(type) { - case string: - return x < y, nil - default: - return invOp2(x, y, op) - } - case uint8: - switch y := b.(type) { - case uint8: - return x < y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x < y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x < y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x < y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - return x.Cmp(y) < 0, nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - return x.Cmp(y) < 0, nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x < y, nil - default: - return invOp2(x, y, op) - } - case time.Time: - switch y := b.(type) { - case time.Time: - return x.Before(y), nil - default: - return invOp2(x, y, op) - } - case []byte: - switch y := b.(type) { - case []byte: - return bytes.Compare(x, y) < 0, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case le: - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - switch y := b.(type) { - case idealFloat: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - switch y := b.(type) { - case float32: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case string: - switch y := b.(type) { - case string: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case uint8: - switch y := b.(type) { - case uint8: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - return x.Cmp(y) <= 0, nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - return x.Cmp(y) <= 0, nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x <= y, nil - default: - return invOp2(x, y, op) - } - case time.Time: - switch y := b.(type) { - case time.Time: - return x.Before(y) || x.Equal(y), nil - default: - return invOp2(x, y, op) - } - case []byte: - switch y := b.(type) { - case []byte: - return bytes.Compare(x, y) <= 0, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case ge: - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - switch y := b.(type) { - case idealFloat: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - switch y := b.(type) { - case float32: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case string: - switch y := b.(type) { - case string: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case uint8: - switch y := b.(type) { - case uint8: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - return x.Cmp(y) >= 0, nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - return x.Cmp(y) >= 0, nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x >= y, nil - default: - return invOp2(x, y, op) - } - case time.Time: - switch y := b.(type) { - case time.Time: - return x.After(y) || x.Equal(y), nil - default: - return invOp2(x, y, op) - } - case []byte: - switch y := b.(type) { - case []byte: - return bytes.Compare(x, y) >= 0, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case neq: - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - switch y := b.(type) { - case idealComplex: - return x != y, nil - default: - return invOp2(x, y, op) - } - case idealFloat: - switch y := b.(type) { - case idealFloat: - return x != y, nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return x != y, nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return x != y, nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return x != y, nil - default: - return invOp2(x, y, op) - } - case bool: - switch y := b.(type) { - case bool: - return x != y, nil - default: - return invOp2(x, y, op) - } - case complex64: - switch y := b.(type) { - case complex64: - return x != y, nil - default: - return invOp2(x, y, op) - } - case complex128: - switch y := b.(type) { - case complex128: - return x != y, nil - default: - return invOp2(x, y, op) - } - case float32: - switch y := b.(type) { - case float32: - return x != y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x != y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x != y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x != y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x != y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x != y, nil - default: - return invOp2(x, y, op) - } - case string: - switch y := b.(type) { - case string: - return x != y, nil - default: - return invOp2(x, y, op) - } - case uint8: - switch y := b.(type) { - case uint8: - return x != y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x != y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x != y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x != y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - return x.Cmp(y) != 0, nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - return x.Cmp(y) != 0, nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x != y, nil - default: - return invOp2(x, y, op) - } - case time.Time: - switch y := b.(type) { - case time.Time: - return !x.Equal(y), nil - default: - return invOp2(x, y, op) - } - case []byte: - switch y := b.(type) { - case []byte: - return !bytes.Equal(x, y), nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case eq: - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - switch y := b.(type) { - case idealComplex: - return x == y, nil - default: - return invOp2(x, y, op) - } - case idealFloat: - switch y := b.(type) { - case idealFloat: - return x == y, nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return x == y, nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return x == y, nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return x == y, nil - default: - return invOp2(x, y, op) - } - case bool: - switch y := b.(type) { - case bool: - return x == y, nil - default: - return invOp2(x, y, op) - } - case complex64: - switch y := b.(type) { - case complex64: - return x == y, nil - default: - return invOp2(x, y, op) - } - case complex128: - switch y := b.(type) { - case complex128: - return x == y, nil - default: - return invOp2(x, y, op) - } - case float32: - switch y := b.(type) { - case float32: - return x == y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x == y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x == y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x == y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x == y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x == y, nil - default: - return invOp2(x, y, op) - } - case string: - switch y := b.(type) { - case string: - return x == y, nil - default: - return invOp2(x, y, op) - } - case uint8: - switch y := b.(type) { - case uint8: - return x == y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x == y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x == y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x == y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - return x.Cmp(y) == 0, nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - return x.Cmp(y) == 0, nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x == y, nil - default: - return invOp2(x, y, op) - } - case time.Time: - switch y := b.(type) { - case time.Time: - return x.Equal(y), nil - default: - return invOp2(x, y, op) - } - case []byte: - switch y := b.(type) { - case []byte: - return bytes.Equal(x, y), nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case '+': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - switch y := b.(type) { - case idealComplex: - return idealComplex(complex64(x) + complex64(y)), nil - default: - return invOp2(x, y, op) - } - case idealFloat: - switch y := b.(type) { - case idealFloat: - return idealFloat(float64(x) + float64(y)), nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return idealInt(int64(x) + int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return idealRune(int64(x) + int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return idealUint(uint64(x) + uint64(y)), nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - switch y := b.(type) { - case complex64: - return x + y, nil - default: - return invOp2(x, y, op) - } - case complex128: - switch y := b.(type) { - case complex128: - return x + y, nil - default: - return invOp2(x, y, op) - } - case float32: - switch y := b.(type) { - case float32: - return x + y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x + y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x + y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x + y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x + y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x + y, nil - default: - return invOp2(x, y, op) - } - case string: - switch y := b.(type) { - case string: - return x + y, nil - default: - return invOp2(x, y, op) - } - case uint8: - switch y := b.(type) { - case uint8: - return x + y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x + y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x + y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x + y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - var z big.Int - return z.Add(x, y), nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - var z big.Rat - return z.Add(x, y), nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x + y, nil - case time.Time: - return y.Add(x), nil - default: - return invOp2(x, y, op) - } - case time.Time: - switch y := b.(type) { - case time.Duration: - return x.Add(y), nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case '-': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - switch y := b.(type) { - case idealComplex: - return idealComplex(complex64(x) - complex64(y)), nil - default: - return invOp2(x, y, op) - } - case idealFloat: - switch y := b.(type) { - case idealFloat: - return idealFloat(float64(x) - float64(y)), nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return idealInt(int64(x) - int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return idealRune(int64(x) - int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return idealUint(uint64(x) - uint64(y)), nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - switch y := b.(type) { - case complex64: - return x - y, nil - default: - return invOp2(x, y, op) - } - case complex128: - switch y := b.(type) { - case complex128: - return x - y, nil - default: - return invOp2(x, y, op) - } - case float32: - switch y := b.(type) { - case float32: - return x - y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x - y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x - y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x - y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x - y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x - y, nil - default: - return invOp2(x, y, op) - } - case string: - return undOp2(a, b, op) - case uint8: - switch y := b.(type) { - case uint8: - return x - y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x - y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x - y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x - y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - var z big.Int - return z.Sub(x, y), nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - var z big.Rat - return z.Sub(x, y), nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x - y, nil - default: - return invOp2(x, y, op) - } - case time.Time: - switch y := b.(type) { - case time.Duration: - return x.Add(-y), nil - case time.Time: - return x.Sub(y), nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case rsh: - a, b := eval2(o.l, o.r, execCtx, ctx) - if a == nil || b == nil { - return - } - - var cnt uint64 - switch y := b.(type) { - //case nil: - case idealComplex: - return invShiftRHS(a, b) - case idealFloat: - return invShiftRHS(a, b) - case idealInt: - cnt = uint64(y) - case idealRune: - cnt = uint64(y) - case idealUint: - cnt = uint64(y) - case bool: - return invShiftRHS(a, b) - case complex64: - return invShiftRHS(a, b) - case complex128: - return invShiftRHS(a, b) - case float32: - return invShiftRHS(a, b) - case float64: - return invShiftRHS(a, b) - case int8: - return invShiftRHS(a, b) - case int16: - return invShiftRHS(a, b) - case int32: - return invShiftRHS(a, b) - case int64: - return invShiftRHS(a, b) - case string: - return invShiftRHS(a, b) - case uint8: - cnt = uint64(y) - case uint16: - cnt = uint64(y) - case uint32: - cnt = uint64(y) - case uint64: - cnt = y - default: - return invOp2(a, b, op) - } - - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - return undOp2(a, b, op) - case idealInt: - return idealInt(int64(x) >> cnt), nil - case idealRune: - return idealRune(int64(x) >> cnt), nil - case idealUint: - return idealUint(uint64(x) >> cnt), nil - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - return undOp2(a, b, op) - case float64: - return undOp2(a, b, op) - case int8: - return x >> cnt, nil - case int16: - return x >> cnt, nil - case int32: - return x >> cnt, nil - case int64: - return x >> cnt, nil - case string: - return undOp2(a, b, op) - case uint8: - return x >> cnt, nil - case uint16: - return x >> cnt, nil - case uint32: - return x >> cnt, nil - case uint64: - return x >> cnt, nil - case *big.Int: - var z big.Int - return z.Rsh(x, uint(cnt)), nil - case time.Duration: - return x >> cnt, nil - default: - return invOp2(a, b, op) - } - case lsh: - a, b := eval2(o.l, o.r, execCtx, ctx) - if a == nil || b == nil { - return - } - - var cnt uint64 - switch y := b.(type) { - //case nil: - case idealComplex: - return invShiftRHS(a, b) - case idealFloat: - return invShiftRHS(a, b) - case idealInt: - cnt = uint64(y) - case idealRune: - cnt = uint64(y) - case idealUint: - cnt = uint64(y) - case bool: - return invShiftRHS(a, b) - case complex64: - return invShiftRHS(a, b) - case complex128: - return invShiftRHS(a, b) - case float32: - return invShiftRHS(a, b) - case float64: - return invShiftRHS(a, b) - case int8: - return invShiftRHS(a, b) - case int16: - return invShiftRHS(a, b) - case int32: - return invShiftRHS(a, b) - case int64: - return invShiftRHS(a, b) - case string: - return invShiftRHS(a, b) - case uint8: - cnt = uint64(y) - case uint16: - cnt = uint64(y) - case uint32: - cnt = uint64(y) - case uint64: - cnt = y - default: - return invOp2(a, b, op) - } - - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - return undOp2(a, b, op) - case idealInt: - return idealInt(int64(x) << cnt), nil - case idealRune: - return idealRune(int64(x) << cnt), nil - case idealUint: - return idealUint(uint64(x) << cnt), nil - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - return undOp2(a, b, op) - case float64: - return undOp2(a, b, op) - case int8: - return x << cnt, nil - case int16: - return x << cnt, nil - case int32: - return x << cnt, nil - case int64: - return x << cnt, nil - case string: - return undOp2(a, b, op) - case uint8: - return x << cnt, nil - case uint16: - return x << cnt, nil - case uint32: - return x << cnt, nil - case uint64: - return x << cnt, nil - case *big.Int: - var z big.Int - return z.Lsh(x, uint(cnt)), nil - case time.Duration: - return x << cnt, nil - default: - return invOp2(a, b, op) - } - case '&': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - return undOp2(a, b, op) - case idealInt: - switch y := b.(type) { - case idealInt: - return idealInt(int64(x) & int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return idealRune(int64(x) & int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return idealUint(uint64(x) & uint64(y)), nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - return undOp2(a, b, op) - case float64: - return undOp2(a, b, op) - case int8: - switch y := b.(type) { - case int8: - return x & y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x & y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x & y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x & y, nil - default: - return invOp2(x, y, op) - } - case string: - return undOp2(a, b, op) - case uint8: - switch y := b.(type) { - case uint8: - return x & y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x & y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x & y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x & y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - var z big.Int - return z.And(x, y), nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x & y, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case '|': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - return undOp2(a, b, op) - case idealInt: - switch y := b.(type) { - case idealInt: - return idealInt(int64(x) | int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return idealRune(int64(x) | int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return idealUint(uint64(x) | uint64(y)), nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - return undOp2(a, b, op) - case float64: - return undOp2(a, b, op) - case int8: - switch y := b.(type) { - case int8: - return x | y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x | y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x | y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x | y, nil - default: - return invOp2(x, y, op) - } - case string: - return undOp2(a, b, op) - case uint8: - switch y := b.(type) { - case uint8: - return x | y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x | y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x | y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x | y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - var z big.Int - return z.Or(x, y), nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x | y, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case andnot: - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - return undOp2(a, b, op) - case idealInt: - switch y := b.(type) { - case idealInt: - return idealInt(int64(x) &^ int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return idealRune(int64(x) &^ int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return idealUint(uint64(x) &^ uint64(y)), nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - return undOp2(a, b, op) - case float64: - return undOp2(a, b, op) - case int8: - switch y := b.(type) { - case int8: - return x &^ y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x &^ y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x &^ y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x &^ y, nil - default: - return invOp2(x, y, op) - } - case string: - return undOp2(a, b, op) - case uint8: - switch y := b.(type) { - case uint8: - return x &^ y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x &^ y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x &^ y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x &^ y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - var z big.Int - return z.AndNot(x, y), nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x &^ y, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case '^': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - return undOp2(a, b, op) - case idealInt: - switch y := b.(type) { - case idealInt: - return idealInt(int64(x) ^ int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return idealRune(int64(x) ^ int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return idealUint(uint64(x) ^ uint64(y)), nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - return undOp2(a, b, op) - case float64: - return undOp2(a, b, op) - case int8: - switch y := b.(type) { - case int8: - return x ^ y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x ^ y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x ^ y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x ^ y, nil - default: - return invOp2(x, y, op) - } - case string: - return undOp2(a, b, op) - case uint8: - switch y := b.(type) { - case uint8: - return x ^ y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x ^ y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x ^ y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x ^ y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - var z big.Int - return z.Xor(x, y), nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x ^ y, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case '%': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp2(a, b, op) - case idealFloat: - return undOp2(a, b, op) - case idealInt: - switch y := b.(type) { - case idealInt: - return idealInt(int64(x) % int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return idealRune(int64(x) % int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return idealUint(uint64(x) % uint64(y)), nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - return undOp2(a, b, op) - case complex128: - return undOp2(a, b, op) - case float32: - return undOp2(a, b, op) - case float64: - return undOp2(a, b, op) - case int8: - switch y := b.(type) { - case int8: - return x % y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x % y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x % y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x % y, nil - default: - return invOp2(x, y, op) - } - case string: - return undOp2(a, b, op) - case uint8: - switch y := b.(type) { - case uint8: - return x % y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x % y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x % y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x % y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - if y.Sign() == 0 { - return nil, errDivByZero - } - - var z big.Int - return z.Mod(x, y), nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x % y, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case '/': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - switch y := b.(type) { - case idealComplex: - return idealComplex(complex64(x) / complex64(y)), nil - default: - return invOp2(x, y, op) - } - case idealFloat: - switch y := b.(type) { - case idealFloat: - return idealFloat(float64(x) / float64(y)), nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return idealInt(int64(x) / int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return idealRune(int64(x) / int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return idealUint(uint64(x) / uint64(y)), nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - switch y := b.(type) { - case complex64: - return x / y, nil - default: - return invOp2(x, y, op) - } - case complex128: - switch y := b.(type) { - case complex128: - return x / y, nil - default: - return invOp2(x, y, op) - } - case float32: - switch y := b.(type) { - case float32: - return x / y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x / y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x / y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x / y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x / y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x / y, nil - default: - return invOp2(x, y, op) - } - case string: - return undOp2(a, b, op) - case uint8: - switch y := b.(type) { - case uint8: - return x / y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x / y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x / y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x / y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - if y.Sign() == 0 { - return nil, errDivByZero - } - - var z big.Int - return z.Quo(x, y), nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - if y.Sign() == 0 { - return nil, errDivByZero - } - - var z big.Rat - return z.Quo(x, y), nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x / y, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - case '*': - a, b := o.get2(execCtx, ctx) - if a == nil || b == nil { - return - } - switch x := a.(type) { - //case nil: - case idealComplex: - switch y := b.(type) { - case idealComplex: - return idealComplex(complex64(x) * complex64(y)), nil - default: - return invOp2(x, y, op) - } - case idealFloat: - switch y := b.(type) { - case idealFloat: - return idealFloat(float64(x) * float64(y)), nil - default: - return invOp2(x, y, op) - } - case idealInt: - switch y := b.(type) { - case idealInt: - return idealInt(int64(x) * int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealRune: - switch y := b.(type) { - case idealRune: - return idealRune(int64(x) * int64(y)), nil - default: - return invOp2(x, y, op) - } - case idealUint: - switch y := b.(type) { - case idealUint: - return idealUint(uint64(x) * uint64(y)), nil - default: - return invOp2(x, y, op) - } - case bool: - return undOp2(a, b, op) - case complex64: - switch y := b.(type) { - case complex64: - return x * y, nil - default: - return invOp2(x, y, op) - } - case complex128: - switch y := b.(type) { - case complex128: - return x * y, nil - default: - return invOp2(x, y, op) - } - case float32: - switch y := b.(type) { - case float32: - return x * y, nil - default: - return invOp2(x, y, op) - } - case float64: - switch y := b.(type) { - case float64: - return x * y, nil - default: - return invOp2(x, y, op) - } - case int8: - switch y := b.(type) { - case int8: - return x * y, nil - default: - return invOp2(x, y, op) - } - case int16: - switch y := b.(type) { - case int16: - return x * y, nil - default: - return invOp2(x, y, op) - } - case int32: - switch y := b.(type) { - case int32: - return x * y, nil - default: - return invOp2(x, y, op) - } - case int64: - switch y := b.(type) { - case int64: - return x * y, nil - default: - return invOp2(x, y, op) - } - case string: - return undOp2(a, b, op) - case uint8: - switch y := b.(type) { - case uint8: - return x * y, nil - default: - return invOp2(x, y, op) - } - case uint16: - switch y := b.(type) { - case uint16: - return x * y, nil - default: - return invOp2(x, y, op) - } - case uint32: - switch y := b.(type) { - case uint32: - return x * y, nil - default: - return invOp2(x, y, op) - } - case uint64: - switch y := b.(type) { - case uint64: - return x * y, nil - default: - return invOp2(x, y, op) - } - case *big.Int: - switch y := b.(type) { - case *big.Int: - var z big.Int - return z.Mul(x, y), nil - default: - return invOp2(x, y, op) - } - case *big.Rat: - switch y := b.(type) { - case *big.Rat: - var z big.Rat - return z.Mul(x, y), nil - default: - return invOp2(x, y, op) - } - case time.Duration: - switch y := b.(type) { - case time.Duration: - return x * y, nil - default: - return invOp2(x, y, op) - } - default: - return invOp2(a, b, op) - } - default: - panic("internal error 037") - } -} - -func (o *binaryOperation) get2(execCtx *execCtx, ctx map[interface{}]interface{}) (x, y interface{}) { - x, y = eval2(o.l, o.r, execCtx, ctx) - //dbg("get2 pIn - ", x, y) - //defer func() {dbg("get2 coerced ", x, y)}() - return coerce(x, y) -} - -type ident struct { - s string -} - -func (i *ident) clone(arg []interface{}, unqualify ...string) (expression, error) { - x := strings.IndexByte(i.s, '.') - if x < 0 { - return &ident{s: i.s}, nil - } - - q := i.s[:x] - for _, v := range unqualify { - if q == v { - return &ident{i.s[x+1:]}, nil - } - } - return &ident{s: i.s}, nil -} - -func (i *ident) isQualified() bool { return strings.Contains(i.s, ".") } - -func (i *ident) isStatic() bool { return false } - -func (i *ident) String() string { return i.s } - -func (i *ident) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - if _, ok := ctx["$agg0"]; ok { - return int64(0), nil - } - - //defer func() { dbg("ident %q -> %v %v", i.s, v, err) }() - v, ok := ctx[i.s] - if !ok { - err = fmt.Errorf("unknown field %s", i.s) - } - return -} - -type pInEval struct { - m map[interface{}]struct{} // IN (SELECT...) results - sample interface{} -} - -type pIn struct { - expr expression - list []expression - not bool - sel *selectStmt -} - -func (n *pIn) clone(arg []interface{}, unqualify ...string) (expression, error) { - expr, err := n.expr.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - list, err := cloneExpressionList(arg, n.list) - if err != nil { - return nil, err - } - - return &pIn{ - expr: expr, - list: list, - not: n.not, - sel: n.sel, - }, nil -} - -func (n *pIn) isStatic() bool { - if !n.expr.isStatic() || n.sel != nil { - return false - } - - for _, v := range n.list { - if !v.isStatic() { - return false - } - } - return true -} - -//LATER newIn - -func (n *pIn) String() string { - if n.sel == nil { - a := []string{} - for _, v := range n.list { - a = append(a, v.String()) - } - if n.not { - return fmt.Sprintf("%s NOT IN (%s)", n.expr, strings.Join(a, ",")) - } - - return fmt.Sprintf("%s IN (%s)", n.expr, strings.Join(a, ",")) - } - - if n.not { - return fmt.Sprintf("%s NOT IN (%s)", n.expr, n.sel) - } - - return fmt.Sprintf("%s IN (%s)", n.expr, n.sel) -} - -func (n *pIn) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - lhs, err := expand1(n.expr.eval(execCtx, ctx)) - if err != nil { - return nil, err - } - - if lhs == nil { - return nil, nil //TODO Add test for NULL LHS. - } - - if n.sel == nil { - for _, v := range n.list { - b, err := newBinaryOperation(eq, value{lhs}, v) - if err != nil { - return nil, err - } - - eval, err := b.eval(execCtx, ctx) - if err != nil { - return nil, err - } - - if x, ok := eval.(bool); ok && x { - return !n.not, nil - } - } - return n.not, nil - } - - var ev *pInEval - ev0 := ctx[n] - if ev0 == nil { // SELECT not yet evaluated. - r, err := n.sel.plan(execCtx) - if err != nil { - return nil, err - } - - if g, e := len(r.fieldNames()), 1; g != e { - return false, fmt.Errorf("IN (%s): mismatched field count, have %d, need %d", n.sel, g, e) - } - - ev = &pInEval{m: map[interface{}]struct{}{}} - ctx[n] = ev - m := ev.m - typechecked := false - if err := r.do(execCtx, func(id interface{}, data []interface{}) (more bool, err error) { - if typechecked { - if data[0] == nil { - return true, nil - } - - m[data[0]] = struct{}{} - } - - if data[0] == nil { - return true, nil - } - - ev.sample = data[0] - switch ev.sample.(type) { - case bool, byte, complex128, complex64, float32, - float64, int16, int32, int64, int8, - string, uint16, uint32, uint64: - typechecked = true - m[ev.sample] = struct{}{} - return true, nil - default: - return false, fmt.Errorf("IN (%s): invalid field type: %T", n.sel, data[0]) - } - - }); err != nil { - return nil, err - } - } else { - ev = ev0.(*pInEval) - } - - if ev.sample == nil { - return nil, nil - } - - _, ok := ev.m[coerce1(lhs, ev.sample)] - return ok != n.not, nil -} - -type value struct { - val interface{} -} - -func (l value) clone(arg []interface{}, unqualify ...string) (expression, error) { - return value{val: l.val}, nil -} - -func (l value) isStatic() bool { return true } - -func (l value) String() string { - switch x := l.val.(type) { - case nil: - return "NULL" - case idealComplex: - s := fmt.Sprint(x) - return s[1 : len(s)-1] - case complex64: - s := fmt.Sprint(x) - return s[1 : len(s)-1] - case complex128: - s := fmt.Sprint(x) - return s[1 : len(s)-1] - case string: - return fmt.Sprintf("%q", x) - case time.Duration: - return fmt.Sprintf("duration(%q)", l.val) - case time.Time: - y, m, d := x.Date() - zone, _ := x.Zone() - return fmt.Sprintf("date(%v, %v, %v, %v, %v, %v, %v, %v)", y, m, d, x.Hour(), x.Minute(), x.Second(), x.Nanosecond(), zone) - case *big.Rat: - return fmt.Sprintf("bigrat(%q)", l.val) - case *big.Int: - return fmt.Sprintf(`bigint("%v")`, l.val) - default: - return fmt.Sprintf("%v", l.val) - } -} - -func (l value) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (interface{}, error) { - return l.val, nil -} - -type conversion struct { - typ int - val expression -} - -func (c *conversion) clone(arg []interface{}, unqualify ...string) (expression, error) { - val, err := c.val.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - return &conversion{typ: c.typ, val: val}, nil -} - -func (c *conversion) isStatic() bool { - return c.val.isStatic() -} - -//LATER newConversion or fake unary op - -func (c *conversion) String() string { - return fmt.Sprintf("%s(%s)", typeStr(c.typ), c.val) -} - -func (c *conversion) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - val, err := expand1(c.val.eval(execCtx, ctx)) - if err != nil { - return - } - - return convert(val, c.typ) -} - -type unaryOperation struct { - op int - v expression -} - -func newUnaryOperation(op int, x interface{}) (v expression, err error) { - l, ok := x.(expression) - if !ok { - panic("internal error 038") - } - - for { - pe, ok := l.(*pexpr) - if ok { - l = pe.expr - continue - } - - break - } - - if l.isStatic() { - val, err := l.eval(nil, nil) - if err != nil { - return nil, err - } - - l = value{val} - } - - if op == '!' { - b, ok := l.(*binaryOperation) - if ok { - switch b.op { - case eq: - b.op = neq - return b, nil - case neq: - b.op = eq - return b, nil - case '>': - b.op = le - return b, nil - case ge: - b.op = '<' - return b, nil - case '<': - b.op = ge - return b, nil - case le: - b.op = '>' - return b, nil - } - } - - u, ok := l.(*unaryOperation) - if ok && u.op == '!' { // !!x: x - return u.v, nil - } - } - - return &unaryOperation{op, l}, nil -} - -func (u *unaryOperation) clone(arg []interface{}, unqualify ...string) (expression, error) { - v, err := u.v.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - return &unaryOperation{op: u.op, v: v}, nil -} - -func (u *unaryOperation) isStatic() bool { return u.v.isStatic() } - -func (u *unaryOperation) String() string { - switch u.v.(type) { - case *binaryOperation: - return fmt.Sprintf("%s(%s)", iop(u.op), u.v) - default: - return fmt.Sprintf("%s%s", iop(u.op), u.v) - } -} - -func (u *unaryOperation) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (r interface{}, err error) { - defer func() { - if e := recover(); e != nil { - switch x := e.(type) { - case error: - r, err = nil, x - default: - r, err = nil, fmt.Errorf("%v", x) - } - } - }() - - switch op := u.op; op { - case '!': - a := eval(u.v, execCtx, ctx) - if a == nil { - return - } - - switch x := a.(type) { - case bool: - return !x, nil - default: - return undOp(a, op) - } - case '^': - a := eval(u.v, execCtx, ctx) - if a == nil { - return - } - - switch x := a.(type) { - //case nil: - case idealComplex: - return undOp(a, op) - case idealFloat: - return undOp(a, op) - case idealInt: - return ^x, nil - case idealRune: - return ^x, nil - case idealUint: - return ^x, nil - case bool: - return undOp(a, op) - case complex64: - return undOp(a, op) - case complex128: - return undOp(a, op) - case float32: - return undOp(a, op) - case float64: - return undOp(a, op) - case int8: - return ^x, nil - case int16: - return ^x, nil - case int32: - return ^x, nil - case int64: - return ^x, nil - case string: - return undOp(a, op) - case uint8: - return ^x, nil - case uint16: - return ^x, nil - case uint32: - return ^x, nil - case uint64: - return ^x, nil - case *big.Int: - var z big.Int - return z.Not(x), nil - case time.Duration: - return ^x, nil - default: - return undOp(a, op) - } - case '+': - a := eval(u.v, execCtx, ctx) - if a == nil { - return - } - - switch x := a.(type) { - //case nil: - case idealComplex: - return +x, nil - case idealFloat: - return +x, nil - case idealInt: - return +x, nil - case idealRune: - return +x, nil - case idealUint: - return +x, nil - case bool: - return undOp(a, op) - case complex64: - return +x, nil - case complex128: - return +x, nil - case float32: - return +x, nil - case float64: - return +x, nil - case int8: - return +x, nil - case int16: - return +x, nil - case int32: - return +x, nil - case int64: - return +x, nil - case string: - return undOp(a, op) - case uint8: - return +x, nil - case uint16: - return +x, nil - case uint32: - return +x, nil - case uint64: - return +x, nil - case *big.Int: - var z big.Int - return z.Set(x), nil - case *big.Rat: - var z big.Rat - return z.Set(x), nil - case time.Duration: - return x, nil - default: - return undOp(a, op) - } - case '-': - a := eval(u.v, execCtx, ctx) - if a == nil { - return - } - - switch x := a.(type) { - //case nil: - case idealComplex: - return -x, nil - case idealFloat: - return -x, nil - case idealInt: - return -x, nil - case idealRune: - return -x, nil - case idealUint: - return -x, nil - case bool: - return undOp(a, op) - case complex64: - return -x, nil - case complex128: - return -x, nil - case float32: - return -x, nil - case float64: - return -x, nil - case int8: - return -x, nil - case int16: - return -x, nil - case int32: - return -x, nil - case int64: - return -x, nil - case string: - return undOp(a, op) - case uint8: - return -x, nil - case uint16: - return -x, nil - case uint32: - return -x, nil - case uint64: - return -x, nil - case *big.Int: - var z big.Int - return z.Neg(x), nil - case *big.Rat: - var z big.Rat - return z.Neg(x), nil - case time.Duration: - return -x, nil - default: - return undOp(a, op) - } - default: - panic("internal error 039") - } -} - -type call struct { - f string - arg []expression -} - -func newCall(f string, arg []expression) (v expression, isAgg bool, err error) { - x := builtin[f] - if x.f == nil { - return nil, false, fmt.Errorf("undefined: %s", f) - } - - isAgg = x.isAggregate - if g, min, max := len(arg), x.minArgs, x.maxArgs; g < min || g > max { - a := []interface{}{} - for _, v := range arg { - a = append(a, v) - } - return nil, false, badNArgs(min, f, a) - } - - c := call{f: f} - for _, val := range arg { - if !val.isStatic() { - c.arg = append(c.arg, val) - continue - } - - eval, err := val.eval(nil, nil) - if err != nil { - return nil, isAgg, err - } - - c.arg = append(c.arg, value{eval}) - } - - return &c, isAgg, nil -} - -func (c *call) clone(arg []interface{}, unqualify ...string) (expression, error) { - list, err := cloneExpressionList(arg, c.arg) - if err != nil { - return nil, err - } - - return &call{f: c.f, arg: list}, nil -} - -func (c *call) isStatic() bool { - v := builtin[c.f] - if v.f == nil || !v.isStatic { - return false - } - - for _, v := range c.arg { - if !v.isStatic() { - return false - } - } - return true -} - -func (c *call) String() string { - a := []string{} - for _, v := range c.arg { - a = append(a, v.String()) - } - return fmt.Sprintf("%s(%s)", c.f, strings.Join(a, ", ")) -} - -func (c *call) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - f, ok := builtin[c.f] - if !ok { - return nil, fmt.Errorf("unknown function %s", c.f) - } - - isID := c.f == "id" - a := make([]interface{}, len(c.arg)) - for i, arg := range c.arg { - if v, err = expand1(arg.eval(execCtx, ctx)); err != nil { - if !isID { - return nil, err - } - - if _, ok := arg.(*ident); !ok { - return nil, err - } - - a[i] = arg - continue - } - - a[i] = v - } - - if ctx != nil { - ctx["$fn"] = c - } - return f.f(a, ctx) -} - -type parameter struct { - n int -} - -func (p parameter) clone(arg []interface{}, unqualify ...string) (expression, error) { - i := p.n - 1 - if i < len(arg) { - return value{val: arg[i]}, nil - } - - return nil, fmt.Errorf("missing %s", p) -} - -func (parameter) isStatic() bool { return false } - -func (p parameter) String() string { return fmt.Sprintf("$%d", p.n) } - -func (p parameter) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - i := p.n - 1 - if i < len(execCtx.arg) { - return execCtx.arg[i], nil - } - - return nil, fmt.Errorf("missing %s", p) -} - -//MAYBE make it an unary operation -type isNull struct { - expr expression - not bool -} - -//LATER newIsNull - -func (is *isNull) clone(arg []interface{}, unqualify ...string) (expression, error) { - expr, err := is.expr.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - return &isNull{expr: expr, not: is.not}, nil -} - -func (is *isNull) isStatic() bool { return is.expr.isStatic() } - -func (is *isNull) String() string { - if is.not { - return fmt.Sprintf("%s IS NOT NULL", is.expr) - } - - return fmt.Sprintf("%s IS NULL", is.expr) -} - -func (is *isNull) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - val, err := is.expr.eval(execCtx, ctx) - if err != nil { - return - } - - return val == nil != is.not, nil -} - -type indexOp struct { - expr, x expression -} - -func newIndex(sv, xv expression) (v expression, err error) { - s, fs, i := "", false, uint64(0) - x := indexOp{sv, xv} - if x.expr.isStatic() { - v, err := x.expr.eval(nil, nil) - if err != nil { - return nil, err - } - - if v == nil { - return value{nil}, nil - } - - if s, fs = v.(string); !fs { - return nil, invXOp(sv, xv) - } - - x.expr = value{s} - } - - if x.x.isStatic() { - v, err := x.x.eval(nil, nil) - if err != nil { - return nil, err - } - - if v == nil { - return value{nil}, nil - } - - var p *string - if fs { - p = &s - } - if i, err = indexExpr(p, v); err != nil { - return nil, err - } - - x.x = value{i} - } - - return &x, nil -} - -func (x *indexOp) clone(arg []interface{}, unqualify ...string) (expression, error) { - expr, err := x.expr.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - x2, err := x.x.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - return &indexOp{expr: expr, x: x2}, nil -} - -func (x *indexOp) isStatic() bool { - return x.expr.isStatic() && x.x.isStatic() -} - -func (x *indexOp) String() string { return fmt.Sprintf("%s[%s]", x.expr, x.x) } - -func (x *indexOp) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - s0, err := x.expr.eval(execCtx, ctx) - if err != nil { - return nil, runErr(err) - } - - s, ok := s0.(string) - if !ok { - return nil, runErr(invXOp(s0, x.x)) - } - - i0, err := x.x.eval(execCtx, ctx) - if err != nil { - return nil, runErr(err) - } - - if i0 == nil { - return nil, nil - } - - i, err := indexExpr(&s, i0) - if err != nil { - return nil, runErr(err) - } - - return s[i], nil -} - -type slice struct { - expr expression - lo, hi *expression -} - -func newSlice(e expression, lo, hi *expression) (v expression, err error) { - y := slice{e, lo, hi} - var val interface{} - if e := y.expr; e.isStatic() { - if val, err = e.eval(nil, nil); err != nil { - return nil, err - } - - if val == nil { - return value{nil}, nil - } - - y.expr = value{val} - } - - if p := y.lo; p != nil { - if e := expr(*p); e.isStatic() { - if val, err = e.eval(nil, nil); err != nil { - return nil, err - } - - if val == nil { - return value{nil}, nil - } - - v := expression(value{val}) - y.lo = &v - } - } - - if p := y.hi; p != nil { - if e := expr(*p); e.isStatic() { - if val, err = e.eval(nil, nil); err != nil { - return nil, err - } - - if val == nil { - return value{nil}, nil - } - - v := expression(value{val}) - y.hi = &v - } - } - return &y, nil -} - -func (s *slice) clone(arg []interface{}, unqualify ...string) (expression, error) { - expr, err := s.expr.clone(arg, unqualify...) - if err != nil { - return nil, err - } - - r := &slice{expr: expr, lo: s.lo, hi: s.hi} - if s.lo != nil { - e, err := (*s.lo).clone(arg, unqualify...) - if err != nil { - return nil, err - } - - r.lo = &e - } - if s.hi != nil { - e, err := (*s.hi).clone(arg, unqualify...) - if err != nil { - return nil, err - } - - r.hi = &e - } - return r, nil -} - -func (s *slice) eval(execCtx *execCtx, ctx map[interface{}]interface{}) (v interface{}, err error) { - s0, err := s.expr.eval(execCtx, ctx) - if err != nil { - return - } - - if s0 == nil { - return - } - - ss, ok := s0.(string) - if !ok { - return nil, runErr(invSOp(s0)) - } - - var iLo, iHi uint64 - if s.lo != nil { - i, err := (*s.lo).eval(execCtx, ctx) - if err != nil { - return nil, err - } - - if i == nil { - return nil, err - } - - if iLo, err = sliceExpr(&ss, i, 0); err != nil { - return nil, err - } - } - - iHi = uint64(len(ss)) - if s.hi != nil { - i, err := (*s.hi).eval(execCtx, ctx) - if err != nil { - return nil, err - } - - if i == nil { - return nil, err - } - - if iHi, err = sliceExpr(&ss, i, 1); err != nil { - return nil, err - } - } - - return ss[iLo:iHi], nil -} - -func (s *slice) isStatic() bool { - if !s.expr.isStatic() { - return false - } - - if p := s.lo; p != nil && !(*p).isStatic() { - return false - } - - if p := s.hi; p != nil && !(*p).isStatic() { - return false - } - - return false -} - -func (s *slice) String() string { - switch { - case s.lo == nil && s.hi == nil: - return fmt.Sprintf("%v[:]", s.expr) - case s.lo == nil && s.hi != nil: - return fmt.Sprintf("%v[:%v]", s.expr, *s.hi) - case s.lo != nil && s.hi == nil: - return fmt.Sprintf("%v[%v:]", s.expr, *s.lo) - default: //case s.lo != nil && s.hi != nil: - return fmt.Sprintf("%v[%v:%v]", s.expr, *s.lo, *s.hi) - } -} diff --git a/vendor/github.com/cznic/ql/file.go b/vendor/github.com/cznic/ql/file.go deleted file mode 100644 index 95d74c0c6..000000000 --- a/vendor/github.com/cznic/ql/file.go +++ /dev/null @@ -1,1349 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Well known handles -// 1: root -// 2: id - -package ql - -import ( - "crypto/sha1" - "fmt" - "io" - "io/ioutil" - "math/big" - "os" - "path/filepath" - "sync" - "time" - - "github.com/cznic/lldb" - "github.com/cznic/mathutil" - "github.com/cznic/ql/vendored/github.com/camlistore/go4/lock" -) - -const ( - magic = "\x60\xdbql" -) - -var ( - _ btreeIndex = (*fileIndex)(nil) - _ btreeIterator = (*fileBTreeIterator)(nil) - _ indexIterator = (*fileIndexIterator)(nil) - _ storage = (*file)(nil) - _ temp = (*fileTemp)(nil) -) - -type chunk struct { // expanded to blob types lazily - f *file - b []byte -} - -func (c chunk) expand() (v interface{}, err error) { - return c.f.loadChunks(c.b) -} - -func expand1(data interface{}, e error) (v interface{}, err error) { - if e != nil { - return nil, e - } - - c, ok := data.(chunk) - if !ok { - return data, nil - } - - return c.expand() -} - -func expand(data []interface{}) (err error) { - for i, v := range data { - if data[i], err = expand1(v, nil); err != nil { - return - } - } - return -} - -// OpenFile returns a DB backed by a named file. The back end limits the size -// of a record to about 64 kB. -func OpenFile(name string, opt *Options) (db *DB, err error) { - var f lldb.OSFile - if f = opt.OSFile; f == nil { - f, err = os.OpenFile(name, os.O_RDWR, 0666) - if err != nil { - if !os.IsNotExist(err) { - return nil, err - } - - if !opt.CanCreate { - return nil, err - } - - f, err = os.OpenFile(name, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666) - if err != nil { - return nil, err - } - } - } - - fi, err := newFileFromOSFile(f, opt.Headroom) // always ACID - if err != nil { - return - } - - if fi.tempFile = opt.TempFile; fi.tempFile == nil { - fi.tempFile = func(dir, prefix string) (f lldb.OSFile, err error) { - f0, err := ioutil.TempFile(dir, prefix) - return f0, err - } - } - - fi.removeEmptyWAL = opt.RemoveEmptyWAL - - return newDB(fi) -} - -// Options amend the behavior of OpenFile. -// -// CanCreate -// -// The CanCreate option enables OpenFile to create the DB file if it does not -// exists. -// -// OSFile -// -// OSFile allows to pass an os.File like back end providing, for example, -// encrypted storage. If this field is nil then OpenFile uses the file named by -// the 'name' parameter instead. -// -// TempFile -// -// TempFile provides a temporary file used for evaluating the GROUP BY, ORDER -// BY, ... clauses. The hook is intended to be used by encrypted DB back ends -// to avoid leaks of unecrypted data to such temp files by providing temp files -// which are encrypted as well. Note that *os.File satisfies the lldb.OSFile -// interface. -// -// If TempFile is nil it defaults to ioutil.TempFile. -// -// Headroom -// -// Headroom selects the minimum size a WAL file will have. The "extra" -// allocated file space serves as a headroom. Commits that fit into the -// headroom should not fail due to 'not enough space on the volume' errors. The -// headroom parameter is first rounded-up to a non negative multiple of the -// size of the lldb.Allocator atom. -// -// RemoveEmptyWAL -// -// RemoveEmptyWAL controls whether empty WAL files should be deleted on -// clean exit. -type Options struct { - CanCreate bool - OSFile lldb.OSFile - TempFile func(dir, prefix string) (f lldb.OSFile, err error) - Headroom int64 - RemoveEmptyWAL bool -} - -type fileBTreeIterator struct { - en *lldb.BTreeEnumerator - t *fileTemp -} - -func (it *fileBTreeIterator) Next() (k, v []interface{}, err error) { - bk, bv, err := it.en.Next() - if err != nil { - return - } - - if k, err = lldb.DecodeScalars(bk); err != nil { - return - } - - for i, val := range k { - b, ok := val.([]byte) - if !ok { - continue - } - - c := chunk{it.t.file, b} - if k[i], err = c.expand(); err != nil { - return nil, nil, err - } - } - - if err = enforce(k, it.t.colsK); err != nil { - return - } - - if v, err = lldb.DecodeScalars(bv); err != nil { - return - } - - for i, val := range v { - b, ok := val.([]byte) - if !ok { - continue - } - - c := chunk{it.t.file, b} - if v[i], err = c.expand(); err != nil { - return nil, nil, err - } - } - - err = enforce(v, it.t.colsV) - return -} - -func enforce(val []interface{}, cols []*col) (err error) { - for i, v := range val { - if val[i], err = convert(v, cols[i].typ); err != nil { - return - } - } - return -} - -//NTYPE -func infer(from []interface{}, to *[]*col) { - if len(*to) == 0 { - *to = make([]*col, len(from)) - for i := range *to { - (*to)[i] = &col{} - } - } - for i, c := range *to { - if f := from[i]; f != nil { - switch x := f.(type) { - //case nil: - case idealComplex: - c.typ = qComplex128 - from[i] = complex128(x) - case idealFloat: - c.typ = qFloat64 - from[i] = float64(x) - case idealInt: - c.typ = qInt64 - from[i] = int64(x) - case idealRune: - c.typ = qInt32 - from[i] = int32(x) - case idealUint: - c.typ = qUint64 - from[i] = uint64(x) - case bool: - c.typ = qBool - case complex128: - c.typ = qComplex128 - case complex64: - c.typ = qComplex64 - case float64: - c.typ = qFloat64 - case float32: - c.typ = qFloat32 - case int8: - c.typ = qInt8 - case int16: - c.typ = qInt16 - case int32: - c.typ = qInt32 - case int64: - c.typ = qInt64 - case string: - c.typ = qString - case uint8: - c.typ = qUint8 - case uint16: - c.typ = qUint16 - case uint32: - c.typ = qUint32 - case uint64: - c.typ = qUint64 - case []byte: - c.typ = qBlob - case *big.Int: - c.typ = qBigInt - case *big.Rat: - c.typ = qBigRat - case time.Time: - c.typ = qTime - case time.Duration: - c.typ = qDuration - case chunk: - vals, err := lldb.DecodeScalars(x.b) - if err != nil { - panic(err) - } - - if len(vals) == 0 { - panic("internal error 040") - } - - i, ok := vals[0].(int64) - if !ok { - panic("internal error 041") - } - - c.typ = int(i) - case map[string]interface{}: // map of ids of a cross join - default: - panic("internal error 042") - } - } - } -} - -type fileTemp struct { - *file - colsK []*col - colsV []*col - t *lldb.BTree -} - -func (t *fileTemp) BeginTransaction() error { - return nil -} - -func (t *fileTemp) Get(k []interface{}) (v []interface{}, err error) { - if err = expand(k); err != nil { - return - } - - if err = t.flatten(k); err != nil { - return nil, err - } - - bk, err := lldb.EncodeScalars(k...) - if err != nil { - return - } - - bv, err := t.t.Get(nil, bk) - if err != nil { - return - } - - return lldb.DecodeScalars(bv) -} - -func (t *fileTemp) Drop() (err error) { - if t.f0 == nil { - return - } - - fn := t.f0.Name() - if err = t.f0.Close(); err != nil { - return - } - - if fn == "" { - return - } - - return os.Remove(fn) -} - -func (t *fileTemp) SeekFirst() (it btreeIterator, err error) { - en, err := t.t.SeekFirst() - if err != nil { - return - } - - return &fileBTreeIterator{t: t, en: en}, nil -} - -func (t *fileTemp) Set(k, v []interface{}) (err error) { - if err = expand(k); err != nil { - return - } - - if err = expand(v); err != nil { - return - } - - infer(k, &t.colsK) - infer(v, &t.colsV) - - if err = t.flatten(k); err != nil { - return - } - - bk, err := lldb.EncodeScalars(k...) - if err != nil { - return - } - - if err = t.flatten(v); err != nil { - return - } - - bv, err := lldb.EncodeScalars(v...) - if err != nil { - return - } - - return t.t.Set(bk, bv) -} - -type file struct { - a *lldb.Allocator - codec *gobCoder - f lldb.Filer - f0 lldb.OSFile - id int64 - lck io.Closer - mu sync.Mutex - name string - tempFile func(dir, prefix string) (f lldb.OSFile, err error) - wal *os.File - removeEmptyWAL bool // Whether empty WAL files should be removed on close -} - -func newFileFromOSFile(f lldb.OSFile, headroom int64) (fi *file, err error) { - nm := lockName(f.Name()) - lck, err := lock.Lock(nm) - if err != nil { - if lck != nil { - lck.Close() - } - return nil, err - } - - close := true - defer func() { - if close && lck != nil { - lck.Close() - } - }() - - var w *os.File - closew := false - wn := walName(f.Name()) - w, err = os.OpenFile(wn, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666) - closew = true - defer func() { - if w != nil && closew { - nm := w.Name() - w.Close() - os.Remove(nm) - w = nil - } - }() - - if err != nil { - if !os.IsExist(err) { - return nil, err - } - - closew = false - w, err = os.OpenFile(wn, os.O_RDWR, 0666) - if err != nil { - return nil, err - } - - closew = true - st, err := w.Stat() - if err != nil { - return nil, err - } - - closew = st.Size() == 0 - } - - info, err := f.Stat() - if err != nil { - return nil, err - } - - switch sz := info.Size(); { - case sz == 0: - b := make([]byte, 16) - copy(b, []byte(magic)) - if _, err := f.Write(b); err != nil { - return nil, err - } - - filer := lldb.Filer(lldb.NewOSFiler(f)) - filer = lldb.NewInnerFiler(filer, 16) - if filer, err = lldb.NewACIDFiler(filer, w, lldb.MinWAL(headroom)); err != nil { - return nil, err - } - - a, err := lldb.NewAllocator(filer, &lldb.Options{}) - if err != nil { - return nil, err - } - - a.Compress = true - s := &file{ - a: a, - codec: newGobCoder(), - f0: f, - f: filer, - lck: lck, - name: f.Name(), - wal: w, - } - if err = s.BeginTransaction(); err != nil { - return nil, err - } - - h, err := s.Create() - if err != nil { - return nil, err - } - - if h != 1 { // root - panic("internal error 043") - } - - if h, err = s.a.Alloc(make([]byte, 8)); err != nil { - return nil, err - } - - if h != 2 { // id - panic("internal error 044") - } - - close, closew = false, false - return s, s.Commit() - default: - b := make([]byte, 16) - if _, err := f.Read(b); err != nil { - return nil, err - } - - if string(b[:len(magic)]) != magic { - return nil, fmt.Errorf("(file-002) unknown file format") - } - - filer := lldb.Filer(lldb.NewOSFiler(f)) - filer = lldb.NewInnerFiler(filer, 16) - if filer, err = lldb.NewACIDFiler(filer, w, lldb.MinWAL(headroom)); err != nil { - return nil, err - } - - a, err := lldb.NewAllocator(filer, &lldb.Options{}) - if err != nil { - return nil, err - } - - bid, err := a.Get(nil, 2) // id - if err != nil { - return nil, err - } - - if len(bid) != 8 { - return nil, fmt.Errorf("(file-003) corrupted DB: id |% x|", bid) - } - - id := int64(0) - for _, v := range bid { - id = (id << 8) | int64(v) - } - - a.Compress = true - s := &file{ - a: a, - codec: newGobCoder(), - f0: f, - f: filer, - id: id, - lck: lck, - name: f.Name(), - wal: w, - } - - close, closew = false, false - return s, nil - } -} - -func (s *file) OpenIndex(unique bool, handle int64) (btreeIndex, error) { - t, err := lldb.OpenBTree(s.a, s.collate, handle) - if err != nil { - return nil, err - } - - return &fileIndex{s, handle, t, unique, newGobCoder()}, nil -} - -func (s *file) CreateIndex(unique bool) ( /* handle */ int64, btreeIndex, error) { - t, h, err := lldb.CreateBTree(s.a, s.collate) - if err != nil { - return -1, nil, err - } - - return h, &fileIndex{s, h, t, unique, newGobCoder()}, nil -} - -func (s *file) Acid() bool { return s.wal != nil } - -func errSet(p *error, errs ...error) (err error) { - err = *p - for _, e := range errs { - if err != nil { - return - } - *p, err = e, e - } - return -} - -func (s *file) lock() func() { - s.mu.Lock() - return s.mu.Unlock -} - -func (s *file) Close() (err error) { - defer s.lock()() - - es := s.f0.Sync() - ef := s.f0.Close() - var ew, estat, eremove error - if s.wal != nil { - remove := false - wn := s.wal.Name() - if s.removeEmptyWAL { - var stat os.FileInfo - stat, estat = s.wal.Stat() - remove = stat.Size() == 0 - } - ew = s.wal.Close() - if remove { - eremove = os.Remove(wn) - } - } - el := s.lck.Close() - return errSet(&err, es, ef, ew, el, estat, eremove) -} - -func (s *file) Name() string { return s.name } - -func (s *file) Verify() (allocs int64, err error) { - defer s.lock()() - var stat lldb.AllocStats - if err = s.a.Verify(lldb.NewMemFiler(), nil, &stat); err != nil { - return - } - - allocs = stat.AllocAtoms - return -} - -func (s *file) expandBytes(d []interface{}) (err error) { - for i, v := range d { - b, ok := v.([]byte) - if !ok { - continue - } - - d[i], err = s.loadChunks(b) - if err != nil { - return - } - } - return -} - -func (s *file) collate(a, b []byte) int { //TODO w/ error return - da, err := lldb.DecodeScalars(a) - if err != nil { - panic(err) - } - - if err = s.expandBytes(da); err != nil { - panic(err) - } - - db, err := lldb.DecodeScalars(b) - if err != nil { - panic(err) - } - - if err = s.expandBytes(db); err != nil { - panic(err) - } - - //dbg("da: %v, db: %v", da, db) - return collate(da, db) -} - -func (s *file) CreateTemp(asc bool) (bt temp, err error) { - f, err := s.tempFile("", "ql-tmp-") - if err != nil { - return nil, err - } - - fn := f.Name() - filer := lldb.NewOSFiler(f) - a, err := lldb.NewAllocator(filer, &lldb.Options{}) - if err != nil { - f.Close() - os.Remove(fn) - return nil, err - } - - k := 1 - if !asc { - k = -1 - } - - t, _, err := lldb.CreateBTree(a, func(a, b []byte) int { //TODO w/ error return - return k * s.collate(a, b) - }) - if err != nil { - f.Close() - if fn != "" { - os.Remove(fn) - } - return nil, err - } - - x := &fileTemp{file: &file{ - a: a, - codec: newGobCoder(), - f0: f, - }, - t: t} - return x, nil -} - -func (s *file) BeginTransaction() (err error) { - defer s.lock()() - return s.f.BeginUpdate() -} - -func (s *file) Rollback() (err error) { - defer s.lock()() - return s.f.Rollback() -} - -func (s *file) Commit() (err error) { - defer s.lock()() - return s.f.EndUpdate() -} - -func (s *file) Create(data ...interface{}) (h int64, err error) { - if err = expand(data); err != nil { - return - } - - if err = s.flatten(data); err != nil { - return - } - - b, err := lldb.EncodeScalars(data...) - if err != nil { - return - } - - defer s.lock()() - return s.a.Alloc(b) -} - -func (s *file) Delete(h int64, blobCols ...*col) (err error) { - switch len(blobCols) { - case 0: - defer s.lock()() - return s.a.Free(h) - default: - return s.free(h, blobCols) - } -} - -func (s *file) ResetID() (err error) { - s.id = 0 - return -} - -func (s *file) ID() (int64, error) { - defer s.lock()() - - s.id++ - b := make([]byte, 8) - id := s.id - for i := 7; i >= 0; i-- { - b[i] = byte(id) - id >>= 8 - } - - return s.id, s.a.Realloc(2, b) -} - -func (s *file) free(h int64, blobCols []*col) (err error) { - b, err := s.a.Get(nil, h) //LATER +bufs - if err != nil { - return - } - - rec, err := lldb.DecodeScalars(b) - if err != nil { - return - } - - for _, col := range blobCols { - if col.index >= len(rec) { - return fmt.Errorf("(file-004) file.free: corrupted DB (record len)") - } - if col.index+2 >= len(rec) { - continue - } - - switch x := rec[col.index+2].(type) { - case nil: - // nop - case []byte: - if err = s.freeChunks(x); err != nil { - return - } - } - } - defer s.lock()() - return s.a.Free(h) -} - -func (s *file) Read(dst []interface{}, h int64, cols ...*col) (data []interface{}, err error) { //NTYPE - b, err := s.a.Get(nil, h) //LATER +bufs - if err != nil { - return - } - - rec, err := lldb.DecodeScalars(b) - if err != nil { - return - } - - for _, col := range cols { - i := col.index + 2 - if i >= len(rec) || rec[i] == nil { - continue - } - - switch col.typ { - case 0: - case qBool: - case qComplex64: - rec[i] = complex64(rec[i].(complex128)) - case qComplex128: - case qFloat32: - rec[i] = float32(rec[i].(float64)) - case qFloat64: - case qInt8: - rec[i] = int8(rec[i].(int64)) - case qInt16: - rec[i] = int16(rec[i].(int64)) - case qInt32: - rec[i] = int32(rec[i].(int64)) - case qInt64: - case qString: - case qUint8: - rec[i] = uint8(rec[i].(uint64)) - case qUint16: - rec[i] = uint16(rec[i].(uint64)) - case qUint32: - rec[i] = uint32(rec[i].(uint64)) - case qUint64: - case qBlob, qBigInt, qBigRat, qTime, qDuration: - switch x := rec[i].(type) { - case []byte: - rec[i] = chunk{f: s, b: x} - default: - return nil, fmt.Errorf("(file-006) corrupted DB: non nil chunk type is not []byte") - } - default: - panic("internal error 045") - } - } - - if cols != nil { - for n, dn := len(cols)+2, len(rec); dn < n; dn++ { - rec = append(rec, nil) - } - } - - return rec, nil -} - -func (s *file) freeChunks(enc []byte) (err error) { - items, err := lldb.DecodeScalars(enc) - if err != nil { - return - } - - var ok bool - var next int64 - switch len(items) { - case 2: - return - case 3: - if next, ok = items[1].(int64); !ok || next == 0 { - return fmt.Errorf("(file-007) corrupted DB: first chunk link") - } - default: - return fmt.Errorf("(file-008) corrupted DB: first chunk") - } - - for next != 0 { - b, err := s.a.Get(nil, next) - if err != nil { - return err - } - - if items, err = lldb.DecodeScalars(b); err != nil { - return err - } - - var h int64 - switch len(items) { - case 1: - // nop - case 2: - if h, ok = items[0].(int64); !ok { - return fmt.Errorf("(file-009) corrupted DB: chunk link") - } - - default: - return fmt.Errorf("(file-010) corrupted DB: chunk items %d (%v)", len(items), items) - } - - s.mu.Lock() - if err = s.a.Free(next); err != nil { - s.mu.Unlock() - return err - } - - s.mu.Unlock() - next = h - } - return -} - -func (s *file) loadChunks(enc []byte) (v interface{}, err error) { - items, err := lldb.DecodeScalars(enc) - if err != nil { - return - } - - var ok bool - var next int64 - switch len(items) { - case 2: - // nop - case 3: - if next, ok = items[1].(int64); !ok || next == 0 { - return nil, fmt.Errorf("(file-011) corrupted DB: first chunk link") - } - default: - //fmt.Printf("%d: %#v\n", len(items), items) - return nil, fmt.Errorf("(file-012) corrupted DB: first chunk") - } - - typ, ok := items[0].(int64) - if !ok { - return nil, fmt.Errorf("(file-013) corrupted DB: first chunk tag") - } - - buf, ok := items[len(items)-1].([]byte) - if !ok { - return nil, fmt.Errorf("(file-014) corrupted DB: first chunk data") - } - - for next != 0 { - b, err := s.a.Get(nil, next) - if err != nil { - return nil, err - } - - if items, err = lldb.DecodeScalars(b); err != nil { - return nil, err - } - - switch len(items) { - case 1: - next = 0 - case 2: - if next, ok = items[0].(int64); !ok { - return nil, fmt.Errorf("(file-015) corrupted DB: chunk link") - } - - items = items[1:] - default: - return nil, fmt.Errorf("(file-016) corrupted DB: chunk items %d (%v)", len(items), items) - } - - if b, ok = items[0].([]byte); !ok { - return nil, fmt.Errorf("(file-017) corrupted DB: chunk data") - } - - buf = append(buf, b...) - } - return s.codec.decode(buf, int(typ)) -} - -func (s *file) Update(h int64, data ...interface{}) (err error) { - b, err := lldb.EncodeScalars(data...) - if err != nil { - return - } - - defer s.lock()() - return s.a.Realloc(h, b) -} - -func (s *file) UpdateRow(h int64, blobCols []*col, data ...interface{}) (err error) { - if len(blobCols) == 0 { - return s.Update(h, data...) - } - - if err = expand(data); err != nil { - return - } - - data0, err := s.Read(nil, h, blobCols...) - if err != nil { - return - } - - for _, c := range blobCols { - if c.index+2 >= len(data0) { - continue - } - - if x := data0[c.index+2]; x != nil { - if err = s.freeChunks(x.(chunk).b); err != nil { - return - } - } - } - - if err = s.flatten(data); err != nil { - return - } - - return s.Update(h, data...) -} - -// []interface{}{qltype, ...}->[]interface{}{lldb scalar type, ...} -// + long blobs are (pre)written to a chain of chunks. -func (s *file) flatten(data []interface{}) (err error) { - for i, v := range data { - tag := 0 - var b []byte - switch x := v.(type) { - case []byte: - tag = qBlob - b = x - case *big.Int: - tag = qBigInt - b, err = s.codec.encode(x) - case *big.Rat: - tag = qBigRat - b, err = s.codec.encode(x) - case time.Time: - tag = qTime - b, err = s.codec.encode(x) - case time.Duration: - tag = qDuration - b, err = s.codec.encode(x) - default: - continue - } - if err != nil { - return - } - - const chunk = 1 << 16 - chunks := 0 - var next int64 - var buf []byte - for rem := len(b); rem > shortBlob; { - n := mathutil.Min(rem, chunk) - part := b[rem-n:] - b = b[:rem-n] - rem -= n - switch next { - case 0: // last chunk - buf, err = lldb.EncodeScalars([]interface{}{part}...) - default: // middle chunk - buf, err = lldb.EncodeScalars([]interface{}{next, part}...) - } - if err != nil { - return - } - - s.mu.Lock() - h, err := s.a.Alloc(buf) - s.mu.Unlock() - if err != nil { - return err - } - - next = h - chunks++ - } - - switch next { - case 0: // single chunk - buf, err = lldb.EncodeScalars([]interface{}{tag, b}...) - default: // multi chunks - buf, err = lldb.EncodeScalars([]interface{}{tag, next, b}...) - } - if err != nil { - return - } - - data[i] = buf - } - return -} - -func lockName(dbname string) string { - base := filepath.Base(filepath.Clean(dbname)) + "lockfile" - h := sha1.New() - io.WriteString(h, base) - return filepath.Join(filepath.Dir(dbname), fmt.Sprintf(".%x", h.Sum(nil))) -} - -func walName(dbname string) (r string) { - base := filepath.Base(filepath.Clean(dbname)) - h := sha1.New() - io.WriteString(h, base) - return filepath.Join(filepath.Dir(dbname), fmt.Sprintf(".%x", h.Sum(nil))) -} - -type fileIndex struct { - f *file - h int64 - t *lldb.BTree - unique bool - codec *gobCoder -} - -func (x *fileIndex) Clear() error { - return x.t.Clear() -} - -var gbZeroInt64 []byte - -func init() { - var err error - if gbZeroInt64, err = lldb.EncodeScalars(int64(0)); err != nil { - panic(err) - } -} - -func isIndexNull(data []interface{}) bool { - for _, v := range data { - if v != nil { - return false - } - } - return true -} - -// The []byte version of the key in the BTree shares chunks, if any, with -// the value stored in the record. -func (x *fileIndex) Create(indexedValues []interface{}, h int64) error { - for i, indexedValue := range indexedValues { - chunk, ok := indexedValue.(chunk) - if ok { - indexedValues[i] = chunk.b - } - } - - t := x.t - switch { - case !x.unique: - k, err := lldb.EncodeScalars(append(indexedValues, h)...) - if err != nil { - return err - } - - return t.Set(k, gbZeroInt64) - case isIndexNull(indexedValues): // unique, NULL - k, err := lldb.EncodeScalars(nil, h) - if err != nil { - return err - } - - return t.Set(k, gbZeroInt64) - default: // unique, non NULL - k, err := lldb.EncodeScalars(append(indexedValues, int64(0))...) - if err != nil { - return err - } - - v, err := lldb.EncodeScalars(h) - if err != nil { - return err - } - - _, _, err = t.Put(nil, k, func(key, old []byte) (new []byte, write bool, err error) { - if old == nil { - return v, true, nil - } - - return nil, false, fmt.Errorf("(file-018) cannot insert into unique index: duplicate value(s): %v", indexedValues) - }) - return err - } -} - -func (x *fileIndex) Delete(indexedValues []interface{}, h int64) error { - for i, indexedValue := range indexedValues { - chunk, ok := indexedValue.(chunk) - if ok { - indexedValues[i] = chunk.b - } - } - - t := x.t - var k []byte - var err error - switch { - case !x.unique: - k, err = lldb.EncodeScalars(append(indexedValues, h)...) - case isIndexNull(indexedValues): // unique, NULL - k, err = lldb.EncodeScalars(nil, h) - default: // unique, non NULL - k, err = lldb.EncodeScalars(append(indexedValues, int64(0))...) - } - if err != nil { - return err - } - - return t.Delete(k) -} - -func (x *fileIndex) Drop() error { - if err := x.Clear(); err != nil { - return err - } - - return x.f.a.Free(x.h) -} - -// []interface{}{qltype, ...}->[]interface{}{lldb scalar type, ...} -func (x *fileIndex) flatten(data []interface{}) (err error) { - for i, v := range data { - tag := 0 - var b []byte - switch xx := v.(type) { - case []byte: - tag = qBlob - b = xx - case *big.Int: - tag = qBigInt - b, err = x.codec.encode(xx) - case *big.Rat: - tag = qBigRat - b, err = x.codec.encode(xx) - case time.Time: - tag = qTime - b, err = x.codec.encode(xx) - case time.Duration: - tag = qDuration - b, err = x.codec.encode(xx) - default: - continue - } - if err != nil { - return - } - - var buf []byte - if buf, err = lldb.EncodeScalars([]interface{}{tag, b}...); err != nil { - return - } - - data[i] = buf - } - return -} - -func (x *fileIndex) Seek(indexedValues []interface{}) (indexIterator, bool, error) { - data := append(indexedValues, 0) - if err := x.flatten(data); err != nil { - return nil, false, err - } - - k, err := lldb.EncodeScalars(data...) - if err != nil { - return nil, false, err - } - - en, hit, err := x.t.Seek(k) - if err != nil { - return nil, false, err - } - - return &fileIndexIterator{x.f, en, x.unique}, hit, nil -} - -func (x *fileIndex) SeekFirst() (iter indexIterator, err error) { - en, err := x.t.SeekFirst() - return &fileIndexIterator{x.f, en, x.unique}, err -} - -func (x *fileIndex) SeekLast() (iter indexIterator, err error) { - en, err := x.t.SeekLast() - return &fileIndexIterator{x.f, en, x.unique}, err -} - -type fileIndexIterator struct { - f *file - en *lldb.BTreeEnumerator - unique bool -} - -func (i *fileIndexIterator) nextPrev(f func() ([]byte, []byte, error)) ([]interface{}, int64, error) { //TODO(indices) blobs: +test - bk, bv, err := f() - if err != nil { - return nil, -1, err - } - - dk, err := lldb.DecodeScalars(bk) - if err != nil { - return nil, -1, err - } - - b, ok := dk[0].([]byte) - if ok { - dk[0] = chunk{i.f, b} - if expand(dk[:1]); err != nil { - return nil, -1, err - } - } - - var k indexKey - k.value = dk[:len(dk)-1] - switch i.unique { - case true: - if isIndexNull(k.value) { - return nil, dk[len(dk)-1].(int64), nil - } - - dv, err := lldb.DecodeScalars(bv) - if err != nil { - return nil, -1, err - } - - return k.value, dv[0].(int64), nil - default: - return k.value, dk[len(dk)-1].(int64), nil - } -} - -func (i *fileIndexIterator) Next() ([]interface{}, int64, error) { //TODO(indices) blobs: +test - return i.nextPrev(i.en.Next) -} - -func (i *fileIndexIterator) Prev() ([]interface{}, int64, error) { //TODO(indices) blobs: +test - return i.nextPrev(i.en.Prev) -} diff --git a/vendor/github.com/cznic/ql/helper/helper.go b/vendor/github.com/cznic/ql/helper/helper.go deleted file mode 100644 index 7ce301539..000000000 --- a/vendor/github.com/cznic/ql/helper/helper.go +++ /dev/null @@ -1,338 +0,0 @@ -// +build ignore - -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import ( - "bufio" - "flag" - "fmt" - "io" - "log" - "os" -) - -type t int - -const ( - qNil t = iota - idealComplex - idealFloat - idealInt - idealRune - idealUint - qBool - qComplex64 - qComplex128 - qFloat32 - qFloat64 - qInt8 - qInt16 - qInt32 - qInt64 - qString - qUint8 - qUint16 - qUint32 - qUint64 - qBigInt - qBigRat - qTime - qDuration - - qEnd -) - -func (n t) String() string { - switch n { - case qNil: - return "nil" - case idealComplex: - return "idealComplex" - case idealFloat: - return "idealFloat" - case idealInt: - return "idealInt" - case idealRune: - return "idealRune" - case idealUint: - return "idealUint" - case qBool: - return "bool" - case qComplex64: - return "complex64" - case qComplex128: - return "complex128" - case qFloat32: - return "float32" - case qFloat64: - return "float64" - case qInt8: - return "int8" - case qInt16: - return "int16" - case qInt32: - return "int32" - case qInt64: - return "int64" - case qString: - return "string" - case qUint8: - return "uint8" - case qUint16: - return "uint16" - case qUint32: - return "uint32" - case qUint64: - return "uint64" - case qBigInt: - return "*big.Int" - case qBigRat: - return "*big.Rat" - case qTime: - return "time.Time" - case qDuration: - return "time.Duration" - default: - panic("internal error 046") - } -} - -func coerceIdealComplex(typ t) string { - switch typ { - case qComplex64, qComplex128: - return fmt.Sprintf("return %s(x)\n", typ) - default: - return "" - } -} - -func coerceIdealFloat(typ t) string { - switch typ { - case idealComplex: - return fmt.Sprintf("return %s(complex(float64(x), 0))\n", typ) - case qComplex64: - return fmt.Sprintf("return %s(complex(float32(x), 0))\n", typ) - case qComplex128: - return fmt.Sprintf("return %s(complex(float64(x), 0))\n", typ) - case idealFloat, qFloat32, qFloat64: - return fmt.Sprintf("return %s(float64(x))\n", typ) - case qBigRat: - return fmt.Sprintf("return big.NewRat(1, 1).SetFloat64(float64(x))\n") - default: - return "" - } - return "" -} - -func coerceIdealInt(typ t) string { - switch typ { - case idealComplex: - return fmt.Sprintf("return %s(complex(float64(x), 0))\n", typ) - case qComplex64: - return fmt.Sprintf("return %s(complex(float32(x), 0))\n", typ) - case qComplex128: - return fmt.Sprintf("return %s(complex(float64(x), 0))\n", typ) - case idealFloat, idealInt, qFloat32, qFloat64, qInt64: - return fmt.Sprintf("return %s(int64(x))\n", typ) - case idealUint: - return fmt.Sprintf("if x >= 0 { return %s(int64(x)) }\n", typ) - case qInt8: - return fmt.Sprintf("if x >= math.MinInt8 && x<= math.MaxInt8 { return %s(int64(x)) }\n", typ) - case qInt16: - return fmt.Sprintf("if x >= math.MinInt16 && x<= math.MaxInt16 { return %s(int64(x)) }\n", typ) - case qInt32: - return fmt.Sprintf("if x >= math.MinInt32 && x<= math.MaxInt32 { return %s(int64(x)) }\n", typ) - case qUint8: - return fmt.Sprintf("if x >= 0 && x<= math.MaxUint8 { return %s(int64(x)) }\n", typ) - case qUint16: - return fmt.Sprintf("if x >= 0 && x<= math.MaxUint16 { return %s(int64(x)) }\n", typ) - case qUint32: - return fmt.Sprintf("if x >= 0 && x<= math.MaxUint32 { return %s(int64(x)) }\n", typ) - case qUint64: - return fmt.Sprintf("if x >= 0 { return %s(int64(x)) }\n", typ) - case qBigInt: - return fmt.Sprintf("return big.NewInt(int64(x))\n") - case qBigRat: - return fmt.Sprintf("return big.NewRat(1, 1).SetInt64(int64(x))\n") - case qDuration: - return fmt.Sprintf("return time.Duration(int64(x))\n") - default: - return "" - } - return "" -} - -func coerceIdealRune(typ t) string { - switch typ { - case idealComplex: - return fmt.Sprintf("return %s(complex(float64(x), 0))\n", typ) - case qComplex64: - return fmt.Sprintf("return %s(complex(float32(x), 0))\n", typ) - case qComplex128: - return fmt.Sprintf("return %s(complex(float64(x), 0))\n", typ) - case idealFloat, idealInt, idealRune, idealUint, qFloat32, qFloat64, qInt8, qInt16, qInt32, qInt64, qUint8, qUint16, qUint32, qUint64: - return fmt.Sprintf("return %s(int64(x))\n", typ) - case qBigInt: - return fmt.Sprintf("return big.NewInt(int64(x))\n") - case qBigRat: - return fmt.Sprintf("return big.NewRat(1, 1).SetInt64(int64(x))\n") - case qDuration: - return fmt.Sprintf("return time.Duration(int64(x))\n") - default: - return "" - } - return "" -} - -func coerceIdealUint(typ t) string { - switch typ { - case idealComplex: - return fmt.Sprintf("return %s(complex(float64(x), 0))\n", typ) - case qComplex64: - return fmt.Sprintf("return %s(complex(float32(x), 0))\n", typ) - case qComplex128: - return fmt.Sprintf("return %s(complex(float64(x), 0))\n", typ) - case idealFloat, idealUint, qFloat32, qFloat64, qUint64: - return fmt.Sprintf("return %s(uint64(x))\n", typ) - case idealInt: - return fmt.Sprintf("if x <= math.MaxInt64 { return %s(int64(x)) }\n", typ) - case qInt8: - return fmt.Sprintf("if x <= math.MaxInt8 { return %s(int64(x)) }\n", typ) - case qInt16: - return fmt.Sprintf("if x<= math.MaxInt16 { return %s(int64(x)) }\n", typ) - case qInt32: - return fmt.Sprintf("if x<= math.MaxInt32 { return %s(int64(x)) }\n", typ) - case qInt64: - return fmt.Sprintf("if x<= math.MaxInt64 { return %s(int64(x)) }\n", typ) - case qUint8: - return fmt.Sprintf("if x >= 0 && x<= math.MaxUint8 { return %s(int64(x)) }\n", typ) - case qUint16: - return fmt.Sprintf("if x >= 0 && x<= math.MaxUint16 { return %s(int64(x)) }\n", typ) - case qUint32: - return fmt.Sprintf("if x >= 0 && x<= math.MaxUint32 { return %s(int64(x)) }\n", typ) - case qBigInt: - return fmt.Sprintf("return big.NewInt(0).SetUint64(uint64(x))\n") - case qBigRat: - return fmt.Sprintf("return big.NewRat(1, 1).SetInt(big.NewInt(0).SetUint64(uint64(x)))\n") - case qDuration: - return fmt.Sprintf("if x <= math.MaxInt64 { return time.Duration(int64(x)) }\n") - default: - return "" - } - return "" -} - -func genCoerce1(w io.Writer, in t, f func(out t) string) { - fmt.Fprintf(w, "\tcase %s:\n", in) - fmt.Fprintf(w, "\t\tswitch otherVal.(type) {\n") - - for i := idealComplex; i < qEnd; i++ { - s := f(i) - switch s { - case "": - fmt.Fprintf(w, "\t\t//case %s:\n", i) - default: - fmt.Fprintf(w, "\t\tcase %s:\n", i) - fmt.Fprintf(w, "\t\t\t%s", s) - } - } - - fmt.Fprintf(w, "\t\t}\n") // switch -} - -func genCoerce(w io.Writer) { - fmt.Fprintf(w, - ` -func coerce1(inVal, otherVal interface{}) (coercedInVal interface{}) { - coercedInVal = inVal - if otherVal == nil { - return - } - - switch x := inVal.(type) { - case nil: - return -`) - genCoerce1(w, idealComplex, coerceIdealComplex) - genCoerce1(w, idealFloat, coerceIdealFloat) - genCoerce1(w, idealInt, coerceIdealInt) - genCoerce1(w, idealRune, coerceIdealRune) - genCoerce1(w, idealUint, coerceIdealUint) - fmt.Fprintf(w, "\t}\n") // switch - - fmt.Fprintf(w, "\treturn\n}\n") // func -} - -func main() { - ofn := flag.String("o", "", "") - flag.Parse() - _, err := os.Stat(*ofn) - if err == nil { - log.Fatalf("%s exists", *ofn) - } - - w := bufio.NewWriter(os.Stdout) - if s := *ofn; s != "" { - f, err := os.Create(s) - if err != nil { - log.Fatal(err) - } - - defer f.Close() - w = bufio.NewWriter(f) - } - defer w.Flush() - - fmt.Fprintf(w, `// Copyright 2013 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// CAUTION: This file was generated automatically by -// -// $ go run helper/helper.go -o coerce.go -// -// DO NOT EDIT! - - package ql - -import ( - "math" - "math/big" - "reflect" - "time" -) - -func coerce(a, b interface{}) (x, y interface{}) { - if reflect.TypeOf(a) == reflect.TypeOf(b) { - return a, b - } - - switch a.(type) { - case idealComplex, idealFloat, idealInt, idealRune, idealUint: - switch b.(type) { - case idealComplex, idealFloat, idealInt, idealRune, idealUint: - x, y = coerce1(a, b), b - if reflect.TypeOf(x) == reflect.TypeOf(y) { - return - } - - return a, coerce1(b, a) - default: - return coerce1(a, b), b - } - default: - switch b.(type) { - case idealComplex, idealFloat, idealInt, idealRune, idealUint: - return a, coerce1(b, a) - default: - return a, b - } - } -} -`) - genCoerce(w) -} diff --git a/vendor/github.com/cznic/ql/httpfs.go b/vendor/github.com/cznic/ql/httpfs.go deleted file mode 100644 index 6dfa30427..000000000 --- a/vendor/github.com/cznic/ql/httpfs.go +++ /dev/null @@ -1,301 +0,0 @@ -// Copyright (c) 2014 ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "fmt" - "io" - "net/http" - "os" - "path" - "path/filepath" - "strings" - "time" - - "github.com/cznic/mathutil" -) - -var ( - _ http.FileSystem = (*HTTPFS)(nil) - _ http.File = (*HTTPFile)(nil) - _ os.FileInfo = (*HTTPFile)(nil) - _ os.FileInfo = (*dirEntry)(nil) -) - -type dirEntry string - -func (d dirEntry) Name() string { return string(d) } -func (d dirEntry) Size() int64 { return -1 } -func (d dirEntry) Mode() os.FileMode { return os.ModeDir } -func (d dirEntry) ModTime() time.Time { return time.Time{} } -func (d dirEntry) IsDir() bool { return true } -func (d dirEntry) Sys() interface{} { return interface{}(nil) } - -// A HTTPFile is returned by the HTTPFS's Open method and can be served by the -// http.FileServer implementation. -type HTTPFile struct { - closed bool - content []byte - dirEntries []os.FileInfo - isFile bool - name string - off int -} - -// Close implements http.File. -func (f *HTTPFile) Close() error { - if f.closed { - return os.ErrInvalid - } - - f.closed = true - return nil -} - -// IsDir implements os.FileInfo -func (f *HTTPFile) IsDir() bool { return !f.isFile } - -// Mode implements os.FileInfo -func (f *HTTPFile) Mode() os.FileMode { - switch f.isFile { - case false: - return os.FileMode(0444) - default: - return os.ModeDir - } -} - -// ModTime implements os.FileInfo -func (f *HTTPFile) ModTime() time.Time { - return time.Time{} -} - -// Name implements os.FileInfo -func (f *HTTPFile) Name() string { return path.Base(f.name) } - -// Size implements os.FileInfo -func (f *HTTPFile) Size() int64 { - switch f.isFile { - case false: - return -1 - default: - return int64(len(f.content)) - } -} - -// Stat implements http.File. -func (f *HTTPFile) Stat() (os.FileInfo, error) { return f, nil } - -// Sys implements os.FileInfo -func (f *HTTPFile) Sys() interface{} { return interface{}(nil) } - -// Readdir implements http.File. -func (f *HTTPFile) Readdir(count int) ([]os.FileInfo, error) { - if f.isFile { - return nil, fmt.Errorf("not a directory: %s", f.name) - } - - if count <= 0 { - r := f.dirEntries - f.dirEntries = f.dirEntries[:0] - return r, nil - } - - rq := mathutil.Min(count, len(f.dirEntries)) - r := f.dirEntries[:rq] - f.dirEntries = f.dirEntries[rq:] - if len(r) != 0 { - return r, nil - } - - return nil, io.EOF -} - -// Read implements http.File. -func (f *HTTPFile) Read(b []byte) (int, error) { - if f.closed { - return 0, os.ErrInvalid - } - - n := copy(b, f.content[f.off:]) - f.off += n - if n != 0 { - return n, nil - } - - return 0, io.EOF -} - -// Seek implements http.File. -func (f *HTTPFile) Seek(offset int64, whence int) (int64, error) { - if f.closed { - return 0, os.ErrInvalid - } - - if offset < 0 { - return int64(f.off), fmt.Errorf("cannot seek before start of file") - } - - switch whence { - case 0: - noff := int64(f.off) + offset - if noff > mathutil.MaxInt { - return int64(f.off), fmt.Errorf("seek target overflows int: %d", noff) - } - - f.off = mathutil.Min(int(offset), len(f.content)) - if f.off == int(offset) { - return offset, nil - } - - return int64(f.off), io.EOF - case 1: - noff := int64(f.off) + offset - if noff > mathutil.MaxInt { - return int64(f.off), fmt.Errorf("seek target overflows int: %d", noff) - } - - off := mathutil.Min(f.off+int(offset), len(f.content)) - if off == f.off+int(offset) { - f.off = off - return int64(off), nil - } - - f.off = off - return int64(off), io.EOF - case 2: - noff := int64(f.off) - offset - if noff < 0 { - return int64(f.off), fmt.Errorf("cannot seek before start of file") - } - - f.off = len(f.content) - int(offset) - return int64(f.off), nil - default: - return int64(f.off), fmt.Errorf("seek: invalid whence %d", whence) - } -} - -// HTTPFS implements a http.FileSystem backed by data in a DB. -type HTTPFS struct { - db *DB - dir, get List -} - -// NewHTTPFS returns a http.FileSystem backed by a result record set of query. -// The record set provides two mandatory fields: path and content (the field -// names are case sensitive). Type of name must be string and type of content -// must be blob (ie. []byte). Field 'path' value is the "file" pathname, which -// must be rooted; and field 'content' value is its "data". -func (db *DB) NewHTTPFS(query string) (*HTTPFS, error) { - if _, err := Compile(query); err != nil { - return nil, err - } - - dir, err := Compile(fmt.Sprintf("SELECT path FROM (%s) WHERE hasPrefix(path, $1)", query)) - if err != nil { - return nil, err - } - - get, err := Compile(fmt.Sprintf("SELECT content FROM (%s) WHERE path == $1", query)) - if err != nil { - return nil, err - } - - return &HTTPFS{db: db, dir: dir, get: get}, nil -} - -// Open implements http.FileSystem. The name parameter represents a file path. -// The elements in a file path are separated by slash ('/', U+002F) characters, -// regardless of host operating system convention. -func (f *HTTPFS) Open(name string) (http.File, error) { - if filepath.Separator != '/' && strings.Contains(name, string(filepath.Separator)) || - strings.Contains(name, "\x00") { - return nil, fmt.Errorf("invalid character in file path: %q", name) - } - - name = path.Clean("/" + name) - rs, _, err := f.db.Execute(nil, f.get, name) - if err != nil { - return nil, err - } - - n := 0 - var fdata []byte - if err = rs[0].Do(false, func(data []interface{}) (more bool, err error) { - switch n { - case 0: - var ok bool - fdata, ok = data[0].([]byte) - if !ok { - return false, fmt.Errorf("open: expected blob, got %T", data[0]) - } - n++ - return true, nil - default: - return false, fmt.Errorf("open: more than one result was returned for %s", name) - } - }); err != nil { - return nil, err - } - - if n == 1 { // file found - return &HTTPFile{name: name, isFile: true, content: fdata}, nil - } - - dirName := name - if dirName[len(dirName)-1] != filepath.Separator { - dirName += string(filepath.Separator) - } - // Open("/a/b"): {/a/b/c.x,/a/b/d.x,/a/e.x,/a/b/f/g.x} -> {c.x,d.x,f} - rs, _, err = f.db.Execute(nil, f.dir, dirName) - if err != nil { - return nil, err - } - - n = 0 - r := &HTTPFile{name: dirName} - m := map[string]bool{} - x := len(dirName) - if err = rs[0].Do(false, func(data []interface{}) (more bool, err error) { - n++ - switch name := data[0].(type) { - case string: - if filepath.Separator != '/' && strings.Contains(name, string(filepath.Separator)) || - strings.Contains(name, "\x00") { - return false, fmt.Errorf("invalid character in file path: %q", name) - } - - name = path.Clean("/" + name) - rest := name[x:] - parts := strings.Split(rest, "/") - if len(parts) == 0 { - return true, nil - } - - nm := parts[0] - switch len(parts) { - case 1: // file - r.dirEntries = append(r.dirEntries, &HTTPFile{isFile: true, name: nm}) - default: // directory - if !m[nm] { - r.dirEntries = append(r.dirEntries, dirEntry(nm)) - } - m[nm] = true - } - return true, nil - default: - return false, fmt.Errorf("expected string path, got %T(%v)", name, name) - } - }); err != nil { - return nil, err - } - - if n != 0 { - return r, nil - } - - return nil, os.ErrNotExist -} diff --git a/vendor/github.com/cznic/ql/introspection.go b/vendor/github.com/cznic/ql/introspection.go deleted file mode 100644 index 61ac9a928..000000000 --- a/vendor/github.com/cznic/ql/introspection.go +++ /dev/null @@ -1,625 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "bytes" - "fmt" - "go/ast" - "reflect" - "strings" - "sync" -) - -var ( - schemaCache = map[reflect.Type]*StructInfo{} - schemaMu sync.RWMutex -) - -// StructInfo describes a struct type. An instance of StructInfo obtained from -// StructSchema is shared and must not be mutated. That includes the values -// pointed to by the elements of Fields and Indices. -type StructInfo struct { - Fields []*StructField // Fields describe the considered fields of a struct type. - HasID bool // Whether the struct has a considered field named ID of type int64. - Indices []*StructIndex // Indices describe indices defined by the index or uindex ql tags. - IsPtr bool // Whether the StructInfo was derived from a pointer to a struct. -} - -// StructIndex describes an index defined by the ql tag index or uindex. -type StructIndex struct { - ColumnName string // Name of the column the index is on. - Name string // Name of the index. - Unique bool // Whether the index is unique. -} - -// StructField describes a considered field of a struct type. -type StructField struct { - Index int // Index is the index of the field for reflect.Value.Field. - IsID bool // Whether the field corresponds to record id(). - IsPtr bool // Whether the field is a pointer type. - MarshalType reflect.Type // The reflect.Type a field must be converted to when marshaling or nil when it is assignable directly. (Field->value) - Name string // Field name or value of the name tag (like in `ql:"name foo"`). - ReflectType reflect.Type // The reflect.Type of the field. - Tags map[string]string // QL tags of this field. (`ql:"a, b c, d"` -> {"a": "", "b": "c", "d": ""}) - Type Type // QL type of the field. - UnmarshalType reflect.Type // The reflect.Type a value must be converted to when unmarshaling or nil when it is assignable directly. (Field<-value) - ZeroPtr reflect.Value // The reflect.Zero value of the field if it's a pointer type. -} - -func (s *StructField) check(v interface{}) error { - t := reflect.TypeOf(v) - if !s.ReflectType.AssignableTo(t) { - if !s.ReflectType.ConvertibleTo(t) { - return fmt.Errorf("type %s (%v) cannot be converted to %T", s.ReflectType.Name(), s.ReflectType.Kind(), t.Name()) - } - - s.MarshalType = t - } - - if !t.AssignableTo(s.ReflectType) { - if !t.ConvertibleTo(s.ReflectType) { - return fmt.Errorf("type %s (%v) cannot be converted to %T", t.Name(), t.Kind(), s.ReflectType.Name()) - } - - s.UnmarshalType = s.ReflectType - } - return nil -} - -func parseTag(s string) map[string]string { - m := map[string]string{} - for _, v := range strings.Split(s, ",") { - v = strings.TrimSpace(v) - switch n := strings.IndexRune(v, ' '); { - case n < 0: - m[v] = "" - default: - m[v[:n]] = v[n+1:] - } - } - return m -} - -// StructSchema returns StructInfo for v which must be a struct instance or a -// pointer to a struct. The info is computed only once for every type. -// Subsequent calls to StructSchema for the same type return a cached -// StructInfo. -// -// Note: The returned StructSchema is shared and must be not mutated, including -// any other data structures it may point to. -func StructSchema(v interface{}) (*StructInfo, error) { - if v == nil { - return nil, fmt.Errorf("cannot derive schema for %T(%v)", v, v) - } - - typ := reflect.TypeOf(v) - schemaMu.RLock() - if r, ok := schemaCache[typ]; ok { - schemaMu.RUnlock() - return r, nil - } - - schemaMu.RUnlock() - var schemaPtr bool - t := typ - if t.Kind() == reflect.Ptr { - t = t.Elem() - schemaPtr = true - } - if k := t.Kind(); k != reflect.Struct { - return nil, fmt.Errorf("cannot derive schema for type %T (%v)", v, k) - } - - r := &StructInfo{IsPtr: schemaPtr} - for i := 0; i < t.NumField(); i++ { - f := t.Field(i) - fn := f.Name - if !ast.IsExported(fn) { - continue - } - - tags := parseTag(f.Tag.Get("ql")) - if _, ok := tags["-"]; ok { - continue - } - - if s := tags["name"]; s != "" { - fn = s - } - - if fn == "ID" && f.Type.Kind() == reflect.Int64 { - r.HasID = true - } - var ix, unique bool - var xn string - xfn := fn - if s := tags["index"]; s != "" { - if _, ok := tags["uindex"]; ok { - return nil, fmt.Errorf("both index and uindex in QL struct tag") - } - - ix, xn = true, s - } else if s := tags["uindex"]; s != "" { - if _, ok := tags["index"]; ok { - return nil, fmt.Errorf("both index and uindex in QL struct tag") - } - - ix, unique, xn = true, true, s - } - if ix { - if fn == "ID" && r.HasID { - xfn = "id()" - } - r.Indices = append(r.Indices, &StructIndex{Name: xn, ColumnName: xfn, Unique: unique}) - } - - sf := &StructField{Index: i, Name: fn, Tags: tags, Type: Type(-1), ReflectType: f.Type} - fk := sf.ReflectType.Kind() - if fk == reflect.Ptr { - sf.IsPtr = true - sf.ZeroPtr = reflect.Zero(sf.ReflectType) - sf.ReflectType = sf.ReflectType.Elem() - fk = sf.ReflectType.Kind() - } - - switch fk { - case reflect.Bool: - sf.Type = Bool - if err := sf.check(false); err != nil { - return nil, err - } - case reflect.Int, reflect.Uint: - return nil, fmt.Errorf("only integers of fixed size can be used to derive a schema: %v", fk) - case reflect.Int8: - sf.Type = Int8 - if err := sf.check(int8(0)); err != nil { - return nil, err - } - case reflect.Int16: - if err := sf.check(int16(0)); err != nil { - return nil, err - } - sf.Type = Int16 - case reflect.Int32: - if err := sf.check(int32(0)); err != nil { - return nil, err - } - sf.Type = Int32 - case reflect.Int64: - if sf.ReflectType.Name() == "Duration" && sf.ReflectType.PkgPath() == "time" { - sf.Type = Duration - break - } - - sf.Type = Int64 - if err := sf.check(int64(0)); err != nil { - return nil, err - } - case reflect.Uint8: - sf.Type = Uint8 - if err := sf.check(uint8(0)); err != nil { - return nil, err - } - case reflect.Uint16: - sf.Type = Uint16 - if err := sf.check(uint16(0)); err != nil { - return nil, err - } - case reflect.Uint32: - sf.Type = Uint32 - if err := sf.check(uint32(0)); err != nil { - return nil, err - } - case reflect.Uint64: - sf.Type = Uint64 - if err := sf.check(uint64(0)); err != nil { - return nil, err - } - case reflect.Float32: - sf.Type = Float32 - if err := sf.check(float32(0)); err != nil { - return nil, err - } - case reflect.Float64: - sf.Type = Float64 - if err := sf.check(float64(0)); err != nil { - return nil, err - } - case reflect.Complex64: - sf.Type = Complex64 - if err := sf.check(complex64(0)); err != nil { - return nil, err - } - case reflect.Complex128: - sf.Type = Complex128 - if err := sf.check(complex128(0)); err != nil { - return nil, err - } - case reflect.Slice: - sf.Type = Blob - if err := sf.check([]byte(nil)); err != nil { - return nil, err - } - case reflect.Struct: - switch sf.ReflectType.PkgPath() { - case "math/big": - switch sf.ReflectType.Name() { - case "Int": - sf.Type = BigInt - case "Rat": - sf.Type = BigRat - } - case "time": - switch sf.ReflectType.Name() { - case "Time": - sf.Type = Time - } - } - case reflect.String: - sf.Type = String - if err := sf.check(""); err != nil { - return nil, err - } - } - - if sf.Type < 0 { - return nil, fmt.Errorf("cannot derive schema for type %s (%v)", sf.ReflectType.Name(), fk) - } - - sf.IsID = fn == "ID" && r.HasID - r.Fields = append(r.Fields, sf) - } - - schemaMu.Lock() - schemaCache[typ] = r - if t != typ { - r2 := *r - r2.IsPtr = false - schemaCache[t] = &r2 - } - schemaMu.Unlock() - return r, nil -} - -// MustStructSchema is like StructSchema but panics on error. It simplifies -// safe initialization of global variables holding StructInfo. -// -// MustStructSchema is safe for concurrent use by multiple goroutines. -func MustStructSchema(v interface{}) *StructInfo { - s, err := StructSchema(v) - if err != nil { - panic(err) - } - - return s -} - -// SchemaOptions amend the result of Schema. -type SchemaOptions struct { - // Don't wrap the CREATE statement(s) in a transaction. - NoTransaction bool - - // Don't insert the IF NOT EXISTS clause in the CREATE statement(s). - NoIfNotExists bool - - // Do not strip the "pkg." part from type name "pkg.Type", produce - // "pkg_Type" table name instead. Applies only when no name is passed - // to Schema(). - KeepPrefix bool -} - -var zeroSchemaOptions SchemaOptions - -// Schema returns a CREATE TABLE/INDEX statement(s) for a table derived from a -// struct or an error, if any. The table is named using the name parameter. If -// name is an empty string then the type name of the struct is used while non -// conforming characters are replaced by underscores. Value v can be also a -// pointer to a struct. -// -// Every considered struct field type must be one of the QL types or a type -// convertible to string, bool, int*, uint*, float* or complex* type or pointer -// to such type. Integers with a width dependent on the architecture can not be -// used. Only exported fields are considered. If an exported field QL tag -// contains "-" (`ql:"-"`) then such field is not considered. A field with name -// ID, having type int64, corresponds to id() - and is thus not a part of the -// CREATE statement. A field QL tag containing "index name" or "uindex name" -// triggers additionally creating an index or unique index on the respective -// field. Fields can be renamed using a QL tag "name newName". Fields are -// considered in the order of appearance. A QL tag is a struct tag part -// prefixed by "ql:". Tags can be combined, for example: -// -// type T struct { -// Foo string `ql:"index xFoo, name Bar"` -// } -// -// If opts.NoTransaction == true then the statement(s) are not wrapped in a -// transaction. If opt.NoIfNotExists == true then the CREATE statement(s) omits -// the IF NOT EXISTS clause. Passing nil opts is equal to passing -// &SchemaOptions{} -// -// Schema is safe for concurrent use by multiple goroutines. -func Schema(v interface{}, name string, opt *SchemaOptions) (List, error) { - if opt == nil { - opt = &zeroSchemaOptions - } - s, err := StructSchema(v) - if err != nil { - return List{}, err - } - - var buf bytes.Buffer - if !opt.NoTransaction { - buf.WriteString("BEGIN TRANSACTION; ") - } - buf.WriteString("CREATE TABLE ") - if !opt.NoIfNotExists { - buf.WriteString("IF NOT EXISTS ") - } - if name == "" { - name = fmt.Sprintf("%T", v) - if !opt.KeepPrefix { - a := strings.Split(name, ".") - if l := len(a); l > 1 { - name = a[l-1] - } - } - nm := []rune{} - for _, v := range name { - switch { - case v >= '0' && v <= '9' || v == '_' || v >= 'a' && v <= 'z' || v >= 'A' && v <= 'Z': - // ok - default: - v = '_' - } - nm = append(nm, v) - } - name = string(nm) - } - buf.WriteString(name + " (") - for _, v := range s.Fields { - if v.IsID { - continue - } - - buf.WriteString(fmt.Sprintf("%s %s, ", v.Name, v.Type)) - } - buf.WriteString("); ") - for _, v := range s.Indices { - buf.WriteString("CREATE ") - if v.Unique { - buf.WriteString("UNIQUE ") - } - buf.WriteString("INDEX ") - if !opt.NoIfNotExists { - buf.WriteString("IF NOT EXISTS ") - } - buf.WriteString(fmt.Sprintf("%s ON %s (%s); ", v.Name, name, v.ColumnName)) - } - if !opt.NoTransaction { - buf.WriteString("COMMIT; ") - } - l, err := Compile(buf.String()) - if err != nil { - return List{}, fmt.Errorf("%s: %v", buf.String(), err) - } - - return l, nil -} - -// MustSchema is like Schema but panics on error. It simplifies safe -// initialization of global variables holding compiled schemas. -// -// MustSchema is safe for concurrent use by multiple goroutines. -func MustSchema(v interface{}, name string, opt *SchemaOptions) List { - l, err := Schema(v, name, opt) - if err != nil { - panic(err) - } - - return l -} - -// Marshal converts, in the order of appearance, fields of a struct instance v -// to []interface{} or an error, if any. Value v can be also a pointer to a -// struct. -// -// Every considered struct field type must be one of the QL types or a type -// convertible to string, bool, int*, uint*, float* or complex* type or pointer -// to such type. Integers with a width dependent on the architecture can not be -// used. Only exported fields are considered. If an exported field QL tag -// contains "-" then such field is not considered. A QL tag is a struct tag -// part prefixed by "ql:". Field with name ID, having type int64, corresponds -// to id() - and is thus not part of the result. -// -// Marshal is safe for concurrent use by multiple goroutines. -func Marshal(v interface{}) ([]interface{}, error) { - s, err := StructSchema(v) - if err != nil { - return nil, err - } - - val := reflect.ValueOf(v) - if s.IsPtr { - val = val.Elem() - } - n := len(s.Fields) - if s.HasID { - n-- - } - r := make([]interface{}, n) - j := 0 - for _, v := range s.Fields { - if v.IsID { - continue - } - - f := val.Field(v.Index) - if v.IsPtr { - if f.IsNil() { - r[j] = nil - j++ - continue - } - - f = f.Elem() - } - if m := v.MarshalType; m != nil { - f = f.Convert(m) - } - r[j] = f.Interface() - j++ - } - return r, nil -} - -// MustMarshal is like Marshal but panics on error. It simplifies marshaling of -// "safe" types, like eg. those which were already verified by Schema or -// MustSchema. When the underlying Marshal returns an error, MustMarshal -// panics. -// -// MustMarshal is safe for concurrent use by multiple goroutines. -func MustMarshal(v interface{}) []interface{} { - r, err := Marshal(v) - if err != nil { - panic(err) - } - - return r -} - -// Unmarshal stores data from []interface{} in the struct value pointed to by -// v. -// -// Every considered struct field type must be one of the QL types or a type -// convertible to string, bool, int*, uint*, float* or complex* type or pointer -// to such type. Integers with a width dependent on the architecture can not be -// used. Only exported fields are considered. If an exported field QL tag -// contains "-" then such field is not considered. A QL tag is a struct tag -// part prefixed by "ql:". Fields are considered in the order of appearance. -// Types of values in data must be compatible with the corresponding considered -// field of v. -// -// If the struct has no ID field then the number of values in data must be equal -// to the number of considered fields of v. -// -// type T struct { -// A bool -// B string -// } -// -// Assuming the schema is -// -// CREATE TABLE T (A bool, B string); -// -// Data might be a result of queries like -// -// SELECT * FROM T; -// SELECT A, B FROM T; -// -// If the struct has a considered ID field then the number of values in data -// must be equal to the number of considered fields in v - or one less. In the -// later case the ID field is not set. -// -// type U struct { -// ID int64 -// A bool -// B string -// } -// -// Assuming the schema is -// -// CREATE TABLE T (A bool, B string); -// -// Data might be a result of queries like -// -// SELECT * FROM T; // ID not set -// SELECT A, B FROM T; // ID not set -// SELECT id(), A, B FROM T; // ID is set -// -// To unmarshal a value from data into a pointer field of v, Unmarshal first -// handles the case of the value being nil. In that case, Unmarshal sets the -// pointer to nil. Otherwise, Unmarshal unmarshals the data value into value -// pointed at by the pointer. If the pointer is nil, Unmarshal allocates a new -// value for it to point to. -// -// Unmarshal is safe for concurrent use by multiple goroutines. -func Unmarshal(v interface{}, data []interface{}) (err error) { - defer func() { - if r := recover(); r != nil { - var ok bool - if err, ok = r.(error); !ok { - err = fmt.Errorf("%v", r) - } - err = fmt.Errorf("unmarshal: %v", err) - } - }() - - s, err := StructSchema(v) - if err != nil { - return err - } - - if !s.IsPtr { - return fmt.Errorf("unmarshal: need a pointer to a struct") - } - - id := false - nv, nf := len(data), len(s.Fields) - switch s.HasID { - case true: - switch { - case nv == nf: - id = true - case nv == nf-1: - // ok - default: - return fmt.Errorf("unmarshal: got %d values, need %d or %d", nv, nf-1, nf) - } - default: - switch { - case nv == nf: - // ok - default: - return fmt.Errorf("unmarshal: got %d values, need %d", nv, nf) - } - } - - j := 0 - vVal := reflect.ValueOf(v) - if s.IsPtr { - vVal = vVal.Elem() - } - for _, sf := range s.Fields { - if sf.IsID && !id { - continue - } - - d := data[j] - val := reflect.ValueOf(d) - j++ - - fVal := vVal.Field(sf.Index) - if u := sf.UnmarshalType; u != nil { - val = val.Convert(u) - } - if !sf.IsPtr { - fVal.Set(val) - continue - } - - if d == nil { - fVal.Set(sf.ZeroPtr) - continue - } - - if fVal.IsNil() { - fVal.Set(reflect.New(sf.ReflectType)) - } - - fVal.Elem().Set(val) - } - return nil -} diff --git a/vendor/github.com/cznic/ql/lexer.go b/vendor/github.com/cznic/ql/lexer.go deleted file mode 100644 index 272f900bb..000000000 --- a/vendor/github.com/cznic/ql/lexer.go +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2017 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "fmt" - "go/scanner" - "go/token" - "math" - "strconv" - "strings" - "unicode" - - "github.com/cznic/golex/lex" -) - -const ( - ccEOF = iota + 0x80 - ccLetter - ccDigit - ccOther -) - -func runeClass(r rune) int { - switch { - case r == lex.RuneEOF: - return ccEOF - case r < 0x80: - return int(r) - case unicode.IsLetter(r): - return ccLetter - case unicode.IsDigit(r): - return ccDigit - default: - return ccOther - } -} - -type lexer struct { - *lex.Lexer - agg []bool - col int - errs scanner.ErrorList - expr expression - file *token.File - inj int - line int - list []stmt - params int - root bool - sc int -} - -func newLexer(src string) (*lexer, error) { - fset := token.NewFileSet() - file := fset.AddFile("", -1, len(src)) - l := &lexer{ - file: file, - } - l0, err := lex.New( - file, - strings.NewReader(src), - lex.ErrorFunc(func(pos token.Pos, msg string) { - l.errPos(pos, msg) - }), - lex.RuneClass(runeClass), - lex.BOMMode(lex.BOMIgnoreFirst), - ) - if err != nil { - return nil, err - } - - l.Lexer = l0 - return l, nil -} - -func (l *lexer) errPos(pos token.Pos, format string, arg ...interface{}) { - l.errs.Add(l.file.Position(pos), fmt.Sprintf(format, arg...)) -} - -func (l *lexer) err(s string, arg ...interface{}) { - l.errPos(l.Last.Pos(), s, arg...) -} - -// Implements yyLexer. -func (l *lexer) Error(s string) { - l.err(s) -} - -func (l *lexer) int(lval *yySymType, im bool) int { - val := l.TokenBytes(nil) - if im { - val = val[:len(val)-1] - } - n, err := strconv.ParseUint(string(val), 0, 64) - if err != nil { - l.err("integer literal: %v", err) - return int(unicode.ReplacementChar) - } - - if im { - lval.item = idealComplex(complex(0, float64(n))) - return imaginaryLit - } - - switch { - case n < math.MaxInt64: - lval.item = idealInt(n) - default: - lval.item = idealUint(n) - } - return intLit -} - -func (l *lexer) float(lval *yySymType, im bool) int { - val := l.TokenBytes(nil) - if im { - val = val[:len(val)-1] - } - n, err := strconv.ParseFloat(string(val), 64) - if err != nil { - l.err("float literal: %v", err) - return int(unicode.ReplacementChar) - } - - if im { - lval.item = idealComplex(complex(0, n)) - return imaginaryLit - } - - lval.item = idealFloat(n) - return floatLit -} - -func (l *lexer) str(lval *yySymType, pref string) int { - val := l.TokenBytes(nil) - l.sc = 0 - s := pref + string(val) - s, err := strconv.Unquote(s) - if err != nil { - l.err("string literal: %v", err) - return int(unicode.ReplacementChar) - } - - lval.item = s - return stringLit -} - -func (l *lexer) npos() (line, col int) { - pos := l.file.Position(l.Last.Pos()) - return pos.Line, pos.Column -} diff --git a/vendor/github.com/cznic/ql/mem.go b/vendor/github.com/cznic/ql/mem.go deleted file mode 100644 index 5530f02e1..000000000 --- a/vendor/github.com/cznic/ql/mem.go +++ /dev/null @@ -1,1282 +0,0 @@ -// Copyright (c) 2014 ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Plain memory storage back end. - -package ql - -import ( - "bytes" - "fmt" - "io" - "math/big" - "sync" - "time" -) - -var ( - _ btreeIndex = (*memIndex)(nil) - _ btreeIterator = (*memBTreeIterator)(nil) - _ indexIterator = (*xenumerator2)(nil) - _ storage = (*mem)(nil) - _ temp = (*memTemp)(nil) -) - -type memIndex struct { - m *mem - t *xtree - unique bool -} - -func newMemIndex(m *mem, unique bool) *memIndex { - r := &memIndex{t: xtreeNew(), unique: unique, m: m} - //dbg("newMemIndex %p, %p", r, m) - return r -} - -func (x *memIndex) Clear() error { - //dbg("memIndex(%p, %p).Clear", x, x.m) - x.m.newUndo(undoClearX, 0, []interface{}{x, x.t}) - x.t = xtreeNew() - return nil -} - -func (x *memIndex) Create(indexedValues []interface{}, h int64) error { - //dbg("memIndex(%p, %p).Create %v, %v", x, x.m, indexedValues, h) - t := x.t - switch { - case !x.unique: - k := indexKey{indexedValues, h} - x.m.newUndo(undoCreateX, 0, []interface{}{x, k}) //TODO why is old value, if any, not saved? - t.Set(k, 0) - case isIndexNull(indexedValues): // unique, NULL - k := indexKey{nil, h} - x.m.newUndo(undoCreateX, 0, []interface{}{x, k}) //TODO why is old value, if any, not saved? - t.Set(k, 0) - default: // unique, non NULL - k := indexKey{indexedValues, 0} - if _, ok := t.Get(k); ok { //LATER need .Put - return fmt.Errorf("cannot insert into unique index: duplicate value(s): %v", indexedValues) - } - - x.m.newUndo(undoCreateX, 0, []interface{}{x, k}) //TODO why is old value, if any, not saved? - t.Set(k, int(h)) - } - return nil -} - -func (x *memIndex) Delete(indexedValues []interface{}, h int64) error { - //dbg("memIndex(%p, %p).Delete %v, %v", x, x.m, indexedValues, h) - t := x.t - var k indexKey - var v interface{} - var ok, okv bool - switch { - case !x.unique: - k = indexKey{indexedValues, h} - v, okv = t.Get(k) - ok = t.delete(k) - case isIndexNull(indexedValues): // unique, NULL - k = indexKey{nil, h} - v, okv = t.Get(k) - ok = t.delete(k) - default: // unique, non NULL - k = indexKey{indexedValues, 0} - v, okv = t.Get(k) - ok = t.delete(k) - } - if ok { - if okv { - x.m.newUndo(undoDeleteX, int64(v.(int)), []interface{}{x, k}) - } - return nil - } - - return fmt.Errorf("internal error 047") -} - -func (x *memIndex) Drop() error { - x.m.newUndo(undoDropX, 0, []interface{}{x, *x}) - *x = memIndex{} - return nil -} - -func (x *memIndex) Seek(indexedValues []interface{}) (indexIterator, bool, error) { - it, hit := x.t.Seek(indexKey{indexedValues, 0}) - return &xenumerator2{*it, x.unique}, hit, nil -} - -func (x *memIndex) SeekFirst() (iter indexIterator, err error) { - it, err := x.t.SeekFirst() - if err != nil { - return nil, err - } - - return &xenumerator2{*it, x.unique}, nil -} - -func (x *memIndex) SeekLast() (iter indexIterator, err error) { - it, err := x.t.SeekLast() - if err != nil { - return nil, err - } - - return &xenumerator2{*it, x.unique}, nil -} - -type xenumerator2 struct { - it xenumerator - unique bool -} - -func (it *xenumerator2) Next() ([]interface{}, int64, error) { - k, h, err := it.it.Next() - if err != nil { - return nil, -1, err - } - - switch it.unique { - case true: - if k.value == nil { - return nil, k.h, nil - } - - return k.value, h, nil - default: - return k.value, k.h, nil - } -} - -func (it *xenumerator2) Prev() ([]interface{}, int64, error) { - k, h, err := it.it.Prev() - if err != nil { - return nil, -1, err - } - - switch it.unique { - case true: - if k.value == nil { - return nil, k.h, nil - } - - return k.value, h, nil - default: - return k.value, k.h, nil - } -} - -type memBTreeIterator enumerator - -func (it *memBTreeIterator) Next() (k, v []interface{}, err error) { - return (*enumerator)(it).Next() -} - -type memTemp struct { - tree *tree - store *mem -} - -func (t *memTemp) BeginTransaction() (err error) { - return nil -} - -func (t *memTemp) Get(k []interface{}) (v []interface{}, err error) { - v, _ = t.tree.Get(k) - return -} - -func (t *memTemp) Create(data ...interface{}) (h int64, err error) { - s := t.store - switch n := len(s.recycler); { - case n != 0: - h = int64(s.recycler[n-1]) - s.recycler = s.recycler[:n-1] - s.data[h] = s.clone(data...) - default: - h = int64(len(s.data)) - s.data = append(s.data, s.clone(data...)) - } - return -} - -func (t *memTemp) Read(dst []interface{}, h int64, cols ...*col) (data []interface{}, err error) { - return t.store.Read(dst, h, cols...) -} - -func (*memTemp) Drop() (err error) { return } - -func (t *memTemp) Set(k, v []interface{}) (err error) { - t.tree.Set(append([]interface{}(nil), k...), t.store.clone(v...)) - return -} - -func (t *memTemp) SeekFirst() (e btreeIterator, err error) { - en, err := t.tree.SeekFirst() - if err != nil { - return - } - - return (*memBTreeIterator)(en), nil -} - -const ( - undoCreateNewHandle = iota - undoCreateRecycledHandle - undoUpdate - undoDelete - undoClearX // {0: *memIndex, 1: *xtree} - undoCreateX // {0: *memIndex, 1: indexKey} - undoDeleteX // {0: *memIndex, 1: indexKey} - undoDropX // {0: *memIndex, 1: memIndex} -) - -type undo struct { - tag int - h int64 - data []interface{} -} - -type undos struct { - list []undo - parent *undos -} - -type mem struct { - data [][]interface{} - id int64 - recycler []int - tnl int - rollback *undos - mu sync.RWMutex -} - -func newMemStorage() (s *mem, err error) { - s = &mem{data: [][]interface{}{nil}} - if err = s.BeginTransaction(); err != nil { - return nil, err - } - - h, err := s.Create() - if h != 1 { - panic("internal error 048") - } - - if err = s.Commit(); err != nil { - return nil, err - } - - return -} - -func (s *mem) OpenIndex(unique bool, handle int64) (btreeIndex, error) { // Never called on the memory backend. - panic("internal error 049") -} - -func (s *mem) newUndo(tag int, h int64, data []interface{}) { - s.rollback.list = append(s.rollback.list, undo{tag, h, data}) -} - -func (s *mem) Acid() bool { return false } - -func (s *mem) Close() (err error) { - s.mu.Lock() - defer s.mu.Unlock() - if s.tnl != 0 { - return fmt.Errorf("cannot close DB while open transaction exist") - } - s.data, s.recycler, s.rollback = nil, nil, nil - s.id, s.tnl = 0, 0 - return -} - -func (s *mem) CreateIndex(unique bool) ( /* handle */ int64, btreeIndex, error) { - return -1, newMemIndex(s, unique), nil // handle of memIndex should never be used -} - -func (s *mem) Name() string { return fmt.Sprintf("/proc/self/mem/%p", s) } // fake, non existing name - -// OpenMem returns a new, empty DB backed by the process' memory. The back end -// has no limits on field/record/table/DB size other than memory available to -// the process. -func OpenMem() (db *DB, err error) { - s, err := newMemStorage() - if err != nil { - return - } - - if db, err = newDB(s); err != nil { - return nil, err - } - - db.isMem = true - return db, nil -} - -func (s *mem) Verify() (allocs int64, err error) { - for _, v := range s.recycler { - if s.data[v] != nil { - return 0, fmt.Errorf("corrupted: non nil free handle %d", s.data[v]) - } - } - - for _, v := range s.data { - if v != nil { - allocs++ - } - } - - if allocs != int64(len(s.data))-1-int64(len(s.recycler)) { - return 0, fmt.Errorf("corrupted: len(data) %d, len(recycler) %d, allocs %d", len(s.data), len(s.recycler), allocs) - } - - return -} - -func (s *mem) String() string { - var b bytes.Buffer - for i, v := range s.data { - b.WriteString(fmt.Sprintf("s.data[%d] %#v\n", i, v)) - } - for i, v := range s.recycler { - b.WriteString(fmt.Sprintf("s.recycler[%d] %v\n", i, v)) - } - return b.String() -} - -func (s *mem) CreateTemp(asc bool) (_ temp, err error) { - st, err := newMemStorage() - if err != nil { - return - } - - return &memTemp{ - tree: treeNew(collators[asc]), - store: st, - }, nil -} - -func (s *mem) ResetID() (err error) { - s.id = 0 - return -} - -func (s *mem) ID() (id int64, err error) { - s.id++ - return s.id, nil -} - -func (s *mem) clone(data ...interface{}) []interface{} { - r := make([]interface{}, len(data)) - for i, v := range data { - switch x := v.(type) { - case nil: - // nop - case idealComplex: - r[i] = complex128(x) - case idealFloat: - r[i] = float64(x) - case idealInt: - r[i] = int64(x) - case idealRune: - r[i] = int32(x) - case idealUint: - r[i] = uint64(x) - case bool: - r[i] = x - case complex64: - r[i] = x - case complex128: - r[i] = x - case float32: - r[i] = x - case float64: - r[i] = x - case int: - r[i] = int64(x) - case int8: - r[i] = x - case int16: - r[i] = x - case int32: - r[i] = x - case int64: - r[i] = x - case string: - r[i] = x - case uint: - r[i] = uint64(x) - case uint8: - r[i] = x - case uint16: - r[i] = x - case uint32: - r[i] = x - case uint64: - r[i] = x - case []byte: - r[i] = append([]byte(nil), x...) - case *big.Int: - r[i] = big.NewInt(0).Set(x) - case *big.Rat: - r[i] = big.NewRat(1, 2).Set(x) - case time.Time: - t := x - r[i] = t - case time.Duration: - r[i] = x - case map[string]interface{}: // map of ids of a cross join - r[i] = x - default: - panic("internal error 050") - } - } - return r -} - -func (s *mem) Create(data ...interface{}) (h int64, err error) { - switch n := len(s.recycler); { - case n != 0: - h = int64(s.recycler[n-1]) - s.recycler = s.recycler[:n-1] - s.data[h] = s.clone(data...) - r := s.rollback - r.list = append(r.list, undo{ - tag: undoCreateRecycledHandle, - h: h, - }) - default: - h = int64(len(s.data)) - s.data = append(s.data, s.clone(data...)) - r := s.rollback - r.list = append(r.list, undo{ - tag: undoCreateNewHandle, - h: h, - }) - } - return -} - -func (s *mem) Read(dst []interface{}, h int64, cols ...*col) (data []interface{}, err error) { - s.mu.RLock() - defer s.mu.RUnlock() - if i := int(h); i != 0 && i < len(s.data) { - d := s.clone(s.data[h]...) - if cols == nil { - return d, nil - } - - for n, dn := len(cols)+2, len(d); dn < n; dn++ { - d = append(d, nil) - } - return d, nil - } - - return nil, errNoDataForHandle -} - -func (s *mem) UpdateRow(h int64, _ []*col, data ...interface{}) (err error) { - return s.Update(h, data...) -} - -func (s *mem) Update(h int64, data ...interface{}) (err error) { - r := s.rollback - r.list = append(r.list, undo{ - tag: undoUpdate, - h: h, - data: s.data[h], - }) - s.data[h] = s.clone(data...) - return -} - -func (s *mem) Delete(h int64, _ ...*col) (err error) { - r := s.rollback - r.list = append(r.list, undo{ - tag: undoDelete, - h: h, - data: s.data[h], - }) - s.recycler = append(s.recycler, int(h)) - s.data[h] = nil - return -} - -func (s *mem) BeginTransaction() (err error) { - s.rollback = &undos{parent: s.rollback} - s.tnl++ - return nil -} - -func (s *mem) Rollback() (err error) { - if s.tnl == 0 { - return errRollbackNotInTransaction - } - - list := s.rollback.list - for i := len(list) - 1; i >= 0; i-- { - undo := list[i] - switch h, data := int(undo.h), undo.data; undo.tag { - case undoCreateNewHandle: - d := s.data - s.data = d[:len(d)-1] - case undoCreateRecycledHandle: - s.data[h] = nil - r := s.recycler - s.recycler = append(r, h) - case undoUpdate: - s.data[h] = data - case undoDelete: - s.data[h] = data - s.recycler = s.recycler[:len(s.recycler)-1] - case undoClearX: - x, t := data[0].(*memIndex), data[1].(*xtree) - x.t = t - case undoCreateX: - x, k := data[0].(*memIndex), data[1].(indexKey) - x.t.delete(k) - case undoDeleteX: - x, k := data[0].(*memIndex), data[1].(indexKey) - x.t.Set(k, h) - case undoDropX: - x, v := data[0].(*memIndex), data[1].(memIndex) - *x = v - default: - panic("internal error 051") - } - } - - s.tnl-- - s.rollback = s.rollback.parent - return nil -} - -func (s *mem) Commit() (err error) { - if s.tnl == 0 { - return errCommitNotInTransaction - } - - s.tnl-- - s.rollback = s.rollback.parent - return nil -} - -// Transaction index B+Tree -//LATER make it just a wrapper of the implementation in btree.go. - -type ( - xd struct { // data page - c int - xd [2*kd + 1]xde - n *xd - p *xd - } - - xde struct { // xd element - k indexKey - v int - } - - // xenumerator captures the state of enumerating a tree. It is returned - // from the Seek* methods. The enumerator is aware of any mutations - // made to the tree in the process of enumerating it and automatically - // resumes the enumeration at the proper key, if possible. - // - // However, once an xenumerator returns io.EOF to signal "no more - // items", it does no more attempt to "resync" on tree mutation(s). In - // other words, io.EOF from an Enumaretor is "sticky" (idempotent). - xenumerator struct { - err error - hit bool - i int - k indexKey - q *xd - t *xtree - ver int64 - } - - // xtree is a B+tree. - xtree struct { - c int - first *xd - last *xd - r interface{} - ver int64 - } - - xxe struct { // xx element - ch interface{} - sep *xd - } - - xx struct { // index page - c int - xx [2*kx + 2]xxe - } -) - -func (a *indexKey) cmp(b *indexKey) int { - r := collate(a.value, b.value) - if r != 0 { - return r - } - - return int(a.h) - int(b.h) -} - -var ( // R/O zero values - zxd xd - zxde xde - zxx xx - zxxe xxe -) - -func xclr(q interface{}) { - switch xx := q.(type) { - case *xx: - for i := 0; i <= xx.c; i++ { // Ch0 Sep0 ... Chn-1 Sepn-1 Chn - xclr(xx.xx[i].ch) - } - *xx = zxx // GC - case *xd: - *xx = zxd // GC - } -} - -// -------------------------------------------------------------------------- xx - -func xnewX(ch0 interface{}) *xx { - r := &xx{} - r.xx[0].ch = ch0 - return r -} - -func (q *xx) extract(i int) { - q.c-- - if i < q.c { - copy(q.xx[i:], q.xx[i+1:q.c+1]) - q.xx[q.c].ch = q.xx[q.c+1].ch - q.xx[q.c].sep = nil // GC - q.xx[q.c+1] = zxxe // GC - } -} - -func (q *xx) insert(i int, xd *xd, ch interface{}) *xx { - c := q.c - if i < c { - q.xx[c+1].ch = q.xx[c].ch - copy(q.xx[i+2:], q.xx[i+1:c]) - q.xx[i+1].sep = q.xx[i].sep - } - c++ - q.c = c - q.xx[i].sep = xd - q.xx[i+1].ch = ch - return q -} - -func (q *xx) siblings(i int) (l, r *xd) { - if i >= 0 { - if i > 0 { - l = q.xx[i-1].ch.(*xd) - } - if i < q.c { - r = q.xx[i+1].ch.(*xd) - } - } - return -} - -// -------------------------------------------------------------------------- xd - -func (l *xd) mvL(r *xd, c int) { - copy(l.xd[l.c:], r.xd[:c]) - copy(r.xd[:], r.xd[c:r.c]) - l.c += c - r.c -= c -} - -func (l *xd) mvR(r *xd, c int) { - copy(r.xd[c:], r.xd[:r.c]) - copy(r.xd[:c], l.xd[l.c-c:]) - r.c += c - l.c -= c -} - -// ----------------------------------------------------------------------- xtree - -// xtreeNew returns a newly created, empty xtree. The compare function is used -// for key collation. -func xtreeNew() *xtree { - return &xtree{} -} - -// Clear removes all K/V pairs from the tree. -func (t *xtree) Clear() { - if t.r == nil { - return - } - - xclr(t.r) - t.c, t.first, t.last, t.r = 0, nil, nil, nil - t.ver++ -} - -func (t *xtree) cat(p *xx, q, r *xd, pi int) { - t.ver++ - q.mvL(r, r.c) - if r.n != nil { - r.n.p = q - } else { - t.last = q - } - q.n = r.n - if p.c > 1 { - p.extract(pi) - p.xx[pi].ch = q - } else { - t.r = q - } -} - -func (t *xtree) catX(p, q, r *xx, pi int) { - t.ver++ - q.xx[q.c].sep = p.xx[pi].sep - copy(q.xx[q.c+1:], r.xx[:r.c]) - q.c += r.c + 1 - q.xx[q.c].ch = r.xx[r.c].ch - if p.c > 1 { - p.c-- - pc := p.c - if pi < pc { - p.xx[pi].sep = p.xx[pi+1].sep - copy(p.xx[pi+1:], p.xx[pi+2:pc+1]) - p.xx[pc].ch = p.xx[pc+1].ch - p.xx[pc].sep = nil // GC - p.xx[pc+1].ch = nil // GC - } - return - } - - t.r = q -} - -//Delete removes the k's KV pair, if it exists, in which case Delete returns -//true. -func (t *xtree) delete(k indexKey) (ok bool) { - pi := -1 - var p *xx - q := t.r - if q == nil { - return - } - - for { - var i int - i, ok = t.find(q, k) - if ok { - switch xx := q.(type) { - case *xx: - dp := xx.xx[i].sep - switch { - case dp.c > kd: - t.extract(dp, 0) - default: - if xx.c < kx && q != t.r { - t.underflowX(p, &xx, pi, &i) - } - pi = i + 1 - p = xx - q = xx.xx[pi].ch - ok = false - continue - } - case *xd: - t.extract(xx, i) - if xx.c >= kd { - return - } - - if q != t.r { - t.underflow(p, xx, pi) - } else if t.c == 0 { - t.Clear() - } - } - return - } - - switch xx := q.(type) { - case *xx: - if xx.c < kx && q != t.r { - t.underflowX(p, &xx, pi, &i) - } - pi = i - p = xx - q = xx.xx[i].ch - case *xd: - return - } - } -} - -func (t *xtree) extract(q *xd, i int) { // (r int64) { - t.ver++ - //r = q.xd[i].v // prepared for Extract - q.c-- - if i < q.c { - copy(q.xd[i:], q.xd[i+1:q.c+1]) - } - q.xd[q.c] = zxde // GC - t.c-- -} - -func (t *xtree) find(q interface{}, k indexKey) (i int, ok bool) { - var mk indexKey - l := 0 - switch xx := q.(type) { - case *xx: - h := xx.c - 1 - for l <= h { - m := (l + h) >> 1 - mk = xx.xx[m].sep.xd[0].k - switch cmp := k.cmp(&mk); { - case cmp > 0: - l = m + 1 - case cmp == 0: - return m, true - default: - h = m - 1 - } - } - case *xd: - h := xx.c - 1 - for l <= h { - m := (l + h) >> 1 - mk = xx.xd[m].k - switch cmp := k.cmp(&mk); { - case cmp > 0: - l = m + 1 - case cmp == 0: - return m, true - default: - h = m - 1 - } - } - } - return l, false -} - -// First returns the first item of the tree in the key collating order, or -// (nil, nil) if the tree is empty. -func (t *xtree) First() (k indexKey, v int) { - if q := t.first; q != nil { - q := &q.xd[0] - k, v = q.k, q.v - } - return -} - -// Get returns the value associated with k and true if it exists. Otherwise Get -// returns (nil, false). -func (t *xtree) Get(k indexKey) (v int, ok bool) { - q := t.r - if q == nil { - return - } - - for { - var i int - if i, ok = t.find(q, k); ok { - switch xx := q.(type) { - case *xx: - return xx.xx[i].sep.xd[0].v, true - case *xd: - return xx.xd[i].v, true - } - } - switch xx := q.(type) { - case *xx: - q = xx.xx[i].ch - default: - return - } - } -} - -func (t *xtree) insert(q *xd, i int, k indexKey, v int) *xd { - t.ver++ - c := q.c - if i < c { - copy(q.xd[i+1:], q.xd[i:c]) - } - c++ - q.c = c - q.xd[i].k, q.xd[i].v = k, v - t.c++ - return q -} - -// Last returns the last item of the tree in the key collating order, or (nil, -// nil) if the tree is empty. -func (t *xtree) Last() (k indexKey, v int) { - if q := t.last; q != nil { - q := &q.xd[q.c-1] - k, v = q.k, q.v - } - return -} - -// Len returns the number of items in the tree. -func (t *xtree) Len() int { - return t.c -} - -func (t *xtree) overflow(p *xx, q *xd, pi, i int, k indexKey, v int) { - t.ver++ - l, r := p.siblings(pi) - - if l != nil && l.c < 2*kd { - l.mvL(q, 1) - t.insert(q, i-1, k, v) - return - } - - if r != nil && r.c < 2*kd { - if i < 2*kd { - q.mvR(r, 1) - t.insert(q, i, k, v) - } else { - t.insert(r, 0, k, v) - } - return - } - - t.split(p, q, pi, i, k, v) -} - -// Seek returns an xenumerator positioned on a an item such that k >= item's -// key. ok reports if k == item.key The xenumerator's position is possibly -// after the last item in the tree. -func (t *xtree) Seek(k indexKey) (e *xenumerator, ok bool) { - q := t.r - if q == nil { - e = &xenumerator{nil, false, 0, k, nil, t, t.ver} - return - } - - for { - var i int - if i, ok = t.find(q, k); ok { - switch xx := q.(type) { - case *xx: - e = &xenumerator{nil, ok, 0, k, xx.xx[i].sep, t, t.ver} - return - case *xd: - e = &xenumerator{nil, ok, i, k, xx, t, t.ver} - return - } - } - switch xx := q.(type) { - case *xx: - q = xx.xx[i].ch - case *xd: - e = &xenumerator{nil, ok, i, k, xx, t, t.ver} - return - } - } -} - -// SeekFirst returns an enumerator positioned on the first KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returned and e will be nil. -func (t *xtree) SeekFirst() (e *xenumerator, err error) { - q := t.first - if q == nil { - return nil, io.EOF - } - - return &xenumerator{nil, true, 0, q.xd[0].k, q, t, t.ver}, nil -} - -// SeekLast returns an enumerator positioned on the last KV pair in the tree, -// if any. For an empty tree, err == io.EOF is returned and e will be nil. -func (t *xtree) SeekLast() (e *xenumerator, err error) { - q := t.last - if q == nil { - return nil, io.EOF - } - - return &xenumerator{nil, true, q.c - 1, q.xd[q.c-1].k, q, t, t.ver}, nil -} - -// Set sets the value associated with k. -func (t *xtree) Set(k indexKey, v int) { - pi := -1 - var p *xx - q := t.r - if q != nil { - for { - i, ok := t.find(q, k) - if ok { - switch xx := q.(type) { - case *xx: - xx.xx[i].sep.xd[0].v = v - case *xd: - xx.xd[i].v = v - } - return - } - - switch xx := q.(type) { - case *xx: - if xx.c > 2*kx { - t.splitX(p, &xx, pi, &i) - } - pi = i - p = xx - q = xx.xx[i].ch - case *xd: - switch { - case xx.c < 2*kd: - t.insert(xx, i, k, v) - default: - t.overflow(p, xx, pi, i, k, v) - } - return - } - } - } - - z := t.insert(&xd{}, 0, k, v) - t.r, t.first, t.last = z, z, z -} - -func (t *xtree) split(p *xx, q *xd, pi, i int, k indexKey, v int) { - t.ver++ - r := &xd{} - if q.n != nil { - r.n = q.n - r.n.p = r - } else { - t.last = r - } - q.n = r - r.p = q - - copy(r.xd[:], q.xd[kd:2*kd]) - for i := range q.xd[kd:] { - q.xd[kd+i] = zxde - } - q.c = kd - r.c = kd - if pi >= 0 { - p.insert(pi, r, r) - } else { - t.r = xnewX(q).insert(0, r, r) - } - if i > kd { - t.insert(r, i-kd, k, v) - return - } - - t.insert(q, i, k, v) -} - -func (t *xtree) splitX(p *xx, pp **xx, pi int, i *int) { - t.ver++ - q := *pp - r := &xx{} - copy(r.xx[:], q.xx[kx+1:]) - q.c = kx - r.c = kx - if pi >= 0 { - p.insert(pi, q.xx[kx].sep, r) - } else { - t.r = xnewX(q).insert(0, q.xx[kx].sep, r) - } - q.xx[kx].sep = nil - for i := range q.xx[kx+1:] { - q.xx[kx+i+1] = zxxe - } - if *i > kx { - *pp = r - *i -= kx + 1 - } -} - -func (t *xtree) underflow(p *xx, q *xd, pi int) { - t.ver++ - l, r := p.siblings(pi) - - if l != nil && l.c+q.c >= 2*kd { - l.mvR(q, 1) - } else if r != nil && q.c+r.c >= 2*kd { - q.mvL(r, 1) - r.xd[r.c] = zxde // GC - } else if l != nil { - t.cat(p, l, q, pi-1) - } else { - t.cat(p, q, r, pi) - } -} - -func (t *xtree) underflowX(p *xx, pp **xx, pi int, i *int) { - t.ver++ - var l, r *xx - q := *pp - - if pi >= 0 { - if pi > 0 { - l = p.xx[pi-1].ch.(*xx) - } - if pi < p.c { - r = p.xx[pi+1].ch.(*xx) - } - } - - if l != nil && l.c > kx { - q.xx[q.c+1].ch = q.xx[q.c].ch - copy(q.xx[1:], q.xx[:q.c]) - q.xx[0].ch = l.xx[l.c].ch - q.xx[0].sep = p.xx[pi-1].sep - q.c++ - *i++ - l.c-- - p.xx[pi-1].sep = l.xx[l.c].sep - return - } - - if r != nil && r.c > kx { - q.xx[q.c].sep = p.xx[pi].sep - q.c++ - q.xx[q.c].ch = r.xx[0].ch - p.xx[pi].sep = r.xx[0].sep - copy(r.xx[:], r.xx[1:r.c]) - r.c-- - rc := r.c - r.xx[rc].ch = r.xx[rc+1].ch - r.xx[rc].sep = nil - r.xx[rc+1].ch = nil - return - } - - if l != nil { - *i += l.c + 1 - t.catX(p, l, q, pi-1) - *pp = l - return - } - - t.catX(p, q, r, pi) -} - -// ----------------------------------------------------------------- xenumerator - -// Next returns the currently enumerated item, if it exists and moves to the -// next item in the key collation order. If there is no item to return, err == -// io.EOF is returned. -func (e *xenumerator) Next() (k indexKey, v int64, err error) { - if err = e.err; err != nil { - return - } - - if e.ver != e.t.ver { - f, hit := e.t.Seek(e.k) - if !e.hit && hit { - if err = f.next(); err != nil { - return - } - } - - *e = *f - } - if e.q == nil { - e.err, err = io.EOF, io.EOF - return - } - - if e.i >= e.q.c { - if err = e.next(); err != nil { - return - } - } - - i := e.q.xd[e.i] - k, v = i.k, int64(i.v) - e.k, e.hit = k, false - e.next() - return -} - -func (e *xenumerator) next() error { - if e.q == nil { - e.err = io.EOF - return io.EOF - } - - switch { - case e.i < e.q.c-1: - e.i++ - default: - if e.q, e.i = e.q.n, 0; e.q == nil { - e.err = io.EOF - } - } - return e.err -} - -// Prev returns the currently enumerated item, if it exists and moves to the -// previous item in the key collation order. If there is no item to return, err -// == io.EOF is returned. -func (e *xenumerator) Prev() (k indexKey, v int64, err error) { - if err = e.err; err != nil { - return - } - - if e.ver != e.t.ver { - f, hit := e.t.Seek(e.k) - if !e.hit && hit { - if err = f.prev(); err != nil { - return - } - } - - *e = *f - } - if e.q == nil { - e.err, err = io.EOF, io.EOF - return - } - - if e.i >= e.q.c { - if err = e.next(); err != nil { - return - } - } - - i := e.q.xd[e.i] - k, v = i.k, int64(i.v) - e.k, e.hit = k, false - e.prev() - return -} - -func (e *xenumerator) prev() error { - if e.q == nil { - e.err = io.EOF - return io.EOF - } - - switch { - case e.i > 0: - e.i-- - default: - if e.q = e.q.p; e.q == nil { - e.err = io.EOF - break - } - - e.i = e.q.c - 1 - } - return e.err -} diff --git a/vendor/github.com/cznic/ql/parser.go b/vendor/github.com/cznic/ql/parser.go deleted file mode 100644 index 24539fc71..000000000 --- a/vendor/github.com/cznic/ql/parser.go +++ /dev/null @@ -1,2805 +0,0 @@ -// Code generated by goyacc - DO NOT EDIT. - -// Copyright (c) 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Initial yacc source generated by ebnf2y[1] -// at 2013-10-04 23:10:47.861401015 +0200 CEST -// -// $ ebnf2y -o ql.y -oe ql.ebnf -start StatementList -pkg ql -p _ -// -// [1]: http://github.com/cznic/ebnf2y - -package ql - -import __yyfmt__ "fmt" - -import ( - "fmt" - - "github.com/cznic/mathutil" -) - -type yySymType struct { - yys int - line int - col int - item interface{} - list []interface{} -} - -type yyXError struct { - state, xsym int -} - -const ( - yyDefault = 57437 - yyEOFCode = 57344 - add = 57352 - alter = 57353 - and = 57354 - andand = 57355 - andnot = 57356 - as = 57357 - asc = 57358 - begin = 57359 - between = 57360 - bigIntType = 57361 - bigRatType = 57362 - blobType = 57363 - boolType = 57364 - by = 57365 - byteType = 57366 - column = 57367 - commit = 57368 - complex128Type = 57369 - complex64Type = 57370 - create = 57371 - defaultKwd = 57372 - deleteKwd = 57373 - desc = 57374 - distinct = 57375 - drop = 57376 - durationType = 57377 - eq = 57378 - yyErrCode = 57345 - exists = 57379 - explain = 57380 - falseKwd = 57381 - float32Type = 57383 - float64Type = 57384 - floatLit = 57346 - floatType = 57382 - from = 57385 - full = 57386 - ge = 57387 - group = 57388 - identifier = 57347 - ifKwd = 57389 - imaginaryLit = 57348 - in = 57390 - index = 57391 - insert = 57392 - int16Type = 57394 - int32Type = 57395 - int64Type = 57396 - int8Type = 57397 - intLit = 57349 - intType = 57393 - into = 57398 - is = 57399 - join = 57400 - le = 57401 - left = 57402 - like = 57403 - limit = 57404 - lsh = 57405 - neq = 57406 - not = 57407 - null = 57408 - offset = 57409 - on = 57410 - or = 57411 - order = 57412 - oror = 57413 - outer = 57414 - parseExpression = 57436 - qlParam = 57350 - right = 57415 - rollback = 57416 - rsh = 57417 - runeType = 57418 - selectKwd = 57419 - set = 57420 - stringLit = 57351 - stringType = 57421 - tableKwd = 57422 - timeType = 57423 - transaction = 57424 - trueKwd = 57425 - truncate = 57426 - uint16Type = 57428 - uint32Type = 57429 - uint64Type = 57430 - uint8Type = 57431 - uintType = 57427 - unique = 57432 - update = 57433 - values = 57434 - where = 57435 - - yyMaxDepth = 200 - yyTabOfs = -222 -) - -var ( - yyPrec = map[int]int{} - - yyXLAT = map[int]int{ - 59: 0, // ';' (204x) - 57344: 1, // $end (203x) - 41: 2, // ')' (178x) - 43: 3, // '+' (135x) - 45: 4, // '-' (135x) - 94: 5, // '^' (135x) - 44: 6, // ',' (130x) - 40: 7, // '(' (129x) - 57347: 8, // identifier (118x) - 57409: 9, // offset (115x) - 57404: 10, // limit (113x) - 57412: 11, // order (102x) - 57435: 12, // where (97x) - 57372: 13, // defaultKwd (94x) - 57388: 14, // group (93x) - 57408: 15, // null (86x) - 57361: 16, // bigIntType (85x) - 57362: 17, // bigRatType (85x) - 57363: 18, // blobType (85x) - 57364: 19, // boolType (85x) - 57366: 20, // byteType (85x) - 57369: 21, // complex128Type (85x) - 57370: 22, // complex64Type (85x) - 57377: 23, // durationType (85x) - 57383: 24, // float32Type (85x) - 57384: 25, // float64Type (85x) - 57382: 26, // floatType (85x) - 57386: 27, // full (85x) - 57394: 28, // int16Type (85x) - 57395: 29, // int32Type (85x) - 57396: 30, // int64Type (85x) - 57397: 31, // int8Type (85x) - 57393: 32, // intType (85x) - 57402: 33, // left (85x) - 57415: 34, // right (85x) - 57418: 35, // runeType (85x) - 57421: 36, // stringType (85x) - 57423: 37, // timeType (85x) - 57428: 38, // uint16Type (85x) - 57429: 39, // uint32Type (85x) - 57430: 40, // uint64Type (85x) - 57431: 41, // uint8Type (85x) - 57427: 42, // uintType (85x) - 57381: 43, // falseKwd (83x) - 57346: 44, // floatLit (83x) - 57348: 45, // imaginaryLit (83x) - 57349: 46, // intLit (83x) - 57350: 47, // qlParam (83x) - 57351: 48, // stringLit (83x) - 57425: 49, // trueKwd (83x) - 57407: 50, // not (82x) - 57411: 51, // or (81x) - 57413: 52, // oror (81x) - 33: 53, // '!' (79x) - 57385: 54, // from (75x) - 57358: 55, // asc (71x) - 57374: 56, // desc (71x) - 93: 57, // ']' (70x) - 57357: 58, // as (69x) - 58: 59, // ':' (67x) - 57354: 60, // and (67x) - 57355: 61, // andand (65x) - 124: 62, // '|' (56x) - 61: 63, // '=' (55x) - 57360: 64, // between (54x) - 57390: 65, // in (54x) - 60: 66, // '<' (53x) - 62: 67, // '>' (53x) - 57378: 68, // eq (53x) - 57387: 69, // ge (53x) - 57399: 70, // is (53x) - 57401: 71, // le (53x) - 57403: 72, // like (53x) - 57406: 73, // neq (53x) - 57515: 74, // Type (52x) - 57453: 75, // Conversion (51x) - 57484: 76, // Literal (51x) - 57485: 77, // Operand (51x) - 57489: 78, // PrimaryExpression (51x) - 57492: 79, // QualifiedIdent (51x) - 42: 80, // '*' (48x) - 57516: 81, // UnaryExpr (47x) - 37: 82, // '%' (44x) - 38: 83, // '&' (44x) - 47: 84, // '/' (44x) - 57356: 85, // andnot (44x) - 57405: 86, // lsh (44x) - 57417: 87, // rsh (44x) - 57491: 88, // PrimaryTerm (40x) - 57490: 89, // PrimaryFactor (36x) - 91: 90, // '[' (31x) - 57471: 91, // Factor (25x) - 57472: 92, // Factor1 (25x) - 57513: 93, // Term (24x) - 57468: 94, // Expression (23x) - 57521: 95, // logOr (16x) - 57419: 96, // selectKwd (12x) - 57446: 97, // ColumnName (10x) - 57498: 98, // SelectStmt (9x) - 57512: 99, // TableName (9x) - 57449: 100, // CommaOpt (7x) - 57469: 101, // ExpressionList (7x) - 57410: 102, // on (7x) - 57379: 103, // exists (6x) - 57400: 104, // join (6x) - 57443: 105, // Call (5x) - 57376: 106, // drop (5x) - 57477: 107, // Index (5x) - 57508: 108, // Slice (5x) - 57445: 109, // ColumnDef (4x) - 57389: 110, // ifKwd (4x) - 57391: 111, // index (4x) - 57414: 112, // outer (4x) - 57422: 113, // tableKwd (4x) - 57434: 114, // values (4x) - 57353: 115, // alter (3x) - 57438: 116, // AlterTableStmt (3x) - 57359: 117, // begin (3x) - 57442: 118, // BeginTransactionStmt (3x) - 57368: 119, // commit (3x) - 57450: 120, // CommitStmt (3x) - 57371: 121, // create (3x) - 57455: 122, // CreateIndexStmt (3x) - 57457: 123, // CreateTableStmt (3x) - 57461: 124, // DeleteFromStmt (3x) - 57373: 125, // deleteKwd (3x) - 57463: 126, // DropIndexStmt (3x) - 57464: 127, // DropTableStmt (3x) - 57465: 128, // EmptyStmt (3x) - 57380: 129, // explain (3x) - 57467: 130, // ExplainStmt (3x) - 57392: 131, // insert (3x) - 57478: 132, // InsertIntoStmt (3x) - 57493: 133, // RecordSet (3x) - 57494: 134, // RecordSet1 (3x) - 57416: 135, // rollback (3x) - 57497: 136, // RollbackStmt (3x) - 57522: 137, // semiOpt (3x) - 57510: 138, // Statement (3x) - 57426: 139, // truncate (3x) - 57514: 140, // TruncateTableStmt (3x) - 57433: 141, // update (3x) - 57517: 142, // UpdateStmt (3x) - 57519: 143, // WhereClause (3x) - 57352: 144, // add (2x) - 57439: 145, // Assignment (2x) - 57365: 146, // by (2x) - 57447: 147, // ColumnNameList (2x) - 57458: 148, // CreateTableStmt1 (2x) - 57473: 149, // Field (2x) - 57520: 150, // logAnd (2x) - 57420: 151, // set (2x) - 46: 152, // '.' (1x) - 57440: 153, // AssignmentList (1x) - 57441: 154, // AssignmentList1 (1x) - 57444: 155, // Call1 (1x) - 57367: 156, // column (1x) - 57448: 157, // ColumnNameList1 (1x) - 57451: 158, // Constraint (1x) - 57452: 159, // ConstraintOpt (1x) - 57454: 160, // CreateIndexIfNotExists (1x) - 57456: 161, // CreateIndexStmtUnique (1x) - 57459: 162, // Default (1x) - 57460: 163, // DefaultOpt (1x) - 57375: 164, // distinct (1x) - 57462: 165, // DropIndexIfExists (1x) - 57466: 166, // Eq (1x) - 57470: 167, // ExpressionList1 (1x) - 57474: 168, // Field1 (1x) - 57475: 169, // FieldList (1x) - 57476: 170, // GroupByClause (1x) - 57479: 171, // InsertIntoStmt1 (1x) - 57480: 172, // InsertIntoStmt2 (1x) - 57398: 173, // into (1x) - 57481: 174, // JoinClause (1x) - 57482: 175, // JoinClauseOpt (1x) - 57483: 176, // JoinType (1x) - 57486: 177, // OrderBy (1x) - 57487: 178, // OrderBy1 (1x) - 57488: 179, // OuterOpt (1x) - 57436: 180, // parseExpression (1x) - 57495: 181, // RecordSet2 (1x) - 57496: 182, // RecordSetList (1x) - 57499: 183, // SelectStmtDistinct (1x) - 57500: 184, // SelectStmtFieldList (1x) - 57501: 185, // SelectStmtFrom (1x) - 57502: 186, // SelectStmtGroup (1x) - 57503: 187, // SelectStmtLimit (1x) - 57504: 188, // SelectStmtOffset (1x) - 57505: 189, // SelectStmtOrder (1x) - 57506: 190, // SelectStmtWhere (1x) - 57507: 191, // SetOpt (1x) - 57509: 192, // Start (1x) - 57511: 193, // StatementList (1x) - 57424: 194, // transaction (1x) - 57432: 195, // unique (1x) - 57518: 196, // UpdateStmt1 (1x) - 57437: 197, // $default (0x) - 57345: 198, // error (0x) - } - - yySymNames = []string{ - "';'", - "$end", - "')'", - "'+'", - "'-'", - "'^'", - "','", - "'('", - "identifier", - "offset", - "limit", - "order", - "where", - "defaultKwd", - "group", - "null", - "bigIntType", - "bigRatType", - "blobType", - "boolType", - "byteType", - "complex128Type", - "complex64Type", - "durationType", - "float32Type", - "float64Type", - "floatType", - "full", - "int16Type", - "int32Type", - "int64Type", - "int8Type", - "intType", - "left", - "right", - "runeType", - "stringType", - "timeType", - "uint16Type", - "uint32Type", - "uint64Type", - "uint8Type", - "uintType", - "falseKwd", - "floatLit", - "imaginaryLit", - "intLit", - "qlParam", - "stringLit", - "trueKwd", - "not", - "or", - "oror", - "'!'", - "from", - "asc", - "desc", - "']'", - "as", - "':'", - "and", - "andand", - "'|'", - "'='", - "between", - "in", - "'<'", - "'>'", - "eq", - "ge", - "is", - "le", - "like", - "neq", - "Type", - "Conversion", - "Literal", - "Operand", - "PrimaryExpression", - "QualifiedIdent", - "'*'", - "UnaryExpr", - "'%'", - "'&'", - "'/'", - "andnot", - "lsh", - "rsh", - "PrimaryTerm", - "PrimaryFactor", - "'['", - "Factor", - "Factor1", - "Term", - "Expression", - "logOr", - "selectKwd", - "ColumnName", - "SelectStmt", - "TableName", - "CommaOpt", - "ExpressionList", - "on", - "exists", - "join", - "Call", - "drop", - "Index", - "Slice", - "ColumnDef", - "ifKwd", - "index", - "outer", - "tableKwd", - "values", - "alter", - "AlterTableStmt", - "begin", - "BeginTransactionStmt", - "commit", - "CommitStmt", - "create", - "CreateIndexStmt", - "CreateTableStmt", - "DeleteFromStmt", - "deleteKwd", - "DropIndexStmt", - "DropTableStmt", - "EmptyStmt", - "explain", - "ExplainStmt", - "insert", - "InsertIntoStmt", - "RecordSet", - "RecordSet1", - "rollback", - "RollbackStmt", - "semiOpt", - "Statement", - "truncate", - "TruncateTableStmt", - "update", - "UpdateStmt", - "WhereClause", - "add", - "Assignment", - "by", - "ColumnNameList", - "CreateTableStmt1", - "Field", - "logAnd", - "set", - "'.'", - "AssignmentList", - "AssignmentList1", - "Call1", - "column", - "ColumnNameList1", - "Constraint", - "ConstraintOpt", - "CreateIndexIfNotExists", - "CreateIndexStmtUnique", - "Default", - "DefaultOpt", - "distinct", - "DropIndexIfExists", - "Eq", - "ExpressionList1", - "Field1", - "FieldList", - "GroupByClause", - "InsertIntoStmt1", - "InsertIntoStmt2", - "into", - "JoinClause", - "JoinClauseOpt", - "JoinType", - "OrderBy", - "OrderBy1", - "OuterOpt", - "parseExpression", - "RecordSet2", - "RecordSetList", - "SelectStmtDistinct", - "SelectStmtFieldList", - "SelectStmtFrom", - "SelectStmtGroup", - "SelectStmtLimit", - "SelectStmtOffset", - "SelectStmtOrder", - "SelectStmtWhere", - "SetOpt", - "Start", - "StatementList", - "transaction", - "unique", - "UpdateStmt1", - "$default", - "error", - } - - yyTokenLiteralStrings = map[int]string{ - 57347: "identifier", - 57409: "OFFSET", - 57404: "LIMIT", - 57412: "ORDER", - 57435: "WHERE", - 57372: "DEFAULT", - 57388: "GROUP", - 57408: "NULL", - 57361: "bigint", - 57362: "bigrat", - 57363: "blob", - 57364: "bool", - 57366: "byte", - 57369: "complex128", - 57370: "complex64", - 57377: "duration", - 57383: "float32", - 57384: "float64", - 57382: "float", - 57386: "FULL", - 57394: "int16", - 57395: "int32", - 57396: "int64", - 57397: "int8", - 57393: "int", - 57402: "LEFT", - 57415: "RIGHT", - 57418: "rune", - 57421: "string", - 57423: "time", - 57428: "uint16", - 57429: "uint32", - 57430: "uint64", - 57431: "uint8", - 57427: "uint", - 57381: "false", - 57346: "floating-point literal", - 57348: "imaginary literal", - 57349: "integer literal", - 57350: "QL parameter", - 57351: "string literal", - 57425: "true", - 57407: "NOT", - 57411: "OR", - 57413: "||", - 57385: "FROM", - 57358: "ASC", - 57374: "DESC", - 57357: "AS", - 57354: "AND", - 57355: "&&", - 57360: "BETWEEN", - 57390: "IN", - 57378: "==", - 57387: ">=", - 57399: "IS", - 57401: "<=", - 57403: "LIKE", - 57406: "!=", - 57356: "&^", - 57405: "<<", - 57417: ">>", - 57419: "SELECT", - 57410: "ON", - 57379: "EXISTS", - 57400: "JOIN", - 57376: "DROP", - 57389: "IF", - 57391: "INDEX", - 57414: "OUTER", - 57422: "TABLE", - 57434: "VALUES", - 57353: "ALTER", - 57359: "BEGIN", - 57368: "COMMIT", - 57371: "CREATE", - 57373: "DELETE", - 57380: "EXPLAIN", - 57392: "INSERT", - 57416: "ROLLBACK", - 57426: "TRUNCATE", - 57433: "UPDATE", - 57352: "ADD", - 57365: "BY", - 57420: "SET", - 57367: "COLUMN", - 57375: "DISTINCT", - 57398: "INTO", - 57436: "parse expression prefix", - 57424: "TRANSACTION", - 57432: "UNIQUE", - } - - yyReductions = map[int]struct{ xsym, components int }{ - 0: {0, 1}, - 1: {192, 1}, - 2: {192, 2}, - 3: {116, 5}, - 4: {116, 6}, - 5: {145, 3}, - 6: {153, 3}, - 7: {154, 0}, - 8: {154, 3}, - 9: {118, 2}, - 10: {105, 3}, - 11: {105, 3}, - 12: {155, 0}, - 13: {155, 1}, - 14: {109, 4}, - 15: {97, 1}, - 16: {147, 3}, - 17: {157, 0}, - 18: {157, 3}, - 19: {120, 1}, - 20: {158, 2}, - 21: {158, 1}, - 22: {159, 0}, - 23: {159, 1}, - 24: {75, 4}, - 25: {122, 10}, - 26: {160, 0}, - 27: {160, 3}, - 28: {161, 0}, - 29: {161, 1}, - 30: {123, 8}, - 31: {123, 11}, - 32: {148, 0}, - 33: {148, 3}, - 34: {162, 2}, - 35: {163, 0}, - 36: {163, 1}, - 37: {124, 3}, - 38: {124, 4}, - 39: {126, 4}, - 40: {165, 0}, - 41: {165, 2}, - 42: {127, 3}, - 43: {127, 5}, - 44: {128, 0}, - 45: {130, 2}, - 46: {94, 1}, - 47: {94, 3}, - 48: {95, 1}, - 49: {95, 1}, - 50: {166, 1}, - 51: {166, 1}, - 52: {101, 3}, - 53: {167, 0}, - 54: {167, 3}, - 55: {91, 1}, - 56: {91, 5}, - 57: {91, 6}, - 58: {91, 6}, - 59: {91, 7}, - 60: {91, 5}, - 61: {91, 6}, - 62: {91, 3}, - 63: {91, 4}, - 64: {92, 1}, - 65: {92, 3}, - 66: {92, 3}, - 67: {92, 3}, - 68: {92, 3}, - 69: {92, 3}, - 70: {92, 3}, - 71: {92, 3}, - 72: {149, 2}, - 73: {168, 0}, - 74: {168, 2}, - 75: {169, 1}, - 76: {169, 3}, - 77: {170, 3}, - 78: {107, 3}, - 79: {132, 10}, - 80: {132, 5}, - 81: {171, 0}, - 82: {171, 3}, - 83: {172, 0}, - 84: {172, 5}, - 85: {76, 1}, - 86: {76, 1}, - 87: {76, 1}, - 88: {76, 1}, - 89: {76, 1}, - 90: {76, 1}, - 91: {76, 1}, - 92: {77, 1}, - 93: {77, 1}, - 94: {77, 1}, - 95: {77, 3}, - 96: {177, 4}, - 97: {178, 0}, - 98: {178, 1}, - 99: {178, 1}, - 100: {78, 1}, - 101: {78, 1}, - 102: {78, 2}, - 103: {78, 2}, - 104: {78, 2}, - 105: {89, 1}, - 106: {89, 3}, - 107: {89, 3}, - 108: {89, 3}, - 109: {89, 3}, - 110: {88, 1}, - 111: {88, 3}, - 112: {88, 3}, - 113: {88, 3}, - 114: {88, 3}, - 115: {88, 3}, - 116: {88, 3}, - 117: {88, 3}, - 118: {79, 1}, - 119: {79, 3}, - 120: {133, 2}, - 121: {134, 1}, - 122: {134, 4}, - 123: {137, 0}, - 124: {137, 1}, - 125: {181, 0}, - 126: {181, 2}, - 127: {182, 1}, - 128: {182, 3}, - 129: {136, 1}, - 130: {176, 1}, - 131: {176, 1}, - 132: {176, 1}, - 133: {179, 0}, - 134: {179, 1}, - 135: {174, 6}, - 136: {175, 0}, - 137: {175, 1}, - 138: {98, 10}, - 139: {185, 0}, - 140: {185, 3}, - 141: {187, 0}, - 142: {187, 2}, - 143: {188, 0}, - 144: {188, 2}, - 145: {183, 0}, - 146: {183, 1}, - 147: {184, 1}, - 148: {184, 1}, - 149: {184, 2}, - 150: {190, 0}, - 151: {190, 1}, - 152: {186, 0}, - 153: {186, 1}, - 154: {189, 0}, - 155: {189, 1}, - 156: {108, 3}, - 157: {108, 4}, - 158: {108, 4}, - 159: {108, 5}, - 160: {138, 1}, - 161: {138, 1}, - 162: {138, 1}, - 163: {138, 1}, - 164: {138, 1}, - 165: {138, 1}, - 166: {138, 1}, - 167: {138, 1}, - 168: {138, 1}, - 169: {138, 1}, - 170: {138, 1}, - 171: {138, 1}, - 172: {138, 1}, - 173: {138, 1}, - 174: {138, 1}, - 175: {193, 1}, - 176: {193, 3}, - 177: {99, 1}, - 178: {93, 1}, - 179: {93, 3}, - 180: {150, 1}, - 181: {150, 1}, - 182: {140, 3}, - 183: {74, 1}, - 184: {74, 1}, - 185: {74, 1}, - 186: {74, 1}, - 187: {74, 1}, - 188: {74, 1}, - 189: {74, 1}, - 190: {74, 1}, - 191: {74, 1}, - 192: {74, 1}, - 193: {74, 1}, - 194: {74, 1}, - 195: {74, 1}, - 196: {74, 1}, - 197: {74, 1}, - 198: {74, 1}, - 199: {74, 1}, - 200: {74, 1}, - 201: {74, 1}, - 202: {74, 1}, - 203: {74, 1}, - 204: {74, 1}, - 205: {74, 1}, - 206: {74, 1}, - 207: {142, 5}, - 208: {196, 0}, - 209: {196, 1}, - 210: {81, 1}, - 211: {81, 2}, - 212: {81, 2}, - 213: {81, 2}, - 214: {81, 2}, - 215: {143, 2}, - 216: {143, 5}, - 217: {143, 6}, - 218: {191, 0}, - 219: {191, 1}, - 220: {100, 0}, - 221: {100, 1}, - } - - yyXErrors = map[yyXError]string{ - {1, -1}: "expected $end", - {43, -1}: "expected '('", - {94, -1}: "expected '('", - {96, -1}: "expected '('", - {168, -1}: "expected '('", - {192, -1}: "expected '('", - {293, -1}: "expected '('", - {321, -1}: "expected '('", - {325, -1}: "expected '('", - {356, -1}: "expected '('", - {98, -1}: "expected ')'", - {101, -1}: "expected ')'", - {127, -1}: "expected ')'", - {128, -1}: "expected ')'", - {129, -1}: "expected ')'", - {198, -1}: "expected ')'", - {200, -1}: "expected ')'", - {201, -1}: "expected ')'", - {205, -1}: "expected ')'", - {207, -1}: "expected ')'", - {239, -1}: "expected ')'", - {291, -1}: "expected ')'", - {296, -1}: "expected ')'", - {302, -1}: "expected ')'", - {330, -1}: "expected ')'", - {347, -1}: "expected ')'", - {358, -1}: "expected ')'", - {36, -1}: "expected '='", - {252, -1}: "expected BY", - {255, -1}: "expected BY", - {364, -1}: "expected COLUMN", - {7, -1}: "expected CREATE INDEX optional UNIQUE clause or one of [INDEX, TABLE, UNIQUE]", - {349, -1}: "expected CREATE INDEX statement optional IF NOT EXISTS cluse or one of [IF, identifier]", - {328, -1}: "expected CREATE TABLE statement colum definition list or optional comma or one of [')', ',']", - {345, -1}: "expected CREATE TABLE statement colum definition list or optional comma or one of [')', ',']", - {305, -1}: "expected DROP INDEX statement optional IF EXISTS clause or one of [IF, identifier]", - {95, -1}: "expected EXISTS", - {308, -1}: "expected EXISTS", - {312, -1}: "expected EXISTS", - {323, -1}: "expected EXISTS", - {352, -1}: "expected EXISTS", - {46, -1}: "expected Eq or one of [!=, $end, &&, ')', ',', ':', ';', '<', '=', '>', ']', <=, ==, >=, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {8, -1}: "expected FROM", - {318, -1}: "expected INDEX", - {319, -1}: "expected INDEX", - {288, -1}: "expected INSERT INTO statement optional column list clause or SELECT statement or one of ['(', SELECT, VALUES]", - {297, -1}: "expected INSERT INTO statement optional values list or optional comma or one of [$end, ',', ';']", - {11, -1}: "expected INTO", - {276, -1}: "expected JOIN", - {277, -1}: "expected JOIN", - {322, -1}: "expected NOT", - {351, -1}: "expected NOT", - {187, -1}: "expected NULL", - {336, -1}: "expected NULL", - {279, -1}: "expected ON", - {354, -1}: "expected ON", - {265, -1}: "expected ORDER BY clause optional collation specification or one of [$end, ')', ';', ASC, DESC, LIMIT, OFFSET]", - {229, -1}: "expected RecordSetList or one of ['(', identifier]", - {13, -1}: "expected SELECT statement field list or SELECT statement optional DISTINCT clause or one of ['!', '(', '*', '+', '-', '^', DISTINCT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {221, -1}: "expected SELECT statement field list or one of ['!', '(', '*', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {226, -1}: "expected SELECT statement optional FROM clause or SELECT statement optional GROUP BY clause or SELECT statement optional JOIN clause or SELECT statement optional LIMIT clause or SELECT statement optional OFFSET clause or SELECT statement optional ORDER BY clause or SELECT statement optional WHERE clause or one of [$end, ')', ';', FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {228, -1}: "expected SELECT statement optional GROUP BY clause or SELECT statement optional JOIN clause or SELECT statement optional LIMIT clause or SELECT statement optional OFFSET clause or SELECT statement optional ORDER BY clause or SELECT statement optional WHERE clause or one of [$end, ')', ';', FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {249, -1}: "expected SELECT statement optional GROUP BY clause or SELECT statement optional LIMIT clause or SELECT statement optional OFFSET clause or SELECT statement optional ORDER BY clause or SELECT statement optional WHERE clause or one of [$end, ')', ';', GROUP, LIMIT, OFFSET, ORDER, WHERE]", - {250, -1}: "expected SELECT statement optional GROUP BY clause or SELECT statement optional LIMIT clause or SELECT statement optional OFFSET clause or SELECT statement optional ORDER BY clause or one of [$end, ')', ';', GROUP, LIMIT, OFFSET, ORDER]", - {253, -1}: "expected SELECT statement optional LIMIT clause or SELECT statement optional OFFSET clause or SELECT statement optional ORDER BY clause or one of [$end, ')', ';', LIMIT, OFFSET, ORDER]", - {256, -1}: "expected SELECT statement optional LIMIT clause or SELECT statement optional OFFSET clause or one of [$end, ')', ';', LIMIT, OFFSET]", - {258, -1}: "expected SELECT statement optional OFFSET clause or one of [$end, ')', ';', OFFSET]", - {97, -1}: "expected SELECT statement or SELECT", - {100, -1}: "expected SELECT statement or SELECT", - {232, -1}: "expected SELECT statement or SELECT", - {197, -1}: "expected SELECT statement or expression list or one of ['!', '(', '+', '-', '^', NULL, QL parameter, SELECT, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {204, -1}: "expected SELECT statement or expression list or one of ['!', '(', '+', '-', '^', NULL, QL parameter, SELECT, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {289, -1}: "expected SELECT statement or one of [SELECT, VALUES]", - {33, -1}: "expected SetOpt or assignment list or one of [SET, identifier]", - {0, -1}: "expected Start or one of [$end, ';', ALTER, BEGIN, COMMIT, CREATE, DELETE, DROP, EXPLAIN, INSERT, ROLLBACK, SELECT, TRUNCATE, UPDATE, parse expression prefix]", - {4, -1}: "expected TABLE", - {30, -1}: "expected TABLE", - {5, -1}: "expected TRANSACTION", - {39, -1}: "expected UPDATE statement optional WHERE clause or one of [$end, ';', WHERE]", - {316, -1}: "expected WHERE clause or one of [$end, ';', WHERE]", - {37, -1}: "expected assignment list optional trailing comma or optional comma or one of [$end, ',', ';', WHERE]", - {34, -1}: "expected assignment list or identifier", - {215, -1}: "expected assignment or one of [$end, ';', WHERE, identifier]", - {269, -1}: "expected column name list or identifier", - {290, -1}: "expected column name list or identifier", - {270, -1}: "expected column name list with optional trailing comma or optional comma or one of [$end, ')', ',', ';', LIMIT, OFFSET, ORDER]", - {365, -1}: "expected column name or identifier", - {274, -1}: "expected column name or one of [$end, ')', ';', LIMIT, OFFSET, ORDER, identifier]", - {118, -1}: "expected expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {130, -1}: "expected expression list expression or logical or operator or optional comma or one of [$end, ')', ',', ';', ASC, DESC, LIMIT, OFFSET, OR, ||]", - {264, -1}: "expected expression list or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {295, -1}: "expected expression list or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {301, -1}: "expected expression list or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {357, -1}: "expected expression list or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {133, -1}: "expected expression or one of [$end, '!', '(', ')', '+', '-', ';', '^', ASC, DESC, LIMIT, NULL, OFFSET, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {105, -1}: "expected expression or one of ['!', '(', '+', '-', ':', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {110, -1}: "expected expression or one of ['!', '(', '+', '-', ']', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {123, -1}: "expected expression or one of ['!', '(', '+', '-', ']', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {42, -1}: "expected expression or one of ['!', '(', '+', '-', '^', EXISTS, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {3, -1}: "expected expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {58, -1}: "expected expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {210, -1}: "expected expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {217, -1}: "expected expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {259, -1}: "expected expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {262, -1}: "expected expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {280, -1}: "expected expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {341, -1}: "expected expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {113, -1}: "expected expression term or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {223, -1}: "expected field expression optional AS clause or logical or operator or one of [$end, ')', ',', ';', AS, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {282, -1}: "expected field expression or one of [$end, '!', '(', ')', '+', '-', ';', '^', FROM, FULL, GROUP, LEFT, LIMIT, NULL, OFFSET, ORDER, QL parameter, RIGHT, WHERE, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {104, -1}: "expected function call optional argument list or one of ['!', '(', ')', '*', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {61, -1}: "expected function call or string index or string slice or one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {103, -1}: "expected function call or string index or string slice or one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {137, -1}: "expected function call or string index or string slice or one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {138, -1}: "expected function call or string index or string slice or one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {139, -1}: "expected function call or string index or string slice or one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {35, -1}: "expected identifier", - {140, -1}: "expected identifier", - {242, -1}: "expected identifier", - {285, -1}: "expected identifier", - {311, -1}: "expected identifier", - {313, -1}: "expected identifier", - {350, -1}: "expected identifier", - {353, -1}: "expected identifier", - {355, -1}: "expected identifier", - {44, -1}: "expected logical and operator or one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {117, -1}: "expected logical and operator or one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {134, -1}: "expected logical or operator or one of [$end, ')', ',', ';', ASC, DESC, LIMIT, OFFSET, OR, ||]", - {337, -1}: "expected logical or operator or one of [$end, ')', ',', ';', DEFAULT, OR, ||]", - {343, -1}: "expected logical or operator or one of [$end, ')', ',', ';', OR, ||]", - {281, -1}: "expected logical or operator or one of [$end, ')', ';', GROUP, LIMIT, OFFSET, OR, ORDER, WHERE, ||]", - {45, -1}: "expected logical or operator or one of [$end, ')', ';', GROUP, LIMIT, OFFSET, OR, ORDER, ||]", - {260, -1}: "expected logical or operator or one of [$end, ')', ';', OFFSET, OR, ||]", - {263, -1}: "expected logical or operator or one of [$end, ')', ';', OR, ||]", - {218, -1}: "expected logical or operator or one of [$end, ',', ';', OR, WHERE, ||]", - {368, -1}: "expected logical or operator or one of [$end, OR, ||]", - {156, -1}: "expected logical or operator or one of [')', OR, ||]", - {211, -1}: "expected logical or operator or one of [')', OR, ||]", - {109, -1}: "expected logical or operator or one of [':', ']', OR, ||]", - {111, -1}: "expected logical or operator or one of [']', OR, ||]", - {124, -1}: "expected logical or operator or one of [']', OR, ||]", - {64, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {48, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {49, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {50, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {51, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {52, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {53, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {54, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {55, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {56, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {57, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {59, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {60, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {106, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {107, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {108, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {112, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {116, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {122, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {125, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {126, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {135, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {136, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {141, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {157, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {212, -1}: "expected one of [!=, $end, &&, &^, '%', '&', '(', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', '[', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {62, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {63, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {149, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {150, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {151, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {152, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {153, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {154, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {155, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {162, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {163, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {164, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {165, -1}: "expected one of [!=, $end, &&, &^, '%', '&', ')', '*', '+', ',', '-', '/', ':', ';', '<', '=', '>', ']', '^', '|', <<, <=, ==, >=, >>, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {47, -1}: "expected one of [!=, $end, &&, ')', '+', ',', '-', ':', ';', '<', '=', '>', ']', '^', '|', <=, ==, >=, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {179, -1}: "expected one of [!=, $end, &&, ')', '+', ',', '-', ':', ';', '<', '=', '>', ']', '^', '|', <=, ==, >=, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {180, -1}: "expected one of [!=, $end, &&, ')', '+', ',', '-', ':', ';', '<', '=', '>', ']', '^', '|', <=, ==, >=, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {181, -1}: "expected one of [!=, $end, &&, ')', '+', ',', '-', ':', ';', '<', '=', '>', ']', '^', '|', <=, ==, >=, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {182, -1}: "expected one of [!=, $end, &&, ')', '+', ',', '-', ':', ';', '<', '=', '>', ']', '^', '|', <=, ==, >=, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {183, -1}: "expected one of [!=, $end, &&, ')', '+', ',', '-', ':', ';', '<', '=', '>', ']', '^', '|', <=, ==, >=, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {184, -1}: "expected one of [!=, $end, &&, ')', '+', ',', '-', ':', ';', '<', '=', '>', ']', '^', '|', <=, ==, >=, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {185, -1}: "expected one of [!=, $end, &&, ')', '+', ',', '-', ':', ';', '<', '=', '>', ']', '^', '|', <=, ==, >=, AND, AS, ASC, BETWEEN, DEFAULT, DESC, FROM, FULL, GROUP, IN, IS, LEFT, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {191, -1}: "expected one of [$end, &&, ')', '+', ',', '-', ':', ';', ']', '^', '|', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {196, -1}: "expected one of [$end, &&, ')', '+', ',', '-', ':', ';', ']', '^', '|', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {65, -1}: "expected one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {121, -1}: "expected one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {186, -1}: "expected one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {188, -1}: "expected one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {202, -1}: "expected one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {203, -1}: "expected one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {208, -1}: "expected one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {209, -1}: "expected one of [$end, &&, ')', ',', ':', ';', ']', AND, AS, ASC, DEFAULT, DESC, FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, OR, ORDER, RIGHT, WHERE, ||]", - {66, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {67, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {68, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {69, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {70, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {71, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {72, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {73, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {74, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {75, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {76, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {77, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {78, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {79, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {80, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {81, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {82, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {83, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {84, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {85, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {86, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {87, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {88, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {89, -1}: "expected one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {32, -1}: "expected one of [$end, '(', ';', ADD, DROP, SELECT, SET, VALUES, WHERE, identifier]", - {300, -1}: "expected one of [$end, '(', ';']", - {38, -1}: "expected one of [$end, ')', ',', ';', '=', LIMIT, OFFSET, ORDER, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, float, float32, float64, int, int16, int32, int64, int8, rune, string, time, uint, uint16, uint32, uint64, uint8]", - {231, -1}: "expected one of [$end, ')', ',', ';', AS, FULL, GROUP, LEFT, LIMIT, OFFSET, ON, ORDER, RIGHT, WHERE]", - {240, -1}: "expected one of [$end, ')', ',', ';', AS, FULL, GROUP, LEFT, LIMIT, OFFSET, ON, ORDER, RIGHT, WHERE]", - {338, -1}: "expected one of [$end, ')', ',', ';', DEFAULT]", - {339, -1}: "expected one of [$end, ')', ',', ';', DEFAULT]", - {224, -1}: "expected one of [$end, ')', ',', ';', FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {225, -1}: "expected one of [$end, ')', ',', ';', FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {283, -1}: "expected one of [$end, ')', ',', ';', FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {284, -1}: "expected one of [$end, ')', ',', ';', FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {286, -1}: "expected one of [$end, ')', ',', ';', FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {241, -1}: "expected one of [$end, ')', ',', ';', FULL, GROUP, LEFT, LIMIT, OFFSET, ON, ORDER, RIGHT, WHERE]", - {243, -1}: "expected one of [$end, ')', ',', ';', FULL, GROUP, LEFT, LIMIT, OFFSET, ON, ORDER, RIGHT, WHERE]", - {233, -1}: "expected one of [$end, ')', ',', ';', FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {237, -1}: "expected one of [$end, ')', ',', ';', FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {275, -1}: "expected one of [$end, ')', ',', ';', LIMIT, OFFSET, ORDER]", - {340, -1}: "expected one of [$end, ')', ',', ';']", - {342, -1}: "expected one of [$end, ')', ',', ';']", - {132, -1}: "expected one of [$end, ')', ';', ASC, DESC, LIMIT, OFFSET]", - {227, -1}: "expected one of [$end, ')', ';', FROM, FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {236, -1}: "expected one of [$end, ')', ';', FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {248, -1}: "expected one of [$end, ')', ';', GROUP, LIMIT, OFFSET, ORDER, WHERE]", - {99, -1}: "expected one of [$end, ')', ';', GROUP, LIMIT, OFFSET, ORDER]", - {102, -1}: "expected one of [$end, ')', ';', GROUP, LIMIT, OFFSET, ORDER]", - {251, -1}: "expected one of [$end, ')', ';', GROUP, LIMIT, OFFSET, ORDER]", - {254, -1}: "expected one of [$end, ')', ';', LIMIT, OFFSET, ORDER]", - {271, -1}: "expected one of [$end, ')', ';', LIMIT, OFFSET, ORDER]", - {273, -1}: "expected one of [$end, ')', ';', LIMIT, OFFSET, ORDER]", - {257, -1}: "expected one of [$end, ')', ';', LIMIT, OFFSET]", - {266, -1}: "expected one of [$end, ')', ';', LIMIT, OFFSET]", - {267, -1}: "expected one of [$end, ')', ';', LIMIT, OFFSET]", - {268, -1}: "expected one of [$end, ')', ';', LIMIT, OFFSET]", - {261, -1}: "expected one of [$end, ')', ';']", - {216, -1}: "expected one of [$end, ',', ';', WHERE]", - {303, -1}: "expected one of [$end, ',', ';']", - {214, -1}: "expected one of [$end, ';', WHERE]", - {2, -1}: "expected one of [$end, ';']", - {6, -1}: "expected one of [$end, ';']", - {12, -1}: "expected one of [$end, ';']", - {14, -1}: "expected one of [$end, ';']", - {15, -1}: "expected one of [$end, ';']", - {16, -1}: "expected one of [$end, ';']", - {17, -1}: "expected one of [$end, ';']", - {18, -1}: "expected one of [$end, ';']", - {19, -1}: "expected one of [$end, ';']", - {20, -1}: "expected one of [$end, ';']", - {21, -1}: "expected one of [$end, ';']", - {22, -1}: "expected one of [$end, ';']", - {23, -1}: "expected one of [$end, ';']", - {24, -1}: "expected one of [$end, ';']", - {25, -1}: "expected one of [$end, ';']", - {26, -1}: "expected one of [$end, ';']", - {27, -1}: "expected one of [$end, ';']", - {28, -1}: "expected one of [$end, ';']", - {29, -1}: "expected one of [$end, ';']", - {40, -1}: "expected one of [$end, ';']", - {41, -1}: "expected one of [$end, ';']", - {220, -1}: "expected one of [$end, ';']", - {294, -1}: "expected one of [$end, ';']", - {299, -1}: "expected one of [$end, ';']", - {304, -1}: "expected one of [$end, ';']", - {307, -1}: "expected one of [$end, ';']", - {310, -1}: "expected one of [$end, ';']", - {314, -1}: "expected one of [$end, ';']", - {317, -1}: "expected one of [$end, ';']", - {333, -1}: "expected one of [$end, ';']", - {348, -1}: "expected one of [$end, ';']", - {359, -1}: "expected one of [$end, ';']", - {360, -1}: "expected one of [$end, ';']", - {366, -1}: "expected one of [$end, ';']", - {367, -1}: "expected one of [$end, ';']", - {370, -1}: "expected one of [$end, ';']", - {222, -1}: "expected one of ['!', '(', '*', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {114, -1}: "expected one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {115, -1}: "expected one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {119, -1}: "expected one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {120, -1}: "expected one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {166, -1}: "expected one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {167, -1}: "expected one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {332, -1}: "expected one of [')', ',']", - {189, -1}: "expected one of ['+', '-', '^', '|', AND]", - {194, -1}: "expected one of ['+', '-', '^', '|', AND]", - {362, -1}: "expected one of [ADD, DROP]", - {169, -1}: "expected one of [BETWEEN, IN]", - {9, -1}: "expected one of [INDEX, TABLE]", - {244, -1}: "expected one of [JOIN, OUTER]", - {245, -1}: "expected one of [JOIN, OUTER]", - {246, -1}: "expected one of [JOIN, OUTER]", - {171, -1}: "expected one of [NOT, NULL]", - {292, -1}: "expected one of [SELECT, VALUES]", - {335, -1}: "expected optional DEFAULT clause or one of [$end, ')', ',', ';', DEFAULT]", - {334, -1}: "expected optional DEFAULT clause or optional column value constraint or one of [$end, '!', '(', ')', '+', ',', '-', ';', '^', DEFAULT, NOT, NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {247, -1}: "expected optional OUTER clause or one of [JOIN, OUTER]", - {131, -1}: "expected optional comma or one of [$end, ')', ',', ';', ASC, DESC, LIMIT, OFFSET]", - {234, -1}: "expected optional comma or one of [$end, ')', ',', ';', FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE]", - {272, -1}: "expected optional comma or one of [$end, ')', ',', ';', LIMIT, OFFSET, ORDER]", - {213, -1}: "expected optional comma or one of [$end, ',', ';', WHERE]", - {298, -1}: "expected optional comma or one of [$end, ',', ';']", - {329, -1}: "expected optional comma or one of [')', ',']", - {346, -1}: "expected optional comma or one of [')', ',']", - {170, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {172, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {173, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {174, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {175, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {176, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {177, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {178, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {190, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {193, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {195, -1}: "expected primary expression factor or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {90, -1}: "expected primary expression or one of ['(', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {91, -1}: "expected primary expression or one of ['(', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {92, -1}: "expected primary expression or one of ['(', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {93, -1}: "expected primary expression or one of ['(', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {158, -1}: "expected primary expression term or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {159, -1}: "expected primary expression term or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {160, -1}: "expected primary expression term or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {161, -1}: "expected primary expression term or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {230, -1}: "expected record set optional AS clause or one of [$end, ')', ',', ';', AS, FULL, GROUP, LEFT, LIMIT, OFFSET, ON, ORDER, RIGHT, WHERE]", - {235, -1}: "expected record set or one of [$end, '(', ')', ';', FULL, GROUP, LEFT, LIMIT, OFFSET, ORDER, RIGHT, WHERE, identifier]", - {278, -1}: "expected record set or one of ['(', identifier]", - {199, -1}: "expected semiOpt or one of [')', ';']", - {206, -1}: "expected semiOpt or one of [')', ';']", - {238, -1}: "expected semiOpt or one of [')', ';']", - {10, -1}: "expected statement or one of [$end, ';', ALTER, BEGIN, COMMIT, CREATE, DELETE, DROP, EXPLAIN, INSERT, ROLLBACK, SELECT, TRUNCATE, UPDATE]", - {369, -1}: "expected statement or one of [$end, ';', ALTER, BEGIN, COMMIT, CREATE, DELETE, DROP, EXPLAIN, INSERT, ROLLBACK, SELECT, TRUNCATE, UPDATE]", - {326, -1}: "expected table column definition or identifier", - {344, -1}: "expected table column definition or identifier", - {363, -1}: "expected table column definition or identifier", - {331, -1}: "expected table column definition or one of [')', identifier]", - {31, -1}: "expected table name or identifier", - {219, -1}: "expected table name or identifier", - {287, -1}: "expected table name or identifier", - {309, -1}: "expected table name or identifier", - {315, -1}: "expected table name or identifier", - {324, -1}: "expected table name or identifier", - {361, -1}: "expected table name or identifier", - {306, -1}: "expected table name or one of [IF, identifier]", - {320, -1}: "expected table name or one of [IF, identifier]", - {327, -1}: "expected type or one of [bigint, bigrat, blob, bool, byte, complex128, complex64, duration, float, float32, float64, int, int16, int32, int64, int8, rune, string, time, uint, uint16, uint32, uint64, uint8]", - {142, -1}: "expected unary expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {143, -1}: "expected unary expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {144, -1}: "expected unary expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {145, -1}: "expected unary expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {146, -1}: "expected unary expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {147, -1}: "expected unary expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - {148, -1}: "expected unary expression or one of ['!', '(', '+', '-', '^', NULL, QL parameter, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, false, float, float32, float64, floating-point literal, identifier, imaginary literal, int, int16, int32, int64, int8, integer literal, rune, string, string literal, time, true, uint, uint16, uint32, uint64, uint8]", - } - - yyParseTab = [371][]uint16{ - // 0 - {178, 178, 96: 235, 98: 248, 106: 231, 115: 226, 237, 227, 238, 228, 239, 229, 240, 241, 242, 230, 243, 244, 236, 232, 245, 233, 246, 135: 234, 247, 138: 251, 252, 249, 253, 250, 180: 225, 192: 223, 224}, - {1: 222}, - {591, 221}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 590}, - {113: 583}, - // 5 - {194: 582}, - {203, 203}, - {111: 194, 113: 542, 161: 540, 195: 541}, - {54: 537}, - {111: 527, 113: 528}, - // 10 - {178, 178, 96: 235, 98: 248, 106: 231, 115: 226, 237, 227, 238, 228, 239, 229, 240, 241, 242, 230, 243, 244, 236, 232, 245, 233, 246, 135: 234, 247, 138: 526, 252, 249, 253, 250}, - {173: 509}, - {93, 93}, - {3: 77, 77, 77, 7: 77, 77, 15: 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 28: 77, 77, 77, 77, 77, 35: 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 53: 77, 80: 77, 164: 444, 183: 443}, - {62, 62}, - // 15 - {61, 61}, - {60, 60}, - {59, 59}, - {58, 58}, - {57, 57}, - // 20 - {56, 56}, - {55, 55}, - {54, 54}, - {53, 53}, - {52, 52}, - // 25 - {51, 51}, - {50, 50}, - {49, 49}, - {48, 48}, - {47, 47}, - // 30 - {113: 441}, - {8: 254, 99: 255}, - {45, 45, 7: 45, 45, 12: 45, 96: 45, 106: 45, 114: 45, 144: 45, 151: 45}, - {8: 4, 151: 257, 191: 256}, - {8: 260, 97: 258, 145: 259, 153: 261}, - // 35 - {8: 3}, - {63: 439}, - {215, 215, 6: 215, 12: 215, 154: 435}, - {207, 207, 207, 6: 207, 9: 207, 207, 207, 16: 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 28: 207, 207, 207, 207, 207, 35: 207, 207, 207, 207, 207, 207, 207, 207, 63: 207}, - {14, 14, 12: 264, 143: 263, 196: 262}, - // 40 - {15, 15}, - {13, 13}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 317, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 267, 103: 316}, - {7: 432}, - {176, 176, 176, 6: 176, 9: 176, 176, 176, 176, 176, 176, 27: 176, 33: 176, 176, 51: 176, 176, 54: 176, 176, 176, 176, 176, 176, 342, 341, 150: 340}, - // 45 - {7, 7, 7, 9: 7, 7, 7, 14: 7, 51: 337, 336, 95: 335}, - {167, 167, 167, 6: 167, 9: 167, 167, 167, 167, 167, 167, 27: 167, 33: 167, 167, 50: 391, 167, 167, 54: 167, 167, 167, 167, 167, 167, 167, 167, 63: 389, 392, 390, 397, 395, 388, 394, 393, 396, 400, 398, 166: 399}, - {158, 158, 158, 383, 382, 380, 158, 9: 158, 158, 158, 158, 158, 158, 27: 158, 33: 158, 158, 50: 158, 158, 158, 54: 158, 158, 158, 158, 158, 158, 158, 158, 381, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158}, - {137, 137, 137, 137, 137, 137, 137, 137, 9: 137, 137, 137, 137, 137, 137, 27: 137, 33: 137, 137, 50: 137, 137, 137, 54: 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 80: 137, 82: 137, 137, 137, 137, 137, 137, 90: 137}, - {136, 136, 136, 136, 136, 136, 136, 136, 9: 136, 136, 136, 136, 136, 136, 27: 136, 33: 136, 136, 50: 136, 136, 136, 54: 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 80: 136, 82: 136, 136, 136, 136, 136, 136, 90: 136}, - // 50 - {135, 135, 135, 135, 135, 135, 135, 135, 9: 135, 135, 135, 135, 135, 135, 27: 135, 33: 135, 135, 50: 135, 135, 135, 54: 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 80: 135, 82: 135, 135, 135, 135, 135, 135, 90: 135}, - {134, 134, 134, 134, 134, 134, 134, 134, 9: 134, 134, 134, 134, 134, 134, 27: 134, 33: 134, 134, 50: 134, 134, 134, 54: 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 80: 134, 82: 134, 134, 134, 134, 134, 134, 90: 134}, - {133, 133, 133, 133, 133, 133, 133, 133, 9: 133, 133, 133, 133, 133, 133, 27: 133, 33: 133, 133, 50: 133, 133, 133, 54: 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 80: 133, 82: 133, 133, 133, 133, 133, 133, 90: 133}, - {132, 132, 132, 132, 132, 132, 132, 132, 9: 132, 132, 132, 132, 132, 132, 27: 132, 33: 132, 132, 50: 132, 132, 132, 54: 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 80: 132, 82: 132, 132, 132, 132, 132, 132, 90: 132}, - {131, 131, 131, 131, 131, 131, 131, 131, 9: 131, 131, 131, 131, 131, 131, 27: 131, 33: 131, 131, 50: 131, 131, 131, 54: 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 80: 131, 82: 131, 131, 131, 131, 131, 131, 90: 131}, - // 55 - {130, 130, 130, 130, 130, 130, 130, 130, 9: 130, 130, 130, 130, 130, 130, 27: 130, 33: 130, 130, 50: 130, 130, 130, 54: 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 80: 130, 82: 130, 130, 130, 130, 130, 130, 90: 130}, - {129, 129, 129, 129, 129, 129, 129, 129, 9: 129, 129, 129, 129, 129, 129, 27: 129, 33: 129, 129, 50: 129, 129, 129, 54: 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 80: 129, 82: 129, 129, 129, 129, 129, 129, 90: 129}, - {128, 128, 128, 128, 128, 128, 128, 128, 9: 128, 128, 128, 128, 128, 128, 27: 128, 33: 128, 128, 50: 128, 128, 128, 54: 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 80: 128, 82: 128, 128, 128, 128, 128, 128, 90: 128}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 378}, - {122, 122, 122, 122, 122, 122, 122, 122, 9: 122, 122, 122, 122, 122, 122, 27: 122, 33: 122, 122, 50: 122, 122, 122, 54: 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 80: 122, 82: 122, 122, 122, 122, 122, 122, 90: 122}, - // 60 - {121, 121, 121, 121, 121, 121, 121, 121, 9: 121, 121, 121, 121, 121, 121, 27: 121, 33: 121, 121, 50: 121, 121, 121, 54: 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 80: 121, 82: 121, 121, 121, 121, 121, 121, 90: 121}, - {12, 12, 12, 12, 12, 12, 12, 326, 9: 12, 12, 12, 12, 12, 12, 27: 12, 33: 12, 12, 50: 12, 12, 12, 54: 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 80: 12, 82: 12, 12, 12, 12, 12, 12, 90: 327, 105: 330, 107: 328, 329}, - {117, 117, 117, 117, 117, 117, 117, 9: 117, 117, 117, 117, 117, 117, 27: 117, 33: 117, 117, 50: 117, 117, 117, 54: 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 80: 370, 82: 368, 365, 369, 364, 366, 367}, - {112, 112, 112, 112, 112, 112, 112, 9: 112, 112, 112, 112, 112, 112, 27: 112, 33: 112, 112, 50: 112, 112, 112, 54: 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 80: 112, 82: 112, 112, 112, 112, 112, 112}, - {104, 104, 104, 104, 104, 104, 104, 104, 9: 104, 104, 104, 104, 104, 104, 27: 104, 33: 104, 104, 50: 104, 104, 104, 54: 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 80: 104, 82: 104, 104, 104, 104, 104, 104, 90: 104, 152: 362}, - // 65 - {44, 44, 44, 6: 44, 9: 44, 44, 44, 44, 44, 44, 27: 44, 33: 44, 44, 51: 44, 44, 54: 44, 44, 44, 44, 44, 44, 44, 44}, - {39, 39, 39, 39, 39, 39, 39, 39, 39, 13: 39, 15: 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 28: 39, 39, 39, 39, 39, 35: 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 53: 39}, - {38, 38, 38, 38, 38, 38, 38, 38, 38, 13: 38, 15: 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 28: 38, 38, 38, 38, 38, 35: 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 53: 38}, - {37, 37, 37, 37, 37, 37, 37, 37, 37, 13: 37, 15: 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 28: 37, 37, 37, 37, 37, 35: 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 53: 37}, - {36, 36, 36, 36, 36, 36, 36, 36, 36, 13: 36, 15: 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 28: 36, 36, 36, 36, 36, 35: 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 53: 36}, - // 70 - {35, 35, 35, 35, 35, 35, 35, 35, 35, 13: 35, 15: 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 28: 35, 35, 35, 35, 35, 35: 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 53: 35}, - {34, 34, 34, 34, 34, 34, 34, 34, 34, 13: 34, 15: 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 28: 34, 34, 34, 34, 34, 35: 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 53: 34}, - {33, 33, 33, 33, 33, 33, 33, 33, 33, 13: 33, 15: 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 28: 33, 33, 33, 33, 33, 35: 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 53: 33}, - {32, 32, 32, 32, 32, 32, 32, 32, 32, 13: 32, 15: 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 28: 32, 32, 32, 32, 32, 35: 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 53: 32}, - {31, 31, 31, 31, 31, 31, 31, 31, 31, 13: 31, 15: 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 28: 31, 31, 31, 31, 31, 35: 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 53: 31}, - // 75 - {30, 30, 30, 30, 30, 30, 30, 30, 30, 13: 30, 15: 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 28: 30, 30, 30, 30, 30, 35: 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 53: 30}, - {29, 29, 29, 29, 29, 29, 29, 29, 29, 13: 29, 15: 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 28: 29, 29, 29, 29, 29, 35: 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 53: 29}, - {28, 28, 28, 28, 28, 28, 28, 28, 28, 13: 28, 15: 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28: 28, 28, 28, 28, 28, 35: 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 53: 28}, - {27, 27, 27, 27, 27, 27, 27, 27, 27, 13: 27, 15: 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28: 27, 27, 27, 27, 27, 35: 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 53: 27}, - {26, 26, 26, 26, 26, 26, 26, 26, 26, 13: 26, 15: 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 28: 26, 26, 26, 26, 26, 35: 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 53: 26}, - // 80 - {25, 25, 25, 25, 25, 25, 25, 25, 25, 13: 25, 15: 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 28: 25, 25, 25, 25, 25, 35: 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 53: 25}, - {24, 24, 24, 24, 24, 24, 24, 24, 24, 13: 24, 15: 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 28: 24, 24, 24, 24, 24, 35: 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 53: 24}, - {23, 23, 23, 23, 23, 23, 23, 23, 23, 13: 23, 15: 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 28: 23, 23, 23, 23, 23, 35: 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 53: 23}, - {22, 22, 22, 22, 22, 22, 22, 22, 22, 13: 22, 15: 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 28: 22, 22, 22, 22, 22, 35: 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 53: 22}, - {21, 21, 21, 21, 21, 21, 21, 21, 21, 13: 21, 15: 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 28: 21, 21, 21, 21, 21, 35: 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 53: 21}, - // 85 - {20, 20, 20, 20, 20, 20, 20, 20, 20, 13: 20, 15: 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 28: 20, 20, 20, 20, 20, 35: 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 53: 20}, - {19, 19, 19, 19, 19, 19, 19, 19, 19, 13: 19, 15: 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 28: 19, 19, 19, 19, 19, 35: 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 53: 19}, - {18, 18, 18, 18, 18, 18, 18, 18, 18, 13: 18, 15: 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 28: 18, 18, 18, 18, 18, 35: 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 53: 18}, - {17, 17, 17, 17, 17, 17, 17, 17, 17, 13: 17, 15: 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 28: 17, 17, 17, 17, 17, 35: 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 53: 17}, - {16, 16, 16, 16, 16, 16, 16, 16, 16, 13: 16, 15: 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 28: 16, 16, 16, 16, 16, 35: 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 53: 16}, - // 90 - {7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 74: 265, 282, 277, 281, 361, 279}, - {7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 74: 265, 282, 277, 281, 360, 279}, - {7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 74: 265, 282, 277, 281, 359, 279}, - {7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 74: 265, 282, 277, 281, 325, 279}, - {7: 322}, - // 95 - {103: 318}, - {7: 319}, - {96: 235, 98: 320}, - {2: 321}, - {5, 5, 5, 9: 5, 5, 5, 14: 5}, - // 100 - {96: 235, 98: 323}, - {2: 324}, - {6, 6, 6, 9: 6, 6, 6, 14: 6}, - {8, 8, 8, 8, 8, 8, 8, 326, 9: 8, 8, 8, 8, 8, 8, 27: 8, 33: 8, 8, 50: 8, 8, 8, 54: 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 80: 8, 82: 8, 8, 8, 8, 8, 8, 90: 327, 105: 330, 107: 328, 329}, - {2: 210, 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 350, 285, 88: 284, 269, 91: 287, 268, 266, 352, 101: 351, 155: 349}, - // 105 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 59: 332, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 331}, - {120, 120, 120, 120, 120, 120, 120, 120, 9: 120, 120, 120, 120, 120, 120, 27: 120, 33: 120, 120, 50: 120, 120, 120, 54: 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 80: 120, 82: 120, 120, 120, 120, 120, 120, 90: 120}, - {119, 119, 119, 119, 119, 119, 119, 119, 9: 119, 119, 119, 119, 119, 119, 27: 119, 33: 119, 119, 50: 119, 119, 119, 54: 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 80: 119, 82: 119, 119, 119, 119, 119, 119, 90: 119}, - {118, 118, 118, 118, 118, 118, 118, 118, 9: 118, 118, 118, 118, 118, 118, 27: 118, 33: 118, 118, 50: 118, 118, 118, 54: 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 80: 118, 82: 118, 118, 118, 118, 118, 118, 90: 118}, - {51: 337, 336, 57: 344, 59: 345, 95: 335}, - // 110 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 57: 334, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 333}, - {51: 337, 336, 57: 338, 95: 335}, - {66, 66, 66, 66, 66, 66, 66, 66, 9: 66, 66, 66, 66, 66, 66, 27: 66, 33: 66, 66, 50: 66, 66, 66, 54: 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 80: 66, 82: 66, 66, 66, 66, 66, 66, 90: 66}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 339}, - {3: 174, 174, 174, 7: 174, 174, 15: 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 28: 174, 174, 174, 174, 174, 35: 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 53: 174}, - // 115 - {3: 173, 173, 173, 7: 173, 173, 15: 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 28: 173, 173, 173, 173, 173, 35: 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 53: 173}, - {65, 65, 65, 65, 65, 65, 65, 65, 9: 65, 65, 65, 65, 65, 65, 27: 65, 33: 65, 65, 50: 65, 65, 65, 54: 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 80: 65, 82: 65, 65, 65, 65, 65, 65, 90: 65}, - {175, 175, 175, 6: 175, 9: 175, 175, 175, 175, 175, 175, 27: 175, 33: 175, 175, 51: 175, 175, 54: 175, 175, 175, 175, 175, 175, 342, 341, 150: 340}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 343, 268}, - {3: 42, 42, 42, 7: 42, 42, 15: 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 28: 42, 42, 42, 42, 42, 35: 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 53: 42}, - // 120 - {3: 41, 41, 41, 7: 41, 41, 15: 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 28: 41, 41, 41, 41, 41, 35: 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 53: 41}, - {43, 43, 43, 6: 43, 9: 43, 43, 43, 43, 43, 43, 27: 43, 33: 43, 43, 51: 43, 43, 54: 43, 43, 43, 43, 43, 43, 43, 43}, - {144, 144, 144, 144, 144, 144, 144, 144, 9: 144, 144, 144, 144, 144, 144, 27: 144, 33: 144, 144, 50: 144, 144, 144, 54: 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 80: 144, 82: 144, 144, 144, 144, 144, 144, 90: 144}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 57: 347, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 346}, - {51: 337, 336, 57: 348, 95: 335}, - // 125 - {64, 64, 64, 64, 64, 64, 64, 64, 9: 64, 64, 64, 64, 64, 64, 27: 64, 33: 64, 64, 50: 64, 64, 64, 54: 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 80: 64, 82: 64, 64, 64, 64, 64, 64, 90: 64}, - {63, 63, 63, 63, 63, 63, 63, 63, 9: 63, 63, 63, 63, 63, 63, 27: 63, 33: 63, 63, 50: 63, 63, 63, 54: 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 80: 63, 82: 63, 63, 63, 63, 63, 63, 90: 63}, - {2: 358}, - {2: 357}, - {2: 209}, - // 130 - {169, 169, 169, 6: 169, 9: 169, 169, 51: 337, 336, 55: 169, 169, 95: 335, 167: 353}, - {2, 2, 2, 6: 355, 9: 2, 2, 55: 2, 2, 100: 354}, - {170, 170, 170, 9: 170, 170, 55: 170, 170}, - {1, 1, 1, 315, 314, 312, 7: 280, 286, 1, 1, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 55: 1, 1, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 356}, - {168, 168, 168, 6: 168, 9: 168, 168, 51: 337, 336, 55: 168, 168, 95: 335}, - // 135 - {211, 211, 211, 211, 211, 211, 211, 211, 9: 211, 211, 211, 211, 211, 211, 27: 211, 33: 211, 211, 50: 211, 211, 211, 54: 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 80: 211, 82: 211, 211, 211, 211, 211, 211, 90: 211}, - {212, 212, 212, 212, 212, 212, 212, 212, 9: 212, 212, 212, 212, 212, 212, 27: 212, 33: 212, 212, 50: 212, 212, 212, 54: 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 80: 212, 82: 212, 212, 212, 212, 212, 212, 90: 212}, - {9, 9, 9, 9, 9, 9, 9, 326, 9: 9, 9, 9, 9, 9, 9, 27: 9, 33: 9, 9, 50: 9, 9, 9, 54: 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 80: 9, 82: 9, 9, 9, 9, 9, 9, 90: 327, 105: 330, 107: 328, 329}, - {10, 10, 10, 10, 10, 10, 10, 326, 9: 10, 10, 10, 10, 10, 10, 27: 10, 33: 10, 10, 50: 10, 10, 10, 54: 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 80: 10, 82: 10, 10, 10, 10, 10, 10, 90: 327, 105: 330, 107: 328, 329}, - {11, 11, 11, 11, 11, 11, 11, 326, 9: 11, 11, 11, 11, 11, 11, 27: 11, 33: 11, 11, 50: 11, 11, 11, 54: 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 80: 11, 82: 11, 11, 11, 11, 11, 11, 90: 327, 105: 330, 107: 328, 329}, - // 140 - {8: 363}, - {103, 103, 103, 103, 103, 103, 103, 103, 9: 103, 103, 103, 103, 103, 103, 27: 103, 33: 103, 103, 50: 103, 103, 103, 54: 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 80: 103, 82: 103, 103, 103, 103, 103, 103, 90: 103}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 377}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 376}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 375}, - // 145 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 374}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 373}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 372}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 371}, - {105, 105, 105, 105, 105, 105, 105, 9: 105, 105, 105, 105, 105, 105, 27: 105, 33: 105, 105, 50: 105, 105, 105, 54: 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 80: 105, 82: 105, 105, 105, 105, 105, 105}, - // 150 - {106, 106, 106, 106, 106, 106, 106, 9: 106, 106, 106, 106, 106, 106, 27: 106, 33: 106, 106, 50: 106, 106, 106, 54: 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 80: 106, 82: 106, 106, 106, 106, 106, 106}, - {107, 107, 107, 107, 107, 107, 107, 9: 107, 107, 107, 107, 107, 107, 27: 107, 33: 107, 107, 50: 107, 107, 107, 54: 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 80: 107, 82: 107, 107, 107, 107, 107, 107}, - {108, 108, 108, 108, 108, 108, 108, 9: 108, 108, 108, 108, 108, 108, 27: 108, 33: 108, 108, 50: 108, 108, 108, 54: 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 80: 108, 82: 108, 108, 108, 108, 108, 108}, - {109, 109, 109, 109, 109, 109, 109, 9: 109, 109, 109, 109, 109, 109, 27: 109, 33: 109, 109, 50: 109, 109, 109, 54: 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 80: 109, 82: 109, 109, 109, 109, 109, 109}, - {110, 110, 110, 110, 110, 110, 110, 9: 110, 110, 110, 110, 110, 110, 27: 110, 33: 110, 110, 50: 110, 110, 110, 54: 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 80: 110, 82: 110, 110, 110, 110, 110, 110}, - // 155 - {111, 111, 111, 111, 111, 111, 111, 9: 111, 111, 111, 111, 111, 111, 27: 111, 33: 111, 111, 50: 111, 111, 111, 54: 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 80: 111, 82: 111, 111, 111, 111, 111, 111}, - {2: 379, 51: 337, 336, 95: 335}, - {127, 127, 127, 127, 127, 127, 127, 127, 9: 127, 127, 127, 127, 127, 127, 27: 127, 33: 127, 127, 50: 127, 127, 127, 54: 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 80: 127, 82: 127, 127, 127, 127, 127, 127, 90: 127}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 387}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 386}, - // 160 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 385}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 384}, - {113, 113, 113, 113, 113, 113, 113, 9: 113, 113, 113, 113, 113, 113, 27: 113, 33: 113, 113, 50: 113, 113, 113, 54: 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 80: 370, 82: 368, 365, 369, 364, 366, 367}, - {114, 114, 114, 114, 114, 114, 114, 9: 114, 114, 114, 114, 114, 114, 27: 114, 33: 114, 114, 50: 114, 114, 114, 54: 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 80: 370, 82: 368, 365, 369, 364, 366, 367}, - {115, 115, 115, 115, 115, 115, 115, 9: 115, 115, 115, 115, 115, 115, 27: 115, 33: 115, 115, 50: 115, 115, 115, 54: 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 80: 370, 82: 368, 365, 369, 364, 366, 367}, - // 165 - {116, 116, 116, 116, 116, 116, 116, 9: 116, 116, 116, 116, 116, 116, 27: 116, 33: 116, 116, 50: 116, 116, 116, 54: 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 80: 370, 82: 368, 365, 369, 364, 366, 367}, - {3: 172, 172, 172, 7: 172, 172, 15: 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 28: 172, 172, 172, 172, 172, 35: 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 53: 172}, - {3: 171, 171, 171, 7: 171, 171, 15: 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 28: 171, 171, 171, 171, 171, 35: 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 53: 171}, - {7: 426}, - {64: 415, 414}, - // 170 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 411}, - {15: 408, 50: 409}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 407}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 406}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 405}, - // 175 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 404}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 403}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 402}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 401}, - {151, 151, 151, 383, 382, 380, 151, 9: 151, 151, 151, 151, 151, 151, 27: 151, 33: 151, 151, 50: 151, 151, 151, 54: 151, 151, 151, 151, 151, 151, 151, 151, 381, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151}, - // 180 - {152, 152, 152, 383, 382, 380, 152, 9: 152, 152, 152, 152, 152, 152, 27: 152, 33: 152, 152, 50: 152, 152, 152, 54: 152, 152, 152, 152, 152, 152, 152, 152, 381, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152}, - {153, 153, 153, 383, 382, 380, 153, 9: 153, 153, 153, 153, 153, 153, 27: 153, 33: 153, 153, 50: 153, 153, 153, 54: 153, 153, 153, 153, 153, 153, 153, 153, 381, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153}, - {154, 154, 154, 383, 382, 380, 154, 9: 154, 154, 154, 154, 154, 154, 27: 154, 33: 154, 154, 50: 154, 154, 154, 54: 154, 154, 154, 154, 154, 154, 154, 154, 381, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154}, - {155, 155, 155, 383, 382, 380, 155, 9: 155, 155, 155, 155, 155, 155, 27: 155, 33: 155, 155, 50: 155, 155, 155, 54: 155, 155, 155, 155, 155, 155, 155, 155, 381, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155}, - {156, 156, 156, 383, 382, 380, 156, 9: 156, 156, 156, 156, 156, 156, 27: 156, 33: 156, 156, 50: 156, 156, 156, 54: 156, 156, 156, 156, 156, 156, 156, 156, 381, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156}, - // 185 - {157, 157, 157, 383, 382, 380, 157, 9: 157, 157, 157, 157, 157, 157, 27: 157, 33: 157, 157, 50: 157, 157, 157, 54: 157, 157, 157, 157, 157, 157, 157, 157, 381, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157}, - {160, 160, 160, 6: 160, 9: 160, 160, 160, 160, 160, 160, 27: 160, 33: 160, 160, 51: 160, 160, 54: 160, 160, 160, 160, 160, 160, 160, 160}, - {15: 410}, - {159, 159, 159, 6: 159, 9: 159, 159, 159, 159, 159, 159, 27: 159, 33: 159, 159, 51: 159, 159, 54: 159, 159, 159, 159, 159, 159, 159, 159}, - {3: 383, 382, 380, 60: 412, 62: 381}, - // 190 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 413}, - {162, 162, 162, 383, 382, 380, 162, 9: 162, 162, 162, 162, 162, 162, 27: 162, 33: 162, 162, 51: 162, 162, 54: 162, 162, 162, 162, 162, 162, 162, 162, 381}, - {7: 419}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 416}, - {3: 383, 382, 380, 60: 417, 62: 381}, - // 195 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 418}, - {161, 161, 161, 383, 382, 380, 161, 9: 161, 161, 161, 161, 161, 161, 27: 161, 33: 161, 161, 51: 161, 161, 54: 161, 161, 161, 161, 161, 161, 161, 161, 381}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 352, 96: 235, 98: 421, 101: 420}, - {2: 425}, - {423, 2: 99, 137: 422}, - // 200 - {2: 424}, - {2: 98}, - {163, 163, 163, 6: 163, 9: 163, 163, 163, 163, 163, 163, 27: 163, 33: 163, 163, 51: 163, 163, 54: 163, 163, 163, 163, 163, 163, 163, 163}, - {165, 165, 165, 6: 165, 9: 165, 165, 165, 165, 165, 165, 27: 165, 33: 165, 165, 51: 165, 165, 54: 165, 165, 165, 165, 165, 165, 165, 165}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 352, 96: 235, 98: 428, 101: 427}, - // 205 - {2: 431}, - {423, 2: 99, 137: 429}, - {2: 430}, - {164, 164, 164, 6: 164, 9: 164, 164, 164, 164, 164, 164, 27: 164, 33: 164, 164, 51: 164, 164, 54: 164, 164, 164, 164, 164, 164, 164, 164}, - {166, 166, 166, 6: 166, 9: 166, 166, 166, 166, 166, 166, 27: 166, 33: 166, 166, 51: 166, 166, 54: 166, 166, 166, 166, 166, 166, 166, 166}, - // 210 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 433}, - {2: 434, 51: 337, 336, 95: 335}, - {198, 198, 198, 198, 198, 198, 198, 198, 9: 198, 198, 198, 198, 198, 198, 27: 198, 33: 198, 198, 50: 198, 198, 198, 54: 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 80: 198, 82: 198, 198, 198, 198, 198, 198, 90: 198}, - {2, 2, 6: 437, 12: 2, 100: 436}, - {216, 216, 12: 216}, - // 215 - {1, 1, 8: 260, 12: 1, 97: 258, 145: 438}, - {214, 214, 6: 214, 12: 214}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 440}, - {217, 217, 6: 217, 12: 217, 51: 337, 336, 95: 335}, - {8: 254, 99: 442}, - // 220 - {40, 40}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 449, 285, 88: 284, 269, 91: 287, 268, 266, 445, 149: 446, 169: 447, 184: 448}, - {3: 76, 76, 76, 7: 76, 76, 15: 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 28: 76, 76, 76, 76, 76, 35: 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 53: 76, 80: 76}, - {149, 149, 149, 6: 149, 9: 149, 149, 149, 149, 14: 149, 27: 149, 33: 149, 149, 51: 337, 336, 54: 149, 58: 507, 95: 335, 168: 506}, - {147, 147, 147, 6: 147, 9: 147, 147, 147, 147, 14: 147, 27: 147, 33: 147, 147, 54: 147}, - // 225 - {74, 74, 74, 6: 504, 9: 74, 74, 74, 74, 14: 74, 27: 74, 33: 74, 74, 54: 74}, - {83, 83, 83, 9: 83, 83, 83, 83, 14: 83, 27: 83, 33: 83, 83, 54: 451, 185: 450}, - {75, 75, 75, 9: 75, 75, 75, 75, 14: 75, 27: 75, 33: 75, 75, 54: 75}, - {86, 86, 86, 9: 86, 86, 86, 86, 14: 86, 27: 468, 33: 466, 467, 174: 470, 471, 469}, - {7: 454, 453, 133: 455, 452, 182: 456}, - // 230 - {97, 97, 97, 6: 97, 9: 97, 97, 97, 97, 14: 97, 27: 97, 33: 97, 97, 58: 464, 102: 97, 181: 463}, - {101, 101, 101, 6: 101, 9: 101, 101, 101, 101, 14: 101, 27: 101, 33: 101, 101, 58: 101, 102: 101}, - {96: 235, 98: 460}, - {95, 95, 95, 6: 95, 9: 95, 95, 95, 95, 14: 95, 27: 95, 33: 95, 95}, - {2, 2, 2, 6: 457, 9: 2, 2, 2, 2, 14: 2, 27: 2, 33: 2, 2, 100: 458}, - // 235 - {1, 1, 1, 7: 454, 453, 1, 1, 1, 1, 14: 1, 27: 1, 33: 1, 1, 133: 459, 452}, - {82, 82, 82, 9: 82, 82, 82, 82, 14: 82, 27: 82, 33: 82, 82}, - {94, 94, 94, 6: 94, 9: 94, 94, 94, 94, 14: 94, 27: 94, 33: 94, 94}, - {423, 2: 99, 137: 461}, - {2: 462}, - // 240 - {100, 100, 100, 6: 100, 9: 100, 100, 100, 100, 14: 100, 27: 100, 33: 100, 100, 58: 100, 102: 100}, - {102, 102, 102, 6: 102, 9: 102, 102, 102, 102, 14: 102, 27: 102, 33: 102, 102, 102: 102}, - {8: 465}, - {96, 96, 96, 6: 96, 9: 96, 96, 96, 96, 14: 96, 27: 96, 33: 96, 96, 102: 96}, - {104: 92, 112: 92}, - // 245 - {104: 91, 112: 91}, - {104: 90, 112: 90}, - {104: 89, 112: 498, 179: 499}, - {85, 85, 85, 9: 85, 85, 85, 85, 14: 85}, - {72, 72, 72, 9: 72, 72, 72, 264, 14: 72, 143: 473, 190: 472}, - // 250 - {70, 70, 70, 9: 70, 70, 70, 14: 474, 170: 476, 186: 475}, - {71, 71, 71, 9: 71, 71, 71, 14: 71}, - {146: 491}, - {68, 68, 68, 9: 68, 68, 477, 177: 479, 189: 478}, - {69, 69, 69, 9: 69, 69, 69}, - // 255 - {146: 486}, - {81, 81, 81, 9: 81, 481, 187: 480}, - {67, 67, 67, 9: 67, 67}, - {79, 79, 79, 9: 484, 188: 483}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 482}, - // 260 - {80, 80, 80, 9: 80, 51: 337, 336, 95: 335}, - {84, 84, 84}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 485}, - {78, 78, 78, 51: 337, 336, 95: 335}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 352, 101: 487}, - // 265 - {125, 125, 125, 9: 125, 125, 55: 489, 490, 178: 488}, - {126, 126, 126, 9: 126, 126}, - {124, 124, 124, 9: 124, 124}, - {123, 123, 123, 9: 123, 123}, - {8: 260, 97: 492, 147: 493}, - // 270 - {205, 205, 205, 6: 205, 9: 205, 205, 205, 157: 494}, - {145, 145, 145, 9: 145, 145, 145}, - {2, 2, 2, 6: 496, 9: 2, 2, 2, 100: 495}, - {206, 206, 206, 9: 206, 206, 206}, - {1, 1, 1, 8: 260, 1, 1, 1, 97: 497}, - // 275 - {204, 204, 204, 6: 204, 9: 204, 204, 204}, - {104: 88}, - {104: 500}, - {7: 454, 453, 133: 501, 452}, - {102: 502}, - // 280 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 503}, - {87, 87, 87, 9: 87, 87, 87, 87, 14: 87, 51: 337, 336, 95: 335}, - {73, 73, 73, 315, 314, 312, 7: 280, 286, 73, 73, 73, 73, 14: 73, 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 73, 300, 301, 302, 303, 299, 73, 73, 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 73, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 445, 149: 505}, - {146, 146, 146, 6: 146, 9: 146, 146, 146, 146, 14: 146, 27: 146, 33: 146, 146, 54: 146}, - {150, 150, 150, 6: 150, 9: 150, 150, 150, 150, 14: 150, 27: 150, 33: 150, 150, 54: 150}, - // 285 - {8: 508}, - {148, 148, 148, 6: 148, 9: 148, 148, 148, 148, 14: 148, 27: 148, 33: 148, 148, 54: 148}, - {8: 254, 99: 510}, - {7: 512, 96: 141, 114: 141, 171: 511}, - {96: 235, 98: 516, 114: 515}, - // 290 - {8: 260, 97: 492, 147: 513}, - {2: 514}, - {96: 140, 114: 140}, - {7: 517}, - {142, 142}, - // 295 - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 352, 101: 518}, - {2: 519}, - {139, 139, 6: 139, 172: 520}, - {2, 2, 6: 522, 100: 521}, - {143, 143}, - // 300 - {1, 1, 7: 523}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 352, 101: 524}, - {2: 525}, - {138, 138, 6: 138}, - {177, 177}, - // 305 - {8: 182, 110: 534, 165: 533}, - {8: 254, 99: 529, 110: 530}, - {180, 180}, - {103: 531}, - {8: 254, 99: 532}, - // 310 - {179, 179}, - {8: 536}, - {103: 535}, - {8: 181}, - {183, 183}, - // 315 - {8: 254, 99: 538}, - {185, 185, 12: 264, 143: 539}, - {184, 184}, - {111: 571}, - {111: 193}, - // 320 - {8: 254, 99: 543, 110: 544}, - {7: 566}, - {50: 545}, - {103: 546}, - {8: 254, 99: 547}, - // 325 - {7: 548}, - {8: 260, 97: 549, 109: 550}, - {16: 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 74: 556}, - {2: 190, 6: 190, 148: 551}, - {2: 2, 6: 553, 100: 552}, - // 330 - {2: 555}, - {2: 1, 8: 260, 97: 549, 109: 554}, - {2: 189, 6: 189}, - {191, 191}, - {200, 200, 200, 315, 314, 312, 200, 280, 286, 13: 200, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 558, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 559, 158: 560, 557}, - // 335 - {187, 187, 187, 6: 187, 13: 563, 162: 564, 562}, - {15: 561}, - {201, 201, 201, 6: 201, 13: 201, 51: 337, 336, 95: 335}, - {199, 199, 199, 6: 199, 13: 199}, - {202, 202, 202, 6: 202, 13: 202}, - // 340 - {208, 208, 208, 6: 208}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 565}, - {186, 186, 186, 6: 186}, - {188, 188, 188, 6: 188, 51: 337, 336, 95: 335}, - {8: 260, 97: 549, 109: 567}, - // 345 - {2: 190, 6: 190, 148: 568}, - {2: 2, 6: 553, 100: 569}, - {2: 570}, - {192, 192}, - {8: 196, 110: 573, 160: 572}, - // 350 - {8: 576}, - {50: 574}, - {103: 575}, - {8: 195}, - {102: 577}, - // 355 - {8: 578}, - {7: 579}, - {3: 315, 314, 312, 7: 280, 286, 15: 271, 288, 289, 290, 291, 292, 293, 294, 295, 297, 298, 296, 28: 300, 301, 302, 303, 299, 35: 304, 305, 306, 308, 309, 310, 311, 307, 270, 273, 274, 275, 278, 276, 272, 53: 313, 74: 265, 282, 277, 281, 283, 279, 81: 285, 88: 284, 269, 91: 287, 268, 266, 352, 101: 580}, - {2: 581}, - {197, 197}, - // 360 - {213, 213}, - {8: 254, 99: 584}, - {106: 586, 144: 585}, - {8: 260, 97: 549, 109: 589}, - {156: 587}, - // 365 - {8: 260, 97: 588}, - {218, 218}, - {219, 219}, - {1: 220, 51: 337, 336, 95: 335}, - {178, 178, 96: 235, 98: 248, 106: 231, 115: 226, 237, 227, 238, 228, 239, 229, 240, 241, 242, 230, 243, 244, 236, 232, 245, 233, 246, 135: 234, 247, 138: 592, 252, 249, 253, 250}, - // 370 - {46, 46}, - } -) - -var yyDebug = 0 - -type yyLexer interface { - Lex(lval *yySymType) int - Error(s string) -} - -type yyLexerEx interface { - yyLexer - Reduced(rule, state int, lval *yySymType) bool -} - -func yySymName(c int) (s string) { - x, ok := yyXLAT[c] - if ok { - return yySymNames[x] - } - - if c < 0x7f { - return __yyfmt__.Sprintf("%q", c) - } - - return __yyfmt__.Sprintf("%d", c) -} - -func yylex1(yylex yyLexer, lval *yySymType) (n int) { - n = yylex.Lex(lval) - if n <= 0 { - n = yyEOFCode - } - if yyDebug >= 3 { - __yyfmt__.Printf("\nlex %s(%#x %d), lval: %+v\n", yySymName(n), n, n, lval) - } - return n -} - -func yyParse(yylex yyLexer) int { - const yyError = 198 - - yyEx, _ := yylex.(yyLexerEx) - var yyn int - var yylval yySymType - var yyVAL yySymType - yyS := make([]yySymType, 200) - - Nerrs := 0 /* number of errors */ - Errflag := 0 /* error recovery flag */ - yyerrok := func() { - if yyDebug >= 2 { - __yyfmt__.Printf("yyerrok()\n") - } - Errflag = 0 - } - _ = yyerrok - yystate := 0 - yychar := -1 - var yyxchar int - var yyshift int - yyp := -1 - goto yystack - -ret0: - return 0 - -ret1: - return 1 - -yystack: - /* put a state and value onto the stack */ - yyp++ - if yyp >= len(yyS) { - nyys := make([]yySymType, len(yyS)*2) - copy(nyys, yyS) - yyS = nyys - } - yyS[yyp] = yyVAL - yyS[yyp].yys = yystate - -yynewstate: - if yychar < 0 { - yylval.yys = yystate - yychar = yylex1(yylex, &yylval) - var ok bool - if yyxchar, ok = yyXLAT[yychar]; !ok { - yyxchar = len(yySymNames) // > tab width - } - } - if yyDebug >= 4 { - var a []int - for _, v := range yyS[:yyp+1] { - a = append(a, v.yys) - } - __yyfmt__.Printf("state stack %v\n", a) - } - row := yyParseTab[yystate] - yyn = 0 - if yyxchar < len(row) { - if yyn = int(row[yyxchar]); yyn != 0 { - yyn += yyTabOfs - } - } - switch { - case yyn > 0: // shift - yychar = -1 - yyVAL = yylval - yystate = yyn - yyshift = yyn - if yyDebug >= 2 { - __yyfmt__.Printf("shift, and goto state %d\n", yystate) - } - if Errflag > 0 { - Errflag-- - } - goto yystack - case yyn < 0: // reduce - case yystate == 1: // accept - if yyDebug >= 2 { - __yyfmt__.Println("accept") - } - goto ret0 - } - - if yyn == 0 { - /* error ... attempt to resume parsing */ - switch Errflag { - case 0: /* brand new error */ - if yyDebug >= 1 { - __yyfmt__.Printf("no action for %s in state %d\n", yySymName(yychar), yystate) - } - msg, ok := yyXErrors[yyXError{yystate, yyxchar}] - if !ok { - msg, ok = yyXErrors[yyXError{yystate, -1}] - } - if !ok && yyshift != 0 { - msg, ok = yyXErrors[yyXError{yyshift, yyxchar}] - } - if !ok { - msg, ok = yyXErrors[yyXError{yyshift, -1}] - } - if yychar > 0 { - ls := yyTokenLiteralStrings[yychar] - if ls == "" { - ls = yySymName(yychar) - } - if ls != "" { - switch { - case msg == "": - msg = __yyfmt__.Sprintf("unexpected %s", ls) - default: - msg = __yyfmt__.Sprintf("unexpected %s, %s", ls, msg) - } - } - } - if msg == "" { - msg = "syntax error" - } - yylex.Error(msg) - Nerrs++ - fallthrough - - case 1, 2: /* incompletely recovered error ... try again */ - Errflag = 3 - - /* find a state where "error" is a legal shift action */ - for yyp >= 0 { - row := yyParseTab[yyS[yyp].yys] - if yyError < len(row) { - yyn = int(row[yyError]) + yyTabOfs - if yyn > 0 { // hit - if yyDebug >= 2 { - __yyfmt__.Printf("error recovery found error shift in state %d\n", yyS[yyp].yys) - } - yystate = yyn /* simulate a shift of "error" */ - goto yystack - } - } - - /* the current p has no shift on "error", pop stack */ - if yyDebug >= 2 { - __yyfmt__.Printf("error recovery pops state %d\n", yyS[yyp].yys) - } - yyp-- - } - /* there is no state on the stack with an error shift ... abort */ - if yyDebug >= 2 { - __yyfmt__.Printf("error recovery failed\n") - } - goto ret1 - - case 3: /* no shift yet; clobber input char */ - if yyDebug >= 2 { - __yyfmt__.Printf("error recovery discards %s\n", yySymName(yychar)) - } - if yychar == yyEOFCode { - goto ret1 - } - - yychar = -1 - goto yynewstate /* try again in the same state */ - } - } - - r := -yyn - x0 := yyReductions[r] - x, n := x0.xsym, x0.components - yypt := yyp - _ = yypt // guard against "declared and not used" - - yyp -= n - if yyp+1 >= len(yyS) { - nyys := make([]yySymType, len(yyS)*2) - copy(nyys, yyS) - yyS = nyys - } - yyVAL = yyS[yyp+1] - - /* consult goto table to find next state */ - exState := yystate - yystate = int(yyParseTab[yyS[yyp].yys][x]) + yyTabOfs - /* reduction by production r */ - if yyDebug >= 2 { - __yyfmt__.Printf("reduce using rule %v (%s), and goto state %d\n", r, yySymNames[x], yystate) - } - - switch r { - case 2: - { - yylex.(*lexer).expr = expr(yyS[yypt-0].item) - } - case 3: - { - yyVAL.item = &alterTableAddStmt{tableName: yyS[yypt-2].item.(string), c: yyS[yypt-0].item.(*col)} - } - case 4: - { - yyVAL.item = &alterTableDropColumnStmt{tableName: yyS[yypt-3].item.(string), colName: yyS[yypt-0].item.(string)} - } - case 5: - { - yyVAL.item = assignment{colName: yyS[yypt-2].item.(string), expr: expr(yyS[yypt-0].item)} - } - case 6: - { - yyVAL.item = append([]assignment{yyS[yypt-2].item.(assignment)}, yyS[yypt-1].item.([]assignment)...) - } - case 7: - { - yyVAL.item = []assignment{} - } - case 8: - { - yyVAL.item = append(yyS[yypt-2].item.([]assignment), yyS[yypt-0].item.(assignment)) - } - case 9: - { - yyVAL.item = beginTransactionStmt{} - } - case 10: - { - yyVAL.item = yyS[yypt-1].item - } - case 11: - { - yyVAL.item = '*' - } - case 12: - { - yyVAL.item = []expression{} - } - case 14: - { - x := &col{name: yyS[yypt-3].item.(string), typ: yyS[yypt-2].item.(int), constraint: yyS[yypt-1].item.(*constraint)} - if yyS[yypt-0].item != nil { - x.dflt = expr(yyS[yypt-0].item) - } - yyVAL.item = x - } - case 16: - { - yyVAL.item = append([]string{yyS[yypt-2].item.(string)}, yyS[yypt-1].item.([]string)...) - } - case 17: - { - yyVAL.item = []string{} - } - case 18: - { - yyVAL.item = append(yyS[yypt-2].item.([]string), yyS[yypt-0].item.(string)) - } - case 19: - { - yyVAL.item = commitStmt{} - } - case 20: - { - yyVAL.item = &constraint{} - } - case 21: - { - yyVAL.item = &constraint{expr(yyS[yypt-0].item)} - } - case 22: - { - yyVAL.item = (*constraint)(nil) - } - case 24: - { - yyVAL.item = &conversion{typ: yyS[yypt-3].item.(int), val: expr(yyS[yypt-1].item)} - } - case 25: - { - indexName, tableName, exprList := yyS[yypt-5].item.(string), yyS[yypt-3].item.(string), yyS[yypt-1].item.([]expression) - simpleIndex := len(exprList) == 1 - var columnName string - if simpleIndex { - expr := exprList[0] - switch x := expr.(type) { - case *ident: - columnName = x.s - case *call: - if x.f == "id" && len(x.arg) == 0 { - columnName = "id()" - break - } - - simpleIndex = false - default: - simpleIndex = false - } - } - - if !simpleIndex { - columnName = "" - } - yyVAL.item = &createIndexStmt{unique: yyS[yypt-8].item.(bool), ifNotExists: yyS[yypt-6].item.(bool), indexName: indexName, tableName: tableName, colName: columnName, exprList: exprList} - - if indexName == tableName || indexName == columnName { - yylex.(*lexer).err("index name collision: %s", indexName) - return 1 - } - - if yylex.(*lexer).root { - break - } - - if isSystemName[indexName] || isSystemName[tableName] { - yylex.(*lexer).err("name is used for system tables: %s", indexName) - return 1 - } - } - case 26: - { - yyVAL.item = false - } - case 27: - { - yyVAL.item = true - } - case 28: - { - yyVAL.item = false - } - case 29: - { - yyVAL.item = true - } - case 30: - { - nm := yyS[yypt-5].item.(string) - yyVAL.item = &createTableStmt{tableName: nm, cols: append([]*col{yyS[yypt-3].item.(*col)}, yyS[yypt-2].item.([]*col)...)} - - if yylex.(*lexer).root { - break - } - - if isSystemName[nm] { - yylex.(*lexer).err("name is used for system tables: %s", nm) - return 1 - } - } - case 31: - { - nm := yyS[yypt-5].item.(string) - yyVAL.item = &createTableStmt{ifNotExists: true, tableName: nm, cols: append([]*col{yyS[yypt-3].item.(*col)}, yyS[yypt-2].item.([]*col)...)} - - if yylex.(*lexer).root { - break - } - - if isSystemName[nm] { - yylex.(*lexer).err("name is used for system tables: %s", nm) - return 1 - } - } - case 32: - { - yyVAL.item = []*col{} - } - case 33: - { - yyVAL.item = append(yyS[yypt-2].item.([]*col), yyS[yypt-0].item.(*col)) - } - case 34: - { - yyVAL.item = yyS[yypt-0].item - } - case 35: - { - yyVAL.item = nil - } - case 37: - { - yyVAL.item = &truncateTableStmt{yyS[yypt-0].item.(string)} - - if yylex.(*lexer).root { - break - } - - if isSystemName[yyS[yypt-0].item.(string)] { - yylex.(*lexer).err("name is used for system tables: %s", yyS[yypt-0].item.(string)) - return 1 - } - } - case 38: - { - yyVAL.item = &deleteStmt{tableName: yyS[yypt-1].item.(string), where: yyS[yypt-0].item.(*whereRset).expr} - - if yylex.(*lexer).root { - break - } - - if isSystemName[yyS[yypt-1].item.(string)] { - yylex.(*lexer).err("name is used for system tables: %s", yyS[yypt-1].item.(string)) - return 1 - } - } - case 39: - { - yyVAL.item = &dropIndexStmt{ifExists: yyS[yypt-1].item.(bool), indexName: yyS[yypt-0].item.(string)} - } - case 40: - { - yyVAL.item = false - } - case 41: - { - yyVAL.item = true - } - case 42: - { - nm := yyS[yypt-0].item.(string) - yyVAL.item = &dropTableStmt{tableName: nm} - - if yylex.(*lexer).root { - break - } - - if isSystemName[nm] { - yylex.(*lexer).err("name is used for system tables: %s", nm) - return 1 - } - } - case 43: - { - nm := yyS[yypt-0].item.(string) - yyVAL.item = &dropTableStmt{ifExists: true, tableName: nm} - - if yylex.(*lexer).root { - break - } - - if isSystemName[nm] { - yylex.(*lexer).err("name is used for system tables: %s", nm) - return 1 - } - } - case 44: - { - yyVAL.item = nil - } - case 45: - { - yyVAL.item = &explainStmt{yyS[yypt-0].item.(stmt)} - } - case 47: - { - var err error - if yyVAL.item, err = newBinaryOperation(oror, yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 52: - { - yyVAL.item = append([]expression{expr(yyS[yypt-2].item)}, yyS[yypt-1].item.([]expression)...) - } - case 53: - { - yyVAL.item = []expression(nil) - } - case 54: - { - yyVAL.item = append(yyS[yypt-2].item.([]expression), expr(yyS[yypt-0].item)) - } - case 56: - { - yyVAL.item = &pIn{expr: yyS[yypt-4].item.(expression), list: yyS[yypt-1].item.([]expression)} - } - case 57: - { - yyVAL.item = &pIn{expr: yyS[yypt-5].item.(expression), not: true, list: yyS[yypt-1].item.([]expression)} - } - case 58: - { - yyVAL.item = &pIn{expr: yyS[yypt-5].item.(expression), sel: yyS[yypt-2].item.(*selectStmt)} - } - case 59: - { - yyVAL.item = &pIn{expr: yyS[yypt-6].item.(expression), not: true, sel: yyS[yypt-2].item.(*selectStmt)} - } - case 60: - { - var err error - if yyVAL.item, err = newBetween(yyS[yypt-4].item, yyS[yypt-2].item, yyS[yypt-0].item, false); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 61: - { - var err error - if yyVAL.item, err = newBetween(yyS[yypt-5].item, yyS[yypt-2].item, yyS[yypt-0].item, true); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 62: - { - yyVAL.item = &isNull{expr: yyS[yypt-2].item.(expression)} - } - case 63: - { - yyVAL.item = &isNull{expr: yyS[yypt-3].item.(expression), not: true} - } - case 65: - { - var err error - if yyVAL.item, err = newBinaryOperation(ge, yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 66: - { - var err error - if yyVAL.item, err = newBinaryOperation('>', yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 67: - { - var err error - if yyVAL.item, err = newBinaryOperation(le, yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 68: - { - var err error - if yyVAL.item, err = newBinaryOperation('<', yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 69: - { - var err error - if yyVAL.item, err = newBinaryOperation(neq, yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 70: - { - var err error - if yyVAL.item, err = newBinaryOperation(eq, yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 71: - { - yyVAL.item = &pLike{expr: yyS[yypt-2].item.(expression), pattern: yyS[yypt-0].item.(expression)} - } - case 72: - { - expr, name := expr(yyS[yypt-1].item), yyS[yypt-0].item.(string) - if name == "" { - s, ok := expr.(*ident) - if ok { - name = s.s - } - } - yyVAL.item = &fld{expr: expr, name: name} - } - case 73: - { - yyVAL.item = "" - } - case 74: - { - yyVAL.item = yyS[yypt-0].item - } - case 75: - { - yyVAL.item = []*fld{yyS[yypt-0].item.(*fld)} - } - case 76: - { - l, f := yyS[yypt-2].item.([]*fld), yyS[yypt-0].item.(*fld) - if f.name != "" { - if f := findFld(l, f.name); f != nil { - yylex.(*lexer).err("duplicate field name %q", f.name) - return 1 - } - } - - yyVAL.item = append(yyS[yypt-2].item.([]*fld), yyS[yypt-0].item.(*fld)) - } - case 77: - { - yyVAL.item = &groupByRset{colNames: yyS[yypt-0].item.([]string)} - } - case 78: - { - yyVAL.item = yyS[yypt-1].item - } - case 79: - { - yyVAL.item = &insertIntoStmt{tableName: yyS[yypt-7].item.(string), colNames: yyS[yypt-6].item.([]string), lists: append([][]expression{yyS[yypt-3].item.([]expression)}, yyS[yypt-1].item.([][]expression)...)} - - if yylex.(*lexer).root { - break - } - - if isSystemName[yyS[yypt-7].item.(string)] { - yylex.(*lexer).err("name is used for system tables: %s", yyS[yypt-7].item.(string)) - return 1 - } - } - case 80: - { - yyVAL.item = &insertIntoStmt{tableName: yyS[yypt-2].item.(string), colNames: yyS[yypt-1].item.([]string), sel: yyS[yypt-0].item.(*selectStmt)} - } - case 81: - { - yyVAL.item = []string{} - } - case 82: - { - yyVAL.item = yyS[yypt-1].item - } - case 83: - { - yyVAL.item = [][]expression{} - } - case 84: - { - yyVAL.item = append(yyS[yypt-4].item.([][]expression), yyS[yypt-1].item.([]expression)) - } - case 92: - { - yyVAL.item = value{yyS[yypt-0].item} - } - case 93: - { - n := yyS[yypt-0].item.(int) - yyVAL.item = parameter{n} - l := yylex.(*lexer) - l.params = mathutil.Max(l.params, n) - if n == 0 { - l.err("parameter number must be non zero") - return 1 - } - } - case 94: - { - yyVAL.item = &ident{yyS[yypt-0].item.(string)} - } - case 95: - { - yyVAL.item = &pexpr{expr: expr(yyS[yypt-1].item)} - } - case 96: - { - yyVAL.item = &orderByRset{by: yyS[yypt-1].item.([]expression), asc: yyS[yypt-0].item.(bool)} - } - case 97: - { - yyVAL.item = true // ASC by default - } - case 98: - { - yyVAL.item = true - } - case 99: - { - yyVAL.item = false - } - case 102: - { - var err error - if yyVAL.item, err = newIndex(yyS[yypt-1].item.(expression), expr(yyS[yypt-0].item)); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 103: - { - var err error - s := yyS[yypt-0].item.([2]*expression) - if yyVAL.item, err = newSlice(yyS[yypt-1].item.(expression), s[0], s[1]); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 104: - { - x := yylex.(*lexer) - f, ok := yyS[yypt-1].item.(*ident) - if !ok { - x.err("expected identifier or qualified identifier") - return 1 - } - - if r, ok := yyS[yypt-0].item.(rune); ok { - if f.isQualified() || f.s != "count" || r != '*' { - x.err(fmt.Sprintf("invalid expression %s(%c)", f, r)) - return 1 - } - - yyS[yypt-0].item = []expression(nil) - } - - var err error - var agg bool - if yyVAL.item, agg, err = newCall(f.s, yyS[yypt-0].item.([]expression)); err != nil { - x.err("%v", err) - return 1 - } - if n := len(x.agg); n > 0 { - x.agg[n-1] = x.agg[n-1] || agg - } - } - case 106: - { - var err error - if yyVAL.item, err = newBinaryOperation('^', yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 107: - { - var err error - if yyVAL.item, err = newBinaryOperation('|', yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 108: - { - var err error - if yyVAL.item, err = newBinaryOperation('-', yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 109: - { - var err error - yyVAL.item, err = newBinaryOperation('+', yyS[yypt-2].item, yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 111: - { - var err error - yyVAL.item, err = newBinaryOperation(andnot, yyS[yypt-2].item, yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 112: - { - var err error - yyVAL.item, err = newBinaryOperation('&', yyS[yypt-2].item, yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 113: - { - var err error - yyVAL.item, err = newBinaryOperation(lsh, yyS[yypt-2].item, yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 114: - { - var err error - yyVAL.item, err = newBinaryOperation(rsh, yyS[yypt-2].item, yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 115: - { - var err error - yyVAL.item, err = newBinaryOperation('%', yyS[yypt-2].item, yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 116: - { - var err error - yyVAL.item, err = newBinaryOperation('/', yyS[yypt-2].item, yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 117: - { - var err error - yyVAL.item, err = newBinaryOperation('*', yyS[yypt-2].item, yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 119: - { - yyVAL.item = fmt.Sprintf("%s.%s", yyS[yypt-2].item.(string), yyS[yypt-0].item.(string)) - } - case 120: - { - yyVAL.item = []interface{}{yyS[yypt-1].item, yyS[yypt-0].item} - } - case 122: - { - yyVAL.item = yyS[yypt-2].item - } - case 125: - { - yyVAL.item = "" - } - case 126: - { - yyVAL.item = yyS[yypt-0].item - } - case 127: - { - yyVAL.list = []interface{}{yyS[yypt-0].item} - } - case 128: - { - yyVAL.list = append(yyS[yypt-2].list, yyS[yypt-0].item) - } - case 129: - { - yyVAL.item = rollbackStmt{} - } - case 130: - { - yyVAL.item = leftJoin - } - case 131: - { - yyVAL.item = rightJoin - } - case 132: - { - yyVAL.item = fullJoin - } - case 133: - { - yyVAL.item = nil - } - case 135: - { - yyVAL.item = []interface{}{yyS[yypt-5].item, yyS[yypt-2].item, yyS[yypt-0].item} - } - case 136: - { - yyVAL.item = nil - } - case 138: - { - x := yylex.(*lexer) - n := len(x.agg) - join := &joinRset{sources: yyS[yypt-6].list} - if o := yyS[yypt-5].item; o != nil { - o := o.([]interface{}) - join.typ = o[0].(int) - join.sources = append(join.sources, o[1].([]interface{})) - join.on = o[2].(expression) - } - yyVAL.item = &selectStmt{ - distinct: yyS[yypt-8].item.(bool), - flds: yyS[yypt-7].item.([]*fld), - from: join, - hasAggregates: x.agg[n-1], - where: yyS[yypt-4].item.(*whereRset), - group: yyS[yypt-3].item.(*groupByRset), - order: yyS[yypt-2].item.(*orderByRset), - limit: yyS[yypt-1].item.(*limitRset), - offset: yyS[yypt-0].item.(*offsetRset), - } - x.agg = x.agg[:n-1] - } - case 139: - { - yyVAL.list = nil - } - case 140: - { - yyVAL.list = yyS[yypt-1].list - } - case 141: - { - yyVAL.item = (*limitRset)(nil) - } - case 142: - { - yyVAL.item = &limitRset{expr: expr(yyS[yypt-0].item)} - } - case 143: - { - yyVAL.item = (*offsetRset)(nil) - } - case 144: - { - yyVAL.item = &offsetRset{expr: expr(yyS[yypt-0].item)} - } - case 145: - { - yyVAL.item = false - } - case 146: - { - yyVAL.item = true - } - case 147: - { - yyVAL.item = []*fld{} - } - case 148: - { - yyVAL.item = yyS[yypt-0].item - } - case 149: - { - yyVAL.item = yyS[yypt-1].item - } - case 150: - { - yyVAL.item = (*whereRset)(nil) - } - case 152: - { - yyVAL.item = (*groupByRset)(nil) - } - case 154: - { - yyVAL.item = (*orderByRset)(nil) - } - case 156: - { - yyVAL.item = [2]*expression{nil, nil} - } - case 157: - { - hi := expr(yyS[yypt-1].item) - yyVAL.item = [2]*expression{nil, &hi} - } - case 158: - { - lo := expr(yyS[yypt-2].item) - yyVAL.item = [2]*expression{&lo, nil} - } - case 159: - { - lo := expr(yyS[yypt-3].item) - hi := expr(yyS[yypt-1].item) - yyVAL.item = [2]*expression{&lo, &hi} - } - case 175: - { - if yyS[yypt-0].item != nil { - yylex.(*lexer).list = []stmt{yyS[yypt-0].item.(stmt)} - } - } - case 176: - { - if yyS[yypt-0].item != nil { - yylex.(*lexer).list = append(yylex.(*lexer).list, yyS[yypt-0].item.(stmt)) - } - } - case 179: - { - var err error - if yyVAL.item, err = newBinaryOperation(andand, yyS[yypt-2].item, yyS[yypt-0].item); err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 182: - { - yyVAL.item = &truncateTableStmt{tableName: yyS[yypt-0].item.(string)} - } - case 207: - { - var expr expression - if w := yyS[yypt-0].item; w != nil { - expr = w.(*whereRset).expr - } - yyVAL.item = &updateStmt{tableName: yyS[yypt-3].item.(string), list: yyS[yypt-1].item.([]assignment), where: expr} - - if yylex.(*lexer).root { - break - } - - if isSystemName[yyS[yypt-3].item.(string)] { - yylex.(*lexer).err("name is used for system tables: %s", yyS[yypt-3].item.(string)) - return 1 - } - } - case 208: - { - yyVAL.item = nil - } - case 211: - { - var err error - yyVAL.item, err = newUnaryOperation('^', yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 212: - { - var err error - yyVAL.item, err = newUnaryOperation('!', yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 213: - { - var err error - yyVAL.item, err = newUnaryOperation('-', yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 214: - { - var err error - yyVAL.item, err = newUnaryOperation('+', yyS[yypt-0].item) - if err != nil { - yylex.(*lexer).err("%v", err) - return 1 - } - } - case 215: - { - yyVAL.item = &whereRset{expr: expr(yyS[yypt-0].item)} - } - case 216: - { - yyVAL.item = &whereRset{exists: true, sel: (yyS[yypt-1].item.(*selectStmt))} - } - case 217: - { - yyVAL.item = &whereRset{sel: (yyS[yypt-1].item.(*selectStmt))} - } - - } - - if yyEx != nil && yyEx.Reduced(r, exState, &yyVAL) { - return -1 - } - goto yystack /* stack new state and value */ -} - -func expr(v interface{}) expression { - e := v.(expression) - for { - x, ok := e.(*pexpr) - if !ok { - return e - } - e = x.expr - } -} diff --git a/vendor/github.com/cznic/ql/plan.go b/vendor/github.com/cznic/ql/plan.go deleted file mode 100644 index 65132d458..000000000 --- a/vendor/github.com/cznic/ql/plan.go +++ /dev/null @@ -1,2829 +0,0 @@ -// Copyright 2015 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "bytes" - "fmt" - "strings" - - "github.com/cznic/b" - "github.com/cznic/strutil" -) - -const ( - _ = iota - indexEq // [L] - indexFalse // [false] - indexGe // [L, ...) - indexGt // (L, ...) - indexIsNotNull // (NULL, ...) - indexIsNull // [NULL] - indexIntervalCC // [L, H] - indexIntervalCO // [L, H) - indexIntervalOC // (L, H] - indexIntervalOO // (L, H) - indexLe // (..., H] - indexLt // (..., H) - indexNe // (L) - indexTrue // [true] -) - -// Note: All plans must have a pointer receiver. Enables planA == planB operation. -var ( - _ plan = (*crossJoinDefaultPlan)(nil) - _ plan = (*distinctDefaultPlan)(nil) - _ plan = (*explainDefaultPlan)(nil) - _ plan = (*filterDefaultPlan)(nil) - _ plan = (*fullJoinDefaultPlan)(nil) - _ plan = (*groupByDefaultPlan)(nil) - _ plan = (*indexPlan)(nil) - _ plan = (*leftJoinDefaultPlan)(nil) - _ plan = (*limitDefaultPlan)(nil) - _ plan = (*nullPlan)(nil) - _ plan = (*offsetDefaultPlan)(nil) - _ plan = (*orderByDefaultPlan)(nil) - _ plan = (*rightJoinDefaultPlan)(nil) - _ plan = (*selectFieldsDefaultPlan)(nil) - _ plan = (*selectFieldsGroupPlan)(nil) - _ plan = (*selectIndexDefaultPlan)(nil) - _ plan = (*selectDummyPlan)(nil) - _ plan = (*sysColumnDefaultPlan)(nil) - _ plan = (*sysIndexDefaultPlan)(nil) - _ plan = (*sysTableDefaultPlan)(nil) - _ plan = (*tableDefaultPlan)(nil) - _ plan = (*tableNilPlan)(nil) -) - -type plan interface { - do(ctx *execCtx, f func(id interface{}, data []interface{}) (more bool, err error)) error - explain(w strutil.Formatter) - fieldNames() []string - filter(expr expression) (p plan, indicesSought []string, err error) - hasID() bool -} - -func isTableOrIndex(p plan) bool { - switch p.(type) { - case - *indexPlan, - *sysColumnDefaultPlan, - *sysIndexDefaultPlan, - *sysTableDefaultPlan, - *tableDefaultPlan: - return true - default: - return false - } -} - -// Invariants -// - All interval plans produce rows in ascending index value collating order. -// - L <= H -type indexPlan struct { - src *table - cname string - xname string - x btreeIndex - kind int // See interval* consts. - lval interface{} // L, H: Ordered and comparable (lldb perspective). - hval interface{} -} - -func (r *indexPlan) doGe(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., L-1, L-1, L, L, L+1, L+1, ... - // --- --- --- --- --- + + +++ +++ +++ - t := r.src - it, _, err := r.x.Seek([]interface{}{r.lval}) - if err != nil { - return noEOF(err) - } - - for { - _, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doGt(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., L-1, L-1, L, L, L+1, L+1, ... - // --- --- --- --- --- - - +++ +++ +++ - t := r.src - it, _, err := r.x.Seek([]interface{}{r.lval}) - if err != nil { - return noEOF(err) - } - - var ok bool - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - if !ok { - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.lval) == 0 { - continue - } - - ok = true - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doInterval00(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., L-1, L-1, L, L, L+1, L+1, ..., H-1, H-1, H, H, H+1, H+1, ... - // --- --- --- --- --- - - +++ +++ +++ +++ +++ - - --- --- --- - t := r.src - it, _, err := r.x.Seek([]interface{}{r.lval}) - if err != nil { - return noEOF(err) - } - - var ok bool - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - if !ok { - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.lval) == 0 { - continue - } - - ok = true - } - - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.hval) == 0 { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doIntervalOC(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., L-1, L-1, L, L, L+1, L+1, ..., H-1, H-1, H, H, H+1, H+1, ... - // --- --- --- --- --- - - +++ +++ +++ +++ +++ + + --- --- --- - t := r.src - it, _, err := r.x.Seek([]interface{}{r.lval}) - if err != nil { - return noEOF(err) - } - - var ok bool - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - if !ok { - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.lval) == 0 { - continue - } - - ok = true - } - - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.hval) > 0 { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doIntervalCC(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., L-1, L-1, L, L, L+1, L+1, ..., H-1, H-1, H, H, H+1, H+1, ... - // --- --- --- --- --- + + +++ +++ +++ +++ +++ + + --- --- --- - t := r.src - it, _, err := r.x.Seek([]interface{}{r.lval}) - if err != nil { - return noEOF(err) - } - - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.hval) > 0 { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doIntervalCO(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., L-1, L-1, L, L, L+1, L+1, ..., H-1, H-1, H, H, H+1, H+1, ... - // --- --- --- --- --- + + +++ +++ +++ +++ +++ - - --- --- --- - t := r.src - it, _, err := r.x.Seek([]interface{}{r.lval}) - if err != nil { - return noEOF(err) - } - - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.hval) >= 0 { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doLe(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., H-1, H-1, H, H, H+1, H+1, ... - // --- --- +++ +++ +++ + + --- --- - t := r.src - it, err := r.x.SeekFirst() - if err != nil { - return noEOF(err) - } - - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - if k == nil || k[0] == nil { - continue - } - - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.hval) > 0 { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doLt(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., H-1, H-1, H, H, H+1, H+1, ... - // --- --- +++ +++ +++ - - --- --- - t := r.src - it, err := r.x.SeekFirst() - if err != nil { - return noEOF(err) - } - - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - if k == nil || k[0] == nil { - continue - } - - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.hval) >= 0 { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doEq(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., L-1, L-1, L, L, L+1, L+1, ... - // --- --- --- --- --- + + --- --- --- - t := r.src - it, _, err := r.x.Seek([]interface{}{r.lval}) - if err != nil { - return noEOF(err) - } - - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.lval) != 0 { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doNe(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ..., L-1, L-1, L, L, L+1, L+1, ... - // --- --- +++ +++ +++ - - +++ +++ +++ - t := r.src - it, err := r.x.SeekFirst() - if err != nil { - return noEOF(err) - } - - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - if k == nil || k[0] == nil { - continue - } - - val, err := expand1(k[0], nil) - if err != nil { - return err - } - - if collate1(val, r.hval) == 0 { - continue - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doIsNull(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ... - // +++ +++ --- - t := r.src - it, err := r.x.SeekFirst() - if err != nil { - return noEOF(err) - } - - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - if k != nil && k[0] != nil { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doIsNotNull(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - // nil, nil, ... - // --- --- +++ - t := r.src - it, _, err := r.x.Seek([]interface{}{false}) // lldb collates false right after NULL. - if err != nil { - return noEOF(err) - } - - for { - _, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doFalse(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - t := r.src - it, _, err := r.x.Seek([]interface{}{false}) - if err != nil { - return noEOF(err) - } - - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - b, ok := k[0].(bool) - if !ok || b { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) doTrue(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - t := r.src - it, _, err := r.x.Seek([]interface{}{true}) - if err != nil { - return noEOF(err) - } - - for { - k, h, err := it.Next() - if err != nil { - return noEOF(err) - } - - if _, ok := k[0].(bool); !ok { - return nil - } - - id, data, err := t.row(ctx, h) - if err != nil { - return err - } - - if more, err := f(id, data); err != nil || !more { - return err - } - } -} - -func (r *indexPlan) do(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) error { - switch r.kind { - case indexEq: - return r.doEq(ctx, f) - case indexGe: - return r.doGe(ctx, f) - case indexGt: - return r.doGt(ctx, f) - case indexLe: - return r.doLe(ctx, f) - case indexLt: - return r.doLt(ctx, f) - case indexNe: - return r.doNe(ctx, f) - case indexIsNull: - return r.doIsNull(ctx, f) - case indexIsNotNull: - return r.doIsNotNull(ctx, f) - case indexFalse: - return r.doFalse(ctx, f) - case indexTrue: - return r.doTrue(ctx, f) - case indexIntervalOO: - return r.doInterval00(ctx, f) - case indexIntervalCC: - return r.doIntervalCC(ctx, f) - case indexIntervalOC: - return r.doIntervalOC(ctx, f) - case indexIntervalCO: - return r.doIntervalCO(ctx, f) - default: - //dbg("", r.kind) - panic("internal error 072") - } -} - -func (r *indexPlan) explain(w strutil.Formatter) { - s := "" - if r.kind == indexFalse { - s = "!" - } - w.Format("┌Iterate all rows of table %q using index %q where %s%s", r.src.name, r.xname, s, r.cname) - switch r.kind { - case indexEq: - w.Format(" == %v", value{r.lval}) - case indexGe: - w.Format(" >= %v", value{r.lval}) - case indexGt: - w.Format(" > %v", value{r.lval}) - case indexLe: - w.Format(" <= %v", value{r.hval}) - case indexLt: - w.Format(" < %v", value{r.hval}) - case indexNe: - w.Format(" != %v", value{r.lval}) - case indexIsNull: - w.Format(" IS NULL") - case indexIsNotNull: - w.Format(" IS NOT NULL") - case indexFalse, indexTrue: - // nop - case indexIntervalOO: - w.Format(" > %v && %s < %v", value{r.lval}, r.cname, value{r.hval}) - case indexIntervalCC: - w.Format(" >= %v && %s <= %v", value{r.lval}, r.cname, value{r.hval}) - case indexIntervalCO: - w.Format(" >= %v && %s < %v", value{r.lval}, r.cname, value{r.hval}) - case indexIntervalOC: - w.Format(" > %v && %s <= %v", value{r.lval}, r.cname, value{r.hval}) - default: - //dbg("", r.kind) - panic("internal error 073") - } - w.Format("\n└Output field names %v\n", qnames(r.fieldNames())) -} - -func (r *indexPlan) fieldNames() []string { return r.src.fieldNames() } - -func (r *indexPlan) filterEq(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(r.lval, val) == 0 { - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case ge: - if collate1(r.lval, val) >= 0 { - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case '>': - if collate1(r.lval, val) > 0 { - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case le: - if collate1(r.lval, val) <= 0 { - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case '<': - if collate1(r.lval, val) < 0 { - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case neq: - if collate1(r.lval, val) != 0 { - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - } - return nil, nil, nil -} - -func (r *indexPlan) filterGe(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(r.lval, val) <= 0 { - r.lval = val - r.kind = indexEq - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case ge: - if collate1(r.lval, val) < 0 { - r.lval = val - } - return r, nil, nil - case '>': - if collate1(r.lval, val) <= 0 { - r.lval = val - r.kind = indexGt - } - return r, nil, nil - case le: - switch c := collate1(r.lval, val); { - case c < 0: - r.hval = val - r.kind = indexIntervalCC - return r, nil, nil - case c == 0: - r.kind = indexEq - return r, nil, nil - default: // c > 0 - return &nullPlan{r.fieldNames()}, nil, nil - } - case '<': - if collate1(r.lval, val) < 0 { - r.hval = val - r.kind = indexIntervalCO - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case neq: - switch c := collate1(r.lval, val); { - case c < 0: - //MAYBE ORed intervals - case c == 0: - r.kind = indexGt - return r, nil, nil - default: // c > 0 - return r, nil, nil - } - } - return nil, nil, nil -} - -func (r *indexPlan) filterGt(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(r.lval, val) < 0 { - r.lval = val - r.kind = indexEq - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case ge: - if collate1(r.lval, val) < 0 { - r.lval = val - r.kind = indexGe - } - return r, nil, nil - case '>': - if collate1(r.lval, val) < 0 { - r.lval = val - } - return r, nil, nil - case le: - if collate1(r.lval, val) < 0 { - r.hval = val - r.kind = indexIntervalOC - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case '<': - if collate1(r.lval, val) < 0 { - r.hval = val - r.kind = indexIntervalOO - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case neq: - if collate1(r.lval, val) >= 0 { - return r, nil, nil - } - } - return nil, nil, nil -} - -func (r *indexPlan) filterLe(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(r.hval, val) >= 0 { - r.lval = val - r.kind = indexEq - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case ge: - switch c := collate1(r.hval, val); { - case c < 0: - return &nullPlan{r.fieldNames()}, nil, nil - case c == 0: - r.lval = val - r.kind = indexEq - return r, nil, nil - default: // c > 0 - r.lval = val - r.kind = indexIntervalCC - return r, nil, nil - } - case '>': - if collate1(r.hval, val) > 0 { - r.lval = val - r.kind = indexIntervalOC - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case le: - if collate1(r.hval, val) > 0 { - r.hval = val - } - return r, nil, nil - case '<': - if collate1(r.hval, val) >= 0 { - r.hval = val - r.kind = indexLt - } - return r, nil, nil - case neq: - switch c := collate1(r.hval, val); { - case c < 0: - return r, nil, nil - case c == 0: - r.kind = indexLt - return r, nil, nil - default: // c > 0 - //bop - } - } - return nil, nil, nil -} - -func (r *indexPlan) filterLt(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(r.hval, val) > 0 { - r.lval = val - r.kind = indexEq - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case ge: - if collate1(r.hval, val) > 0 { - r.lval = val - r.kind = indexIntervalCO - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case '>': - if collate1(r.hval, val) > 0 { - r.lval = val - r.kind = indexIntervalOO - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case le: - if collate1(r.hval, val) > 0 { - r.hval = val - r.kind = indexLe - } - return r, nil, nil - case '<': - if collate1(r.hval, val) > 0 { - r.hval = val - } - return r, nil, nil - case neq: - if collate1(r.hval, val) > 0 { - return nil, nil, nil - } - - return r, nil, nil - } - return nil, nil, nil -} - -func (r *indexPlan) filterCC(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(val, r.lval) < 0 || collate1(val, r.hval) > 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - r.lval = val - r.kind = indexEq - return r, nil, nil - case ge: - if collate1(val, r.lval) <= 0 { - return r, nil, nil - } - - switch c := collate1(val, r.hval); { - case c < 0: - r.lval = val - return r, nil, nil - case c == 0: - r.lval = val - r.kind = indexEq - return r, nil, nil - default: - return &nullPlan{r.fieldNames()}, nil, nil - } - case '>': - switch c := collate1(val, r.lval); { - case c < 0: - return r, nil, nil - case c == 0: - r.kind = indexIntervalOC - return r, nil, nil - default: - if collate1(val, r.hval) < 0 { - r.lval = val - r.kind = indexIntervalOC - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - } - case le: - switch c := collate1(val, r.lval); { - case c < 0: - return &nullPlan{r.fieldNames()}, nil, nil - case c == 0: - r.kind = indexEq - return r, nil, nil - default: - if collate1(val, r.hval) < 0 { - r.hval = val - } - return r, nil, nil - } - case '<': - if collate1(val, r.lval) <= 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - if collate1(val, r.hval) <= 0 { - r.hval = val - r.kind = indexIntervalCO - } - return r, nil, nil - case neq: - switch c := collate1(val, r.lval); { - case c < 0: - return r, nil, nil - case c == 0: - r.kind = indexIntervalOC - return r, nil, nil - default: - switch c := collate1(val, r.hval); { - case c == 0: - r.kind = indexIntervalCO - return r, nil, nil - case c > 0: - return r, nil, nil - default: - return nil, nil, nil - } - } - } - return nil, nil, nil -} - -func (r *indexPlan) filterOC(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(val, r.lval) <= 0 || collate1(val, r.hval) > 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - r.lval = val - r.kind = indexEq - return r, nil, nil - case ge: - if collate1(val, r.lval) <= 0 { - return r, nil, nil - } - - switch c := collate1(val, r.hval); { - case c < 0: - r.lval = val - r.kind = indexIntervalCC - return r, nil, nil - case c == 0: - r.lval = val - r.kind = indexEq - return r, nil, nil - default: - return &nullPlan{r.fieldNames()}, nil, nil - } - case '>': - if collate1(val, r.lval) <= 0 { - return r, nil, nil - } - - if collate1(val, r.hval) < 0 { - r.lval = val - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case le: - if collate1(val, r.lval) <= 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - if collate1(val, r.hval) < 0 { - r.hval = val - } - return r, nil, nil - case '<': - if collate1(val, r.lval) <= 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - switch c := collate1(val, r.hval); { - case c < 0: - r.hval = val - r.kind = indexIntervalOO - case c == 0: - r.kind = indexIntervalOO - } - return r, nil, nil - case neq: - if collate1(val, r.lval) <= 0 { - return r, nil, nil - } - - switch c := collate1(val, r.hval); { - case c < 0: - return nil, nil, nil - case c == 0: - r.kind = indexIntervalOO - return r, nil, nil - default: - return r, nil, nil - } - } - return nil, nil, nil -} - -func (r *indexPlan) filterOO(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(val, r.lval) <= 0 || collate1(val, r.hval) >= 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - r.lval = val - r.kind = indexEq - return r, nil, nil - case ge: - if collate1(val, r.lval) <= 0 { - return r, nil, nil - } - - if collate1(val, r.hval) < 0 { - r.lval = val - r.kind = indexIntervalCO - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case '>': - if collate1(val, r.lval) <= 0 { - return r, nil, nil - } - - if collate1(val, r.hval) < 0 { - r.lval = val - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case le: - if collate1(val, r.lval) <= 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - if collate1(val, r.hval) < 0 { - r.hval = val - r.kind = indexIntervalOC - } - return r, nil, nil - case '<': - if collate1(val, r.lval) <= 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - if collate1(val, r.hval) < 0 { - r.hval = val - } - return r, nil, nil - case neq: - if collate1(val, r.lval) <= 0 || collate1(val, r.hval) >= 0 { - return r, nil, nil - } - - return nil, nil, nil - } - return nil, nil, nil -} - -func (r *indexPlan) filterCO(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(val, r.lval) < 0 || collate1(val, r.hval) >= 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - r.lval = val - r.kind = indexEq - return r, nil, nil - case ge: - if collate1(val, r.lval) <= 0 { - return r, nil, nil - } - - if collate1(val, r.hval) < 0 { - r.lval = val - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case '>': - switch c := collate1(val, r.lval); { - case c < 0: - return r, nil, nil - case c == 0: - r.kind = indexIntervalOO - return r, nil, nil - default: - if collate1(val, r.hval) < 0 { - r.lval = val - r.kind = indexIntervalOO - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - } - case le: - switch c := collate1(val, r.lval); { - case c < 0: - return &nullPlan{r.fieldNames()}, nil, nil - case c == 0: - r.kind = indexEq - return r, nil, nil - default: - if collate1(val, r.hval) < 0 { - r.hval = val - r.kind = indexIntervalCC - } - return r, nil, nil - } - case '<': - if collate1(val, r.lval) <= 0 { - return &nullPlan{r.fieldNames()}, nil, nil - } - - if collate1(val, r.hval) < 0 { - r.hval = val - } - return r, nil, nil - case neq: - switch c := collate1(val, r.lval); { - case c < 0: - return r, nil, nil - case c == 0: - r.kind = indexIntervalOO - return r, nil, nil - default: - if collate1(val, r.hval) < 0 { - return nil, nil, nil - } - - return r, nil, nil - } - } - return nil, nil, nil -} - -func (r *indexPlan) filterNe(binOp2 int, val interface{}) (plan, []string, error) { - switch binOp2 { - case eq: - if collate1(val, r.lval) != 0 { - r.lval = val - r.kind = indexEq - return r, nil, nil - } - - return &nullPlan{r.fieldNames()}, nil, nil - case ge: - switch c := collate1(val, r.lval); { - case c < 0: - return nil, nil, nil //TODO - case c == 0: - r.kind = indexGt - return r, nil, nil - default: - r.lval = val - r.kind = indexGe - return r, nil, nil - } - case '>': - if collate1(val, r.lval) < 0 { - return nil, nil, nil //TODO - } - - r.lval = val - r.kind = indexGt - return r, nil, nil - case le: - switch c := collate1(val, r.lval); { - case c < 0: - r.hval = val - r.kind = indexLe - return r, nil, nil - case c == 0: - r.kind = indexLt - return r, nil, nil - default: - return nil, nil, nil //TODO - } - case '<': - if collate1(val, r.lval) <= 0 { - r.hval = val - r.kind = indexLt - return r, nil, nil - } - - return nil, nil, nil //TODO - case neq: - if collate1(val, r.lval) == 0 { - return r, nil, nil - } - - return nil, nil, nil - } - return nil, nil, nil -} - -func (r *indexPlan) filter(expr expression) (plan, []string, error) { - switch x := expr.(type) { - case *binaryOperation: - ok, cname, val, err := x.isIdentRelOpVal() - if err != nil { - return nil, nil, err - } - - if !ok || r.cname != cname { - break - } - - if val, err = typeCheck1(val, findCol(r.src.cols, cname)); err != nil { - return nil, nil, err - } - - switch r.kind { - case indexEq: // [L] - return r.filterEq(x.op, val) - case indexGe: // [L, ...) - return r.filterGe(x.op, val) - case indexGt: // (L, ...) - return r.filterGt(x.op, val) - case indexIntervalCC: // [L, H] - return r.filterCC(x.op, val) - case indexIntervalCO: // [L, H) - return r.filterCO(x.op, val) - case indexIntervalOC: // (L, H] - return r.filterOC(x.op, val) - case indexIntervalOO: // (L, H) - return r.filterOO(x.op, val) - case indexLe: // (..., H] - return r.filterLe(x.op, val) - case indexLt: // (..., H) - return r.filterLt(x.op, val) - case indexNe: // (L) - return r.filterNe(x.op, val) - } - case *ident: - cname := x.s - if r.cname != cname { - break - } - - switch r.kind { - case indexFalse: // [false] - return &nullPlan{r.fieldNames()}, nil, nil - case indexTrue: // [true] - return r, nil, nil - } - case *unaryOperation: - if x.op != '!' { - break - } - - operand, ok := x.v.(*ident) - if !ok { - break - } - - cname := operand.s - if r.cname != cname { - break - } - - switch r.kind { - case indexFalse: // [false] - return r, nil, nil - case indexTrue: // [true] - return &nullPlan{r.fieldNames()}, nil, nil - } - } - - return nil, nil, nil -} - -func (r *indexPlan) hasID() bool { return true } - -type explainDefaultPlan struct { - s stmt -} - -func (r *explainDefaultPlan) hasID() bool { return false } - -func (r *explainDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (more bool, err error)) error { - var buf bytes.Buffer - switch x := r.s.(type) { - default: - w := strutil.IndentFormatter(&buf, "│ ") - x.explain(ctx, w) - } - - a := bytes.Split(buf.Bytes(), []byte{'\n'}) - for _, v := range a[:len(a)-1] { - if more, err := f(nil, []interface{}{string(v)}); !more || err != nil { - return err - } - } - return nil -} - -func (r *explainDefaultPlan) explain(w strutil.Formatter) {} - -func (r *explainDefaultPlan) fieldNames() []string { - return []string{""} -} - -func (r *explainDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -type filterDefaultPlan struct { - plan - expr expression - is []string -} - -func (r *filterDefaultPlan) hasID() bool { return r.plan.hasID() } - -func (r *filterDefaultPlan) explain(w strutil.Formatter) { - r.plan.explain(w) - w.Format("┌Filter on %v\n", r.expr) - if len(r.is) != 0 { - w.Format("│Possibly useful indices\n") - m := map[string]bool{} - for _, v := range r.is { - if !m[v] { - m[v] = true - n := "" - for _, r := range v { - if r >= '0' && r <= '9' || r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' || r == '_' { - n += string(r) - continue - } - - n += "_" - } - for strings.Contains(n, "__") { - n = strings.Replace(n, "__", "_", -1) - } - for strings.HasSuffix(n, "_") { - n = n[:len(n)-1] - } - w.Format("│CREATE INDEX x%s ON %s;\n", n, v) - } - } - } - w.Format("└Output field names %v\n", qnames(r.plan.fieldNames())) -} - -func (r *filterDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) (err error) { - m := map[interface{}]interface{}{} - fields := r.plan.fieldNames() - return r.plan.do(ctx, func(rid interface{}, data []interface{}) (bool, error) { - for i, v := range fields { - m[v] = data[i] - } - m["$id"] = rid - val, err := r.expr.eval(ctx, m) - if err != nil { - return false, err - } - - if val == nil { - return true, nil - } - - x, ok := val.(bool) - if !ok { - return false, fmt.Errorf("invalid boolean expression %s (value of type %T)", val, val) - } - - if !x { - return true, nil - } - - return f(rid, data) - }) -} - -type crossJoinDefaultPlan struct { - rsets []plan - names []string - fields []string -} - -func (r *crossJoinDefaultPlan) hasID() bool { return false } - -func (r *crossJoinDefaultPlan) explain(w strutil.Formatter) { - w.Format("┌Compute Cartesian product of%i\n") - for i, v := range r.rsets { - sel := !isTableOrIndex(v) - if sel { - w.Format("┌Iterate all rows of virtual table %q%i\n", r.names[i]) - } - v.explain(w) - if sel { - w.Format("%u└Output field names %v\n", qnames(v.fieldNames())) - } - } - w.Format("%u└Output field names %v\n", qnames(r.fields)) -} - -func (r *crossJoinDefaultPlan) filter(expr expression) (plan, []string, error) { - var is []string - for i, v := range r.names { - e2, err := expr.clone(nil, v) - if err != nil { - return nil, nil, err - } - - p2, is2, err := r.rsets[i].filter(e2) - is = append(is, is2...) - if err != nil { - return nil, nil, err - } - - if p2 != nil { - r.rsets[i] = p2 - return r, is, nil - } - } - return nil, is, nil -} - -func (r *crossJoinDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) error { - if len(r.rsets) == 1 { - return r.rsets[0].do(ctx, f) - } - - ids := map[string]interface{}{} - var g func([]interface{}, []plan, int) error - g = func(prefix []interface{}, rsets []plan, x int) (err error) { - return rsets[0].do(ctx, func(id interface{}, in []interface{}) (bool, error) { - ids[r.names[x]] = id - if len(rsets) > 1 { - return true, g(append(prefix, in...), rsets[1:], x+1) - } - - return f(ids, append(prefix, in...)) - }) - } - return g(nil, r.rsets, 0) -} - -func (r *crossJoinDefaultPlan) fieldNames() []string { return r.fields } - -type distinctDefaultPlan struct { - src plan - fields []string -} - -func (r *distinctDefaultPlan) hasID() bool { return false } - -func (r *distinctDefaultPlan) explain(w strutil.Formatter) { - r.src.explain(w) - w.Format("┌Compute distinct rows\n└Output field names %v\n", r.fields) -} - -func (r *distinctDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *distinctDefaultPlan) fieldNames() []string { return r.fields } - -func (r *distinctDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) (err error) { - t, err := ctx.db.store.CreateTemp(true) - if err != nil { - return - } - - defer func() { - if derr := t.Drop(); derr != nil && err == nil { - err = derr - } - }() - - if err = r.src.do(ctx, func(id interface{}, in []interface{}) (bool, error) { - if err = t.Set(in, nil); err != nil { - return false, err - } - - return true, nil - }); err != nil { - return - } - - var data []interface{} - more := true - it, err := t.SeekFirst() - for more && err == nil { - data, _, err = it.Next() - if err != nil { - break - } - - more, err = f(nil, data) - } - return noEOF(err) -} - -type groupByDefaultPlan struct { - colNames []string - src plan - fields []string -} - -func (r *groupByDefaultPlan) hasID() bool { return false } - -func (r *groupByDefaultPlan) explain(w strutil.Formatter) { - r.src.explain(w) - switch { - case len(r.colNames) == 0: //TODO this case should not exist for this plan, should become tableDefaultPlan - w.Format("┌Group by distinct rows") - default: - w.Format("┌Group by") - for _, v := range r.colNames { - w.Format(" %s,", v) - } - } - w.Format("\n└Output field names %v\n", qnames(r.fields)) -} - -func (r *groupByDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *groupByDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) (err error) { - t, err := ctx.db.store.CreateTemp(true) - if err != nil { - return - } - - defer func() { - if derr := t.Drop(); derr != nil && err == nil { - err = derr - } - }() - - var gcols []*col - var cols []*col - m := map[string]int{} - for i, v := range r.src.fieldNames() { - m[v] = i - } - for _, c := range r.colNames { - i, ok := m[c] - if !ok { - return fmt.Errorf("unknown field %s", c) - } - - gcols = append(gcols, &col{name: c, index: i}) - } - k := make([]interface{}, len(r.colNames)) //TODO optimize when len(r.cols) == 0, should become tableDefaultPlan - if err = r.src.do(ctx, func(rid interface{}, in []interface{}) (more bool, err error) { - infer(in, &cols) - for i, c := range gcols { - k[i] = in[c.index] - } - h0, err := t.Get(k) - if err != nil { - return false, err - } - - var h int64 - if len(h0) != 0 { - h, _ = h0[0].(int64) - } - nh, err := t.Create(append([]interface{}{h, nil}, in...)...) - if err != nil { - return false, err - } - - for i, c := range gcols { - k[i] = in[c.index] - } - err = t.Set(k, []interface{}{nh}) - if err != nil { - return false, err - } - - return true, nil - }); err != nil { - return - } - - for i, v := range r.src.fieldNames()[:len(cols)] { - cols[i].name = v - cols[i].index = i - } - if more, err := f(nil, []interface{}{t, cols}); !more || err != nil { - return err - } - - it, err := t.SeekFirst() - more := true - var data []interface{} - for more && err == nil { - if _, data, err = it.Next(); err != nil { - break - } - - more, err = f(nil, data) - } - return noEOF(err) -} - -func (r *groupByDefaultPlan) fieldNames() []string { return r.fields } - -type selectIndexDefaultPlan struct { - nm string - x interface{} -} - -func (r *selectIndexDefaultPlan) hasID() bool { return false } - -func (r *selectIndexDefaultPlan) explain(w strutil.Formatter) { - w.Format("┌Iterate all values of index %q\n└Output field names N/A\n", r.nm) -} - -func (r *selectIndexDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *selectIndexDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) (err error) { - var x btreeIndex - switch ix := r.x.(type) { - case *indexedCol: - x = ix.x - case *index2: - x = ix.x - default: - panic("internal error 007") - } - - en, err := x.SeekFirst() - if err != nil { - return noEOF(err) - } - - var id int64 - for { - k, _, err := en.Next() - if err != nil { - return noEOF(err) - } - - id++ - if more, err := f(id, k); !more || err != nil { - return err - } - } -} - -func (r *selectIndexDefaultPlan) fieldNames() []string { - return []string{r.nm} -} - -type limitDefaultPlan struct { - expr expression - src plan - fields []string -} - -func (r *limitDefaultPlan) hasID() bool { return r.src.hasID() } - -func (r *limitDefaultPlan) explain(w strutil.Formatter) { - r.src.explain(w) - w.Format("┌Pass first %v records\n└Output field names %v\n", r.expr, r.fields) -} - -func (r *limitDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *limitDefaultPlan) fieldNames() []string { return r.fields } - -func (r *limitDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (more bool, err error)) (err error) { - m := map[interface{}]interface{}{} - var eval bool - var lim uint64 - return r.src.do(ctx, func(rid interface{}, in []interface{}) (more bool, err error) { - if !eval { - for i, fld := range r.fields { - if fld != "" { - m[fld] = in[i] - } - } - m["$id"] = rid - val, err := r.expr.eval(ctx, m) - if err != nil { - return false, err - } - - if val == nil { - return true, nil - } - - if lim, err = limOffExpr(val); err != nil { - return false, err - } - - eval = true - } - switch lim { - case 0: - return false, nil - default: - lim-- - return f(rid, in) - } - }) -} - -type offsetDefaultPlan struct { - expr expression - src plan - fields []string -} - -func (r *offsetDefaultPlan) hasID() bool { return r.src.hasID() } - -func (r *offsetDefaultPlan) explain(w strutil.Formatter) { - r.src.explain(w) - w.Format("┌Skip first %v records\n└Output field names %v\n", r.expr, qnames(r.fields)) -} - -func (r *offsetDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *offsetDefaultPlan) fieldNames() []string { return r.fields } - -func (r *offsetDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) error { - m := map[interface{}]interface{}{} - var eval bool - var off uint64 - return r.src.do(ctx, func(rid interface{}, in []interface{}) (bool, error) { - if !eval { - for i, fld := range r.fields { - if fld != "" { - m[fld] = in[i] - } - } - m["$id"] = rid - val, err := r.expr.eval(ctx, m) - if err != nil { - return false, err - } - - if val == nil { - return true, nil - } - - if off, err = limOffExpr(val); err != nil { - return false, err - } - - eval = true - } - if off > 0 { - off-- - return true, nil - } - - return f(rid, in) - }) -} - -type orderByDefaultPlan struct { - asc bool - by []expression - src plan - fields []string -} - -func (r *orderByDefaultPlan) hasID() bool { return r.src.hasID() } - -func (r *orderByDefaultPlan) explain(w strutil.Formatter) { - r.src.explain(w) - w.Format("┌Order%s by", map[bool]string{false: " descending"}[r.asc]) - for _, v := range r.by { - w.Format(" %s,", v) - } - w.Format("\n└Output field names %v\n", qnames(r.fields)) -} - -func (r *orderByDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *orderByDefaultPlan) fieldNames() []string { return r.fields } - -func (r *orderByDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) (err error) { - t, err := ctx.db.store.CreateTemp(r.asc) - if err != nil { - return - } - - defer func() { - if derr := t.Drop(); derr != nil && err == nil { - err = derr - } - }() - - m := map[interface{}]interface{}{} - flds := r.fields - k := make([]interface{}, len(r.by)+1) - id := int64(-1) - if err = r.src.do(ctx, func(rid interface{}, in []interface{}) (bool, error) { - id++ - for i, fld := range flds { - if fld != "" { - m[fld] = in[i] - } - } - m["$id"] = rid - for i, expr := range r.by { - val, err := expr.eval(ctx, m) - if err != nil { - return false, err - } - - if val != nil { - val, ordered, err := isOrderedType(val) - if err != nil { - return false, err - } - - if !ordered { - return false, fmt.Errorf("cannot order by %v (type %T)", val, val) - - } - } - - k[i] = val - } - k[len(r.by)] = id - if err = t.Set(k, in); err != nil { - return false, err - } - - return true, nil - }); err != nil { - return - } - - it, err := t.SeekFirst() - if err != nil { - return noEOF(err) - } - - var data []interface{} - more := true - for more && err == nil { - if _, data, err = it.Next(); err != nil { - break - } - - more, err = f(nil, data) - } - return noEOF(err) -} - -type selectFieldsDefaultPlan struct { - flds []*fld - src plan - fields []string -} - -func (r *selectFieldsDefaultPlan) hasID() bool { return r.src.hasID() } - -func (r *selectFieldsDefaultPlan) explain(w strutil.Formatter) { - //TODO check for non existing fields - r.src.explain(w) - w.Format("┌Evaluate") - for _, v := range r.flds { - w.Format(" %s as %s,", v.expr, fmt.Sprintf("%q", v.name)) - } - w.Format("\n└Output field names %v\n", qnames(r.fields)) -} - -func (r *selectFieldsDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *selectFieldsDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) error { - fields := r.src.fieldNames() - m := map[interface{}]interface{}{} - return r.src.do(ctx, func(rid interface{}, in []interface{}) (bool, error) { - for i, nm := range fields { - if nm != "" { - m[nm] = in[i] - } - } - m["$id"] = rid - out := make([]interface{}, len(r.flds)) - for i, fld := range r.flds { - var err error - if out[i], err = fld.expr.eval(ctx, m); err != nil { - return false, err - } - } - return f(rid, out) - }) -} - -func (r *selectFieldsDefaultPlan) fieldNames() []string { return r.fields } - -type selectFieldsGroupPlan struct { - flds []*fld - src *groupByDefaultPlan - fields []string -} - -func (r *selectFieldsGroupPlan) hasID() bool { return false } - -func (r *selectFieldsGroupPlan) explain(w strutil.Formatter) { - //TODO check for non existing fields - r.src.explain(w) - w.Format("┌Evaluate") - for _, v := range r.flds { - w.Format(" %s as %s,", v.expr, fmt.Sprintf("%q", v.name)) - } - w.Format("\n└Output field names %v\n", qnames(r.fields)) -} - -func (r *selectFieldsGroupPlan) fieldNames() []string { return r.fields } - -func (r *selectFieldsGroupPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *selectFieldsGroupPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) error { - var t temp - var cols []*col - var err error - out := make([]interface{}, len(r.flds)) - ok := false - rows := false - if err = r.src.do(ctx, func(rid interface{}, in []interface{}) (bool, error) { - if ok { - h := in[0].(int64) - m := map[interface{}]interface{}{} - for h != 0 { - in, err = t.Read(nil, h, cols...) - if err != nil { - return false, err - } - - rec := in[2:] - for i, c := range cols { - if nm := c.name; nm != "" { - m[nm] = rec[i] - } - } - m["$id"] = rid - for _, fld := range r.flds { - if _, err = fld.expr.eval(ctx, m); err != nil { - return false, err - } - } - - h = in[0].(int64) - } - m["$agg"] = true - for i, fld := range r.flds { - if out[i], err = fld.expr.eval(ctx, m); err != nil { - return false, err - } - } - rows = true - return f(nil, out) - } - - ok = true - t = in[0].(temp) - cols = in[1].([]*col) - if len(r.flds) == 0 { // SELECT * - r.flds = make([]*fld, len(cols)) - for i, v := range cols { - r.flds[i] = &fld{expr: &ident{v.name}, name: v.name} - } - out = make([]interface{}, len(r.flds)) - } - return true, nil - }); err != nil { - return err - } - - if rows { - return nil - } - - m := map[interface{}]interface{}{"$agg0": true} // aggregate empty record set - for i, fld := range r.flds { - if out[i], err = fld.expr.eval(ctx, m); err != nil { - return err - } - } - _, err = f(nil, out) - - return err -} - -type sysColumnDefaultPlan struct{} - -func (r *sysColumnDefaultPlan) hasID() bool { return false } - -func (r *sysColumnDefaultPlan) explain(w strutil.Formatter) { - w.Format("┌Iterate all rows of table \"__Column\"\n└Output field names %v\n", qnames(r.fieldNames())) -} - -func (r *sysColumnDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *sysColumnDefaultPlan) fieldNames() []string { - return []string{"TableName", "Ordinal", "Name", "Type"} -} - -func (r *sysColumnDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) error { - rec := make([]interface{}, 4) - di, err := ctx.db.info() - if err != nil { - return err - } - - var id int64 - for _, ti := range di.Tables { - rec[0] = ti.Name - var ix int64 - for _, ci := range ti.Columns { - ix++ - rec[1] = ix - rec[2] = ci.Name - rec[3] = ci.Type.String() - id++ - if more, err := f(id, rec); !more || err != nil { - return err - } - } - } - return nil -} - -type sysIndexDefaultPlan struct{} - -func (r *sysIndexDefaultPlan) hasID() bool { return false } - -func (r *sysIndexDefaultPlan) explain(w strutil.Formatter) { - w.Format("┌Iterate all rows of table \"__Index\"\n└Output field names %v\n", qnames(r.fieldNames())) -} - -func (r *sysIndexDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *sysIndexDefaultPlan) fieldNames() []string { - return []string{"TableName", "ColumnName", "Name", "IsUnique"} -} - -func (r *sysIndexDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) error { - rec := make([]interface{}, 4) - di, err := ctx.db.info() - if err != nil { - return err - } - - var id int64 - for _, xi := range di.Indices { - rec[0] = xi.Table - rec[1] = xi.Column - rec[2] = xi.Name - rec[3] = xi.Unique - id++ - if more, err := f(id, rec); !more || err != nil { - return err - } - } - return nil -} - -type sysTableDefaultPlan struct{} - -func (r *sysTableDefaultPlan) hasID() bool { return false } - -func (r *sysTableDefaultPlan) explain(w strutil.Formatter) { - w.Format("┌Iterate all rows of table \"__Table\"\n└Output field names %v\n", qnames(r.fieldNames())) -} - -func (r *sysTableDefaultPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *sysTableDefaultPlan) fieldNames() []string { return []string{"Name", "Schema"} } - -func (r *sysTableDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) error { - rec := make([]interface{}, 2) - di, err := ctx.db.info() - if err != nil { - return err - } - - var id int64 - for _, ti := range di.Tables { - rec[0] = ti.Name - a := []string{} - for _, ci := range ti.Columns { - s := "" - if ci.NotNull { - s += " NOT NULL" - } - if c := ci.Constraint; c != "" { - s += " " + c - } - if d := ci.Default; d != "" { - s += " DEFAULT " + d - } - a = append(a, fmt.Sprintf("%s %s%s", ci.Name, ci.Type, s)) - } - rec[1] = fmt.Sprintf("CREATE TABLE %s (%s);", ti.Name, strings.Join(a, ", ")) - id++ - if more, err := f(id, rec); !more || err != nil { - return err - } - } - return nil -} - -type tableNilPlan struct { - t *table -} - -func (r *tableNilPlan) hasID() bool { return true } - -func (r *tableNilPlan) explain(w strutil.Formatter) { - w.Format("┌Iterate all rows of table %q\n└Output field names %v\n", r.t.name, qnames(r.fieldNames())) -} - -func (r *tableNilPlan) fieldNames() []string { return []string{} } - -func (r *tableNilPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *tableNilPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) (err error) { - t := r.t - h := t.head - cols := t.cols - for h > 0 { - rec, err := t.store.Read(nil, h, cols...) // 0:next, 1:id, 2...: data - if err != nil { - return err - } - - if m, err := f(rec[1], nil); !m || err != nil { - return err - } - - h = rec[0].(int64) // next - } - return nil -} - -type tableDefaultPlan struct { - t *table - fields []string -} - -func (r *tableDefaultPlan) hasID() bool { return true } - -func (r *tableDefaultPlan) explain(w strutil.Formatter) { - w.Format("┌Iterate all rows of table %q\n└Output field names %v\n", r.t.name, qnames(r.fields)) -} - -func (r *tableDefaultPlan) filterBinOp(x *binaryOperation) (plan, []string, error) { - ok, cn, rval, err := x.isIdentRelOpVal() - if err != nil { - return nil, nil, err - } - - if !ok { - return nil, nil, nil - } - - t := r.t - c, ix := t.findIndexByColName(cn) - if ix == nil { // Column cn has no index. - return nil, []string{fmt.Sprintf("%s(%s)", t.name, cn)}, nil - } - - if rval, err = typeCheck1(rval, c); err != nil { - return nil, nil, err - } - - switch x.op { - case eq: - return &indexPlan{t, cn, ix.name, ix.x, indexEq, rval, rval}, nil, nil - case '<': - return &indexPlan{t, cn, ix.name, ix.x, indexLt, nil, rval}, nil, nil - case le: - return &indexPlan{t, cn, ix.name, ix.x, indexLe, nil, rval}, nil, nil - case ge: - return &indexPlan{t, cn, ix.name, ix.x, indexGe, rval, nil}, nil, nil - case '>': - return &indexPlan{t, cn, ix.name, ix.x, indexGt, rval, nil}, nil, nil - case neq: - return &indexPlan{t, cn, ix.name, ix.x, indexNe, rval, rval}, nil, nil - default: - panic("internal error 069") - } -} - -func (r *tableDefaultPlan) filterIdent(x *ident, trueValue bool) (plan, []string, error) { - cn := x.s - t := r.t - for _, v := range t.cols { - if v.name != cn { - continue - } - - if v.typ != qBool { - return nil, nil, nil - } - - xi := v.index + 1 // 0: id() - if xi >= len(t.indices) { - return nil, nil, nil - } - - ix := t.indices[xi] - if ix == nil { // Column cn has no index. - return nil, []string{fmt.Sprintf("%s(%s)", t.name, cn)}, nil - } - - kind := indexFalse - if trueValue { - kind = indexTrue - } - return &indexPlan{t, cn, ix.name, ix.x, kind, nil, nil}, nil, nil - } - return nil, nil, nil -} - -func (r *tableDefaultPlan) filterIsNull(x *isNull) (plan, []string, error) { - ok, cn := isColumnExpression(x.expr) - if !ok { - return nil, nil, nil - } - - t := r.t - _, ix := t.findIndexByColName(cn) - if ix == nil { // Column cn has no index. - return nil, []string{fmt.Sprintf("%s(%s)", t.name, cn)}, nil - } - - switch { - case x.not: - return &indexPlan{t, cn, ix.name, ix.x, indexIsNotNull, nil, nil}, nil, nil - default: - return &indexPlan{t, cn, ix.name, ix.x, indexIsNull, nil, nil}, nil, nil - } -} - -func (r *tableDefaultPlan) filter(expr expression) (plan, []string, error) { - cols := mentionedColumns(expr) - for _, v := range r.fields { - delete(cols, v) - } - for k := range cols { - return nil, nil, fmt.Errorf("unknown field %s", k) - } - - var is []string - - //TODO var sexpr string - //TODO for _, ix := range t.indices2 { - //TODO if len(ix.exprList) != 1 { - //TODO continue - //TODO } - - //TODO if sexpr == "" { - //TODO sexpr = expr.String() - //TODO } - //TODO if ix.sources[0] != sexpr { - //TODO continue - //TODO } - - //TODO } - - switch x := expr.(type) { - case *binaryOperation: - return r.filterBinOp(x) - case *ident: - return r.filterIdent(x, true) - case *isNull: - return r.filterIsNull(x) - case *unaryOperation: - if x.op != '!' { - break - } - - if operand, ok := x.v.(*ident); ok { - return r.filterIdent(operand, false) - } - default: - //dbg("", expr) - return nil, is, nil //TODO - } - - return nil, is, nil -} - -func (r *tableDefaultPlan) do(ctx *execCtx, f func(interface{}, []interface{}) (bool, error)) (err error) { - t := r.t - cols := t.cols - h := t.head - for h > 0 { - rec, err := t.row0(ctx, h) - if err != nil { - return err - } - - h = rec[0].(int64) - id := rec[1].(int64) - for i, c := range cols { - rec[i] = rec[c.index+2] - } - if m, err := f(id, rec[:len(cols)]); !m || err != nil { - return err - } - } - return nil -} - -func (r *tableDefaultPlan) fieldNames() []string { return r.fields } - -type nullPlan struct { - fields []string -} - -func (r *nullPlan) hasID() bool { return false } - -func (r *nullPlan) fieldNames() []string { return r.fields } - -func (r *nullPlan) explain(w strutil.Formatter) { - w.Format("┌Iterate no rows\n└Output field names %v\n", qnames(r.fields)) -} - -func (r *nullPlan) do(*execCtx, func(interface{}, []interface{}) (bool, error)) error { - return nil -} - -func (r *nullPlan) filter(expr expression) (plan, []string, error) { - return r, nil, nil -} - -type leftJoinDefaultPlan struct { - on expression - rsets []plan - names []string - right int - fields []string -} - -func (r *leftJoinDefaultPlan) hasID() bool { return false } - -func (r *leftJoinDefaultPlan) explain(w strutil.Formatter) { - w.Format("┌Compute Cartesian product of%i\n") - for i, v := range r.rsets { - sel := !isTableOrIndex(v) - if sel { - w.Format("┌Iterate all rows of virtual table %q%i\n", r.names[i]) - } - v.explain(w) - if sel { - w.Format("%u└Output field names %v\n", qnames(v.fieldNames())) - } - } - w.Format("Extend the product with all NULL rows of %q when no match for %v%u\n", r.names[len(r.names)-1], r.on) - w.Format("└Output field names %v\n", qnames(r.fields)) -} - -func (r *leftJoinDefaultPlan) filter(expr expression) (plan, []string, error) { - var is []string - for i, v := range r.names { - e2, err := expr.clone(nil, v) - if err != nil { - return nil, nil, err - } - - p2, is2, err := r.rsets[i].filter(e2) - is = append(is, is2...) - if err != nil { - return nil, nil, err - } - - if p2 != nil { - r.rsets[i] = p2 - return r, is, nil - } - } - return nil, is, nil -} - -type rightJoinDefaultPlan struct { - leftJoinDefaultPlan -} - -func (r *rightJoinDefaultPlan) hasID() bool { return false } - -func (r *rightJoinDefaultPlan) explain(w strutil.Formatter) { - w.Format("┌Compute Cartesian product of%i\n") - for i, v := range r.rsets { - sel := !isTableOrIndex(v) - if sel { - w.Format("┌Iterate all rows of virtual table %q%i\n", r.names[i]) - } - v.explain(w) - if sel { - w.Format("%u└Output field names %v\n", qnames(v.fieldNames())) - } - } - w.Format("Extend the product with all NULL rows of all but %q when no match for %v%u\n", r.names[len(r.names)-1], r.on) - w.Format("└Output field names %v\n", qnames(r.fields)) -} - -func (r *rightJoinDefaultPlan) filter(expr expression) (plan, []string, error) { - var is []string - for i, v := range r.names { - e2, err := expr.clone(nil, v) - if err != nil { - return nil, nil, err - } - - p2, is2, err := r.rsets[i].filter(e2) - is = append(is, is2...) - if err != nil { - return nil, nil, err - } - - if p2 != nil { - r.rsets[i] = p2 - return r, is, nil - } - } - return nil, is, nil -} - -type fullJoinDefaultPlan struct { - leftJoinDefaultPlan -} - -func (r *fullJoinDefaultPlan) hasID() bool { return false } - -func (r *fullJoinDefaultPlan) explain(w strutil.Formatter) { - w.Format("┌Compute Cartesian product of%i\n") - for i, v := range r.rsets { - sel := !isTableOrIndex(v) - if sel { - w.Format("┌Iterate all rows of virtual table %q%i\n", r.names[i]) - } - v.explain(w) - if sel { - w.Format("%u└Output field names %v\n", qnames(v.fieldNames())) - } - } - w.Format("Extend the product with all NULL rows of %q when no match for %v\n", r.names[len(r.names)-1], r.on) - w.Format("Extend the product with all NULL rows of all but %q when no match for %v%u\n", r.names[len(r.names)-1], r.on) - w.Format("└Output field names %v\n", qnames(r.fields)) -} - -func (r *fullJoinDefaultPlan) filter(expr expression) (plan, []string, error) { - var is []string - for i, v := range r.names { - e2, err := expr.clone(nil, v) - if err != nil { - return nil, nil, err - } - - p2, is2, err := r.rsets[i].filter(e2) - is = append(is, is2...) - if err != nil { - return nil, nil, err - } - - if p2 != nil { - r.rsets[i] = p2 - return r, is, nil - } - } - return nil, is, nil -} - -func (r *leftJoinDefaultPlan) fieldNames() []string { return r.fields } - -func (r *leftJoinDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (more bool, err error)) error { - m := map[interface{}]interface{}{} - ids := map[string]interface{}{} - var g func([]interface{}, []plan, int) error - var match bool - g = func(prefix []interface{}, rsets []plan, x int) (err error) { - return rsets[0].do(ctx, func(id interface{}, in []interface{}) (bool, error) { - ids[r.names[x]] = id - row := append(prefix, in...) - if len(rsets) > 1 { - if len(rsets) == 2 { - match = false - } - if err = g(row, rsets[1:], x+1); err != nil { - return false, err - } - - if len(rsets) != 2 || match { - return true, nil - } - - ids[r.names[x+1]] = nil - return f(ids, append(row, make([]interface{}, r.right)...)) - } - - for i, fld := range r.fields { - if fld != "" { - m[fld] = row[i] - } - } - - val, err := r.on.eval(ctx, m) - if err != nil { - return false, err - } - - if val == nil { - return true, nil - } - - x, ok := val.(bool) - if !ok { - return false, fmt.Errorf("invalid ON expression %s (value of type %T)", val, val) - } - - if !x { - return true, nil - } - - match = true - return f(ids, row) - }) - } - return g(nil, r.rsets, 0) -} - -func (r *rightJoinDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (more bool, err error)) error { - right := r.right - left := len(r.fields) - right - n := len(r.rsets) - m := map[interface{}]interface{}{} - ids := map[string]interface{}{} - var g func([]interface{}, []plan, int) error - var match bool - nf := len(r.fields) - fields := append(append([]string(nil), r.fields[nf-right:]...), r.fields[:nf-right]...) - g = func(prefix []interface{}, rsets []plan, x int) (err error) { - return rsets[0].do(ctx, func(id interface{}, in []interface{}) (bool, error) { - ids[r.names[x]] = id - row := append(prefix, in...) - if len(rsets) > 1 { - if len(rsets) == n { - match = false - } - if err = g(row, rsets[1:], x+1); err != nil { - return false, err - } - - if len(rsets) != n || match { - return true, nil - } - - for i := 0; i < n-1; i++ { - ids[r.names[i]] = nil - } - - // rigth, left -> left, right - return f(ids, append(make([]interface{}, left), row[:right]...)) - } - - for i, fld := range fields { - if fld != "" { - m[fld] = row[i] - } - } - - val, err := r.on.eval(ctx, m) - if err != nil { - return false, err - } - - if val == nil { - return true, nil - } - - x, ok := val.(bool) - if !ok { - return false, fmt.Errorf("invalid ON expression %s (value of type %T)", val, val) - } - - if !x { - return true, nil - } - - match = true - // rigth, left -> left, right - return f(ids, append(append([]interface{}(nil), row[right:]...), row[:right]...)) - }) - } - return g(nil, append([]plan{r.rsets[n-1]}, r.rsets[:n-1]...), 0) -} - -func (r *fullJoinDefaultPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (more bool, err error)) error { - b3 := b.TreeNew(func(a, b interface{}) int { - x := a.(int64) - y := b.(int64) - if x < y { - return -1 - } - - if x == y { - return 0 - } - - return 1 - }) - m := map[interface{}]interface{}{} - ids := map[string]interface{}{} - var g func([]interface{}, []plan, int) error - var match bool - var rid int64 - firstR := true - g = func(prefix []interface{}, rsets []plan, x int) (err error) { - return rsets[0].do(ctx, func(id interface{}, in []interface{}) (bool, error) { - ids[r.names[x]] = id - row := append(prefix, in...) - if len(rsets) > 1 { - if len(rsets) == 2 { - match = false - rid = 0 - } - if err = g(row, rsets[1:], x+1); err != nil { - return false, err - } - - if len(rsets) == 2 { - firstR = false - } - if len(rsets) != 2 || match { - return true, nil - } - - ids[r.names[x+1]] = nil - return f(ids, append(row, make([]interface{}, r.right)...)) - } - - rid++ - if firstR { - b3.Set(rid, in) - } - for i, fld := range r.fields { - if fld != "" { - m[fld] = row[i] - } - } - - val, err := r.on.eval(ctx, m) - if err != nil { - return false, err - } - - if val == nil { - return true, nil - } - - x, ok := val.(bool) - if !ok { - return false, fmt.Errorf("invalid ON expression %s (value of type %T)", val, val) - } - - if !x { - return true, nil - } - - match = true - b3.Delete(rid) - return f(ids, row) - }) - } - if err := g(nil, r.rsets, 0); err != nil { - return err - } - - it, err := b3.SeekFirst() - if err != nil { - return noEOF(err) - } - - pref := make([]interface{}, len(r.fields)-r.right) - for { - _, v, err := it.Next() - if err != nil { - return noEOF(err) - } - - more, err := f(nil, append(pref, v.([]interface{})...)) - if err != nil || !more { - return err - } - } -} - -type selectDummyPlan struct { - flds []*fld -} - -func (r *selectDummyPlan) hasID() bool { return true } - -func (r *selectDummyPlan) explain(w strutil.Formatter) { - w.Format("┌Selects values from dummy table\n└Output field names %v\n", qnames(r.fieldNames())) -} - -func (r *selectDummyPlan) fieldNames() []string { return make([]string, len(r.flds)) } - -func (r *selectDummyPlan) filter(expr expression) (plan, []string, error) { - return nil, nil, nil -} - -func (r *selectDummyPlan) do(ctx *execCtx, f func(id interface{}, data []interface{}) (bool, error)) (err error) { - m := map[interface{}]interface{}{} - data := []interface{}{} - for _, v := range r.flds { - rst, err := v.expr.eval(ctx, m) - if err != nil { - return err - } - data = append(data, rst) - } - _, err = f(nil, data) - return -} diff --git a/vendor/github.com/cznic/ql/ql.go b/vendor/github.com/cznic/ql/ql.go deleted file mode 100644 index e66024cdb..000000000 --- a/vendor/github.com/cznic/ql/ql.go +++ /dev/null @@ -1,1809 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//LATER profile mem -//LATER profile cpu -//LATER coverage - -package ql - -import ( - "bytes" - "errors" - "fmt" - "math/big" - "strconv" - "strings" - "sync" - "time" - - "github.com/cznic/strutil" -) - -const ( - crossJoin = iota - leftJoin - rightJoin - fullJoin -) - -// NOTE: all rset implementations must be safe for concurrent use by multiple -// goroutines. If the do method requires any execution domain local data, they -// must be held out of the implementing instance. -var ( - _ rset = (*distinctRset)(nil) - _ rset = (*groupByRset)(nil) - _ rset = (*joinRset)(nil) - _ rset = (*limitRset)(nil) - _ rset = (*offsetRset)(nil) - _ rset = (*orderByRset)(nil) - _ rset = (*selectRset)(nil) - _ rset = (*selectStmt)(nil) - _ rset = (*tableRset)(nil) - _ rset = (*whereRset)(nil) - - isTesting bool // enables test hook: select from an index -) - -type rset interface { - plan(ctx *execCtx) (plan, error) -} - -type recordset struct { - ctx *execCtx - plan - tx *TCtx -} - -func (r recordset) fieldNames() []interface{} { - f := r.plan.fieldNames() - a := make([]interface{}, len(f)) - for i, v := range f { - a[i] = v - } - return a -} - -// Do implements Recordset. -func (r recordset) Do(names bool, f func(data []interface{}) (bool, error)) error { - if names { - if more, err := f(r.fieldNames()); err != nil || !more { - return err - } - } - return r.ctx.db.do(r, f) -} - -// Fields implements Recordset. -func (r recordset) Fields() (names []string, err error) { - return r.plan.fieldNames(), nil -} - -// FirstRow implements Recordset. -func (r recordset) FirstRow() (row []interface{}, err error) { - rows, err := r.Rows(1, 0) - if err != nil { - return nil, err - } - - if len(rows) != 0 { - return rows[0], nil - } - - return nil, nil -} - -// Rows implements Recordset. -func (r recordset) Rows(limit, offset int) ([][]interface{}, error) { - var rows [][]interface{} - if err := r.Do(false, func(row []interface{}) (bool, error) { - if offset > 0 { - offset-- - return true, nil - } - - switch { - case limit < 0: - rows = append(rows, row) - return true, nil - case limit == 0: - return false, nil - default: // limit > 0 - rows = append(rows, row) - limit-- - return limit > 0, nil - } - }); err != nil { - return nil, err - } - - return rows, nil -} - -// List represents a group of compiled statements. -type List struct { - l []stmt - params int -} - -// String implements fmt.Stringer -func (l List) String() string { - var b bytes.Buffer - f := strutil.IndentFormatter(&b, "\t") - for _, s := range l.l { - switch s.(type) { - case beginTransactionStmt: - f.Format("%s\n%i", s) - case commitStmt, rollbackStmt: - f.Format("%u%s\n", s) - default: - f.Format("%s\n", s) - } - } - return b.String() -} - -// IsExplainStmt reports whether l is a single EXPLAIN statement or a single EXPLAIN -// statement enclosed in a transaction. -func (l List) IsExplainStmt() bool { - switch len(l.l) { - case 1: - _, ok := l.l[0].(*explainStmt) - return ok - case 3: - if _, ok := l.l[0].(beginTransactionStmt); !ok { - return false - } - if _, ok := l.l[1].(*explainStmt); !ok { - return false - } - _, ok := l.l[2].(commitStmt) - return ok - default: - return false - } -} - -type groupByRset struct { - colNames []string - src plan -} - -func (r *groupByRset) plan(ctx *execCtx) (plan, error) { - fields := r.src.fieldNames() - for _, v := range r.colNames { - found := false - for _, v2 := range fields { - if v == v2 { - found = true - break - } - } - if !found { - return nil, fmt.Errorf("unknown field %s", v) - } - } - return &groupByDefaultPlan{colNames: r.colNames, src: r.src, fields: fields}, nil -} - -// TCtx represents transaction context. It enables to execute multiple -// statement lists in the same context. The same context guarantees the state -// of the DB cannot change in between the separated executions. -// -// LastInsertID -// -// LastInsertID is updated by INSERT INTO statements. The value considers -// performed ROLLBACK statements, if any, even though roll backed IDs are not -// reused. QL clients should treat the field as read only. -// -// RowsAffected -// -// RowsAffected is updated by INSERT INTO, DELETE FROM and UPDATE statements. -// The value does not (yet) consider any ROLLBACK statements involved. QL -// clients should treat the field as read only. -type TCtx struct { - LastInsertID int64 - RowsAffected int64 -} - -// NewRWCtx returns a new read/write transaction context. NewRWCtx is safe for -// concurrent use by multiple goroutines, every one of them will get a new, -// unique context. -func NewRWCtx() *TCtx { return &TCtx{} } - -// Recordset is a result of a select statement. It can call a user function for -// every row (record) in the set using the Do method. -// -// Recordsets can be safely reused. Evaluation of the rows is performed lazily. -// Every invocation of Do will see the current, potentially actualized data. -// -// Do -// -// Do will call f for every row (record) in the Recordset. -// -// If f returns more == false or err != nil then f will not be called for any -// remaining rows in the set and the err value is returned from Do. -// -// If names == true then f is firstly called with a virtual row -// consisting of field (column) names of the RecordSet. -// -// Do is executed in a read only context and performs a RLock of the -// database. -// -// Do is safe for concurrent use by multiple goroutines. -// -// Fields -// -// Fields return a slice of field names of the recordset. The result is computed -// without actually computing the recordset rows. -// -// FirstRow -// -// FirstRow will return the first row of the RecordSet or an error, if any. If -// the Recordset has no rows the result is (nil, nil). -// -// Rows -// -// Rows will return rows in Recordset or an error, if any. The semantics of -// limit and offset are the same as of the LIMIT and OFFSET clauses of the -// SELECT statement. To get all rows pass limit < 0. If there are no rows to -// return the result is (nil, nil). -type Recordset interface { - Do(names bool, f func(data []interface{}) (more bool, err error)) error - Fields() (names []string, err error) - FirstRow() (row []interface{}, err error) - Rows(limit, offset int) (rows [][]interface{}, err error) -} - -type assignment struct { - colName string - expr expression -} - -func (a *assignment) String() string { - return fmt.Sprintf("%s=%s", a.colName, a.expr) -} - -type distinctRset struct { - src plan -} - -func (r *distinctRset) plan(ctx *execCtx) (plan, error) { - return &distinctDefaultPlan{src: r.src, fields: r.src.fieldNames()}, nil -} - -type orderByRset struct { - asc bool - by []expression - src plan -} - -func (r *orderByRset) String() string { - a := make([]string, len(r.by)) - for i, v := range r.by { - a[i] = v.String() - } - s := strings.Join(a, ", ") - if !r.asc { - s += " DESC" - } - return s -} - -func (r *orderByRset) plan(ctx *execCtx) (plan, error) { - if _, ok := r.src.(*nullPlan); ok { - return r.src, nil - } - - var by []expression - fields := r.src.fieldNames() - for _, e := range r.by { - cols := mentionedColumns(e) - for k := range cols { - found := false - for _, v := range fields { - if k == v { - found = true - break - } - } - if !found { - return nil, fmt.Errorf("unknown field %s", k) - } - } - if len(cols) == 0 { - v, err := e.eval(ctx, nil) - if err != nil { - by = append(by, e) - continue - } - - if isConstValue(v) != nil { - continue - } - } - - by = append(by, e) - } - return &orderByDefaultPlan{asc: r.asc, by: by, src: r.src, fields: fields}, nil -} - -type whereRset struct { - expr expression - src plan - sel *selectStmt - exists bool -} - -func (r *whereRset) String() string { - if r.sel != nil { - s := "" - if !r.exists { - s += " NOT " - } - return fmt.Sprintf("%s EXISTS ( %s )", s, strings.TrimSuffix(r.sel.String(), ";")) - } - return r.expr.String() -} - -func (r *whereRset) planBinOp(x *binaryOperation) (plan, error) { - p := r.src - ok, cn := isColumnExpression(x.l) - if ok && cn == "id()" { - if v := isConstValue(x.r); v != nil { - v, err := typeCheck1(v, idCol) - if err != nil { - return nil, err - } - - rv := v.(int64) - switch { - case p.hasID(): - switch x.op { - case '<': - if rv <= 1 { - return &nullPlan{p.fieldNames()}, nil - } - case '>': - if rv <= 0 { - return p, nil - } - case ge: - if rv >= 1 { - return p, nil - } - case neq: - if rv <= 0 { - return p, nil - } - case eq: - if rv <= 0 { - return &nullPlan{p.fieldNames()}, nil - } - case le: - if rv <= 0 { - return &nullPlan{p.fieldNames()}, nil - } - } - } - } - } - - var err error - var p2 plan - var is []string - switch x.op { - case eq, ge, '>', le, '<', neq: - if p2, is, err = p.filter(x); err != nil { - return nil, err - } - - if p2 != nil { - return p2, nil - } - case andand: - var in []expression - var f func(expression) - f = func(e expression) { - b, ok := e.(*binaryOperation) - if !ok || b.op != andand { - in = append(in, e) - return - } - - f(b.l) - f(b.r) - } - f(x) - out := []expression{} - p := r.src - isNewPlan := false - for _, e := range in { - p2, is2, err := p.filter(e) - if err != nil { - return nil, err - } - - if p2 == nil { - is = append(is, is2...) - out = append(out, e) - continue - } - - p = p2 - isNewPlan = true - } - - if !isNewPlan { - break - } - - if len(out) == 0 { - return p, nil - } - - for len(out) > 1 { - n := len(out) - e, err := newBinaryOperation(andand, out[n-2], out[n-1]) - if err != nil { - return nil, err - } - - out = out[:n-1] - out[n-2] = e - } - - return &filterDefaultPlan{p, out[0], is}, nil - } - - return &filterDefaultPlan{p, x, is}, nil -} - -func (r *whereRset) planIdent(x *ident) (plan, error) { - p := r.src - p2, is, err := p.filter(x) - if err != nil { - return nil, err - } - - if p2 != nil { - return p2, nil - } - - return &filterDefaultPlan{p, x, is}, nil -} - -func (r *whereRset) planIsNull(x *isNull) (plan, error) { - p := r.src - ok, cn := isColumnExpression(x.expr) - if !ok { - return &filterDefaultPlan{p, x, nil}, nil - } - - if cn == "id()" { - switch { - case p.hasID(): - switch { - case x.not: // IS NOT NULL - return p, nil - default: // IS NULL - return &nullPlan{p.fieldNames()}, nil - } - default: - switch { - case x.not: // IS NOT NULL - return &nullPlan{p.fieldNames()}, nil - default: // IS NULL - return p, nil - } - } - } - - p2, is, err := p.filter(x) - if err != nil { - return nil, err - } - - if p2 != nil { - return p2, nil - } - - return &filterDefaultPlan{p, x, is}, nil -} - -func (r *whereRset) planUnaryOp(x *unaryOperation) (plan, error) { - p := r.src - p2, is, err := p.filter(x) - if err != nil { - return nil, err - } - - if p2 != nil { - return p2, nil - } - - return &filterDefaultPlan{p, x, is}, nil -} - -func (r *whereRset) plan(ctx *execCtx) (plan, error) { - o := r.src - if r.sel != nil { - var exists bool - ctx.mu.RLock() - m, ok := ctx.cache[r.sel] - ctx.mu.RUnlock() - if ok { - exists = m.(bool) - } else { - p, err := r.sel.plan(ctx) - if err != nil { - return nil, err - } - err = p.do(ctx, func(i interface{}, data []interface{}) (bool, error) { - if len(data) > 0 { - exists = true - } - return false, nil - }) - if err != nil { - return nil, err - } - ctx.mu.Lock() - ctx.cache[r.sel] = true - ctx.mu.Unlock() - } - if r.exists == exists { - return o, nil - } - return &nullPlan{fields: o.fieldNames()}, nil - } - return r.planExpr(ctx) -} - -func (r *whereRset) planExpr(ctx *execCtx) (plan, error) { - if r.expr == nil { - return &nullPlan{}, nil - } - expr, err := r.expr.clone(ctx.arg) - if err != nil { - return nil, err - } - - switch r.src.(type) { - case *leftJoinDefaultPlan, *rightJoinDefaultPlan, *fullJoinDefaultPlan: - return &filterDefaultPlan{r.src, expr, nil}, nil - } - - switch x := expr.(type) { - case *binaryOperation: - return r.planBinOp(x) - case *ident: - return r.planIdent(x) - case *isNull: - return r.planIsNull(x) - case *pIn: - //TODO optimize - //TODO show plan - case *pLike: - //TODO optimize - case *unaryOperation: - return r.planUnaryOp(x) - } - - return &filterDefaultPlan{r.src, expr, nil}, nil -} - -type offsetRset struct { - expr expression - src plan -} - -func (r *offsetRset) plan(ctx *execCtx) (plan, error) { - return &offsetDefaultPlan{expr: r.expr, src: r.src, fields: r.src.fieldNames()}, nil -} - -type limitRset struct { - expr expression - src plan -} - -func (r *limitRset) plan(ctx *execCtx) (plan, error) { - return &limitDefaultPlan{expr: r.expr, src: r.src, fields: r.src.fieldNames()}, nil -} - -type selectRset struct { - flds []*fld - src plan -} - -func (r *selectRset) plan(ctx *execCtx) (plan, error) { - if r.src == nil { - return nil, nil - } - - var flds2 []*fld - if len(r.flds) != 0 { - m := map[string]struct{}{} - for _, v := range r.flds { - mentionedColumns0(v.expr, true, true, m) - } - for _, v := range r.src.fieldNames() { - delete(m, v) - } - for k := range m { - return nil, fmt.Errorf("unknown field %s", k) - } - - flds2 = append(flds2, r.flds...) - } - - if x, ok := r.src.(*groupByDefaultPlan); ok { - if len(r.flds) == 0 { - fields := x.fieldNames() - flds := make([]*fld, len(fields)) - for i, v := range fields { - flds[i] = &fld{&ident{v}, v} - } - return &selectFieldsGroupPlan{flds: flds, src: x, fields: fields}, nil - } - - p := &selectFieldsGroupPlan{flds: flds2, src: x} - for _, v := range r.flds { - p.fields = append(p.fields, v.name) - } - return p, nil - } - - if len(r.flds) == 0 { - return r.src, nil - } - - f0 := r.src.fieldNames() - if len(f0) == len(flds2) { - match := true - for i, v := range flds2 { - if x, ok := v.expr.(*ident); ok && x.s == f0[i] && v.name == f0[i] { - continue - } - - match = false - break - } - - if match { - return r.src, nil - } - } - - src := r.src - if x, ok := src.(*tableDefaultPlan); ok { - isconst := true - for _, v := range flds2 { - if isConstValue(v.expr) == nil { - isconst = false - break - } - } - if isconst { // #250 - src = &tableNilPlan{x.t} - } - } - - p := &selectFieldsDefaultPlan{flds: flds2, src: src} - for _, v := range r.flds { - p.fields = append(p.fields, v.name) - } - return p, nil -} - -type tableRset string - -func (r tableRset) plan(ctx *execCtx) (plan, error) { - switch r { - case "__Table": - return &sysTableDefaultPlan{}, nil - case "__Column": - return &sysColumnDefaultPlan{}, nil - case "__Index": - return &sysIndexDefaultPlan{}, nil - } - - t, ok := ctx.db.root.tables[string(r)] - if !ok && isTesting { - if _, x0 := ctx.db.root.findIndexByName(string(r)); x0 != nil { - return &selectIndexDefaultPlan{nm: string(r), x: x0}, nil - } - } - - if !ok { - return nil, fmt.Errorf("table %s does not exist", r) - } - - rs := &tableDefaultPlan{t: t} - for _, col := range t.cols { - rs.fields = append(rs.fields, col.name) - } - return rs, nil -} - -func findFld(fields []*fld, name string) (f *fld) { - for _, f = range fields { - if f.name == name { - return - } - } - - return nil -} - -type col struct { - index int - name string - typ int - constraint *constraint - dflt expression -} - -var idCol = &col{name: "id()", typ: qInt64} - -func findCol(cols []*col, name string) (c *col) { - for _, c = range cols { - if c.name == name { - return - } - } - - return nil -} - -func (f *col) clone() *col { - r := *f - r.constraint = f.constraint.clone() - if f.dflt != nil { - r.dflt, _ = r.dflt.clone(nil) - } - return &r -} - -func (f *col) typeCheck(x interface{}) (ok bool) { //NTYPE - switch x.(type) { - case nil: - return true - case bool: - return f.typ == qBool - case complex64: - return f.typ == qComplex64 - case complex128: - return f.typ == qComplex128 - case float32: - return f.typ == qFloat32 - case float64: - return f.typ == qFloat64 - case int8: - return f.typ == qInt8 - case int16: - return f.typ == qInt16 - case int32: - return f.typ == qInt32 - case int64: - return f.typ == qInt64 - case string: - return f.typ == qString - case uint8: - return f.typ == qUint8 - case uint16: - return f.typ == qUint16 - case uint32: - return f.typ == qUint32 - case uint64: - return f.typ == qUint64 - case []byte: - return f.typ == qBlob - case *big.Int: - return f.typ == qBigInt - case *big.Rat: - return f.typ == qBigRat - case time.Time: - return f.typ == qTime - case time.Duration: - return f.typ == qDuration - case chunk: - return true // was checked earlier - } - return -} - -func cols2meta(f []*col) (s string) { - a := []string{} - for _, f := range f { - a = append(a, string(f.typ)+f.name) - } - return strings.Join(a, "|") -} - -// DB represent the database capable of executing QL statements. -type DB struct { - cc *TCtx // Current transaction context - exprCache map[string]expression - exprCacheMu sync.Mutex - hasIndex2 int // 0: nope, 1: in progress, 2: yes. - isMem bool - mu sync.Mutex - queue []chan struct{} - root *root - rw bool // DB FSM - rwmu sync.RWMutex - store storage - tnl int // Transaction nesting level -} - -var selIndex2Expr = MustCompile("select Expr from __Index2_Expr where Index2_ID == $1") - -func newDB(store storage) (db *DB, err error) { - db0 := &DB{ - exprCache: map[string]expression{}, - store: store, - } - if db0.root, err = newRoot(store); err != nil { - return - } - - ctx := newExecCtx(db0, nil) - for _, t := range db0.root.tables { - if err := t.constraintsAndDefaults(ctx); err != nil { - return nil, err - } - } - - if !db0.hasAllIndex2() { - return db0, nil - } - - db0.hasIndex2 = 2 - rss, _, err := db0.Run(nil, "select id(), TableName, IndexName, IsUnique, Root from __Index2 where !IsSimple") - if err != nil { - return nil, err - } - - rows, err := rss[0].Rows(-1, 0) - if err != nil { - return nil, err - } - - for _, row := range rows { - defer func() { - if e := recover(); e != nil { - err = fmt.Errorf("error loading DB indices: %v", e) - } - }() - - id := row[0].(int64) - tn := row[1].(string) - xn := row[2].(string) - unique := row[3].(bool) - xroot := row[4].(int64) - - t := db0.root.tables[tn] - if t == nil { - return nil, fmt.Errorf("DB index refers to nonexistent table: %s", tn) - } - - x, err := store.OpenIndex(unique, xroot) - if err != nil { - return nil, err - } - - if v := t.indices2[xn]; v != nil { - return nil, fmt.Errorf("duplicate DB index: %s", xn) - } - - ix := &index2{ - unique: unique, - x: x, - xroot: xroot, - } - - rss, _, err := db0.Execute(nil, selIndex2Expr, id) - if err != nil { - return nil, err - } - - rows, err := rss[0].Rows(-1, 0) - if err != nil { - return nil, err - } - - if len(rows) == 0 { - return nil, fmt.Errorf("index has no expression: %s", xn) - } - - var sources []string - var list []expression - for _, row := range rows { - src, ok := row[0].(string) - if !ok { - return nil, fmt.Errorf("index %s: expression of type %T", xn, row[0]) - } - - expr, err := db0.str2expr(src) - if err != nil { - return nil, fmt.Errorf("index %s: expression error: %v", xn, err) - } - - sources = append(sources, src) - list = append(list, expr) - } - - ix.sources = sources - ix.exprList = list - if t.indices2 == nil { - t.indices2 = map[string]*index2{} - } - t.indices2[xn] = ix - } - return db0, nil -} - -func (db *DB) deleteIndex2ByIndexName(nm string) error { - for _, s := range deleteIndex2ByIndexName.l { - if _, err := s.exec(newExecCtx(db, []interface{}{nm})); err != nil { - return err - } - } - return nil -} - -func (db *DB) deleteIndex2ByTableName(nm string) error { - for _, s := range deleteIndex2ByTableName.l { - if _, err := s.exec(newExecCtx(db, []interface{}{nm})); err != nil { - return err - } - } - return nil -} - -func (db *DB) createIndex2() error { - if db.hasIndex2 != 0 { - return nil - } - - db.hasIndex2 = 1 - ctx := execCtx{db: db} - for _, s := range createIndex2.l { - if _, err := s.exec(&ctx); err != nil { - db.hasIndex2 = 0 - return err - } - } - - for t := db.root.thead; t != nil; t = t.tnext { - for i, index := range t.indices { - if index == nil { - continue - } - - expr := "id()" - if i != 0 { - expr = t.cols0[i-1].name - } - - if err := db.insertIndex2(t.name, index.name, []string{expr}, index.unique, true, index.xroot); err != nil { - db.hasIndex2 = 0 - return err - } - } - } - - db.hasIndex2 = 2 - return nil -} - -func (db *DB) insertIndex2(tableName, indexName string, expr []string, unique, isSimple bool, h int64) error { - ctx := execCtx{db: db} - ctx.arg = []interface{}{ - tableName, - indexName, - unique, - isSimple, - h, - } - if _, err := insertIndex2.l[0].exec(&ctx); err != nil { - return err - } - - id := db.root.lastInsertID - for _, e := range expr { - ctx.arg = []interface{}{id, e} - if _, err := insertIndex2Expr.l[0].exec(&ctx); err != nil { - return err - } - } - return nil -} - -func (db *DB) hasAllIndex2() bool { - t := db.root.tables - if _, ok := t["__Index2"]; !ok { - return false - } - - _, ok := t["__Index2_Expr"] - return ok -} - -func (db *DB) str2expr(expr string) (expression, error) { - db.exprCacheMu.Lock() - e := db.exprCache[expr] - db.exprCacheMu.Unlock() - if e != nil { - return e, nil - } - - e, err := compileExpr(expr) - if err != nil { - return nil, err - } - - db.exprCacheMu.Lock() - for k := range db.exprCache { - if len(db.exprCache) < 1000 { - break - } - - delete(db.exprCache, k) - } - db.exprCache[expr] = e - db.exprCacheMu.Unlock() - return e, nil -} - -// Name returns the name of the DB. -func (db *DB) Name() string { return db.store.Name() } - -// Run compiles and executes a statement list. It returns, if applicable, a -// RecordSet slice and/or an index and error. -// -// For more details please see DB.Execute -// -// Run is safe for concurrent use by multiple goroutines. -func (db *DB) Run(ctx *TCtx, ql string, arg ...interface{}) (rs []Recordset, index int, err error) { - l, err := Compile(ql) - if err != nil { - return nil, -1, err - } - - return db.Execute(ctx, l, arg...) -} - -func (db *DB) run(ctx *TCtx, ql string, arg ...interface{}) (rs []Recordset, index int, err error) { - l, err := compile(ql) - if err != nil { - return nil, -1, err - } - - return db.Execute(ctx, l, arg...) -} - -// Compile parses the ql statements from src and returns a compiled list for -// DB.Execute or an error if any. -// -// Compile is safe for concurrent use by multiple goroutines. -func Compile(src string) (List, error) { - l, err := newLexer(src) - if err != nil { - return List{}, err - } - - if yyParse(l) != 0 { - return List{}, l.errs - } - - return List{l.list, l.params}, nil -} - -func compileExpr(src string) (expression, error) { - l, err := newLexer(src) - if err != nil { - return nil, err - } - - l.inj = parseExpression - if yyParse(l) != 0 { - return nil, l.errs - } - - return l.expr, nil -} - -func compile(src string) (List, error) { - l, err := newLexer(src) - if err != nil { - return List{}, err - } - - l.root = true - if yyParse(l) != 0 { - return List{}, l.errs - } - - return List{l.list, l.params}, nil -} - -// MustCompile is like Compile but panics if the ql statements in src cannot be -// compiled. It simplifies safe initialization of global variables holding -// compiled statement lists for DB.Execute. -// -// MustCompile is safe for concurrent use by multiple goroutines. -func MustCompile(src string) List { - list, err := Compile(src) - if err != nil { - panic("ql: Compile(" + strconv.Quote(src) + "): " + err.Error()) // panic ok here - } - - return list -} - -func mustCompile(src string) List { - list, err := compile(src) - if err != nil { - panic("ql: compile(" + strconv.Quote(src) + "): " + err.Error()) // panic ok here - } - - return list -} - -// Execute executes statements in a list while substituting QL parameters from -// arg. -// -// The resulting []Recordset corresponds to the SELECT FROM statements in the -// list. -// -// If err != nil then index is the zero based index of the failed QL statement. -// Empty statements do not count. -// -// The FSM STT describing the relations between DB states, statements and the -// ctx parameter. -// -// +-----------+---------------------+------------------+------------------+------------------+ -// |\ Event | | | | | -// | \-------\ | BEGIN | | | Other | -// | State \| TRANSACTION | COMMIT | ROLLBACK | statement | -// +-----------+---------------------+------------------+------------------+------------------+ -// | RD | if PC == nil | return error | return error | DB.RLock | -// | | return error | | | Execute(1) | -// | CC == nil | | | | DB.RUnlock | -// | TNL == 0 | DB.Lock | | | | -// | | CC = PC | | | | -// | | TNL++ | | | | -// | | DB.BeginTransaction | | | | -// | | State = WR | | | | -// +-----------+---------------------+------------------+------------------+------------------+ -// | WR | if PC == nil | if PC != CC | if PC != CC | if PC == nil | -// | | return error | return error | return error | DB.Rlock | -// | CC != nil | | | | Execute(1) | -// | TNL != 0 | if PC != CC | DB.Commit | DB.Rollback | RUnlock | -// | | DB.Lock | TNL-- | TNL-- | else if PC != CC | -// | | CC = PC | if TNL == 0 | if TNL == 0 | return error | -// | | | CC = nil | CC = nil | else | -// | | TNL++ | State = RD | State = RD | Execute(2) | -// | | DB.BeginTransaction | DB.Unlock | DB.Unlock | | -// +-----------+---------------------+------------------+------------------+------------------+ -// CC: Curent transaction context -// PC: Passed transaction context -// TNL: Transaction nesting level -// -// Lock, Unlock, RLock, RUnlock semantics above are the same as in -// sync.RWMutex. -// -// (1): Statement list is executed outside of a transaction. Attempts to update -// the DB will fail, the execution context is read-only. Other statements with -// read only context will execute concurrently. If any statement fails, the -// execution of the statement list is aborted. -// -// Note that the RLock/RUnlock surrounds every single "other" statement when it -// is executed outside of a transaction. If read consistency is required by a -// list of more than one statement then an explicit BEGIN TRANSACTION / COMMIT -// or ROLLBACK wrapper must be provided. Otherwise the state of the DB may -// change in between executing any two out-of-transaction statements. -// -// (2): Statement list is executed inside an isolated transaction. Execution of -// statements can update the DB, the execution context is read-write. If any -// statement fails, the execution of the statement list is aborted and the DB -// is automatically rolled back to the TNL which was active before the start of -// execution of the statement list. -// -// Execute is safe for concurrent use by multiple goroutines, but one must -// consider the blocking issues as discussed above. -// -// ACID -// -// Atomicity: Transactions are atomic. Transactions can be nested. Commit or -// rollbacks work on the current transaction level. Transactions are made -// persistent only on the top level commit. Reads made from within an open -// transaction are dirty reads. -// -// Consistency: Transactions bring the DB from one structurally consistent -// state to other structurally consistent state. -// -// Isolation: Transactions are isolated. Isolation is implemented by -// serialization. -// -// Durability: Transactions are durable. A two phase commit protocol and a -// write ahead log is used. Database is recovered after a crash from the write -// ahead log automatically on open. -func (db *DB) Execute(ctx *TCtx, l List, arg ...interface{}) (rs []Recordset, index int, err error) { - // Sanitize args - for i, v := range arg { - switch x := v.(type) { - case nil, bool, complex64, complex128, float32, float64, string, - int8, int16, int32, int64, int, - uint8, uint16, uint32, uint64, uint, - *big.Int, *big.Rat, []byte, time.Duration, time.Time: - case big.Int: - arg[i] = &x - case big.Rat: - arg[i] = &x - default: - return nil, 0, fmt.Errorf("cannot use arg[%d] (type %T):unsupported type", i, v) - } - } - - tnl0 := -1 - if ctx != nil { - ctx.LastInsertID, ctx.RowsAffected = 0, 0 - } - - list := l.l - for _, s := range list { - r, tnla, tnl, err := db.run1(ctx, s, arg...) - if tnl0 < 0 { - tnl0 = tnla - } - if err != nil { - for tnl > tnl0 { - var e2 error - if _, _, tnl, e2 = db.run1(ctx, rollbackStmt{}); e2 != nil { - err = e2 - } - } - return rs, index, err - } - - if r != nil { - if x, ok := r.(recordset); ok { - x.tx = ctx - r = x - } - rs = append(rs, r) - } - } - return -} - -func (db *DB) muUnlock() { - if n := len(db.queue); n != 0 { - db.queue[0] <- struct{}{} - copy(db.queue, db.queue[1:]) - db.queue = db.queue[:n-1] - } - db.mu.Unlock() -} - -func (db *DB) run1(pc *TCtx, s stmt, arg ...interface{}) (rs Recordset, tnla, tnlb int, err error) { - db.mu.Lock() - tnla = db.tnl - tnlb = db.tnl - switch db.rw { - case false: - switch s.(type) { - case beginTransactionStmt: - defer db.muUnlock() - if pc == nil { - return nil, tnla, tnlb, errors.New("BEGIN TRANSACTION: cannot start a transaction in nil TransactionCtx") - } - - if err = db.store.BeginTransaction(); err != nil { - return - } - - db.rwmu.Lock() - db.beginTransaction() - db.cc = pc - db.tnl++ - tnlb = db.tnl - db.rw = true - return - case commitStmt: - defer db.muUnlock() - return nil, tnla, tnlb, errCommitNotInTransaction - case rollbackStmt: - defer db.muUnlock() - return nil, tnla, tnlb, errRollbackNotInTransaction - default: - if s.isUpdating() { - db.muUnlock() - return nil, tnla, tnlb, fmt.Errorf("attempt to update the DB outside of a transaction") - } - - db.rwmu.RLock() // can safely grab before Unlock - db.muUnlock() - defer db.rwmu.RUnlock() - rs, err = s.exec(newExecCtx(db, arg)) // R/O tctx - return rs, tnla, tnlb, err - } - default: // case true: - switch s.(type) { - case beginTransactionStmt: - defer db.muUnlock() - - if pc == nil { - return nil, tnla, tnlb, errBeginTransNoCtx - } - - if pc != db.cc { - for db.rw { - ch := make(chan struct{}, 1) - db.queue = append(db.queue, ch) - db.mu.Unlock() - <-ch - db.mu.Lock() - } - - db.rw = true - db.rwmu.Lock() - - } - - if err = db.store.BeginTransaction(); err != nil { - return - } - - db.beginTransaction() - db.cc = pc - db.tnl++ - tnlb = db.tnl - return - case commitStmt: - defer db.muUnlock() - if pc != db.cc { - return nil, tnla, tnlb, fmt.Errorf("invalid passed transaction context") - } - - db.commit() - err = db.store.Commit() - db.tnl-- - tnlb = db.tnl - if db.tnl != 0 { - return - } - - db.cc = nil - db.rw = false - db.rwmu.Unlock() - return - case rollbackStmt: - defer db.muUnlock() - defer func() { pc.LastInsertID = db.root.lastInsertID }() - if pc != db.cc { - return nil, tnla, tnlb, fmt.Errorf("invalid passed transaction context") - } - - db.rollback() - err = db.store.Rollback() - db.tnl-- - tnlb = db.tnl - if db.tnl != 0 { - return - } - - db.cc = nil - db.rw = false - db.rwmu.Unlock() - return - default: - if pc == nil { - if s.isUpdating() { - db.muUnlock() - return nil, tnla, tnlb, fmt.Errorf("attempt to update the DB outside of a transaction") - } - - db.muUnlock() // must Unlock before RLock - db.rwmu.RLock() - defer db.rwmu.RUnlock() - rs, err = s.exec(newExecCtx(db, arg)) - return rs, tnla, tnlb, err - } - - defer db.muUnlock() - defer func() { pc.LastInsertID = db.root.lastInsertID }() - if pc != db.cc { - return nil, tnla, tnlb, fmt.Errorf("invalid passed transaction context") - } - - rs, err = s.exec(newExecCtx(db, arg)) - return rs, tnla, tnlb, err - } - } -} - -// Flush ends the transaction collecting window, if applicable. IOW, if the DB -// is dirty, it schedules a 2PC (WAL + DB file) commit on the next outer most -// DB.Commit or performs it synchronously if there's currently no open -// transaction. -// -// The collecting window is an implementation detail and future versions of -// Flush may become a no operation while keeping the operation semantics. -func (db *DB) Flush() (err error) { - return nil -} - -// Close will close the DB. Successful Close is idempotent. -func (db *DB) Close() error { - db.mu.Lock() - defer db.muUnlock() - if db.store == nil { - return nil - } - - if db.tnl != 0 { - return fmt.Errorf("cannot close DB while open transaction exist") - } - - err := db.store.Close() - db.root, db.store = nil, nil - return err -} - -func (db *DB) do(r recordset, f func(data []interface{}) (bool, error)) (err error) { - db.mu.Lock() - switch db.rw { - case false: - db.rwmu.RLock() // can safely grab before Unlock - db.muUnlock() - defer db.rwmu.RUnlock() - default: // case true: - if r.tx == nil { - db.muUnlock() // must Unlock before RLock - db.rwmu.RLock() - defer db.rwmu.RUnlock() - break - } - - defer db.muUnlock() - if r.tx != db.cc { - return fmt.Errorf("invalid passed transaction context") - } - } - - return r.do(r.ctx, func(id interface{}, data []interface{}) (bool, error) { - if err = expand(data); err != nil { - return false, err - } - - return f(data) - }) -} - -func (db *DB) beginTransaction() { //TODO Rewrite, must use much smaller undo info! - root := *db.root - root.parent = db.root - root.tables = make(map[string]*table, len(db.root.tables)) - var tprev *table - for t := db.root.thead; t != nil; t = t.tnext { - t2 := t.clone() - root.tables[t2.name] = t2 - t2.tprev = tprev - switch { - case tprev == nil: - root.thead = t2 - default: - tprev.tnext = t2 - } - tprev = t2 - } - db.root = &root -} - -func (db *DB) rollback() { - db.root = db.root.parent -} - -func (db *DB) commit() { - db.root.parent = db.root.parent.parent -} - -// Type represents a QL type (bigint, int, string, ...) -type Type int - -// Values of ColumnInfo.Type. -const ( - BigInt Type = qBigInt - BigRat = qBigRat - Blob = qBlob - Bool = qBool - Complex128 = qComplex128 - Complex64 = qComplex64 - Duration = qDuration - Float32 = qFloat32 - Float64 = qFloat64 - Int16 = qInt16 - Int32 = qInt32 - Int64 = qInt64 - Int8 = qInt8 - String = qString - Time = qTime - Uint16 = qUint16 - Uint32 = qUint32 - Uint64 = qUint64 - Uint8 = qUint8 -) - -// String implements fmt.Stringer. -func (t Type) String() string { - return typeStr(int(t)) -} - -// ColumnInfo provides meta data describing a table column. -type ColumnInfo struct { - Name string // Column name. - Type Type // Column type (BigInt, BigRat, ...). - NotNull bool // Column cannot be NULL. - Constraint string // Constraint expression, if any. - Default string // Default expression, if any. -} - -// TableInfo provides meta data describing a DB table. -type TableInfo struct { - // Table name. - Name string - - // Table schema. Columns are listed in the order in which they appear - // in the schema. - Columns []ColumnInfo -} - -// IndexInfo provides meta data describing a DB index. It corresponds to the -// statement -// -// CREATE INDEX Name ON Table (Column); -type IndexInfo struct { - Name string // Index name - Table string // Table name. - Column string // Column name. - Unique bool // Whether the index is unique. - ExpressionList []string // Index expression list. -} - -// DbInfo provides meta data describing a DB. -type DbInfo struct { - Name string // DB name. - Tables []TableInfo // Tables in the DB. - Indices []IndexInfo // Indices in the DB. -} - -func (db *DB) info() (r *DbInfo, err error) { - _, hasColumn2 := db.root.tables["__Column2"] - r = &DbInfo{Name: db.Name()} - for nm, t := range db.root.tables { - ti := TableInfo{Name: nm} - m := map[string]*ColumnInfo{} - if hasColumn2 { - rs, err := selectColumn2.l[0].exec(newExecCtx(db, []interface{}{nm})) - if err != nil { - return nil, err - } - - if err := rs.(recordset).do( - newExecCtx(db, []interface{}{nm}), - func(id interface{}, data []interface{}) (bool, error) { - ci := &ColumnInfo{NotNull: data[1].(bool), Constraint: data[2].(string), Default: data[3].(string)} - m[data[0].(string)] = ci - return true, nil - }, - ); err != nil { - return nil, err - } - } - for _, c := range t.cols { - ci := ColumnInfo{Name: c.name, Type: Type(c.typ)} - if c2 := m[c.name]; c2 != nil { - ci.NotNull = c2.NotNull - ci.Constraint = c2.Constraint - ci.Default = c2.Default - } - ti.Columns = append(ti.Columns, ci) - } - r.Tables = append(r.Tables, ti) - for i, x := range t.indices { - if x == nil { - continue - } - - var cn string - switch { - case i == 0: - cn = "id()" - default: - cn = t.cols0[i-1].name - } - r.Indices = append(r.Indices, IndexInfo{x.name, nm, cn, x.unique, []string{cn}}) - } - var a []string - for k := range t.indices2 { - a = append(a, k) - } - for _, k := range a { - x := t.indices2[k] - a = a[:0] - for _, e := range x.exprList { - a = append(a, e.String()) - } - r.Indices = append(r.Indices, IndexInfo{k, nm, "", x.unique, a}) - } - } - return -} - -// Info provides meta data describing a DB or an error if any. It locks the DB -// to obtain the result. -func (db *DB) Info() (r *DbInfo, err error) { - db.mu.Lock() - defer db.muUnlock() - return db.info() -} - -type constraint struct { - expr expression // If expr == nil: constraint is 'NOT NULL' -} - -func (c *constraint) clone() *constraint { - if c == nil { - return nil - } - - var e expression - if c.expr != nil { - e, _ = c.expr.clone(nil) - } - return &constraint{e} -} - -type joinRset struct { - sources []interface{} - typ int - on expression -} - -func (r *joinRset) isZero() bool { - return len(r.sources) == 0 && r.typ == 0 && r.on == nil - -} - -func (r *joinRset) String() string { - if r.isZero() { - return "" - } - a := make([]string, len(r.sources)) - for i, pair0 := range r.sources { - pair := pair0.([]interface{}) - altName := pair[1].(string) - switch x := pair[0].(type) { - case string: // table name - switch { - case altName == "": - a[i] = x - default: - a[i] = fmt.Sprintf("%s AS %s", x, altName) - } - case *selectStmt: - switch { - case altName == "": - a[i] = fmt.Sprintf("(%s)", x) - default: - a[i] = fmt.Sprintf("(%s) AS %s", x, altName) - } - default: - panic("internal error 054") - } - } - n := len(a) - a2 := a[:n-1] - j := a[n-1] - var s string - switch r.typ { - case crossJoin: - return strings.Join(a, ", ") - case leftJoin: - s = strings.Join(a2, ",") + " LEFT" - case rightJoin: - s = strings.Join(a2, ",") + " RIGHT" - case fullJoin: - s = strings.Join(a2, ",") + " FULL" - } - s += " OUTER JOIN " + j + " ON " + r.on.String() - return s -} - -func (r *joinRset) plan(ctx *execCtx) (plan, error) { - if r.isZero() { - return nil, nil - } - rsets := make([]plan, len(r.sources)) - names := make([]string, len(r.sources)) - var err error - m := map[string]bool{} - var fields []string - for i, v := range r.sources { - pair := v.([]interface{}) - src := pair[0] - nm := pair[1].(string) - if s, ok := src.(string); ok { - src = tableRset(s) - if nm == "" { - nm = s - } - } - if m[nm] { - return nil, fmt.Errorf("%s: duplicate name %s", r.String(), nm) - } - - if nm != "" { - m[nm] = true - } - names[i] = nm - var q plan - switch x := src.(type) { - case rset: - if q, err = x.plan(ctx); err != nil { - return nil, err - } - case plan: - q = x - default: - panic("internal error 008") - } - - switch { - case len(r.sources) == 1: - fields = q.fieldNames() - default: - for _, f := range q.fieldNames() { - if strings.Contains(f, ".") { - return nil, fmt.Errorf("cannot join on recordset with already qualified field names (use the AS clause): %s", f) - } - - if f != "" && nm != "" { - f = fmt.Sprintf("%s.%s", nm, f) - } - fields = append(fields, f) - } - } - rsets[i] = q - } - - switch len(rsets) { - case 0: - return nil, nil - case 1: - return rsets[0], nil - } - right := len(rsets[len(rsets)-1].fieldNames()) - switch r.typ { - case crossJoin: - return &crossJoinDefaultPlan{rsets: rsets, names: names, fields: fields}, nil - case leftJoin: - return &leftJoinDefaultPlan{rsets: rsets, names: names, fields: fields, on: r.on, right: right}, nil - case rightJoin: - return &rightJoinDefaultPlan{leftJoinDefaultPlan{rsets: rsets, names: names, fields: fields, on: r.on, right: right}}, nil - case fullJoin: - return &fullJoinDefaultPlan{leftJoinDefaultPlan{rsets: rsets, names: names, fields: fields, on: r.on, right: right}}, nil - default: - panic("internal error 010") - } -} - -type fld struct { - expr expression - name string -} diff --git a/vendor/github.com/cznic/ql/ql/main.go b/vendor/github.com/cznic/ql/ql/main.go deleted file mode 100644 index 144cfa721..000000000 --- a/vendor/github.com/cznic/ql/ql/main.go +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Command ql is a utility to explore a database, prototype a schema or test -// drive a query, etc. -// -// Installation: -// -// $ go get github.com/cznic/ql/ql -// -// Usage: -// -// ql [-db name] [-schema regexp] [-tables regexp] [-fld] statement_list -// -// Options: -// -// -db name Name of the database to use. Defaults to "ql.db". -// If the DB file does not exists it is created automatically. -// -// -schema re If re != "" show the CREATE statements of matching tables and exit. -// -// -tables re If re != "" show the matching table names and exit. -// -// -fld First row of a query result set will show field names. -// -// statement_list QL statements to execute. -// If no non flag arguments are present, ql reads from stdin. -// The list is wrapped into an automatic transaction. -// -// -t Report and measure time to execute, including creating/opening and closing the DB. -// -// Example: -// -// $ ql 'create table t (i int, s string)' -// $ ql << EOF -// > insert into t values -// > (1, "a"), -// > (2, "b"), -// > (3, "c"), -// > EOF -// $ ql 'select * from t' -// 3, "c" -// 2, "b" -// 1, "a" -// $ ql -fld 'select * from t where i != 2 order by s' -// "i", "s" -// 1, "a" -// 3, "c" -// $ -package main - -import ( - "bufio" - "flag" - "fmt" - "io/ioutil" - "log" - "os" - "regexp" - "runtime" - "sort" - "strings" - "time" - - "github.com/cznic/ql" -) - -func str(data []interface{}) string { - a := make([]string, len(data)) - for i, v := range data { - switch x := v.(type) { - case string: - a[i] = fmt.Sprintf("%q", x) - default: - a[i] = fmt.Sprint(x) - } - } - return strings.Join(a, ", ") -} - -func main() { - if err := do(); err != nil { - log.Fatal(err) - } -} - -type config struct { - db string - flds bool - schema string - tables string - time bool - help bool - interactive bool -} - -func (c *config) parse() { - db := flag.String("db", "ql.db", "The DB file to open. It'll be created if missing.") - flds := flag.Bool("fld", false, "Show recordset's field names.") - schema := flag.String("schema", "", "If non empty, show the CREATE statements of matching tables and exit.") - tables := flag.String("tables", "", "If non empty, list matching table names and exit.") - time := flag.Bool("t", false, "Measure and report time to execute the statement(s) including DB create/open/close.") - help := flag.Bool("h", false, "Shows this help text.") - interactive := flag.Bool("i", false, "runs in interactive mode") - flag.Parse() - c.flds = *flds - c.db = *db - c.schema = *schema - c.tables = *tables - c.time = *time - c.help = *help - c.interactive = *interactive -} - -func do() (err error) { - cfg := &config{} - cfg.parse() - if cfg.help { - flag.PrintDefaults() - return nil - } - if flag.NArg() == 0 && !cfg.interactive { - - // Somehow we expect input to the ql tool. - // This will block trying to read input from stdin - b, err := ioutil.ReadAll(os.Stdin) - if err != nil || len(b) == 0 { - flag.PrintDefaults() - return nil - } - db, err := ql.OpenFile(cfg.db, &ql.Options{CanCreate: true}) - if err != nil { - return err - } - defer func() { - ec := db.Close() - switch { - case ec != nil && err != nil: - log.Println(ec) - case ec != nil: - err = ec - } - }() - return run(cfg, bufio.NewWriter(os.Stdout), string(b), db) - } - db, err := ql.OpenFile(cfg.db, &ql.Options{CanCreate: true}) - if err != nil { - return err - } - - defer func() { - ec := db.Close() - switch { - case ec != nil && err != nil: - log.Println(ec) - case ec != nil: - err = ec - } - }() - r := bufio.NewReader(os.Stdin) - o := bufio.NewWriter(os.Stdout) - if cfg.interactive { - for { - o.WriteString("ql> ") - o.Flush() - src, err := readSrc(cfg.interactive, r) - if err != nil { - return err - } - err = run(cfg, o, src, db) - if err != nil { - fmt.Fprintln(o, err) - o.Flush() - } - } - return nil - } - src, err := readSrc(cfg.interactive, r) - if err != nil { - return err - } - return run(cfg, o, src, db) -} - -func readSrc(i bool, in *bufio.Reader) (string, error) { - if i { - return in.ReadString('\n') - } - var src string - switch n := flag.NArg(); n { - case 0: - b, err := ioutil.ReadAll(in) - if err != nil { - return "", err - } - - src = string(b) - default: - a := make([]string, n) - for i := range a { - a[i] = flag.Arg(i) - } - src = strings.Join(a, " ") - } - return src, nil -} - -func run(cfg *config, o *bufio.Writer, src string, db *ql.DB) (err error) { - defer o.Flush() - if cfg.interactive { - src = strings.TrimSpace(src) - if strings.HasPrefix(src, "\\") || - strings.HasPrefix(src, ".") { - switch src { - case "\\clear", ".clear": - switch runtime.GOOS { - case "darwin", "linux": - fmt.Fprintln(o, "\033[H\033[2J") - default: - fmt.Fprintln(o, "clear not supported in this system") - } - return nil - case "\\q", "\\exit", ".q", ".exit": - // we make sure to close the database before exiting - db.Close() - os.Exit(1) - } - } - - } - - t0 := time.Now() - if cfg.time { - defer func() { - fmt.Fprintf(os.Stderr, "%s\n", time.Since(t0)) - }() - } - if pat := cfg.schema; pat != "" { - re, err := regexp.Compile(pat) - if err != nil { - return err - } - - nfo, err := db.Info() - if err != nil { - return err - } - - r := []string{} - for _, ti := range nfo.Tables { - if !re.MatchString(ti.Name) { - continue - } - - a := []string{} - for _, ci := range ti.Columns { - a = append(a, fmt.Sprintf("%s %s", ci.Name, ci.Type)) - } - r = append(r, fmt.Sprintf("CREATE TABLE %s (%s);", ti.Name, strings.Join(a, ", "))) - } - sort.Strings(r) - if len(r) != 0 { - fmt.Fprintln(o, strings.Join(r, "\n")) - } - return nil - } - - if pat := cfg.tables; pat != "" { - re, err := regexp.Compile(pat) - if err != nil { - return err - } - - nfo, err := db.Info() - if err != nil { - return err - } - - r := []string{} - for _, ti := range nfo.Tables { - if !re.MatchString(ti.Name) { - continue - } - - r = append(r, ti.Name) - } - sort.Strings(r) - if len(r) != 0 { - fmt.Fprintln(o, strings.Join(r, "\n")) - } - return nil - } - - src = strings.TrimSpace(src) - - commit := "COMMIT;" - if !strings.HasSuffix(src, ";") { - commit = "; " + commit - } - src = "BEGIN TRANSACTION; " + src + commit - l, err := ql.Compile(src) - if err != nil { - log.Println(src) - return err - } - - rs, i, err := db.Execute(ql.NewRWCtx(), l) - if err != nil { - a := strings.Split(strings.TrimSpace(fmt.Sprint(l)), "\n") - return fmt.Errorf("%v: %s", err, a[i]) - } - - if len(rs) == 0 { - return - } - - switch { - case l.IsExplainStmt(): - return rs[len(rs)-1].Do(cfg.flds, func(data []interface{}) (bool, error) { - fmt.Fprintln(o, data[0]) - return true, nil - }) - default: - for _, rst := range rs { - err = rst.Do(cfg.flds, func(data []interface{}) (bool, error) { - fmt.Fprintln(o, str(data)) - return true, nil - }) - o.Flush() - if err != nil { - return - } - } - return - } -} diff --git a/vendor/github.com/cznic/ql/scanner.go b/vendor/github.com/cznic/ql/scanner.go deleted file mode 100644 index 79229ee1a..000000000 --- a/vendor/github.com/cznic/ql/scanner.go +++ /dev/null @@ -1,4795 +0,0 @@ -// Code generated by golex. DO NOT EDIT. - -// Copyright (c) 2014 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "fmt" - "strconv" -) - -// Implements yyLexer. -func (l *lexer) Lex(lval *yySymType) (r int) { - const ( - INITIAL = iota - S1 - S2 - ) - if n := l.inj; n != 0 { - l.inj = 0 - return n - } - - defer func() { - pos := l.file.Position(l.First.Pos()) - l.line = pos.Line - l.col = pos.Column - lval.line, lval.col = l.line, l.col - }() - c := l.Enter() - -yystate0: - yyrule := -1 - _ = yyrule - c = l.Rule0() - - switch yyt := l.sc; yyt { - default: - panic(fmt.Errorf(`invalid start condition %d`, yyt)) - case 0: // start condition: INITIAL - goto yystart1 - case 1: // start condition: S1 - goto yystart315 - case 2: // start condition: S2 - goto yystart321 - } - - goto yystate0 // silence unused label error - goto yyAction // silence unused label error -yyAction: - switch yyrule { - case 1: - goto yyrule1 - case 2: - goto yyrule2 - case 3: - goto yyrule3 - case 4: - goto yyrule4 - case 5: - goto yyrule5 - case 6: - goto yyrule6 - case 7: - goto yyrule7 - case 8: - goto yyrule8 - case 9: - goto yyrule9 - case 10: - goto yyrule10 - case 11: - goto yyrule11 - case 12: - goto yyrule12 - case 13: - goto yyrule13 - case 14: - goto yyrule14 - case 15: - goto yyrule15 - case 16: - goto yyrule16 - case 17: - goto yyrule17 - case 18: - goto yyrule18 - case 19: - goto yyrule19 - case 20: - goto yyrule20 - case 21: - goto yyrule21 - case 22: - goto yyrule22 - case 23: - goto yyrule23 - case 24: - goto yyrule24 - case 25: - goto yyrule25 - case 26: - goto yyrule26 - case 27: - goto yyrule27 - case 28: - goto yyrule28 - case 29: - goto yyrule29 - case 30: - goto yyrule30 - case 31: - goto yyrule31 - case 32: - goto yyrule32 - case 33: - goto yyrule33 - case 34: - goto yyrule34 - case 35: - goto yyrule35 - case 36: - goto yyrule36 - case 37: - goto yyrule37 - case 38: - goto yyrule38 - case 39: - goto yyrule39 - case 40: - goto yyrule40 - case 41: - goto yyrule41 - case 42: - goto yyrule42 - case 43: - goto yyrule43 - case 44: - goto yyrule44 - case 45: - goto yyrule45 - case 46: - goto yyrule46 - case 47: - goto yyrule47 - case 48: - goto yyrule48 - case 49: - goto yyrule49 - case 50: - goto yyrule50 - case 51: - goto yyrule51 - case 52: - goto yyrule52 - case 53: - goto yyrule53 - case 54: - goto yyrule54 - case 55: - goto yyrule55 - case 56: - goto yyrule56 - case 57: - goto yyrule57 - case 58: - goto yyrule58 - case 59: - goto yyrule59 - case 60: - goto yyrule60 - case 61: - goto yyrule61 - case 62: - goto yyrule62 - case 63: - goto yyrule63 - case 64: - goto yyrule64 - case 65: - goto yyrule65 - case 66: - goto yyrule66 - case 67: - goto yyrule67 - case 68: - goto yyrule68 - case 69: - goto yyrule69 - case 70: - goto yyrule70 - case 71: - goto yyrule71 - case 72: - goto yyrule72 - case 73: - goto yyrule73 - case 74: - goto yyrule74 - case 75: - goto yyrule75 - case 76: - goto yyrule76 - case 77: - goto yyrule77 - case 78: - goto yyrule78 - case 79: - goto yyrule79 - case 80: - goto yyrule80 - case 81: - goto yyrule81 - case 82: - goto yyrule82 - case 83: - goto yyrule83 - case 84: - goto yyrule84 - case 85: - goto yyrule85 - case 86: - goto yyrule86 - case 87: - goto yyrule87 - case 88: - goto yyrule88 - case 89: - goto yyrule89 - case 90: - goto yyrule90 - case 91: - goto yyrule91 - case 92: - goto yyrule92 - case 93: - goto yyrule93 - case 94: - goto yyrule94 - case 95: - goto yyrule95 - case 96: - goto yyrule96 - case 97: - goto yyrule97 - case 98: - goto yyrule98 - case 99: - goto yyrule99 - case 100: - goto yyrule100 - } - goto yystate1 // silence unused label error -yystate1: - c = l.Next() -yystart1: - switch { - default: - goto yyabort - case c == '!': - goto yystate3 - case c == '"': - goto yystate5 - case c == '$' || c == '?': - goto yystate6 - case c == '&': - goto yystate9 - case c == '-': - goto yystate16 - case c == '.': - goto yystate18 - case c == '/': - goto yystate24 - case c == '0': - goto yystate29 - case c == '<': - goto yystate36 - case c == '=': - goto yystate39 - case c == '>': - goto yystate41 - case c == 'A' || c == 'a': - goto yystate44 - case c == 'B' || c == 'b': - goto yystate56 - case c == 'C' || c == 'c': - goto yystate83 - case c == 'D' || c == 'd': - goto yystate107 - case c == 'E' || c == 'e': - goto yystate137 - case c == 'F' || c == 'f': - goto yystate148 - case c == 'G' || c == 'g': - goto yystate167 - case c == 'H' || c == 'K' || c == 'M' || c == 'P' || c == 'Q' || c >= 'X' && c <= 'Z' || c == '_' || c == 'h' || c == 'k' || c == 'm' || c == 'p' || c == 'q' || c >= 'x' && c <= 'z' || c == '\u0081': - goto yystate45 - case c == 'I' || c == 'i': - goto yystate172 - case c == 'J' || c == 'j': - goto yystate192 - case c == 'L' || c == 'l': - goto yystate196 - case c == 'N' || c == 'n': - goto yystate206 - case c == 'O' || c == 'o': - goto yystate212 - case c == 'R' || c == 'r': - goto yystate227 - case c == 'S' || c == 's': - goto yystate242 - case c == 'T' || c == 't': - goto yystate254 - case c == 'U' || c == 'u': - goto yystate279 - case c == 'V' || c == 'v': - goto yystate300 - case c == 'W' || c == 'w': - goto yystate306 - case c == '\'': - goto yystate12 - case c == '\t' || c == '\n' || c == '\r' || c == ' ': - goto yystate2 - case c == '\u0080': - goto yystate314 - case c == '`': - goto yystate311 - case c == '|': - goto yystate312 - case c >= '1' && c <= '9': - goto yystate35 - } - -yystate2: - c = l.Next() - yyrule = 2 - l.Mark() - switch { - default: - goto yyrule2 - case c == '\t' || c == '\n' || c == '\r' || c == ' ': - goto yystate2 - } - -yystate3: - c = l.Next() - switch { - default: - goto yyabort - case c == '=': - goto yystate4 - } - -yystate4: - c = l.Next() - yyrule = 15 - l.Mark() - goto yyrule15 - -yystate5: - c = l.Next() - yyrule = 10 - l.Mark() - goto yyrule10 - -yystate6: - c = l.Next() - switch { - default: - goto yyabort - case c >= '0' && c <= '9': - goto yystate7 - case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081': - goto yystate8 - } - -yystate7: - c = l.Next() - yyrule = 100 - l.Mark() - switch { - default: - goto yyrule100 - case c >= '0' && c <= '9': - goto yystate7 - } - -yystate8: - c = l.Next() - yyrule = 100 - l.Mark() - switch { - default: - goto yyrule100 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate8 - } - -yystate9: - c = l.Next() - switch { - default: - goto yyabort - case c == '&': - goto yystate10 - case c == '^': - goto yystate11 - } - -yystate10: - c = l.Next() - yyrule = 16 - l.Mark() - goto yyrule16 - -yystate11: - c = l.Next() - yyrule = 17 - l.Mark() - goto yyrule17 - -yystate12: - c = l.Next() - switch { - default: - goto yyabort - case c == '\'': - goto yystate13 - case c == '\\': - goto yystate14 - case c >= '\x01' && c <= '&' || c >= '(' && c <= '[' || c >= ']' && c <= 'ÿ': - goto yystate12 - } - -yystate13: - c = l.Next() - yyrule = 12 - l.Mark() - goto yyrule12 - -yystate14: - c = l.Next() - switch { - default: - goto yyabort - case c == '\'': - goto yystate15 - case c == '\\': - goto yystate14 - case c >= '\x01' && c <= '&' || c >= '(' && c <= '[' || c >= ']' && c <= 'ÿ': - goto yystate12 - } - -yystate15: - c = l.Next() - yyrule = 12 - l.Mark() - switch { - default: - goto yyrule12 - case c == '\'': - goto yystate13 - case c == '\\': - goto yystate14 - case c >= '\x01' && c <= '&' || c >= '(' && c <= '[' || c >= ']' && c <= 'ÿ': - goto yystate12 - } - -yystate16: - c = l.Next() - switch { - default: - goto yyabort - case c == '-': - goto yystate17 - } - -yystate17: - c = l.Next() - yyrule = 3 - l.Mark() - switch { - default: - goto yyrule3 - case c >= '\x01' && c <= '\t' || c >= '\v' && c <= 'ÿ': - goto yystate17 - } - -yystate18: - c = l.Next() - switch { - default: - goto yyabort - case c >= '0' && c <= '9': - goto yystate19 - } - -yystate19: - c = l.Next() - yyrule = 9 - l.Mark() - switch { - default: - goto yyrule9 - case c == 'E' || c == 'e': - goto yystate20 - case c == 'I' || c == 'i': - goto yystate23 - case c >= '0' && c <= '9': - goto yystate19 - } - -yystate20: - c = l.Next() - switch { - default: - goto yyabort - case c == '+' || c == '-': - goto yystate21 - case c >= '0' && c <= '9': - goto yystate22 - } - -yystate21: - c = l.Next() - switch { - default: - goto yyabort - case c >= '0' && c <= '9': - goto yystate22 - } - -yystate22: - c = l.Next() - yyrule = 9 - l.Mark() - switch { - default: - goto yyrule9 - case c == 'I' || c == 'i': - goto yystate23 - case c >= '0' && c <= '9': - goto yystate22 - } - -yystate23: - c = l.Next() - yyrule = 7 - l.Mark() - goto yyrule7 - -yystate24: - c = l.Next() - switch { - default: - goto yyabort - case c == '*': - goto yystate25 - case c == '/': - goto yystate28 - } - -yystate25: - c = l.Next() - switch { - default: - goto yyabort - case c == '*': - goto yystate26 - case c >= '\x01' && c <= ')' || c >= '+' && c <= 'ÿ': - goto yystate25 - } - -yystate26: - c = l.Next() - switch { - default: - goto yyabort - case c == '*': - goto yystate26 - case c == '/': - goto yystate27 - case c >= '\x01' && c <= ')' || c >= '+' && c <= '.' || c >= '0' && c <= 'ÿ': - goto yystate25 - } - -yystate27: - c = l.Next() - yyrule = 5 - l.Mark() - goto yyrule5 - -yystate28: - c = l.Next() - yyrule = 4 - l.Mark() - switch { - default: - goto yyrule4 - case c >= '\x01' && c <= '\t' || c >= '\v' && c <= 'ÿ': - goto yystate28 - } - -yystate29: - c = l.Next() - yyrule = 8 - l.Mark() - switch { - default: - goto yyrule8 - case c == '.': - goto yystate19 - case c == '8' || c == '9': - goto yystate31 - case c == 'E' || c == 'e': - goto yystate20 - case c == 'I' || c == 'i': - goto yystate32 - case c == 'X' || c == 'x': - goto yystate33 - case c >= '0' && c <= '7': - goto yystate30 - } - -yystate30: - c = l.Next() - yyrule = 8 - l.Mark() - switch { - default: - goto yyrule8 - case c == '.': - goto yystate19 - case c == '8' || c == '9': - goto yystate31 - case c == 'E' || c == 'e': - goto yystate20 - case c == 'I' || c == 'i': - goto yystate32 - case c >= '0' && c <= '7': - goto yystate30 - } - -yystate31: - c = l.Next() - switch { - default: - goto yyabort - case c == '.': - goto yystate19 - case c == 'E' || c == 'e': - goto yystate20 - case c == 'I' || c == 'i': - goto yystate32 - case c >= '0' && c <= '9': - goto yystate31 - } - -yystate32: - c = l.Next() - yyrule = 6 - l.Mark() - goto yyrule6 - -yystate33: - c = l.Next() - switch { - default: - goto yyabort - case c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f': - goto yystate34 - } - -yystate34: - c = l.Next() - yyrule = 8 - l.Mark() - switch { - default: - goto yyrule8 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f': - goto yystate34 - } - -yystate35: - c = l.Next() - yyrule = 8 - l.Mark() - switch { - default: - goto yyrule8 - case c == '.': - goto yystate19 - case c == 'E' || c == 'e': - goto yystate20 - case c == 'I' || c == 'i': - goto yystate32 - case c >= '0' && c <= '9': - goto yystate35 - } - -yystate36: - c = l.Next() - switch { - default: - goto yyabort - case c == '<': - goto yystate37 - case c == '=': - goto yystate38 - } - -yystate37: - c = l.Next() - yyrule = 18 - l.Mark() - goto yyrule18 - -yystate38: - c = l.Next() - yyrule = 19 - l.Mark() - goto yyrule19 - -yystate39: - c = l.Next() - switch { - default: - goto yyabort - case c == '=': - goto yystate40 - } - -yystate40: - c = l.Next() - yyrule = 20 - l.Mark() - goto yyrule20 - -yystate41: - c = l.Next() - switch { - default: - goto yyabort - case c == '=': - goto yystate42 - case c == '>': - goto yystate43 - } - -yystate42: - c = l.Next() - yyrule = 21 - l.Mark() - goto yyrule21 - -yystate43: - c = l.Next() - yyrule = 22 - l.Mark() - goto yyrule22 - -yystate44: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'D' || c == 'd': - goto yystate46 - case c == 'L' || c == 'l': - goto yystate48 - case c == 'N' || c == 'n': - goto yystate52 - case c == 'S' || c == 's': - goto yystate54 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'C' || c >= 'E' && c <= 'K' || c == 'M' || c >= 'O' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'c' || c >= 'e' && c <= 'k' || c == 'm' || c >= 'o' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate45: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate46: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'D' || c == 'd': - goto yystate47 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'C' || c >= 'E' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'c' || c >= 'e' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate47: - c = l.Next() - yyrule = 24 - l.Mark() - switch { - default: - goto yyrule24 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate48: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate49 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate49: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate50 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate50: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'R' || c == 'r': - goto yystate51 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate51: - c = l.Next() - yyrule = 25 - l.Mark() - switch { - default: - goto yyrule25 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate52: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'D' || c == 'd': - goto yystate53 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'C' || c >= 'E' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'c' || c >= 'e' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate53: - c = l.Next() - yyrule = 26 - l.Mark() - switch { - default: - goto yyrule26 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate54: - c = l.Next() - yyrule = 28 - l.Mark() - switch { - default: - goto yyrule28 - case c == 'C' || c == 'c': - goto yystate55 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate55: - c = l.Next() - yyrule = 27 - l.Mark() - switch { - default: - goto yyrule27 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate56: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate57 - case c == 'I' || c == 'i': - goto yystate66 - case c == 'L' || c == 'l': - goto yystate74 - case c == 'O' || c == 'o': - goto yystate77 - case c == 'Y' || c == 'y': - goto yystate80 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'H' || c == 'J' || c == 'K' || c == 'M' || c == 'N' || c >= 'P' && c <= 'X' || c == 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'h' || c == 'j' || c == 'k' || c == 'm' || c == 'n' || c >= 'p' && c <= 'x' || c == 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate57: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'G' || c == 'g': - goto yystate58 - case c == 'T' || c == 't': - goto yystate61 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'H' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'f' || c >= 'h' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate58: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate59 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate59: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate60 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate60: - c = l.Next() - yyrule = 29 - l.Mark() - switch { - default: - goto yyrule29 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate61: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'W' || c == 'w': - goto yystate62 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'V' || c >= 'X' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'v' || c >= 'x' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate62: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate63 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate63: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate64 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate64: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate65 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate65: - c = l.Next() - yyrule = 30 - l.Mark() - switch { - default: - goto yyrule30 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate66: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'G' || c == 'g': - goto yystate67 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'H' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'f' || c >= 'h' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate67: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate68 - case c == 'R' || c == 'r': - goto yystate71 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate68: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate69 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate69: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate70 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate70: - c = l.Next() - yyrule = 75 - l.Mark() - switch { - default: - goto yyrule75 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate71: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate72 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate72: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate73 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate73: - c = l.Next() - yyrule = 76 - l.Mark() - switch { - default: - goto yyrule76 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate74: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate75 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate75: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'B' || c == 'b': - goto yystate76 - case c >= '0' && c <= '9' || c == 'A' || c >= 'C' && c <= 'Z' || c == '_' || c == 'a' || c >= 'c' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate76: - c = l.Next() - yyrule = 77 - l.Mark() - switch { - default: - goto yyrule77 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate77: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate78 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate78: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate79 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate79: - c = l.Next() - yyrule = 78 - l.Mark() - switch { - default: - goto yyrule78 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate80: - c = l.Next() - yyrule = 31 - l.Mark() - switch { - default: - goto yyrule31 - case c == 'T' || c == 't': - goto yystate81 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate81: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate82 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate82: - c = l.Next() - yyrule = 79 - l.Mark() - switch { - default: - goto yyrule79 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate83: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate84 - case c == 'R' || c == 'r': - goto yystate102 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c == 'P' || c == 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c == 'p' || c == 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate84: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate85 - case c == 'M' || c == 'm': - goto yystate89 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'N' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'n' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate85: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'U' || c == 'u': - goto yystate86 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate86: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'M' || c == 'm': - goto yystate87 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'L' || c >= 'N' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'l' || c >= 'n' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate87: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate88 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate88: - c = l.Next() - yyrule = 32 - l.Mark() - switch { - default: - goto yyrule32 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate89: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'M' || c == 'm': - goto yystate90 - case c == 'P' || c == 'p': - goto yystate93 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'L' || c == 'N' || c == 'O' || c >= 'Q' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'l' || c == 'n' || c == 'o' || c >= 'q' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate90: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate91 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate91: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate92 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate92: - c = l.Next() - yyrule = 33 - l.Mark() - switch { - default: - goto yyrule33 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate93: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate94 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate94: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate95 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate95: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'X' || c == 'x': - goto yystate96 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'W' || c == 'Y' || c == 'Z' || c == '_' || c >= 'a' && c <= 'w' || c == 'y' || c == 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate96: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '0' || c >= '2' && c <= '5' || c >= '7' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - case c == '1': - goto yystate97 - case c == '6': - goto yystate100 - } - -yystate97: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '0' || c == '1' || c >= '3' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - case c == '2': - goto yystate98 - } - -yystate98: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '8': - goto yystate99 - case c >= '0' && c <= '7' || c == '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate99: - c = l.Next() - yyrule = 80 - l.Mark() - switch { - default: - goto yyrule80 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate100: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '4': - goto yystate101 - case c >= '0' && c <= '3' || c >= '5' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate101: - c = l.Next() - yyrule = 81 - l.Mark() - switch { - default: - goto yyrule81 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate102: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate103 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate103: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate104 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate104: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate105 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate105: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate106 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate106: - c = l.Next() - yyrule = 34 - l.Mark() - switch { - default: - goto yyrule34 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate107: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate108 - case c == 'I' || c == 'i': - goto yystate120 - case c == 'R' || c == 'r': - goto yystate127 - case c == 'U' || c == 'u': - goto yystate130 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'H' || c >= 'J' && c <= 'Q' || c == 'S' || c == 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'h' || c >= 'j' && c <= 'q' || c == 's' || c == 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate108: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'F' || c == 'f': - goto yystate109 - case c == 'L' || c == 'l': - goto yystate114 - case c == 'S' || c == 's': - goto yystate118 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'E' || c >= 'G' && c <= 'K' || c >= 'M' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'e' || c >= 'g' && c <= 'k' || c >= 'm' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate109: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate110 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate110: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'U' || c == 'u': - goto yystate111 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate111: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate112 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate112: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate113 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate113: - c = l.Next() - yyrule = 35 - l.Mark() - switch { - default: - goto yyrule35 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate114: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate115 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate115: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate116 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate116: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate117 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate117: - c = l.Next() - yyrule = 36 - l.Mark() - switch { - default: - goto yyrule36 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate118: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'C' || c == 'c': - goto yystate119 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate119: - c = l.Next() - yyrule = 37 - l.Mark() - switch { - default: - goto yyrule37 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate120: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'S' || c == 's': - goto yystate121 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate121: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate122 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate122: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate123 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate123: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate124 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate124: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'C' || c == 'c': - goto yystate125 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate125: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate126 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate126: - c = l.Next() - yyrule = 38 - l.Mark() - switch { - default: - goto yyrule38 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate127: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate128 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate128: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'P' || c == 'p': - goto yystate129 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'O' || c >= 'Q' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'o' || c >= 'q' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate129: - c = l.Next() - yyrule = 39 - l.Mark() - switch { - default: - goto yyrule39 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate130: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'R' || c == 'r': - goto yystate131 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate131: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate132 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate132: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate133 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate133: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate134 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate134: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate135 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate135: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate136 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate136: - c = l.Next() - yyrule = 82 - l.Mark() - switch { - default: - goto yyrule82 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate137: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'X' || c == 'x': - goto yystate138 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'W' || c == 'Y' || c == 'Z' || c == '_' || c >= 'a' && c <= 'w' || c == 'y' || c == 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate138: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate139 - case c == 'P' || c == 'p': - goto yystate143 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'O' || c >= 'Q' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'o' || c >= 'q' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate139: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'S' || c == 's': - goto yystate140 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate140: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate141 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate141: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'S' || c == 's': - goto yystate142 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate142: - c = l.Next() - yyrule = 40 - l.Mark() - switch { - default: - goto yyrule40 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate143: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate144 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate144: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate145 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate145: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate146 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate146: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate147 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate147: - c = l.Next() - yyrule = 41 - l.Mark() - switch { - default: - goto yyrule41 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate148: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate149 - case c == 'L' || c == 'l': - goto yystate153 - case c == 'R' || c == 'r': - goto yystate161 - case c == 'U' || c == 'u': - goto yystate164 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'K' || c >= 'M' && c <= 'Q' || c == 'S' || c == 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'k' || c >= 'm' && c <= 'q' || c == 's' || c == 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate149: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate150 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate150: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'S' || c == 's': - goto yystate151 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate151: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate152 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate152: - c = l.Next() - yyrule = 73 - l.Mark() - switch { - default: - goto yyrule73 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate153: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate154 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate154: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate155 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate155: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate156 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate156: - c = l.Next() - yyrule = 83 - l.Mark() - switch { - default: - goto yyrule83 - case c == '3': - goto yystate157 - case c == '6': - goto yystate159 - case c >= '0' && c <= '2' || c == '4' || c == '5' || c >= '7' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate157: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '0' || c == '1' || c >= '3' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - case c == '2': - goto yystate158 - } - -yystate158: - c = l.Next() - yyrule = 84 - l.Mark() - switch { - default: - goto yyrule84 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate159: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '4': - goto yystate160 - case c >= '0' && c <= '3' || c >= '5' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate160: - c = l.Next() - yyrule = 85 - l.Mark() - switch { - default: - goto yyrule85 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate161: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate162 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate162: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'M' || c == 'm': - goto yystate163 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'L' || c >= 'N' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'l' || c >= 'n' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate163: - c = l.Next() - yyrule = 42 - l.Mark() - switch { - default: - goto yyrule42 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate164: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate165 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate165: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate166 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate166: - c = l.Next() - yyrule = 43 - l.Mark() - switch { - default: - goto yyrule43 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate167: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'R' || c == 'r': - goto yystate168 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate168: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate169 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate169: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'U' || c == 'u': - goto yystate170 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate170: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'P' || c == 'p': - goto yystate171 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'O' || c >= 'Q' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'o' || c >= 'q' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate171: - c = l.Next() - yyrule = 44 - l.Mark() - switch { - default: - goto yyrule44 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate172: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'F' || c == 'f': - goto yystate173 - case c == 'N' || c == 'n': - goto yystate174 - case c == 'S' || c == 's': - goto yystate191 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'E' || c >= 'G' && c <= 'M' || c >= 'O' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'e' || c >= 'g' && c <= 'm' || c >= 'o' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate173: - c = l.Next() - yyrule = 45 - l.Mark() - switch { - default: - goto yyrule45 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate174: - c = l.Next() - yyrule = 49 - l.Mark() - switch { - default: - goto yyrule49 - case c == 'D' || c == 'd': - goto yystate175 - case c == 'S' || c == 's': - goto yystate178 - case c == 'T' || c == 't': - goto yystate182 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'C' || c >= 'E' && c <= 'R' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'c' || c >= 'e' && c <= 'r' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate175: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate176 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate176: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'X' || c == 'x': - goto yystate177 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'W' || c == 'Y' || c == 'Z' || c == '_' || c >= 'a' && c <= 'w' || c == 'y' || c == 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate177: - c = l.Next() - yyrule = 46 - l.Mark() - switch { - default: - goto yyrule46 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate178: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate179 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate179: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'R' || c == 'r': - goto yystate180 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate180: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate181 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate181: - c = l.Next() - yyrule = 47 - l.Mark() - switch { - default: - goto yyrule47 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate182: - c = l.Next() - yyrule = 86 - l.Mark() - switch { - default: - goto yyrule86 - case c == '0' || c == '2' || c == '4' || c == '5' || c == '7' || c == '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - case c == '1': - goto yystate183 - case c == '3': - goto yystate185 - case c == '6': - goto yystate187 - case c == '8': - goto yystate189 - case c == 'O' || c == 'o': - goto yystate190 - } - -yystate183: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '6': - goto yystate184 - case c >= '0' && c <= '5' || c >= '7' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate184: - c = l.Next() - yyrule = 87 - l.Mark() - switch { - default: - goto yyrule87 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate185: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '0' || c == '1' || c >= '3' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - case c == '2': - goto yystate186 - } - -yystate186: - c = l.Next() - yyrule = 88 - l.Mark() - switch { - default: - goto yyrule88 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate187: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '4': - goto yystate188 - case c >= '0' && c <= '3' || c >= '5' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate188: - c = l.Next() - yyrule = 89 - l.Mark() - switch { - default: - goto yyrule89 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate189: - c = l.Next() - yyrule = 90 - l.Mark() - switch { - default: - goto yyrule90 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate190: - c = l.Next() - yyrule = 48 - l.Mark() - switch { - default: - goto yyrule48 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate191: - c = l.Next() - yyrule = 50 - l.Mark() - switch { - default: - goto yyrule50 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate192: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate193 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate193: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate194 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate194: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate195 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate195: - c = l.Next() - yyrule = 51 - l.Mark() - switch { - default: - goto yyrule51 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate196: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate197 - case c == 'I' || c == 'i': - goto yystate200 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate197: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'F' || c == 'f': - goto yystate198 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'E' || c >= 'G' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'e' || c >= 'g' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate198: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate199 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate199: - c = l.Next() - yyrule = 52 - l.Mark() - switch { - default: - goto yyrule52 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate200: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'K' || c == 'k': - goto yystate201 - case c == 'M' || c == 'm': - goto yystate203 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'J' || c == 'L' || c >= 'N' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'j' || c == 'l' || c >= 'n' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate201: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate202 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate202: - c = l.Next() - yyrule = 53 - l.Mark() - switch { - default: - goto yyrule53 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate203: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate204 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate204: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate205 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate205: - c = l.Next() - yyrule = 54 - l.Mark() - switch { - default: - goto yyrule54 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate206: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate207 - case c == 'U' || c == 'u': - goto yystate209 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate207: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate208 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate208: - c = l.Next() - yyrule = 55 - l.Mark() - switch { - default: - goto yyrule55 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate209: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate210 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate210: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate211 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate211: - c = l.Next() - yyrule = 72 - l.Mark() - switch { - default: - goto yyrule72 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate212: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'F' || c == 'f': - goto yystate213 - case c == 'N' || c == 'n': - goto yystate218 - case c == 'R' || c == 'r': - goto yystate219 - case c == 'U' || c == 'u': - goto yystate223 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'E' || c >= 'G' && c <= 'M' || c >= 'O' && c <= 'Q' || c == 'S' || c == 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'e' || c >= 'g' && c <= 'm' || c >= 'o' && c <= 'q' || c == 's' || c == 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate213: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'F' || c == 'f': - goto yystate214 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'E' || c >= 'G' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'e' || c >= 'g' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate214: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'S' || c == 's': - goto yystate215 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate215: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate216 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate216: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate217 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate217: - c = l.Next() - yyrule = 56 - l.Mark() - switch { - default: - goto yyrule56 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate218: - c = l.Next() - yyrule = 57 - l.Mark() - switch { - default: - goto yyrule57 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate219: - c = l.Next() - yyrule = 59 - l.Mark() - switch { - default: - goto yyrule59 - case c == 'D' || c == 'd': - goto yystate220 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'C' || c >= 'E' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'c' || c >= 'e' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate220: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate221 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate221: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'R' || c == 'r': - goto yystate222 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate222: - c = l.Next() - yyrule = 58 - l.Mark() - switch { - default: - goto yyrule58 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate223: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate224 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate224: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate225 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate225: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'R' || c == 'r': - goto yystate226 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate226: - c = l.Next() - yyrule = 60 - l.Mark() - switch { - default: - goto yyrule60 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate227: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate228 - case c == 'O' || c == 'o': - goto yystate232 - case c == 'U' || c == 'u': - goto yystate239 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'N' || c >= 'P' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'n' || c >= 'p' && c <= 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate228: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'G' || c == 'g': - goto yystate229 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'H' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'f' || c >= 'h' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate229: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'H' || c == 'h': - goto yystate230 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'G' || c >= 'I' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'g' || c >= 'i' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate230: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate231 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate231: - c = l.Next() - yyrule = 61 - l.Mark() - switch { - default: - goto yyrule61 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate232: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate233 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate233: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate234 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate234: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'B' || c == 'b': - goto yystate235 - case c >= '0' && c <= '9' || c == 'A' || c >= 'C' && c <= 'Z' || c == '_' || c == 'a' || c >= 'c' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate235: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate236 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate236: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'C' || c == 'c': - goto yystate237 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate237: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'K' || c == 'k': - goto yystate238 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'J' || c >= 'L' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'j' || c >= 'l' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate238: - c = l.Next() - yyrule = 62 - l.Mark() - switch { - default: - goto yyrule62 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate239: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate240 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate240: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate241 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate241: - c = l.Next() - yyrule = 91 - l.Mark() - switch { - default: - goto yyrule91 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate242: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate243 - case c == 'T' || c == 't': - goto yystate249 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate243: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate244 - case c == 'T' || c == 't': - goto yystate248 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate244: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate245 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate245: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'C' || c == 'c': - goto yystate246 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate246: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate247 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate247: - c = l.Next() - yyrule = 63 - l.Mark() - switch { - default: - goto yyrule63 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate248: - c = l.Next() - yyrule = 64 - l.Mark() - switch { - default: - goto yyrule64 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate249: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'R' || c == 'r': - goto yystate250 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate250: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate251 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate251: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate252 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate252: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'G' || c == 'g': - goto yystate253 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'H' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'f' || c >= 'h' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate253: - c = l.Next() - yyrule = 92 - l.Mark() - switch { - default: - goto yyrule92 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate254: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate255 - case c == 'I' || c == 'i': - goto yystate259 - case c == 'R' || c == 'r': - goto yystate262 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'H' || c >= 'J' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'h' || c >= 'j' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate255: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'B' || c == 'b': - goto yystate256 - case c >= '0' && c <= '9' || c == 'A' || c >= 'C' && c <= 'Z' || c == '_' || c == 'a' || c >= 'c' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate256: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate257 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate257: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate258 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate258: - c = l.Next() - yyrule = 65 - l.Mark() - switch { - default: - goto yyrule65 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate259: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'M' || c == 'm': - goto yystate260 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'L' || c >= 'N' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'l' || c >= 'n' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate260: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate261 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate261: - c = l.Next() - yyrule = 93 - l.Mark() - switch { - default: - goto yyrule93 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate262: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate263 - case c == 'U' || c == 'u': - goto yystate272 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'b' && c <= 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate263: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate264 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate264: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'S' || c == 's': - goto yystate265 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate265: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate266 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate266: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'C' || c == 'c': - goto yystate267 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate267: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate268 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate268: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate269 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate269: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'O' || c == 'o': - goto yystate270 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'N' || c >= 'P' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'n' || c >= 'p' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate270: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate271 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate271: - c = l.Next() - yyrule = 66 - l.Mark() - switch { - default: - goto yyrule66 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate272: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate273 - case c == 'N' || c == 'n': - goto yystate274 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate273: - c = l.Next() - yyrule = 74 - l.Mark() - switch { - default: - goto yyrule74 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate274: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'C' || c == 'c': - goto yystate275 - case c >= '0' && c <= '9' || c == 'A' || c == 'B' || c >= 'D' && c <= 'Z' || c == '_' || c == 'a' || c == 'b' || c >= 'd' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate275: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate276 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate276: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate277 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate277: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate278 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate278: - c = l.Next() - yyrule = 67 - l.Mark() - switch { - default: - goto yyrule67 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate279: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate280 - case c == 'N' || c == 'n': - goto yystate290 - case c == 'P' || c == 'p': - goto yystate295 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'M' || c == 'O' || c >= 'Q' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'm' || c == 'o' || c >= 'q' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate280: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'N' || c == 'n': - goto yystate281 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'M' || c >= 'O' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'm' || c >= 'o' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate281: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate282 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate282: - c = l.Next() - yyrule = 94 - l.Mark() - switch { - default: - goto yyrule94 - case c == '0' || c == '2' || c == '4' || c == '5' || c == '7' || c == '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - case c == '1': - goto yystate283 - case c == '3': - goto yystate285 - case c == '6': - goto yystate287 - case c == '8': - goto yystate289 - } - -yystate283: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '6': - goto yystate284 - case c >= '0' && c <= '5' || c >= '7' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate284: - c = l.Next() - yyrule = 95 - l.Mark() - switch { - default: - goto yyrule95 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate285: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '0' || c == '1' || c >= '3' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - case c == '2': - goto yystate286 - } - -yystate286: - c = l.Next() - yyrule = 96 - l.Mark() - switch { - default: - goto yyrule96 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate287: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == '4': - goto yystate288 - case c >= '0' && c <= '3' || c >= '5' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate288: - c = l.Next() - yyrule = 97 - l.Mark() - switch { - default: - goto yyrule97 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate289: - c = l.Next() - yyrule = 98 - l.Mark() - switch { - default: - goto yyrule98 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate290: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'I' || c == 'i': - goto yystate291 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'H' || c >= 'J' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'h' || c >= 'j' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate291: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'Q' || c == 'q': - goto yystate292 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'P' || c >= 'R' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'p' || c >= 'r' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate292: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'U' || c == 'u': - goto yystate293 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate293: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate294 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate294: - c = l.Next() - yyrule = 69 - l.Mark() - switch { - default: - goto yyrule69 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate295: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'D' || c == 'd': - goto yystate296 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'C' || c >= 'E' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'c' || c >= 'e' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate296: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate297 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate297: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'T' || c == 't': - goto yystate298 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'S' || c >= 'U' && c <= 'Z' || c == '_' || c >= 'a' && c <= 's' || c >= 'u' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate298: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate299 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate299: - c = l.Next() - yyrule = 68 - l.Mark() - switch { - default: - goto yyrule68 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate300: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'A' || c == 'a': - goto yystate301 - case c >= '0' && c <= '9' || c >= 'B' && c <= 'Z' || c == '_' || c >= 'b' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate301: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'L' || c == 'l': - goto yystate302 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'K' || c >= 'M' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'k' || c >= 'm' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate302: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'U' || c == 'u': - goto yystate303 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'T' || c >= 'V' && c <= 'Z' || c == '_' || c >= 'a' && c <= 't' || c >= 'v' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate303: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate304 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate304: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'S' || c == 's': - goto yystate305 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'R' || c >= 'T' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'r' || c >= 't' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate305: - c = l.Next() - yyrule = 70 - l.Mark() - switch { - default: - goto yyrule70 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate306: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'H' || c == 'h': - goto yystate307 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'G' || c >= 'I' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'g' || c >= 'i' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate307: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate308 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate308: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'R' || c == 'r': - goto yystate309 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Q' || c >= 'S' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'q' || c >= 's' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate309: - c = l.Next() - yyrule = 99 - l.Mark() - switch { - default: - goto yyrule99 - case c == 'E' || c == 'e': - goto yystate310 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'D' || c >= 'F' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'd' || c >= 'f' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate310: - c = l.Next() - yyrule = 71 - l.Mark() - switch { - default: - goto yyrule71 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == '\u0081' || c == '\u0082': - goto yystate45 - } - -yystate311: - c = l.Next() - yyrule = 11 - l.Mark() - goto yyrule11 - -yystate312: - c = l.Next() - switch { - default: - goto yyabort - case c == '|': - goto yystate313 - } - -yystate313: - c = l.Next() - yyrule = 23 - l.Mark() - goto yyrule23 - -yystate314: - c = l.Next() - yyrule = 1 - l.Mark() - goto yyrule1 - - goto yystate315 // silence unused label error -yystate315: - c = l.Next() -yystart315: - switch { - default: - goto yyabort - case c == '"': - goto yystate317 - case c == '\\': - goto yystate318 - case c == '\u0080': - goto yystate320 - case c >= '\x01' && c <= '!' || c >= '#' && c <= '[' || c >= ']' && c <= '\u007f' || c >= '\u0081' && c <= 'ÿ': - goto yystate316 - } - -yystate316: - c = l.Next() - switch { - default: - goto yyabort - case c == '"': - goto yystate317 - case c == '\\': - goto yystate318 - case c >= '\x01' && c <= '!' || c >= '#' && c <= '[' || c >= ']' && c <= 'ÿ': - goto yystate316 - } - -yystate317: - c = l.Next() - yyrule = 13 - l.Mark() - goto yyrule13 - -yystate318: - c = l.Next() - switch { - default: - goto yyabort - case c == '"': - goto yystate319 - case c == '\\': - goto yystate318 - case c >= '\x01' && c <= '!' || c >= '#' && c <= '[' || c >= ']' && c <= 'ÿ': - goto yystate316 - } - -yystate319: - c = l.Next() - yyrule = 13 - l.Mark() - switch { - default: - goto yyrule13 - case c == '"': - goto yystate317 - case c == '\\': - goto yystate318 - case c >= '\x01' && c <= '!' || c >= '#' && c <= '[' || c >= ']' && c <= 'ÿ': - goto yystate316 - } - -yystate320: - c = l.Next() - yyrule = 1 - l.Mark() - switch { - default: - goto yyrule1 - case c == '"': - goto yystate317 - case c == '\\': - goto yystate318 - case c >= '\x01' && c <= '!' || c >= '#' && c <= '[' || c >= ']' && c <= 'ÿ': - goto yystate316 - } - - goto yystate321 // silence unused label error -yystate321: - c = l.Next() -yystart321: - switch { - default: - goto yyabort - case c == '\u0080': - goto yystate324 - case c == '`': - goto yystate323 - case c >= '\x01' && c <= '_' || c >= 'a' && c <= '\u007f' || c >= '\u0081' && c <= 'ÿ': - goto yystate322 - } - -yystate322: - c = l.Next() - switch { - default: - goto yyabort - case c == '`': - goto yystate323 - case c >= '\x01' && c <= '_' || c >= 'a' && c <= 'ÿ': - goto yystate322 - } - -yystate323: - c = l.Next() - yyrule = 14 - l.Mark() - goto yyrule14 - -yystate324: - c = l.Next() - yyrule = 1 - l.Mark() - switch { - default: - goto yyrule1 - case c == '`': - goto yystate323 - case c >= '\x01' && c <= '_' || c >= 'a' && c <= 'ÿ': - goto yystate322 - } - -yyrule1: // \x80 - { - return 0 - } -yyrule2: // [ \t\n\r]+ - - goto yystate0 -yyrule3: // --.* - - goto yystate0 -yyrule4: // \/\/.* - - goto yystate0 -yyrule5: // \/\*([^*]|\*+[^*/])*\*+\/ - - goto yystate0 -yyrule6: // {imaginary_ilit} - { - return l.int(lval, true) - } -yyrule7: // {imaginary_lit} - { - return l.float(lval, true) - } -yyrule8: // {int_lit} - { - return l.int(lval, false) - } -yyrule9: // {float_lit} - { - return l.float(lval, false) - } -yyrule10: // \" - { - l.sc = S1 - goto yystate0 - } -yyrule11: // ` - { - l.sc = S2 - goto yystate0 - } -yyrule12: // '(\\.|[^'])*' - { - if ret := l.str(lval, ""); ret != stringLit { - return ret - } - lval.item = idealRune(lval.item.(string)[0]) - return intLit - } -yyrule13: // (\\.|[^\"])*\" - { - return l.str(lval, "\"") - } -yyrule14: // ([^`]|\n)*` - { - return l.str(lval, "`") - } -yyrule15: // "!=" - { - return neq - } -yyrule16: // "&&" - { - return andand - } -yyrule17: // "&^" - { - return andnot - } -yyrule18: // "<<" - { - return lsh - } -yyrule19: // "<=" - { - return le - } -yyrule20: // "==" - { - return eq - } -yyrule21: // ">=" - { - return ge - } -yyrule22: // ">>" - { - return rsh - } -yyrule23: // "||" - { - return oror - } -yyrule24: // {add} - { - return add - } -yyrule25: // {alter} - { - return alter - } -yyrule26: // {and} - { - return and - } -yyrule27: // {asc} - { - return asc - } -yyrule28: // {as} - { - return as - } -yyrule29: // {begin} - { - return begin - } -yyrule30: // {between} - { - return between - } -yyrule31: // {by} - { - return by - } -yyrule32: // {column} - { - return column - } -yyrule33: // {commit} - { - return commit - } -yyrule34: // {create} - { - return create - } -yyrule35: // {default} - { - return defaultKwd - } -yyrule36: // {delete} - { - return deleteKwd - } -yyrule37: // {desc} - { - return desc - } -yyrule38: // {distinct} - { - return distinct - } -yyrule39: // {drop} - { - return drop - } -yyrule40: // {exists} - { - return exists - } -yyrule41: // {explain} - { - return explain - } -yyrule42: // {from} - { - return from - } -yyrule43: // {full} - { - return full - } -yyrule44: // {group} - { - return group - } -yyrule45: // {if} - { - return ifKwd - } -yyrule46: // {index} - { - return index - } -yyrule47: // {insert} - { - return insert - } -yyrule48: // {into} - { - return into - } -yyrule49: // {in} - { - return in - } -yyrule50: // {is} - { - return is - } -yyrule51: // {join} - { - return join - } -yyrule52: // {left} - { - return left - } -yyrule53: // {like} - { - return like - } -yyrule54: // {limit} - { - return limit - } -yyrule55: // {not} - { - return not - } -yyrule56: // {offset} - { - return offset - } -yyrule57: // {on} - { - return on - } -yyrule58: // {order} - { - return order - } -yyrule59: // {or} - { - return or - } -yyrule60: // {outer} - { - return outer - } -yyrule61: // {right} - { - return right - } -yyrule62: // {rollback} - { - return rollback - } -yyrule63: // {select} - { - l.agg = append(l.agg, false) - return selectKwd - } -yyrule64: // {set} - { - return set - } -yyrule65: // {table} - { - return tableKwd - } -yyrule66: // {transaction} - { - return transaction - } -yyrule67: // {truncate} - { - return truncate - } -yyrule68: // {update} - { - return update - } -yyrule69: // {unique} - { - return unique - } -yyrule70: // {values} - { - return values - } -yyrule71: // {where} - { - return where - } -yyrule72: // {null} - { - lval.item = nil - return null - } -yyrule73: // {false} - { - lval.item = false - return falseKwd - } -yyrule74: // {true} - { - lval.item = true - return trueKwd - } -yyrule75: // {bigint} - { - lval.item = qBigInt - return bigIntType - } -yyrule76: // {bigrat} - { - lval.item = qBigRat - return bigRatType - } -yyrule77: // {blob} - { - lval.item = qBlob - return blobType - } -yyrule78: // {bool} - { - lval.item = qBool - return boolType - } -yyrule79: // {byte} - { - lval.item = qUint8 - return byteType - } -yyrule80: // {complex}128 - { - lval.item = qComplex128 - return complex128Type - } -yyrule81: // {complex}64 - { - lval.item = qComplex64 - return complex64Type - } -yyrule82: // {duration} - { - lval.item = qDuration - return durationType - } -yyrule83: // {float} - { - lval.item = qFloat64 - return floatType - } -yyrule84: // {float}32 - { - lval.item = qFloat32 - return float32Type - } -yyrule85: // {float}64 - { - lval.item = qFloat64 - return float64Type - } -yyrule86: // {int} - { - lval.item = qInt64 - return intType - } -yyrule87: // {int}16 - { - lval.item = qInt16 - return int16Type - } -yyrule88: // {int}32 - { - lval.item = qInt32 - return int32Type - } -yyrule89: // {int}64 - { - lval.item = qInt64 - return int64Type - } -yyrule90: // {int}8 - { - lval.item = qInt8 - return int8Type - } -yyrule91: // {rune} - { - lval.item = qInt32 - return runeType - } -yyrule92: // {string} - { - lval.item = qString - return stringType - } -yyrule93: // {time} - { - lval.item = qTime - return timeType - } -yyrule94: // {uint} - { - lval.item = qUint64 - return uintType - } -yyrule95: // {uint}16 - { - lval.item = qUint16 - return uint16Type - } -yyrule96: // {uint}32 - { - lval.item = qUint32 - return uint32Type - } -yyrule97: // {uint}64 - { - lval.item = qUint64 - return uint64Type - } -yyrule98: // {uint}8 - { - lval.item = qUint8 - return uint8Type - } -yyrule99: // {ident} - { - lval.item = string(l.TokenBytes(nil)) - return identifier - } -yyrule100: // ($|\?)({D}|{ident}) - { - s := string(l.TokenBytes(nil)[1:]) - lval.item, _ = strconv.Atoi(s) - if s != "" && s[0] < '1' || s[0] > '9' { - l.err("parameter number must be non zero") - } - return qlParam - } - panic("unreachable") - - goto yyabort // silence unused label error - -yyabort: // no lexem recognized - if c, ok := l.Abort(); ok { - return c - } - - goto yyAction -} diff --git a/vendor/github.com/cznic/ql/stmt.go b/vendor/github.com/cznic/ql/stmt.go deleted file mode 100644 index 9dd2e546a..000000000 --- a/vendor/github.com/cznic/ql/stmt.go +++ /dev/null @@ -1,1289 +0,0 @@ -// Copyright (c) 2014 ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "bytes" - "fmt" - "strings" - - "sync" - - "github.com/cznic/strutil" -) - -// NOTE: all stmt implementations must be safe for concurrent use by multiple -// goroutines. If the exec method requires any execution domain local data, -// they must be held out of the implementing instance. -var ( - _ stmt = (*alterTableAddStmt)(nil) - _ stmt = (*alterTableDropColumnStmt)(nil) - _ stmt = (*createIndexStmt)(nil) - _ stmt = (*createTableStmt)(nil) - _ stmt = (*deleteStmt)(nil) //TODO optimizer plan - _ stmt = (*dropIndexStmt)(nil) - _ stmt = (*dropTableStmt)(nil) - _ stmt = (*explainStmt)(nil) - _ stmt = (*insertIntoStmt)(nil) - _ stmt = (*selectStmt)(nil) - _ stmt = (*truncateTableStmt)(nil) - _ stmt = (*updateStmt)(nil) //TODO optimizer plan - _ stmt = beginTransactionStmt{} - _ stmt = commitStmt{} - _ stmt = rollbackStmt{} -) - -var ( - createColumn2 = mustCompile(` - create table if not exists __Column2 ( - TableName string, - Name string, - NotNull bool, - ConstraintExpr string, - DefaultExpr string, - ); - create index if not exists __Column2TableName on __Column2(TableName); - `) - - insertColumn2 = mustCompile(`insert into __Column2 values($1, $2, $3, $4, $5)`) - - selectColumn2 = MustCompile(` - select Name, NotNull, ConstraintExpr, DefaultExpr - from __Column2 - where TableName == $1 - `) - - deleteColumn2 = mustCompile(` - delete from __Column2 - where TableName == $1 && Name == $2 - `) - - createIndex2 = mustCompile(` - // Index register 2. - create table if not exists __Index2( - TableName string, - IndexName string, - IsUnique bool, - IsSimple bool, // Just a column name or id(). - Root int64, // BTree handle - ); - - // Expressions for given index. Compared in order of id(__Index2_Expr). - create table if not exists __Index2_Expr( - Index2_ID int, - Expr string, - ); - - create index if not exists __xIndex2_TableName on __Index2(TableName); - create unique index if not exists __xIndex2_IndexName on __Index2(IndexName); - create index if not exists __xIndex2_ID on __Index2(id()); - create index if not exists __xIndex2_Expr_Index2_ID on __Index2_Expr(Index2_ID); -`) - - insertIndex2 = mustCompile("insert into __Index2 values($1, $2, $3, $4, $5)") - insertIndex2Expr = mustCompile("insert into __Index2_Expr values($1, $2)") - - deleteIndex2ByIndexName = mustCompile(` - delete from __Index2_Expr - where Index2_ID in ( - select id() from __Index2 where IndexName == $1; - ); - - delete from __Index2 - where IndexName == $1; -`) - deleteIndex2ByTableName = mustCompile(` - delete from __Index2_Expr - where Index2_ID in ( - select id() from __Index2 where TableName == $1; - ); - - delete from __Index2 - where TableName == $1; -`) -) - -type stmt interface { - // never invoked for - // - beginTransactionStmt - // - commitStmt - // - rollbackStmt - exec(ctx *execCtx) (Recordset, error) - - explain(ctx *execCtx, w strutil.Formatter) - - // return value ignored for - // - beginTransactionStmt - // - commitStmt - // - rollbackStmt - isUpdating() bool - String() string -} - -type execCtx struct { //LATER +shared temp - db *DB - arg []interface{} - cache map[interface{}]interface{} - mu sync.RWMutex -} - -func newExecCtx(db *DB, arg []interface{}) *execCtx { - return &execCtx{ - db: db, - arg: arg, - cache: make(map[interface{}]interface{}), - } -} - -type explainStmt struct { - s stmt -} - -func (s *explainStmt) explain(ctx *execCtx, w strutil.Formatter) { - for { - x, ok := s.s.(*explainStmt) - if !ok { - s.s.explain(ctx, w) - return - } - - s = x - } -} - -func (s *explainStmt) String() string { - return "EXPLAIN " + s.s.String() -} - -func (*explainStmt) isUpdating() bool { return false } - -func (s *explainStmt) exec(ctx *execCtx) (_ Recordset, err error) { - return recordset{ctx, &explainDefaultPlan{s.s}, ctx.db.cc}, nil -} - -type updateStmt struct { - tableName string - list []assignment - where expression -} - -func (s *updateStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *updateStmt) String() string { - u := fmt.Sprintf("UPDATE %s", s.tableName) - a := make([]string, len(s.list)) - for i, v := range s.list { - a[i] = v.String() - } - w := "" - if s.where != nil { - w = fmt.Sprintf(" WHERE %s", s.where) - } - return fmt.Sprintf("%s %s%s;", u, strings.Join(a, ", "), w) -} - -func (s *updateStmt) exec(ctx *execCtx) (_ Recordset, err error) { - t, ok := ctx.db.root.tables[s.tableName] - if !ok { - return nil, fmt.Errorf("UPDATE: table %s does not exist", s.tableName) - } - - tcols := make([]*col, len(s.list)) - for i, asgn := range s.list { - col := findCol(t.cols, asgn.colName) - if col == nil { - return nil, fmt.Errorf("UPDATE: unknown column %s", asgn.colName) - } - tcols[i] = col - } - - m := map[interface{}]interface{}{} - var nh int64 - expr := s.where - blobCols := t.blobCols() - cc := ctx.db.cc - var old []interface{} - var touched []bool - if t.hasIndices() { - old = make([]interface{}, len(t.cols0)) - touched = make([]bool, len(t.cols0)) - } - for h := t.head; h != 0; h = nh { - // Read can return lazily expanded chunks - data, err := t.store.Read(nil, h, t.cols...) - if err != nil { - return nil, err - } - - nh = data[0].(int64) - for _, col := range t.cols { - m[col.name] = data[2+col.index] - } - id := data[1].(int64) - m["$id"] = id - if expr != nil { - val, err := s.where.eval(ctx, m) - if err != nil { - return nil, err - } - - if val == nil { - continue - } - - x, ok := val.(bool) - if !ok { - return nil, fmt.Errorf("invalid WHERE expression %s (value of type %T)", val, val) - } - - if !x { - continue - } - } - - // hit - for _, ix := range t.indices2 { - vlist, err := ix.eval(ctx, t.cols, id, data[2:]) - if err != nil { - return nil, err - } - - if err := ix.x.Delete(vlist, h); err != nil { - return nil, err - } - } - for i, asgn := range s.list { - val, err := asgn.expr.eval(ctx, m) - if err != nil { - return nil, err - } - - colIndex := tcols[i].index - if t.hasIndices() { - old[colIndex] = data[2+colIndex] - touched[colIndex] = true - } - data[2+colIndex] = val - } - if err = typeCheck(data[2:], t.cols); err != nil { - return nil, err - } - - if err = t.checkConstraintsAndDefaults(ctx, data[2:], m); err != nil { - return nil, err - } - - for i, v := range t.indices { - if i == 0 { // id() N/A - continue - } - - if v == nil || !touched[i-1] { - continue - } - - if err = v.x.Delete([]interface{}{old[i-1]}, h); err != nil { - return nil, err - } - } - - if err = t.store.UpdateRow(h, blobCols, data...); err != nil { //LATER detect which blobs are actually affected - return nil, err - } - - for i, v := range t.indices { - if i == 0 { // id() N/A - continue - } - - if v == nil || !touched[i-1] { - continue - } - - if err = v.x.Create([]interface{}{data[2+i-1]}, h); err != nil { - return nil, err - } - } - for _, ix := range t.indices2 { - vlist, err := ix.eval(ctx, t.cols, id, data[2:]) - if err != nil { - return nil, err - } - - if err := ix.x.Create(vlist, h); err != nil { - return nil, err - } - } - - cc.RowsAffected++ - } - return -} - -func (s *updateStmt) isUpdating() bool { return true } - -type deleteStmt struct { - tableName string - where expression -} - -func (s *deleteStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *deleteStmt) String() string { - switch { - case s.where == nil: - return fmt.Sprintf("DELETE FROM %s;", s.tableName) - default: - return fmt.Sprintf("DELETE FROM %s WHERE %s;", s.tableName, s.where) - } -} - -func (s *deleteStmt) exec(ctx *execCtx) (_ Recordset, err error) { - t, ok := ctx.db.root.tables[s.tableName] - if !ok { - return nil, fmt.Errorf("DELETE FROM: table %s does not exist", s.tableName) - } - - m := map[interface{}]interface{}{} - var ph, h, nh int64 - var data []interface{} - blobCols := t.blobCols() - cc := ctx.db.cc - for h = t.head; h != 0; ph, h = h, nh { - for i, v := range data { - c, ok := v.(chunk) - if !ok { - continue - } - - data[i] = c.b - } - // Read can return lazily expanded chunks - data, err = t.store.Read(nil, h, t.cols...) - if err != nil { - return nil, err - } - - nh = data[0].(int64) - for _, col := range t.cols { - m[col.name] = data[2+col.index] - } - id := data[1].(int64) - m["$id"] = id - val, err := s.where.eval(ctx, m) - if err != nil { - return nil, err - } - - if val == nil { - continue - } - - x, ok := val.(bool) - if !ok { - return nil, fmt.Errorf("invalid WHERE expression %s (value of type %T)", val, val) - } - - if !x { - continue - } - - // hit - for i, v := range t.indices { - if v == nil { - continue - } - - // overflow chunks left in place - if err = v.x.Delete([]interface{}{data[i+1]}, h); err != nil { - return nil, err - } - } - for _, ix := range t.indices2 { - vlist, err := ix.eval(ctx, t.cols, id, data[2:]) - if err != nil { - return nil, err - } - - if err := ix.x.Delete(vlist, h); err != nil { - return nil, err - } - } - - // overflow chunks freed here - if err = t.store.Delete(h, blobCols...); err != nil { - return nil, err - } - - cc.RowsAffected++ - switch { - case ph == 0 && nh == 0: // "only" - fallthrough - case ph == 0 && nh != 0: // "first" - if err = t.store.Update(t.hhead, nh); err != nil { - return nil, err - } - - t.head, h = nh, 0 - case ph != 0 && nh == 0: // "last" - fallthrough - case ph != 0 && nh != 0: // "inner" - pdata, err := t.store.Read(nil, ph, t.cols...) - if err != nil { - return nil, err - } - - for i, v := range pdata { - if x, ok := v.(chunk); ok { - pdata[i] = x.b - } - } - pdata[0] = nh - if err = t.store.Update(ph, pdata...); err != nil { - return nil, err - } - - h = ph - } - } - - return -} - -func (s *deleteStmt) isUpdating() bool { return true } - -type truncateTableStmt struct { - tableName string -} - -func (s *truncateTableStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *truncateTableStmt) String() string { return fmt.Sprintf("TRUNCATE TABLE %s;", s.tableName) } - -func (s *truncateTableStmt) exec(ctx *execCtx) (Recordset, error) { - t, ok := ctx.db.root.tables[s.tableName] - if !ok { - return nil, fmt.Errorf("TRUNCATE TABLE: table %s does not exist", s.tableName) - } - - return nil, t.truncate() -} - -func (s *truncateTableStmt) isUpdating() bool { return true } - -type dropIndexStmt struct { - ifExists bool - indexName string -} - -func (s *dropIndexStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *dropIndexStmt) String() string { return fmt.Sprintf("DROP INDEX %s;", s.indexName) } - -func (s *dropIndexStmt) exec(ctx *execCtx) (Recordset, error) { - t, x := ctx.db.root.findIndexByName(s.indexName) - if x == nil { - if s.ifExists { - return nil, nil - } - - return nil, fmt.Errorf("DROP INDEX: index %s does not exist", s.indexName) - } - - if ctx.db.hasAllIndex2() { - if err := ctx.db.deleteIndex2ByIndexName(s.indexName); err != nil { - return nil, err - } - } - - switch ix := x.(type) { - case *indexedCol: - for i, v := range t.indices { - if v == nil || v.name != s.indexName { - continue - } - - return nil, t.dropIndex(i) - } - case *index2: - delete(t.indices2, s.indexName) - return nil, ix.x.Drop() - } - - panic("internal error 058") -} - -func (s *dropIndexStmt) isUpdating() bool { return true } - -type dropTableStmt struct { - ifExists bool - tableName string -} - -func (s *dropTableStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *dropTableStmt) String() string { return fmt.Sprintf("DROP TABLE %s;", s.tableName) } - -func (s *dropTableStmt) exec(ctx *execCtx) (Recordset, error) { - t, ok := ctx.db.root.tables[s.tableName] - if !ok { - if s.ifExists { - return nil, nil - } - - return nil, fmt.Errorf("DROP TABLE: table %s does not exist", s.tableName) - } - - if ctx.db.hasAllIndex2() { - if err := ctx.db.deleteIndex2ByTableName(s.tableName); err != nil { - return nil, err - } - } - - return nil, ctx.db.root.dropTable(t) -} - -func (s *dropTableStmt) isUpdating() bool { return true } - -type alterTableDropColumnStmt struct { - tableName, colName string -} - -func (s *alterTableDropColumnStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *alterTableDropColumnStmt) String() string { - return fmt.Sprintf("ALTER TABLE %s DROP COLUMN %s;", s.tableName, s.colName) -} - -func (s *alterTableDropColumnStmt) exec(ctx *execCtx) (Recordset, error) { - t, ok := ctx.db.root.tables[s.tableName] - if !ok { - return nil, fmt.Errorf("ALTER TABLE: table %s does not exist", s.tableName) - } - - cols := t.cols - for _, c := range cols { - if c.name == s.colName { - if len(cols) == 1 { - return nil, fmt.Errorf("ALTER TABLE %s DROP COLUMN: cannot drop the only column: %s", s.tableName, s.colName) - } - - if _, ok := ctx.db.root.tables["__Column2"]; ok { - if _, err := deleteColumn2.l[0].exec(newExecCtx(ctx.db, []interface{}{s.tableName, c.name})); err != nil { - return nil, err - } - } - - c.name = "" - t.cols0[c.index].name = "" - if t.hasIndices() { - if len(t.indices) != 0 { - if v := t.indices[c.index+1]; v != nil { - if err := t.dropIndex(c.index + 1); err != nil { - return nil, err - } - - if ctx.db.hasAllIndex2() { - if err := ctx.db.deleteIndex2ByIndexName(v.name); err != nil { - return nil, err - } - } - } - } - - for nm, ix := range t.indices2 { - for _, e := range ix.exprList { - m := mentionedColumns(e) - if _, ok := m[s.colName]; ok { - if err := ctx.db.deleteIndex2ByIndexName(nm); err != nil { - return nil, err - } - - if err := ix.x.Drop(); err != nil { - return nil, err - } - - delete(t.indices2, nm) - break - } - } - } - } - if err := t.constraintsAndDefaults(ctx); err != nil { - return nil, err - } - - return nil, t.updated() - } - } - - return nil, fmt.Errorf("ALTER TABLE %s DROP COLUMN: column %s does not exist", s.tableName, s.colName) -} - -func (s *alterTableDropColumnStmt) isUpdating() bool { return true } - -type alterTableAddStmt struct { - tableName string - c *col -} - -func (s *alterTableAddStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *alterTableAddStmt) String() string { - r := fmt.Sprintf("ALTER TABLE %s ADD %s %s", s.tableName, s.c.name, typeStr(s.c.typ)) - c := s.c - if x := c.constraint; x != nil { //TODO add (*col).String() - switch e := x.expr; { - case e != nil: - r += " " + e.String() - default: - r += " NOT NULL" - } - } - if x := c.dflt; x != nil { - r += " DEFAULT " + x.String() - } - return r + ";" -} - -func (s *alterTableAddStmt) exec(ctx *execCtx) (Recordset, error) { - t, ok := ctx.db.root.tables[s.tableName] - if !ok { - return nil, fmt.Errorf("ALTER TABLE: table %s does not exist", s.tableName) - } - - hasRecords := t.head != 0 - c := s.c - if c.constraint != nil && hasRecords { - return nil, fmt.Errorf("ALTER TABLE %s ADD %s: cannot add constrained column to table with existing data", s.tableName, c.name) - } - - cols := t.cols - for _, c := range cols { - nm := c.name - if nm == s.c.name { - return nil, fmt.Errorf("ALTER TABLE %s ADD: column %s exists", s.tableName, nm) - } - } - - if len(t.indices) != 0 { - t.indices = append(t.indices, nil) - t.xroots = append(t.xroots, 0) - if err := t.store.Update(t.hxroots, t.xroots...); err != nil { - return nil, err - } - } - - if c.constraint != nil || c.dflt != nil { - for _, s := range createColumn2.l { - _, err := s.exec(newExecCtx(ctx.db, nil)) - if err != nil { - return nil, err - } - } - notNull := c.constraint != nil && c.constraint.expr == nil - var co, d string - if c.constraint != nil && c.constraint.expr != nil { - co = c.constraint.expr.String() - } - if e := c.dflt; e != nil { - d = e.String() - } - if _, err := insertColumn2.l[0].exec(newExecCtx(ctx.db, []interface{}{s.tableName, c.name, notNull, co, d})); err != nil { - return nil, err - } - } - - t.cols0 = append(t.cols0, s.c) - if err := t.constraintsAndDefaults(ctx); err != nil { - return nil, err - } - - return nil, t.updated() -} - -func (s *alterTableAddStmt) isUpdating() bool { return true } - -type selectStmt struct { - distinct bool - flds []*fld - from *joinRset - group *groupByRset - hasAggregates bool - limit *limitRset - offset *offsetRset - order *orderByRset - where *whereRset -} - -func (s *selectStmt) explain(ctx *execCtx, w strutil.Formatter) { - p, err := s.plan(ctx) - if err != nil { - w.Format("ERROR: %v\n", err) - return - } - - p.explain(w) -} - -func (s *selectStmt) String() string { - var b bytes.Buffer - b.WriteString("SELECT") - if s.distinct { - b.WriteString(" DISTINCT") - } - switch { - case len(s.flds) == 0: - b.WriteString(" *") - default: - a := make([]string, len(s.flds)) - for i, v := range s.flds { - s := v.expr.String() - if v.name != "" && v.name != s { - s += " AS " + v.name - } - a[i] = s - } - b.WriteString(" " + strings.Join(a, ", ")) - } - if s.from != nil { - if !s.from.isZero() { - b.WriteString(" FROM ") - b.WriteString(s.from.String()) - } - } - - if s.where != nil { - b.WriteString(" WHERE ") - b.WriteString(s.where.String()) - } - if s.group != nil { - b.WriteString(" GROUP BY ") - b.WriteString(strings.Join(s.group.colNames, ", ")) - } - if s.order != nil { - b.WriteString(" ORDER BY ") - b.WriteString(s.order.String()) - } - if s.limit != nil { - b.WriteString(" LIMIT ") - b.WriteString(s.limit.expr.String()) - } - if s.offset != nil { - b.WriteString(" OFFSET ") - b.WriteString(s.offset.expr.String()) - } - b.WriteRune(';') - return b.String() -} - -func (s *selectStmt) plan(ctx *execCtx) (plan, error) { //LATER overlapping goroutines/pipelines - var r plan - var err error - if s.from != nil { - r, err = s.from.plan(ctx) - if err != nil { - return nil, err - } - } - if r == nil { - return &selectDummyPlan{flds: s.flds}, nil - } - if w := s.where; w != nil { - if r, err = (&whereRset{expr: w.expr, src: r, sel: w.sel, exists: w.exists}).plan(ctx); err != nil { - return nil, err - } - } - switch { - case !s.hasAggregates && s.group == nil: // nop - case !s.hasAggregates && s.group != nil: - if r, err = (&groupByRset{colNames: s.group.colNames, src: r}).plan(ctx); err != nil { - return nil, err - } - case s.hasAggregates && s.group == nil: - if r, err = (&groupByRset{src: r}).plan(ctx); err != nil { - return nil, err - } - case s.hasAggregates && s.group != nil: - if r, err = (&groupByRset{colNames: s.group.colNames, src: r}).plan(ctx); err != nil { - return nil, err - } - } - if r, err = (&selectRset{flds: s.flds, src: r}).plan(ctx); err != nil { - return nil, err - } - - if s.distinct { - if r, err = (&distinctRset{src: r}).plan(ctx); err != nil { - return nil, err - } - } - if s := s.order; s != nil { - if r, err = (&orderByRset{asc: s.asc, by: s.by, src: r}).plan(ctx); err != nil { - return nil, err - } - } - if s := s.offset; s != nil { - if r, err = (&offsetRset{s.expr, r}).plan(ctx); err != nil { - return nil, err - } - } - if s := s.limit; s != nil { - if r, err = (&limitRset{s.expr, r}).plan(ctx); err != nil { - return nil, err - } - } - return r, nil -} - -func (s *selectStmt) exec(ctx *execCtx) (rs Recordset, err error) { - r, err := s.plan(ctx) - if err != nil { - return nil, err - } - - return recordset{ctx, r, nil}, nil -} - -func (s *selectStmt) isUpdating() bool { return false } - -type insertIntoStmt struct { - colNames []string - lists [][]expression - sel *selectStmt - tableName string -} - -func (s *insertIntoStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *insertIntoStmt) String() string { - cn := "" - if len(s.colNames) != 0 { - cn = fmt.Sprintf(" (%s)", strings.Join(s.colNames, ", ")) - } - switch { - case s.sel != nil: - return fmt.Sprintf("INSERT INTO %s%s %s;", s.tableName, cn, s.sel) - default: - a := make([]string, len(s.lists)) - for i, v := range s.lists { - b := make([]string, len(v)) - for i, v := range v { - b[i] = v.String() - } - a[i] = fmt.Sprintf("(%s)", strings.Join(b, ", ")) - } - return fmt.Sprintf("INSERT INTO %s%s VALUES %s;", s.tableName, cn, strings.Join(a, ", ")) - } -} - -func (s *insertIntoStmt) execSelect(t *table, cols []*col, ctx *execCtx) (_ Recordset, err error) { - //TODO missing rs column number eq check - r, err := s.sel.plan(ctx) - if err != nil { - return nil, err - } - - h := t.head - data0 := make([]interface{}, len(t.cols0)+2) - cc := ctx.db.cc - m := map[interface{}]interface{}{} - if err = r.do(ctx, func(_ interface{}, data []interface{}) (more bool, err error) { - for i, d := range data { - data0[cols[i].index+2] = d - } - if err = typeCheck(data0[2:], cols); err != nil { - return - } - - if err = t.checkConstraintsAndDefaults(ctx, data0[2:], m); err != nil { - return false, err - } - - id, err := t.store.ID() - if err != nil { - return false, err - } - - data0[0] = h - data0[1] = id - - // Any overflow chunks are written here. - if h, err = t.store.Create(data0...); err != nil { - return false, err - } - - for i, v := range t.indices { - if v == nil { - continue - } - - // Any overflow chunks are shared with the BTree key - if err = v.x.Create([]interface{}{data0[i+1]}, h); err != nil { - return false, err - } - } - for _, ix := range t.indices2 { - vlist, err := ix.eval(ctx, t.cols, id, data0[2:]) - if err != nil { - return false, err - } - - if err := ix.x.Create(vlist, h); err != nil { - return false, err - } - } - - cc.RowsAffected++ - ctx.db.root.lastInsertID = id - return true, nil - }); err != nil { - return nil, err - } - - t.head = h - return nil, t.store.Update(t.hhead, h) -} - -func (s *insertIntoStmt) exec(ctx *execCtx) (_ Recordset, err error) { - root := ctx.db.root - t, ok := root.tables[s.tableName] - if !ok { - return nil, fmt.Errorf("INSERT INTO %s: table does not exist", s.tableName) - } - - var cols []*col - switch len(s.colNames) { - case 0: - cols = t.cols - default: - for _, colName := range s.colNames { - if col := findCol(t.cols, colName); col != nil { - cols = append(cols, col) - continue - } - - return nil, fmt.Errorf("INSERT INTO %s: unknown column %s", s.tableName, colName) - } - } - - if s.sel != nil { - return s.execSelect(t, cols, ctx) - } - - for _, list := range s.lists { - if g, e := len(list), len(cols); g != e { - return nil, fmt.Errorf("INSERT INTO %s: expected %d value(s), have %d", s.tableName, e, g) - } - } - - cc := ctx.db.cc - r := make([]interface{}, len(t.cols0)) - m := map[interface{}]interface{}{} - for _, list := range s.lists { - for i, expr := range list { - val, err := expr.eval(ctx, m) - if err != nil { - return nil, err - } - - r[cols[i].index] = val - } - if err = typeCheck(r, cols); err != nil { - return nil, err - } - - if err = t.checkConstraintsAndDefaults(ctx, r, m); err != nil { - return nil, err - } - - id, err := t.addRecord(ctx, r) - if err != nil { - return nil, err - } - - cc.RowsAffected++ - root.lastInsertID = id - } - return nil, nil -} - -func (s *insertIntoStmt) isUpdating() bool { return true } - -type beginTransactionStmt struct{} - -func (s beginTransactionStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (beginTransactionStmt) String() string { return "BEGIN TRANSACTION;" } -func (beginTransactionStmt) exec(*execCtx) (Recordset, error) { - panic("internal error 059") -} -func (beginTransactionStmt) isUpdating() bool { - panic("internal error 060") -} - -type commitStmt struct{} - -func (s commitStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (commitStmt) String() string { return "COMMIT;" } -func (commitStmt) exec(*execCtx) (Recordset, error) { - panic("internal error 061") -} -func (commitStmt) isUpdating() bool { - panic("internal error 062") -} - -type rollbackStmt struct{} - -func (s rollbackStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (rollbackStmt) String() string { return "ROLLBACK;" } -func (rollbackStmt) exec(*execCtx) (Recordset, error) { - panic("internal error 063") -} -func (rollbackStmt) isUpdating() bool { - panic("internal error 064") -} - -type createIndexStmt struct { - colName string // alt. "id()" for simple index on id() - ifNotExists bool - indexName string - tableName string - unique bool - exprList []expression -} - -func (s *createIndexStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *createIndexStmt) isSimpleIndex() bool { return s.colName != "" } - -func (s *createIndexStmt) String() string { - u := "" - if s.unique { - u = "UNIQUE " - } - e := "" - if s.ifNotExists { - e = "IF NOT EXISTS " - } - expr := s.colName - if !s.isSimpleIndex() { - var a []string - for _, v := range s.exprList { - a = append(a, v.String()) - } - expr = strings.Join(a, ", ") - } - return fmt.Sprintf("CREATE %sINDEX %s%s ON %s (%s);", u, e, s.indexName, s.tableName, expr) -} - -func (s *createIndexStmt) exec(ctx *execCtx) (Recordset, error) { - root := ctx.db.root - if t, i := root.findIndexByName(s.indexName); i != nil { - if s.ifNotExists { - return nil, nil - } - - return nil, fmt.Errorf("CREATE INDEX: table %s already has an index named %s", t.name, s.indexName) - } - - if root.tables[s.indexName] != nil { - return nil, fmt.Errorf("CREATE INDEX: index name collision with existing table: %s", s.indexName) - } - - t, ok := root.tables[s.tableName] - if !ok { - return nil, fmt.Errorf("CREATE INDEX: table does not exist %s", s.tableName) - } - - if findCol(t.cols, s.indexName) != nil { - return nil, fmt.Errorf("CREATE INDEX: index name collision with existing column: %s", s.indexName) - } - - var h int64 - var err error - switch { - case s.isSimpleIndex(): - colIndex := -1 - if s.colName != "id()" { - c := findCol(t.cols, s.colName) - if c == nil { - return nil, fmt.Errorf("CREATE INDEX: column does not exist: %s", s.colName) - } - - colIndex = c.index - } - - if h, err = t.addIndex(s.unique, s.indexName, colIndex); err != nil { - return nil, fmt.Errorf("CREATE INDEX: %v", err) - } - - if err = t.updated(); err != nil { - return nil, err - } - default: - for _, e := range s.exprList { - m := mentionedColumns(e) - for colName := range m { - c := findCol(t.cols, colName) - if c == nil { - return nil, fmt.Errorf("CREATE INDEX: column does not exist: %s", colName) - } - } - } - if h, err = t.addIndex2(ctx, s.unique, s.indexName, s.exprList); err != nil { - return nil, fmt.Errorf("CREATE INDEX: %v", err) - } - } - - switch ctx.db.hasIndex2 { - case 0: - if err := ctx.db.createIndex2(); err != nil { - return nil, err - } - - if s.isSimpleIndex() { - return nil, nil - } - case 1: - return nil, nil - case 2: - if s.isSimpleIndex() { - return nil, ctx.db.insertIndex2(s.tableName, s.indexName, []string{s.colName}, s.unique, true, h) - } - default: - panic("internal error 011") - } - - exprList := make([]string, 0, len(s.exprList)) - for _, e := range s.exprList { - exprList = append(exprList, e.String()) - } - return nil, ctx.db.insertIndex2(s.tableName, s.indexName, exprList, s.unique, false, h) -} - -func (s *createIndexStmt) isUpdating() bool { return true } - -type createTableStmt struct { - ifNotExists bool - tableName string - cols []*col -} - -func (s *createTableStmt) explain(ctx *execCtx, w strutil.Formatter) { - w.Format("%s\n", s) -} - -func (s *createTableStmt) String() string { - a := make([]string, len(s.cols)) - for i, v := range s.cols { - var c, d string - if x := v.constraint; x != nil { - switch e := x.expr; { - case e != nil: - c = " " + e.String() - default: - c = " NOT NULL" - } - } - if x := v.dflt; x != nil { - d = " DEFAULT " + x.String() - } - a[i] = fmt.Sprintf("%s %s%s%s", v.name, typeStr(v.typ), c, d) - } - e := "" - if s.ifNotExists { - e = "IF NOT EXISTS " - } - return fmt.Sprintf("CREATE TABLE %s%s (%s);", e, s.tableName, strings.Join(a, ", ")) -} - -func (s *createTableStmt) exec(ctx *execCtx) (_ Recordset, err error) { - var cols []*col - for _, v := range s.cols { - cols = append(cols, v.clone()) - } - root := ctx.db.root - if _, ok := root.tables[s.tableName]; ok { - if s.ifNotExists { - return nil, nil - } - - return nil, fmt.Errorf("CREATE TABLE: table exists %s", s.tableName) - } - - if t, x := root.findIndexByName(s.tableName); x != nil { - return nil, fmt.Errorf("CREATE TABLE: table %s has index %s", t.name, s.tableName) - } - - m := map[string]bool{} - mustCreateColumn2 := true - for i, c := range cols { - nm := c.name - if m[nm] { - return nil, fmt.Errorf("CREATE TABLE: duplicate column %s", nm) - } - - m[nm] = true - c.index = i - if c.constraint != nil || c.dflt != nil { - if mustCreateColumn2 { - for _, stmt := range createColumn2.l { - _, err := stmt.exec(newExecCtx(ctx.db, nil)) - if err != nil { - return nil, err - } - } - } - - mustCreateColumn2 = false - notNull := c.constraint != nil && c.constraint.expr == nil - var co, d string - if c.constraint != nil && c.constraint.expr != nil { - co = c.constraint.expr.String() - } - if e := c.dflt; e != nil { - d = e.String() - } - if _, err := insertColumn2.l[0].exec(newExecCtx(ctx.db, []interface{}{s.tableName, c.name, notNull, co, d})); err != nil { - return nil, err - } - } - } - t, err := root.createTable(s.tableName, cols) - if err != nil { - return nil, err - } - - return nil, t.constraintsAndDefaults(ctx) -} - -func (s *createTableStmt) isUpdating() bool { return true } diff --git a/vendor/github.com/cznic/ql/storage.go b/vendor/github.com/cznic/ql/storage.go deleted file mode 100644 index 924d7c7aa..000000000 --- a/vendor/github.com/cznic/ql/storage.go +++ /dev/null @@ -1,986 +0,0 @@ -// Copyright (c) 2014 ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ql - -import ( - "fmt" - "strings" -) - -type storage interface { - Acid() bool - BeginTransaction() error - Close() error - Commit() error - Create(data ...interface{}) (h int64, err error) - CreateIndex(unique bool) (handle int64, x btreeIndex, err error) - CreateTemp(asc bool) (bt temp, err error) - Delete(h int64, blobCols ...*col) error //LATER split the nil blobCols case - ID() (id int64, err error) - Name() string - OpenIndex(unique bool, handle int64) (btreeIndex, error) // Never called on the memory backend. - Read(dst []interface{}, h int64, cols ...*col) (data []interface{}, err error) - ResetID() (err error) - Rollback() error - Update(h int64, data ...interface{}) error - UpdateRow(h int64, blobCols []*col, data ...interface{}) error - Verify() (allocs int64, err error) -} - -type btreeIterator interface { - Next() (k, v []interface{}, err error) -} - -type temp interface { - BeginTransaction() error - Create(data ...interface{}) (h int64, err error) - Drop() (err error) - Get(k []interface{}) (v []interface{}, err error) - Read(dst []interface{}, h int64, cols ...*col) (data []interface{}, err error) - SeekFirst() (e btreeIterator, err error) - Set(k, v []interface{}) (err error) -} - -type indexIterator interface { - Next() (k []interface{}, h int64, err error) - Prev() (k []interface{}, h int64, err error) -} - -type btreeIndex interface { - Clear() error // supports truncate table statement - Create(indexedValues []interface{}, h int64) error // supports insert into statement - Delete(indexedValues []interface{}, h int64) error // supports delete from statement - Drop() error // supports drop table, drop index statements - Seek(indexedValues []interface{}) (iter indexIterator, hit bool, err error) // supports where clause - SeekFirst() (iter indexIterator, err error) // supports aggregate min / ascending order by - SeekLast() (iter indexIterator, err error) // supports aggregate max / descending order by -} - -type indexedCol struct { // Column name or id() index. - name string - unique bool - x btreeIndex - xroot int64 -} - -type index2 struct { // Expression list index. - unique bool - x btreeIndex - xroot int64 - sources []string - exprList []expression -} - -func (x *index2) eval(ctx *execCtx, cols []*col, id int64, r []interface{}) ([]interface{}, error) { - f, isFile := ctx.db.store.(*file) - vlist := make([]interface{}, len(x.exprList)) - m := map[interface{}]interface{}{"$id": id} - for _, col := range cols { - ci := col.index - v := interface{}(nil) - if ci < len(r) { - v = r[ci] - } - if b, ok := v.([]byte); ok && isFile { - var err error - if v, err = expand1(chunk{f: f, b: b}, nil); err != nil { - return nil, err - } - } - m[col.name] = v - } - for i, e := range x.exprList { - v, err := e.eval(ctx, m) - if err != nil { - return nil, err - } - - if ok, typ := isBlobType(v); ok { - return nil, fmt.Errorf("value of a complex index cannot be of blob-like type: %v", typ) - } - - vlist[i] = v - } - return vlist, nil -} - -type indexKey struct { - value []interface{} - h int64 -} - -// storage fields -// 0: next int64 -// 1: scols string -// 2: hhead int64 -// 3: name string -// 4: indices string - optional -// 5: hxroots int64 - optional -type table struct { - cols []*col // logical - cols0 []*col // physical - h int64 // - head int64 // head of the single linked record list - hhead int64 // handle of the head of the single linked record list - hxroots int64 - indices []*indexedCol - indices2 map[string]*index2 - name string - next int64 // single linked table list - store storage - tnext *table - tprev *table - xroots []interface{} - constraints []*constraint - defaults []expression -} - -func (t *table) hasIndices() bool { return len(t.indices) != 0 || len(t.indices2) != 0 } - -func (t *table) constraintsAndDefaults(ctx *execCtx) error { - if isSystemName[t.name] { - return nil - } - - _, ok := ctx.db.root.tables["__Column2"] - if !ok { - return nil - } - - cols := t.cols - constraints := make([]*constraint, len(cols)) - defaults := make([]expression, len(cols)) - arg := []interface{}{t.name} - rs, err := selectColumn2.l[0].exec(newExecCtx(ctx.db, arg)) - if err != nil { - return err - } - - var rows [][]interface{} - ok = false - if err := rs.(recordset).do( - newExecCtx(ctx.db, arg), - func(id interface{}, data []interface{}) (more bool, err error) { - rows = append(rows, data) - return true, nil - }, - ); err != nil { - return err - } - - for _, row := range rows { - nm := row[0].(string) - nonNull := row[1].(bool) - cexpr := row[2].(string) - dexpr := row[3].(string) - for i, c := range cols { - if c.name == nm { - var co *constraint - if nonNull || cexpr != "" { - co = &constraint{} - constraints[i] = co - if cexpr != "" { - if co.expr, err = ctx.db.str2expr(cexpr); err != nil { - return fmt.Errorf("constraint %q: %v", cexpr, err) - } - } - - t.constraints = constraints - } - if dexpr != "" { - if defaults[i], err = ctx.db.str2expr(dexpr); err != nil { - return fmt.Errorf("constraint %q: %v", dexpr, err) - } - - t.defaults = defaults - } - } - } - } - return nil -} - -func (t *table) checkConstraintsAndDefaults(ctx *execCtx, row []interface{}, m map[interface{}]interface{}) error { - cols := t.cols - - if len(t.defaults) != 0 { - // 1. - for _, c := range cols { - m[c.name] = row[c.index] - } - - // 2. - for i, c := range cols { - val := row[c.index] - expr := t.defaults[i] - if val != nil || expr == nil { - continue - } - - dval, err := expr.eval(ctx, m) - if err != nil { - return err - } - - row[c.index] = dval - if err = typeCheck(row, []*col{c}); err != nil { - return err - } - } - } - - if len(t.constraints) != 0 { - // 3. - for _, c := range cols { - m[c.name] = row[c.index] - } - - // 4. - for i, c := range cols { - constraint := t.constraints[i] - if constraint == nil { - continue - } - - val := row[c.index] - expr := constraint.expr - if expr == nil { // Constraint: NOT NULL - if val == nil { - return fmt.Errorf("column %s: constraint violation: NOT NULL", c.name) - } - - continue - } - - // Constraint is an expression - cval, err := expr.eval(ctx, m) - if err != nil { - return err - } - - if cval == nil { - return fmt.Errorf("column %s: constraint violation: %s", c.name, expr) - } - - bval, ok := cval.(bool) - if !ok { - return fmt.Errorf("column %s: non bool constraint expression: %s", c.name, expr) - } - - if !bval { - return fmt.Errorf("column %s: constraint violation: %s", c.name, expr) - } - } - } - - return nil -} - -func (t *table) clone() *table { - r := &table{} - *r = *t - r.constraints = append([]*constraint(nil), t.constraints...) - r.defaults = append([]expression(nil), t.defaults...) - r.indices2 = nil - if n := len(t.indices2); n != 0 { - r.indices2 = make(map[string]*index2, n) - for k, v := range t.indices2 { - r.indices2[k] = v - } - } - r.cols = make([]*col, len(t.cols)) - for i, v := range t.cols { - c := &col{} - *c = *v - r.cols[i] = c - } - r.cols0 = make([]*col, len(t.cols0)) - for i, v := range t.cols0 { - c := &col{} - *c = *v - r.cols0[i] = c - } - r.indices = make([]*indexedCol, len(t.indices)) - for i, v := range t.indices { - if v != nil { - c := &indexedCol{} - *c = *v - r.indices[i] = c - } - } - r.xroots = make([]interface{}, len(t.xroots)) - copy(r.xroots, t.xroots) - r.tnext, r.tprev = nil, nil - return r -} - -func (t *table) findIndexByColName(name string) (*col, *indexedCol) { - for i, v := range t.indices { - if v == nil { - continue - } - - if i == 0 { - if name == "id()" { - return idCol, v - } - - continue - } - - if c := t.cols0[i-1]; c.name == name { - return c, v - } - } - - return nil, nil -} - -func (t *table) findIndexByName(name string) interface{} { - for _, v := range t.indices { - if v != nil && v.name == name { - return v - } - } - for k, v := range t.indices2 { - if k == name { - return v - } - } - return nil -} - -func (t *table) load() (err error) { - data, err := t.store.Read(nil, t.h) - if err != nil { - return - } - - var hasIndices bool - switch n := len(data); n { - case 4: - case 6: - hasIndices = true - default: - return fmt.Errorf("corrupted DB: table data len %d", n) - } - - var ok bool - if t.next, ok = data[0].(int64); !ok { - return fmt.Errorf("corrupted DB: table data[0] of type %T", data[0]) - } - - scols, ok := data[1].(string) - if !ok { - return fmt.Errorf("corrupted DB: table data[1] of type %T", data[1]) - } - - if t.hhead, ok = data[2].(int64); !ok { - return fmt.Errorf("corrupted DB: table data[2] of type %T", data[2]) - } - - if t.name, ok = data[3].(string); !ok { - return fmt.Errorf("corrupted DB: table data[3] of type %T", data[3]) - } - - var head []interface{} - if head, err = t.store.Read(nil, t.hhead); err != nil { - return err - } - - if len(head) != 1 { - return fmt.Errorf("corrupted DB: table head data len %d", len(head)) - } - - if t.head, ok = head[0].(int64); !ok { - return fmt.Errorf("corrupted DB: table head data[0] of type %T", head[0]) - } - - a := strings.Split(scols, "|") - t.cols0 = make([]*col, len(a)) - for i, v := range a { - if len(v) < 1 { - return fmt.Errorf("corrupted DB: field info %q", v) - } - - col := &col{name: v[1:], typ: int(v[0]), index: i} - t.cols0[i] = col - if col.name != "" { - t.cols = append(t.cols, col) - } - } - - if !hasIndices { - return - } - - if t.hxroots, ok = data[5].(int64); !ok { - return fmt.Errorf("corrupted DB: table data[5] of type %T", data[5]) - } - - xroots, err := t.store.Read(nil, t.hxroots) - if err != nil { - return err - } - - if g, e := len(xroots), len(t.cols0)+1; g != e { - return fmt.Errorf("corrupted DB: got %d index roots, expected %d", g, e) - } - - indices, ok := data[4].(string) - if !ok { - return fmt.Errorf("corrupted DB: table data[4] of type %T", data[4]) - } - - a = strings.Split(indices, "|") - if g, e := len(a), len(t.cols0)+1; g != e { - return fmt.Errorf("corrupted DB: got %d index definitions, expected %d", g, e) - } - - t.indices = make([]*indexedCol, len(a)) - for i, v := range a { - if v == "" { - continue - } - - if len(v) < 2 { - return fmt.Errorf("corrupted DB: invalid index definition %q", v) - } - - nm := v[1:] - h, ok := xroots[i].(int64) - if !ok { - return fmt.Errorf("corrupted DB: table index root of type %T", xroots[i]) - } - - if h == 0 { - return fmt.Errorf("corrupted DB: missing root for index %s", nm) - } - - unique := v[0] == 'u' - x, err := t.store.OpenIndex(unique, h) - if err != nil { - return err - } - - t.indices[i] = &indexedCol{nm, unique, x, h} - } - t.xroots = xroots - - return -} - -func newTable(store storage, name string, next int64, cols []*col, tprev, tnext *table) (t *table, err error) { - hhead, err := store.Create(int64(0)) - if err != nil { - return - } - - scols := cols2meta(cols) - h, err := store.Create(next, scols, hhead, name) - if err != nil { - return - } - - t = &table{ - cols0: cols, - h: h, - hhead: hhead, - name: name, - next: next, - store: store, - tnext: tnext, - tprev: tprev, - } - return t.updateCols(), nil -} - -func (t *table) blobCols() (r []*col) { - for _, c := range t.cols0 { - switch c.typ { - case qBlob, qBigInt, qBigRat, qTime, qDuration: - r = append(r, c) - } - } - return -} - -func (t *table) truncate() (err error) { - h := t.head - var rec []interface{} - blobCols := t.blobCols() - for h != 0 { - rec, err := t.store.Read(rec, h) - if err != nil { - return err - } - nh := rec[0].(int64) - - if err = t.store.Delete(h, blobCols...); err != nil { //LATER remove double read for len(blobCols) != 0 - return err - } - - h = nh - } - if err = t.store.Update(t.hhead, 0); err != nil { - return - } - - for _, v := range t.indices { - if v == nil { - continue - } - - if err := v.x.Clear(); err != nil { - return err - } - } - for _, ix := range t.indices2 { - if err := ix.x.Clear(); err != nil { - return err - } - } - t.head = 0 - return t.updated() -} - -func (t *table) addIndex0(unique bool, indexName string, colIndex int) (int64, btreeIndex, error) { - switch len(t.indices) { - case 0: - indices := make([]*indexedCol, len(t.cols0)+1) - h, x, err := t.store.CreateIndex(unique) - if err != nil { - return -1, nil, err - } - - indices[colIndex+1] = &indexedCol{indexName, unique, x, h} - xroots := make([]interface{}, len(indices)) - xroots[colIndex+1] = h - hx, err := t.store.Create(xroots...) - if err != nil { - return -1, nil, err - } - - t.hxroots, t.xroots, t.indices = hx, xroots, indices - return h, x, t.updated() - default: - ex := t.indices[colIndex+1] - if ex != nil && ex.name != "" { - colName := "id()" - if colIndex >= 0 { - colName = t.cols0[colIndex].name - } - return -1, nil, fmt.Errorf("column %s already has an index: %s", colName, ex.name) - } - - h, x, err := t.store.CreateIndex(unique) - if err != nil { - return -1, nil, err - } - - t.xroots[colIndex+1] = h - if err := t.store.Update(t.hxroots, t.xroots...); err != nil { - return -1, nil, err - } - - t.indices[colIndex+1] = &indexedCol{indexName, unique, x, h} - return h, x, t.updated() - } -} - -func (t *table) addIndex(unique bool, indexName string, colIndex int) (int64, error) { - hx, x, err := t.addIndex0(unique, indexName, colIndex) - if err != nil { - return -1, err - } - - // Must fill the new index. - ncols := len(t.cols0) - h, store := t.head, t.store - for h != 0 { - rec, err := store.Read(nil, h, t.cols...) - if err != nil { - return -1, err - } - - if n := ncols + 2 - len(rec); n > 0 { - rec = append(rec, make([]interface{}, n)...) - } - - if err = x.Create([]interface{}{rec[colIndex+2]}, h); err != nil { - return -1, err - } - - h = rec[0].(int64) - } - return hx, nil -} - -func (t *table) addIndex2(execCtx *execCtx, unique bool, indexName string, exprList []expression) (int64, error) { - if _, ok := t.indices2[indexName]; ok { - panic("internal error 009") - } - - hx, x, err := t.store.CreateIndex(unique) - if err != nil { - return -1, err - } - var a []string - for _, v := range exprList { - a = append(a, v.String()) - } - x2 := &index2{unique, x, hx, a, exprList} - if t.indices2 == nil { - t.indices2 = map[string]*index2{} - } - t.indices2[indexName] = x2 - - // Must fill the new index. - m := map[interface{}]interface{}{} - h, store := t.head, t.store - for h != 0 { - rec, err := store.Read(nil, h, t.cols...) - if err != nil { - return -1, err - } - - for _, col := range t.cols { - ci := col.index - v := interface{}(nil) - if ci < len(rec) { - v = rec[ci+2] - } - m[col.name] = v - } - - id := rec[1].(int64) - vlist, err := x2.eval(execCtx, t.cols, id, rec[2:]) - if err != nil { - return -1, err - } - - if err := x2.x.Create(vlist, h); err != nil { - return -1, err - } - - h = rec[0].(int64) - } - return hx, nil -} - -func (t *table) dropIndex(xIndex int) error { - t.xroots[xIndex] = 0 - if err := t.indices[xIndex].x.Drop(); err != nil { - return err - } - - t.indices[xIndex] = nil - return t.updated() -} - -func (t *table) updated() (err error) { - switch { - case len(t.indices) != 0: - a := []string{} - for _, v := range t.indices { - if v == nil { - a = append(a, "") - continue - } - - s := "n" - if v.unique { - s = "u" - } - a = append(a, s+v.name) - } - return t.store.Update(t.h, t.next, cols2meta(t.updateCols().cols0), t.hhead, t.name, strings.Join(a, "|"), t.hxroots) - default: - return t.store.Update(t.h, t.next, cols2meta(t.updateCols().cols0), t.hhead, t.name) - } -} - -// storage fields -// 0: next record handle int64 -// 1: record id int64 -// 2...: data row -func (t *table) addRecord(execCtx *execCtx, r []interface{}) (id int64, err error) { - if id, err = t.store.ID(); err != nil { - return - } - - r = append([]interface{}{t.head, id}, r...) - h, err := t.store.Create(r...) - if err != nil { - return - } - - for i, v := range t.indices { - if v == nil { - continue - } - - if err = v.x.Create([]interface{}{r[i+1]}, h); err != nil { - return - } - } - - for _, ix := range t.indices2 { - vlist, err := ix.eval(execCtx, t.cols, id, r[2:]) - if err != nil { - return -1, err - } - - if err := ix.x.Create(vlist, h); err != nil { - return -1, err - } - } - - if err = t.store.Update(t.hhead, h); err != nil { - return - } - - t.head = h - return -} - -func (t *table) fieldNames() []string { - r := make([]string, len(t.cols)) - for i, v := range t.cols { - r[i] = v.name - } - return r -} - -func (t *table) updateCols() *table { - t.cols = t.cols[:0] - for i, c := range t.cols0 { - if c.name != "" { - c.index = i - t.cols = append(t.cols, c) - } - } - return t -} - -func (t *table) row0(ctx *execCtx, h int64) ([]interface{}, error) { - rec, err := ctx.db.store.Read(nil, h, t.cols...) - if err != nil { - return nil, err - } - - if d := len(t.cols) - (len(rec) - 2); d > 0 { - rec = append(rec, make([]interface{}, d)...) - } - - return rec, nil -} - -func (t *table) row(ctx *execCtx, h int64) (int64, []interface{}, error) { - rec, err := t.row0(ctx, h) - if err != nil { - return -1, nil, err - } - - id := rec[1].(int64) - for i, c := range t.cols { - rec[i] = rec[c.index+2] - } - return id, rec[:len(t.cols)], nil -} - -// storage fields -// 0: handle of first table in DB int64 -type root struct { - head int64 // Single linked table list - lastInsertID int64 - parent *root - //rowsAffected int64 //LATER implement - store storage - tables map[string]*table - thead *table -} - -func newRoot(store storage) (r *root, err error) { - data, err := store.Read(nil, 1) - if err != nil { - return - } - - switch len(data) { - case 0: // new empty DB, create empty table list - if err = store.BeginTransaction(); err != nil { - return - } - - if err = store.Update(1, int64(0)); err != nil { - store.Rollback() - return - } - - if err = store.Commit(); err != nil { - return - } - - return &root{ - store: store, - tables: map[string]*table{}, - }, nil - case 1: // existing DB, load tables - if len(data) != 1 { - return nil, fmt.Errorf("corrupted DB: root is an %d-scalar", len(data)) - } - - p, ok := data[0].(int64) - if !ok { - return nil, fmt.Errorf("corrupted DB: root head has type %T", data[0]) - } - - r := &root{ - head: p, - store: store, - tables: map[string]*table{}, - } - - var tprev *table - for p != 0 { - t := &table{ - h: p, - store: store, - tprev: tprev, - } - - if r.thead == nil { - r.thead = t - } - if tprev != nil { - tprev.tnext = t - } - tprev = t - - if err = t.load(); err != nil { - return nil, err - } - - if r.tables[t.name] != nil { // duplicate - return nil, fmt.Errorf("corrupted DB: duplicate table metadata for table %s", t.name) - } - - r.tables[t.name] = t - p = t.next - } - return r, nil - default: - return nil, errIncompatibleDBFormat - } -} - -func (r *root) findIndexByName(name string) (*table, interface{}) { - for _, t := range r.tables { - if i := t.findIndexByName(name); i != nil { - return t, i - } - } - - return nil, nil -} - -func (r *root) updated() (err error) { - return r.store.Update(1, r.head) -} - -func (r *root) createTable(name string, cols []*col) (t *table, err error) { - if _, ok := r.tables[name]; ok { - panic("internal error 065") - } - - if t, err = newTable(r.store, name, r.head, cols, nil, r.thead); err != nil { - return nil, err - } - - if err = r.store.Update(1, t.h); err != nil { - return nil, err - } - - if p := r.thead; p != nil { - p.tprev = t - } - r.tables[name], r.head, r.thead = t, t.h, t - return -} - -func (r *root) dropTable(t *table) (err error) { - defer func() { - if err != nil { - return - } - - delete(r.tables, t.name) - }() - - if err = t.truncate(); err != nil { - return - } - - if err = t.store.Delete(t.hhead); err != nil { - return - } - - if err = t.store.Delete(t.h); err != nil { - return - } - - for _, v := range t.indices { - if v != nil && v.x != nil { - if err = v.x.Drop(); err != nil { - return - } - } - } - for _, v := range t.indices2 { - if err = v.x.Drop(); err != nil { - return - } - } - - if h := t.hxroots; h != 0 { - if err = t.store.Delete(h); err != nil { - return - } - } - - switch { - case t.tprev == nil && t.tnext == nil: - r.head = 0 - r.thead = nil - err = r.updated() - return errSet(&err, r.store.ResetID()) - case t.tprev == nil && t.tnext != nil: - next := t.tnext - next.tprev = nil - r.head = next.h - r.thead = next - if err = r.updated(); err != nil { - return - } - - return next.updated() - case t.tprev != nil && t.tnext == nil: // last in list - prev := t.tprev - prev.next = 0 - prev.tnext = nil - return prev.updated() - default: //case t.tprev != nil && t.tnext != nil: - prev, next := t.tprev, t.tnext - prev.next = next.h - prev.tnext = next - next.tprev = prev - if err = prev.updated(); err != nil { - return - } - - return next.updated() - } -} diff --git a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock.go b/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock.go deleted file mode 100644 index a9fb802de..000000000 --- a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock.go +++ /dev/null @@ -1,186 +0,0 @@ -/* -Copyright 2013 The Go Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package lock is a file locking library. -package lock - -import ( - "encoding/json" - "fmt" - "io" - "os" - "path/filepath" - "sync" -) - -// Lock locks the given file, creating the file if necessary. If the -// file already exists, it must have zero size or an error is returned. -// The lock is an exclusive lock (a write lock), but locked files -// should neither be read from nor written to. Such files should have -// zero size and only exist to co-ordinate ownership across processes. -// -// A nil Closer is returned if an error occurred. Otherwise, close that -// Closer to release the lock. -// -// On Linux, FreeBSD and OSX, a lock has the same semantics as fcntl(2)'s -// advisory locks. In particular, closing any other file descriptor for the -// same file will release the lock prematurely. -// -// Attempting to lock a file that is already locked by the current process -// has undefined behavior. -// -// On other operating systems, lock will fallback to using the presence and -// content of a file named name + '.lock' to implement locking behavior. -func Lock(name string) (io.Closer, error) { - abs, err := filepath.Abs(name) - if err != nil { - return nil, err - } - lockmu.Lock() - defer lockmu.Unlock() - if locked[abs] { - return nil, fmt.Errorf("file %q already locked", abs) - } - - c, err := lockFn(abs) - if err != nil { - return nil, fmt.Errorf("cannot acquire lock: %v", err) - } - locked[abs] = true - return c, nil -} - -var lockFn = lockPortable - -// lockPortable is a portable version not using fcntl. Doesn't handle crashes as gracefully, -// since it can leave stale lock files. -func lockPortable(name string) (io.Closer, error) { - fi, err := os.Stat(name) - if err == nil && fi.Size() > 0 { - st := portableLockStatus(name) - switch st { - case statusLocked: - return nil, fmt.Errorf("file %q already locked", name) - case statusStale: - os.Remove(name) - case statusInvalid: - return nil, fmt.Errorf("can't Lock file %q: has invalid contents", name) - } - } - f, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_EXCL, 0666) - if err != nil { - return nil, fmt.Errorf("failed to create lock file %s %v", name, err) - } - if err := json.NewEncoder(f).Encode(&pidLockMeta{OwnerPID: os.Getpid()}); err != nil { - return nil, fmt.Errorf("cannot write owner pid: %v", err) - } - return &unlocker{ - f: f, - abs: name, - portable: true, - }, nil -} - -type lockStatus int - -const ( - statusInvalid lockStatus = iota - statusLocked - statusUnlocked - statusStale -) - -type pidLockMeta struct { - OwnerPID int -} - -func portableLockStatus(path string) lockStatus { - f, err := os.Open(path) - if err != nil { - return statusUnlocked - } - defer f.Close() - var meta pidLockMeta - if json.NewDecoder(f).Decode(&meta) != nil { - return statusInvalid - } - if meta.OwnerPID == 0 { - return statusInvalid - } - p, err := os.FindProcess(meta.OwnerPID) - if err != nil { - // e.g. on Windows - return statusStale - } - // On unix, os.FindProcess always is true, so we have to send - // it a signal to see if it's alive. - if signalZero != nil { - if p.Signal(signalZero) != nil { - return statusStale - } - } - return statusLocked -} - -var signalZero os.Signal // nil or set by lock_sigzero.go - -var ( - lockmu sync.Mutex - locked = map[string]bool{} // abs path -> true -) - -type unlocker struct { - portable bool - f *os.File - abs string - // once guards the close method call. - once sync.Once - // err holds the error returned by Close. - err error -} - -func (u *unlocker) Close() error { - u.once.Do(u.close) - return u.err -} - -func (u *unlocker) close() { - lockmu.Lock() - defer lockmu.Unlock() - delete(locked, u.abs) - - if u.portable { - // In the portable lock implementation, it's - // important to close before removing because - // Windows won't allow us to remove an open - // file. - if err := u.f.Close(); err != nil { - u.err = err - } - if err := os.Remove(u.abs); err != nil { - // Note that if both Close and Remove fail, - // we care more about the latter than the former - // so we'll return that error. - u.err = err - } - return - } - // In other implementatioons, it's nice for us to clean up. - // If we do do this, though, it needs to be before the - // u.f.Close below. - os.Remove(u.abs) - u.err = u.f.Close() -} diff --git a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_appengine.go b/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_appengine.go deleted file mode 100644 index ab4cad6ab..000000000 --- a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_appengine.go +++ /dev/null @@ -1,32 +0,0 @@ -// +build appengine - -/* -Copyright 2013 The Go Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package lock - -import ( - "errors" - "io" -) - -func init() { - lockFn = lockAppEngine -} - -func lockAppEngine(name string) (io.Closer, error) { - return nil, errors.New("Lock not available on App Engine") -} diff --git a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_darwin_amd64.go b/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_darwin_amd64.go deleted file mode 100644 index 35f5787ba..000000000 --- a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_darwin_amd64.go +++ /dev/null @@ -1,67 +0,0 @@ -// +build darwin,amd64 -// +build !appengine - -/* -Copyright 2013 The Go Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package lock - -import ( - "fmt" - "io" - "os" - "syscall" - "unsafe" -) - -func init() { - lockFn = lockFcntl -} - -func lockFcntl(name string) (io.Closer, error) { - fi, err := os.Stat(name) - if err == nil && fi.Size() > 0 { - return nil, fmt.Errorf("can't Lock file %q: has non-zero size", name) - } - - f, err := os.Create(name) - if err != nil { - return nil, fmt.Errorf("Lock Create of %s failed: %v", name, err) - } - - // This type matches C's "struct flock" defined in /usr/include/sys/fcntl.h. - // TODO: move this into the standard syscall package. - k := struct { - Start uint64 // sizeof(off_t): 8 - Len uint64 // sizeof(off_t): 8 - Pid uint32 // sizeof(pid_t): 4 - Type uint16 // sizeof(short): 2 - Whence uint16 // sizeof(short): 2 - }{ - Type: syscall.F_WRLCK, - Whence: uint16(os.SEEK_SET), - Start: 0, - Len: 0, // 0 means to lock the entire file. - Pid: uint32(os.Getpid()), - } - - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_SETLK), uintptr(unsafe.Pointer(&k))) - if errno != 0 { - f.Close() - return nil, errno - } - return &unlocker{f: f, abs: name}, nil -} diff --git a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_freebsd.go b/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_freebsd.go deleted file mode 100644 index ee2767a0a..000000000 --- a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_freebsd.go +++ /dev/null @@ -1,66 +0,0 @@ -/* -Copyright 2013 The Go Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package lock - -import ( - "fmt" - "io" - "os" - "syscall" - "unsafe" -) - -func init() { - lockFn = lockFcntl -} - -func lockFcntl(name string) (io.Closer, error) { - fi, err := os.Stat(name) - if err == nil && fi.Size() > 0 { - return nil, fmt.Errorf("can't Lock file %q: has non-zero size", name) - } - - f, err := os.Create(name) - if err != nil { - return nil, err - } - - // This type matches C's "struct flock" defined in /usr/include/fcntl.h. - // TODO: move this into the standard syscall package. - k := struct { - Start int64 /* off_t starting offset */ - Len int64 /* off_t len = 0 means until end of file */ - Pid int32 /* pid_t lock owner */ - Type int16 /* short lock type: read/write, etc. */ - Whence int16 /* short type of l_start */ - Sysid int32 /* int remote system id or zero for local */ - }{ - Start: 0, - Len: 0, // 0 means to lock the entire file. - Pid: int32(os.Getpid()), - Type: syscall.F_WRLCK, - Whence: int16(os.SEEK_SET), - Sysid: 0, - } - - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_SETLK), uintptr(unsafe.Pointer(&k))) - if errno != 0 { - f.Close() - return nil, errno - } - return &unlocker{f: f, abs: name}, nil -} diff --git a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_linux_amd64.go b/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_linux_amd64.go deleted file mode 100644 index 08b3aae92..000000000 --- a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_linux_amd64.go +++ /dev/null @@ -1,67 +0,0 @@ -// +build linux,amd64 -// +build !appengine - -/* -Copyright 2013 The Go Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package lock - -import ( - "fmt" - "io" - "os" - "syscall" - "unsafe" -) - -func init() { - lockFn = lockFcntl -} - -func lockFcntl(name string) (io.Closer, error) { - fi, err := os.Stat(name) - if err == nil && fi.Size() > 0 { - return nil, fmt.Errorf("can't Lock file %q: has non-zero size", name) - } - - f, err := os.Create(name) - if err != nil { - return nil, err - } - - // This type matches C's "struct flock" defined in /usr/include/bits/fcntl.h. - // TODO: move this into the standard syscall package. - k := struct { - Type uint32 - Whence uint32 - Start uint64 - Len uint64 - Pid uint32 - }{ - Type: syscall.F_WRLCK, - Whence: uint32(os.SEEK_SET), - Start: 0, - Len: 0, // 0 means to lock the entire file. - Pid: uint32(os.Getpid()), - } - - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_SETLK), uintptr(unsafe.Pointer(&k))) - if errno != 0 { - f.Close() - return nil, errno - } - return &unlocker{f: f, abs: name}, nil -} diff --git a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_linux_arm.go b/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_linux_arm.go deleted file mode 100644 index ebf87bd3e..000000000 --- a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_linux_arm.go +++ /dev/null @@ -1,68 +0,0 @@ -// +build linux,arm -// +build !appengine - -/* -Copyright 2013 The Go Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package lock - -import ( - "fmt" - "io" - "os" - "syscall" - "unsafe" -) - -func init() { - lockFn = lockFcntl -} - -func lockFcntl(name string) (io.Closer, error) { - fi, err := os.Stat(name) - if err == nil && fi.Size() > 0 { - return nil, fmt.Errorf("can't Lock file %q: has non-zero size", name) - } - - f, err := os.Create(name) - if err != nil { - return nil, err - } - - // This type matches C's "struct flock" defined in /usr/include/bits/fcntl.h. - // TODO: move this into the standard syscall package. - k := struct { - Type uint16 - Whence uint16 - Start uint32 - Len uint32 - Pid uint32 - }{ - Type: syscall.F_WRLCK, - Whence: uint16(os.SEEK_SET), - Start: 0, - Len: 0, // 0 means to lock the entire file. - Pid: uint32(os.Getpid()), - } - - const F_SETLK = 6 // actual value. syscall package is wrong: golang.org/issue/7059 - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(F_SETLK), uintptr(unsafe.Pointer(&k))) - if errno != 0 { - f.Close() - return nil, errno - } - return &unlocker{f: f, abs: name}, nil -} diff --git a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_plan9.go b/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_plan9.go deleted file mode 100644 index d841c27d7..000000000 --- a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_plan9.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2013 The Go Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package lock - -import ( - "fmt" - "io" - "os" -) - -func init() { - lockFn = lockPlan9 -} - -func lockPlan9(name string) (io.Closer, error) { - fi, err := os.Stat(name) - if err == nil && fi.Size() > 0 { - return nil, fmt.Errorf("can't Lock file %q: has non-zero size", name) - } - - f, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE, os.ModeExclusive|0644) - if err != nil { - return nil, fmt.Errorf("Lock Create of %s failed: %v", name, err) - } - - return &unlocker{f: f, abs: name}, nil -} diff --git a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_sigzero.go b/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_sigzero.go deleted file mode 100644 index fd3ba2db1..000000000 --- a/vendor/github.com/cznic/ql/vendored/github.com/camlistore/go4/lock/lock_sigzero.go +++ /dev/null @@ -1,26 +0,0 @@ -// +build !appengine -// +build linux darwin freebsd openbsd netbsd dragonfly - -/* -Copyright 2013 The Go Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package lock - -import "syscall" - -func init() { - signalZero = syscall.Signal(0) -} diff --git a/vendor/github.com/cznic/sortutil/LICENSE b/vendor/github.com/cznic/sortutil/LICENSE deleted file mode 100644 index 67983e0e6..000000000 --- a/vendor/github.com/cznic/sortutil/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014 The sortutil Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/sortutil/sortutil.go b/vendor/github.com/cznic/sortutil/sortutil.go deleted file mode 100644 index 132d3546e..000000000 --- a/vendor/github.com/cznic/sortutil/sortutil.go +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright 2014 The sortutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package sortutil provides utilities supplementing the standard 'sort' package. -// -// Changelog -// -// 2015-06-17: Added utils for math/big.{Int,Rat}. -package sortutil - -import ( - "math/big" -) - -import "sort" - -// BigIntSlice attaches the methods of sort.Interface to []*big.Int, sorting in increasing order. -type BigIntSlice []*big.Int - -func (s BigIntSlice) Len() int { return len(s) } -func (s BigIntSlice) Less(i, j int) bool { return s[i].Cmp(s[j]) < 0 } -func (s BigIntSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s BigIntSlice) Sort() { - sort.Sort(s) -} - -// SearchBigInts searches for x in a sorted slice of *big.Int and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchBigInts(a []*big.Int, x *big.Int) int { - return sort.Search(len(a), func(i int) bool { return a[i].Cmp(x) >= 0 }) -} - -// BigRatSlice attaches the methods of sort.Interface to []*big.Rat, sorting in increasing order. -type BigRatSlice []*big.Rat - -func (s BigRatSlice) Len() int { return len(s) } -func (s BigRatSlice) Less(i, j int) bool { return s[i].Cmp(s[j]) < 0 } -func (s BigRatSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s BigRatSlice) Sort() { - sort.Sort(s) -} - -// SearchBigRats searches for x in a sorted slice of *big.Int and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchBigRats(a []*big.Rat, x *big.Rat) int { - return sort.Search(len(a), func(i int) bool { return a[i].Cmp(x) >= 0 }) -} - -// ByteSlice attaches the methods of sort.Interface to []byte, sorting in increasing order. -type ByteSlice []byte - -func (s ByteSlice) Len() int { return len(s) } -func (s ByteSlice) Less(i, j int) bool { return s[i] < s[j] } -func (s ByteSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s ByteSlice) Sort() { - sort.Sort(s) -} - -// SearchBytes searches for x in a sorted slice of bytes and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchBytes(a []byte, x byte) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// Float32Slice attaches the methods of sort.Interface to []float32, sorting in increasing order. -type Float32Slice []float32 - -func (s Float32Slice) Len() int { return len(s) } -func (s Float32Slice) Less(i, j int) bool { return s[i] < s[j] } -func (s Float32Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s Float32Slice) Sort() { - sort.Sort(s) -} - -// SearchFloat32s searches for x in a sorted slice of float32 and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchFloat32s(a []float32, x float32) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// Int8Slice attaches the methods of sort.Interface to []int8, sorting in increasing order. -type Int8Slice []int8 - -func (s Int8Slice) Len() int { return len(s) } -func (s Int8Slice) Less(i, j int) bool { return s[i] < s[j] } -func (s Int8Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s Int8Slice) Sort() { - sort.Sort(s) -} - -// SearchInt8s searches for x in a sorted slice of int8 and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchInt8s(a []int8, x int8) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// Int16Slice attaches the methods of sort.Interface to []int16, sorting in increasing order. -type Int16Slice []int16 - -func (s Int16Slice) Len() int { return len(s) } -func (s Int16Slice) Less(i, j int) bool { return s[i] < s[j] } -func (s Int16Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s Int16Slice) Sort() { - sort.Sort(s) -} - -// SearchInt16s searches for x in a sorted slice of int16 and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchInt16s(a []int16, x int16) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// Int32Slice attaches the methods of sort.Interface to []int32, sorting in increasing order. -type Int32Slice []int32 - -func (s Int32Slice) Len() int { return len(s) } -func (s Int32Slice) Less(i, j int) bool { return s[i] < s[j] } -func (s Int32Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s Int32Slice) Sort() { - sort.Sort(s) -} - -// SearchInt32s searches for x in a sorted slice of int32 and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchInt32s(a []int32, x int32) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// Int64Slice attaches the methods of sort.Interface to []int64, sorting in increasing order. -type Int64Slice []int64 - -func (s Int64Slice) Len() int { return len(s) } -func (s Int64Slice) Less(i, j int) bool { return s[i] < s[j] } -func (s Int64Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s Int64Slice) Sort() { - sort.Sort(s) -} - -// SearchInt64s searches for x in a sorted slice of int64 and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchInt64s(a []int64, x int64) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// UintSlice attaches the methods of sort.Interface to []uint, sorting in increasing order. -type UintSlice []uint - -func (s UintSlice) Len() int { return len(s) } -func (s UintSlice) Less(i, j int) bool { return s[i] < s[j] } -func (s UintSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s UintSlice) Sort() { - sort.Sort(s) -} - -// SearchUints searches for x in a sorted slice of uints and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchUints(a []uint, x uint) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// Uint16Slice attaches the methods of sort.Interface to []uint16, sorting in increasing order. -type Uint16Slice []uint16 - -func (s Uint16Slice) Len() int { return len(s) } -func (s Uint16Slice) Less(i, j int) bool { return s[i] < s[j] } -func (s Uint16Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s Uint16Slice) Sort() { - sort.Sort(s) -} - -// SearchUint16s searches for x in a sorted slice of uint16 and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchUint16s(a []uint16, x uint16) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// Uint32Slice attaches the methods of sort.Interface to []uint32, sorting in increasing order. -type Uint32Slice []uint32 - -func (s Uint32Slice) Len() int { return len(s) } -func (s Uint32Slice) Less(i, j int) bool { return s[i] < s[j] } -func (s Uint32Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s Uint32Slice) Sort() { - sort.Sort(s) -} - -// SearchUint32s searches for x in a sorted slice of uint32 and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchUint32s(a []uint32, x uint32) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// Uint64Slice attaches the methods of sort.Interface to []uint64, sorting in increasing order. -type Uint64Slice []uint64 - -func (s Uint64Slice) Len() int { return len(s) } -func (s Uint64Slice) Less(i, j int) bool { return s[i] < s[j] } -func (s Uint64Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s Uint64Slice) Sort() { - sort.Sort(s) -} - -// SearchUint64s searches for x in a sorted slice of uint64 and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchUint64s(a []uint64, x uint64) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// RuneSlice attaches the methods of sort.Interface to []rune, sorting in increasing order. -type RuneSlice []rune - -func (s RuneSlice) Len() int { return len(s) } -func (s RuneSlice) Less(i, j int) bool { return s[i] < s[j] } -func (s RuneSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort is a convenience method. -func (s RuneSlice) Sort() { - sort.Sort(s) -} - -// SearchRunes searches for x in a sorted slice of uint64 and returns the index -// as specified by sort.Search. The slice must be sorted in ascending order. -func SearchRunes(a []rune, x rune) int { - return sort.Search(len(a), func(i int) bool { return a[i] >= x }) -} - -// Dedupe returns n, the number of distinct elements in data. The resulting -// elements are sorted in elements [0, n) or data[:n] for a slice. -func Dedupe(data sort.Interface) (n int) { - if n = data.Len(); n < 2 { - return n - } - - sort.Sort(data) - a, b := 0, 1 - for b < n { - if data.Less(a, b) { - a++ - if a != b { - data.Swap(a, b) - } - } - b++ - } - return a + 1 -} diff --git a/vendor/github.com/cznic/strutil/LICENSE b/vendor/github.com/cznic/strutil/LICENSE deleted file mode 100644 index 2fdd92cf7..000000000 --- a/vendor/github.com/cznic/strutil/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014 The strutil Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/strutil/strutil.go b/vendor/github.com/cznic/strutil/strutil.go deleted file mode 100644 index cf375580e..000000000 --- a/vendor/github.com/cznic/strutil/strutil.go +++ /dev/null @@ -1,700 +0,0 @@ -// Copyright (c) 2014 The sortutil Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package strutil collects utils supplemental to the standard strings package. -package strutil - -import ( - "bytes" - "encoding/base32" - "encoding/base64" - "fmt" - "io" - "os" - "path/filepath" - "reflect" - "runtime" - "sort" - "strconv" - "strings" - "sync" -) - -// Base32ExtDecode decodes base32 extended (RFC 4648) text to binary data. -func Base32ExtDecode(text []byte) (data []byte, err error) { - n := base32.HexEncoding.DecodedLen(len(text)) - data = make([]byte, n) - decoder := base32.NewDecoder(base32.HexEncoding, bytes.NewBuffer(text)) - if n, err = decoder.Read(data); err != nil { - n = 0 - } - data = data[:n] - return -} - -// Base32ExtEncode encodes binary data to base32 extended (RFC 4648) encoded text. -func Base32ExtEncode(data []byte) (text []byte) { - n := base32.HexEncoding.EncodedLen(len(data)) - buf := bytes.NewBuffer(make([]byte, 0, n)) - encoder := base32.NewEncoder(base32.HexEncoding, buf) - encoder.Write(data) - encoder.Close() - if buf.Len() != n { - panic("internal error") - } - return buf.Bytes() -} - -// Base64Decode decodes base64 text to binary data. -func Base64Decode(text []byte) (data []byte, err error) { - n := base64.StdEncoding.DecodedLen(len(text)) - data = make([]byte, n) - decoder := base64.NewDecoder(base64.StdEncoding, bytes.NewBuffer(text)) - if n, err = decoder.Read(data); err != nil { - n = 0 - } - data = data[:n] - return -} - -// Base64Encode encodes binary data to base64 encoded text. -func Base64Encode(data []byte) (text []byte) { - n := base64.StdEncoding.EncodedLen(len(data)) - buf := bytes.NewBuffer(make([]byte, 0, n)) - encoder := base64.NewEncoder(base64.StdEncoding, buf) - encoder.Write(data) - encoder.Close() - if buf.Len() != n { - panic("internal error") - } - return buf.Bytes() -} - -// Formatter is an io.Writer extended by a fmt.Printf like function Format -type Formatter interface { - io.Writer - Format(format string, args ...interface{}) (n int, errno error) -} - -type indentFormatter struct { - io.Writer - indent []byte - indentLevel int - state int -} - -const ( - st0 = iota - stBOL - stPERC - stBOLPERC -) - -// IndentFormatter returns a new Formatter which interprets %i and %u in the -// Format() format string as indent and undent commands. The commands can -// nest. The Formatter writes to io.Writer 'w' and inserts one 'indent' -// string per current indent level value. -// Behaviour of commands reaching negative indent levels is undefined. -// IndentFormatter(os.Stdout, "\t").Format("abc%d%%e%i\nx\ny\n%uz\n", 3) -// output: -// abc3%e -// x -// y -// z -// The Go quoted string literal form of the above is: -// "abc%%e\n\tx\n\tx\nz\n" -// The commands can be scattered between separate invocations of Format(), -// i.e. the formatter keeps track of the indent level and knows if it is -// positioned on start of a line and should emit indentation(s). -// The same output as above can be produced by e.g.: -// f := IndentFormatter(os.Stdout, " ") -// f.Format("abc%d%%e%i\nx\n", 3) -// f.Format("y\n%uz\n") -func IndentFormatter(w io.Writer, indent string) Formatter { - return &indentFormatter{w, []byte(indent), 0, stBOL} -} - -func (f *indentFormatter) format(flat bool, format string, args ...interface{}) (n int, errno error) { - buf := []byte{} - for i := 0; i < len(format); i++ { - c := format[i] - switch f.state { - case st0: - switch c { - case '\n': - cc := c - if flat && f.indentLevel != 0 { - cc = ' ' - } - buf = append(buf, cc) - f.state = stBOL - case '%': - f.state = stPERC - default: - buf = append(buf, c) - } - case stBOL: - switch c { - case '\n': - cc := c - if flat && f.indentLevel != 0 { - cc = ' ' - } - buf = append(buf, cc) - case '%': - f.state = stBOLPERC - default: - if !flat { - for i := 0; i < f.indentLevel; i++ { - buf = append(buf, f.indent...) - } - } - buf = append(buf, c) - f.state = st0 - } - case stBOLPERC: - switch c { - case 'i': - f.indentLevel++ - f.state = stBOL - case 'u': - f.indentLevel-- - f.state = stBOL - default: - if !flat { - for i := 0; i < f.indentLevel; i++ { - buf = append(buf, f.indent...) - } - } - buf = append(buf, '%', c) - f.state = st0 - } - case stPERC: - switch c { - case 'i': - f.indentLevel++ - f.state = st0 - case 'u': - f.indentLevel-- - f.state = st0 - default: - buf = append(buf, '%', c) - f.state = st0 - } - default: - panic("unexpected state") - } - } - switch f.state { - case stPERC, stBOLPERC: - buf = append(buf, '%') - } - return f.Write([]byte(fmt.Sprintf(string(buf), args...))) -} - -func (f *indentFormatter) Format(format string, args ...interface{}) (n int, errno error) { - return f.format(false, format, args...) -} - -type flatFormatter indentFormatter - -// FlatFormatter returns a newly created Formatter with the same functionality as the one returned -// by IndentFormatter except it allows a newline in the 'format' string argument of Format -// to pass through iff indent level is currently zero. -// -// If indent level is non-zero then such new lines are changed to a space character. -// There is no indent string, the %i and %u format verbs are used solely to determine the indent level. -// -// The FlatFormatter is intended for flattening of normally nested structure textual representation to -// a one top level structure per line form. -// FlatFormatter(os.Stdout, " ").Format("abc%d%%e%i\nx\ny\n%uz\n", 3) -// output in the form of a Go quoted string literal: -// "abc3%%e x y z\n" -func FlatFormatter(w io.Writer) Formatter { - return (*flatFormatter)(IndentFormatter(w, "").(*indentFormatter)) -} - -func (f *flatFormatter) Format(format string, args ...interface{}) (n int, errno error) { - return (*indentFormatter)(f).format(true, format, args...) -} - -// Pool handles aligning of strings having equal values to the same string instance. -// Intended use is to conserve some memory e.g. where a large number of identically valued strings -// with non identical backing arrays may exists in several semantically distinct instances of some structs. -// Pool is *not* concurrent access safe. It doesn't handle common prefix/suffix aligning, -// e.g. having s1 == "abc" and s2 == "bc", s2 is not automatically aligned as s1[1:]. -type Pool struct { - pool map[string]string -} - -// NewPool returns a newly created Pool. -func NewPool() *Pool { - return &Pool{map[string]string{}} -} - -// Align returns a string with the same value as its argument. It guarantees that -// all aligned strings share a single instance in memory. -func (p *Pool) Align(s string) string { - if a, ok := p.pool[s]; ok { - return a - } - - s = StrPack(s) - p.pool[s] = s - return s -} - -// Count returns the number of items in the pool. -func (p *Pool) Count() int { - return len(p.pool) -} - -// GoPool is a concurrent access safe version of Pool. -type GoPool struct { - pool map[string]string - rwm *sync.RWMutex -} - -// NewGoPool returns a newly created GoPool. -func NewGoPool() (p *GoPool) { - return &GoPool{map[string]string{}, &sync.RWMutex{}} -} - -// Align returns a string with the same value as its argument. It guarantees that -// all aligned strings share a single instance in memory. -func (p *GoPool) Align(s string) (y string) { - if s != "" { - p.rwm.RLock() // R++ - if a, ok := p.pool[s]; ok { // found - p.rwm.RUnlock() // R-- - return a - } - - p.rwm.RUnlock() // R-- - // not found but with a race condition, retry within a write lock - p.rwm.Lock() // W++ - defer p.rwm.Unlock() // W-- - if a, ok := p.pool[s]; ok { // done in a race - return a - } - - // we won - s = StrPack(s) - p.pool[s] = s - return s - } - - return -} - -// Count returns the number of items in the pool. -func (p *GoPool) Count() int { - return len(p.pool) -} - -// Dict is a string <-> id bijection. Dict is *not* concurrent access safe for assigning new ids -// to strings not yet contained in the bijection. -// Id for an empty string is guaranteed to be 0, -// thus Id for any non empty string is guaranteed to be non zero. -type Dict struct { - si map[string]int - is []string -} - -// NewDict returns a newly created Dict. -func NewDict() (d *Dict) { - d = &Dict{map[string]int{}, []string{}} - d.Id("") - return -} - -// Count returns the number of items in the dict. -func (d *Dict) Count() int { - return len(d.is) -} - -// Id maps string s to its numeric identificator. -func (d *Dict) Id(s string) (y int) { - if y, ok := d.si[s]; ok { - return y - } - - s = StrPack(s) - y = len(d.is) - d.si[s] = y - d.is = append(d.is, s) - return -} - -// S maps an id to its string value and ok == true. Id values not contained in the bijection -// return "", false. -func (d *Dict) S(id int) (s string, ok bool) { - if id >= len(d.is) { - return "", false - } - return d.is[id], true -} - -// GoDict is a concurrent access safe version of Dict. -type GoDict struct { - si map[string]int - is []string - rwm *sync.RWMutex -} - -// NewGoDict returns a newly created GoDict. -func NewGoDict() (d *GoDict) { - d = &GoDict{map[string]int{}, []string{}, &sync.RWMutex{}} - d.Id("") - return -} - -// Count returns the number of items in the dict. -func (d *GoDict) Count() int { - return len(d.is) -} - -// Id maps string s to its numeric identificator. The implementation honors getting -// an existing id at the cost of assigning a new one. -func (d *GoDict) Id(s string) (y int) { - d.rwm.RLock() // R++ - if y, ok := d.si[s]; ok { // found - d.rwm.RUnlock() // R-- - return y - } - - d.rwm.RUnlock() // R-- - - // not found but with a race condition - d.rwm.Lock() // W++ recheck with write lock - defer d.rwm.Unlock() // W-- - if y, ok := d.si[s]; ok { // some other goroutine won already - return y - } - - // a race free not found state => insert the string - s = StrPack(s) - y = len(d.is) - d.si[s] = y - d.is = append(d.is, s) - return -} - -// S maps an id to its string value and ok == true. Id values not contained in the bijection -// return "", false. -func (d *GoDict) S(id int) (s string, ok bool) { - d.rwm.RLock() // R++ - defer d.rwm.RUnlock() // R-- - if id >= len(d.is) { - return "", false - } - return d.is[id], true -} - -// StrPack returns a new instance of s which is tightly packed in memory. -// It is intended for avoiding the situation where having a live reference -// to a string slice over an unreferenced biger underlying string keeps the biger one -// in memory anyway - it can't be GCed. -func StrPack(s string) string { - return string([]byte(s)) // T(U(T)) intentional. -} - -// JoinFields returns strings in flds joined by sep. Flds may contain arbitrary -// bytes, including the sep as they are safely escaped. JoinFields panics if -// sep is the backslash character or if len(sep) != 1. -func JoinFields(flds []string, sep string) string { - if len(sep) != 1 || sep == "\\" { - panic("invalid separator") - } - - a := make([]string, len(flds)) - for i, v := range flds { - v = strings.Replace(v, "\\", "\\0", -1) - a[i] = strings.Replace(v, sep, "\\1", -1) - } - return strings.Join(a, sep) -} - -// SplitFields splits s, which must be produced by JoinFields using the same -// sep, into flds. SplitFields panics if sep is the backslash character or if -// len(sep) != 1. -func SplitFields(s, sep string) (flds []string) { - if len(sep) != 1 || sep == "\\" { - panic("invalid separator") - } - - a := strings.Split(s, sep) - r := make([]string, len(a)) - for i, v := range a { - v = strings.Replace(v, "\\1", sep, -1) - r[i] = strings.Replace(v, "\\0", "\\", -1) - } - return r -} - -// PrettyPrintHooks allow to customize the result of PrettyPrint for types -// listed in the map value. -type PrettyPrintHooks map[reflect.Type]func(f Formatter, v interface{}, prefix, suffix string) - -// PrettyString returns the output of PrettyPrint as a string. -func PrettyString(v interface{}, prefix, suffix string, hooks PrettyPrintHooks) string { - var b bytes.Buffer - PrettyPrint(&b, v, prefix, suffix, hooks) - return b.String() -} - -// PrettyPrint pretty prints v to w. Zero values and unexported struct fields -// are omitted. -func PrettyPrint(w io.Writer, v interface{}, prefix, suffix string, hooks PrettyPrintHooks) { - if v == nil { - return - } - - f := IndentFormatter(w, "· ") - - defer func() { - if e := recover(); e != nil { - f.Format("\npanic: %v", e) - } - }() - - prettyPrint(nil, f, prefix, suffix, v, hooks) -} - -func prettyPrint(protect map[interface{}]struct{}, sf Formatter, prefix, suffix string, v interface{}, hooks PrettyPrintHooks) { - if v == nil { - return - } - - rt := reflect.TypeOf(v) - if handler := hooks[rt]; handler != nil { - handler(sf, v, prefix, suffix) - return - } - - rv := reflect.ValueOf(v) - switch rt.Kind() { - case reflect.Slice: - if rv.Len() == 0 { - return - } - - sf.Format("%s[]%T{ // len %d%i\n", prefix, rv.Index(0).Interface(), rv.Len()) - for i := 0; i < rv.Len(); i++ { - prettyPrint(protect, sf, fmt.Sprintf("%d: ", i), ",\n", rv.Index(i).Interface(), hooks) - } - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%u}" + suffix) - case reflect.Array: - if reflect.Zero(rt).Interface() == rv.Interface() { - return - } - - sf.Format("%s[%d]%T{%i\n", prefix, rv.Len(), rv.Index(0).Interface()) - for i := 0; i < rv.Len(); i++ { - prettyPrint(protect, sf, fmt.Sprintf("%d: ", i), ",\n", rv.Index(i).Interface(), hooks) - } - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%u}" + suffix) - case reflect.Struct: - if rt.NumField() == 0 { - return - } - - if reflect.DeepEqual(reflect.Zero(rt).Interface(), rv.Interface()) { - return - } - - sf.Format("%s%T{%i\n", prefix, v) - for i := 0; i < rt.NumField(); i++ { - f := rv.Field(i) - if !f.CanInterface() { - continue - } - - prettyPrint(protect, sf, fmt.Sprintf("%s: ", rt.Field(i).Name), ",\n", f.Interface(), hooks) - } - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%u}" + suffix) - case reflect.Ptr: - if rv.IsNil() { - return - } - - rvi := rv.Interface() - if _, ok := protect[rvi]; ok { - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s&%T{ /* recursive/repetitive pointee not shown */ }"+suffix, prefix, rv.Elem().Interface()) - return - } - - if protect == nil { - protect = map[interface{}]struct{}{} - } - protect[rvi] = struct{}{} - prettyPrint(protect, sf, prefix+"&", suffix, rv.Elem().Interface(), hooks) - case reflect.Int, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int8: - if v := rv.Int(); v != 0 { - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s%v"+suffix, prefix, v) - } - case reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint8: - if v := rv.Uint(); v != 0 { - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s%v"+suffix, prefix, v) - } - case reflect.Float32, reflect.Float64: - if v := rv.Float(); v != 0 { - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s%v"+suffix, prefix, v) - } - case reflect.Complex64, reflect.Complex128: - if v := rv.Complex(); v != 0 { - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s%v"+suffix, prefix, v) - } - case reflect.Uintptr: - if v := rv.Uint(); v != 0 { - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s%v"+suffix, prefix, v) - } - case reflect.UnsafePointer: - s := fmt.Sprintf("%p", rv.Interface()) - if s == "0x0" { - return - } - - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s%s"+suffix, prefix, s) - case reflect.Bool: - if v := rv.Bool(); v { - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s%v"+suffix, prefix, rv.Bool()) - } - case reflect.String: - s := rv.Interface().(string) - if s == "" { - return - } - - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s%q"+suffix, prefix, s) - case reflect.Chan: - if reflect.Zero(rt).Interface() == rv.Interface() { - return - } - - c := rv.Cap() - s := "" - if c != 0 { - s = fmt.Sprintf("// capacity: %d", c) - } - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%s%s %s%s"+suffix, prefix, rt.ChanDir(), rt.Elem().Name(), s) - case reflect.Func: - if rv.IsNil() { - return - } - - var in, out []string - for i := 0; i < rt.NumIn(); i++ { - x := reflect.Zero(rt.In(i)) - in = append(in, fmt.Sprintf("%T", x.Interface())) - } - if rt.IsVariadic() { - i := len(in) - 1 - in[i] = "..." + in[i][2:] - } - for i := 0; i < rt.NumOut(); i++ { - out = append(out, rt.Out(i).Name()) - } - s := "(" + strings.Join(in, ", ") + ")" - t := strings.Join(out, ", ") - if len(out) > 1 { - t = "(" + t + ")" - } - if t != "" { - t = " " + t - } - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%sfunc%s%s { ... }"+suffix, prefix, s, t) - case reflect.Map: - keys := rv.MapKeys() - if len(keys) == 0 { - return - } - - var buf bytes.Buffer - nf := IndentFormatter(&buf, "· ") - var skeys []string - for i, k := range keys { - prettyPrint(protect, nf, "", "", k.Interface(), hooks) - skeys = append(skeys, fmt.Sprintf("%s%10d", buf.Bytes(), i)) - buf.Reset() - } - sort.Strings(skeys) - sf.Format("%s%T{%i\n", prefix, v) - for _, k := range skeys { - si := strings.TrimSpace(k[len(k)-10:]) - k = k[:len(k)-10] - n, _ := strconv.ParseUint(si, 10, 64) - mv := rv.MapIndex(keys[n]) - prettyPrint(protect, sf, fmt.Sprintf("%s: ", k), ",\n", mv.Interface(), hooks) - } - suffix = strings.Replace(suffix, "%", "%%", -1) - sf.Format("%u}" + suffix) - } -} - -// Gopath returns the value of the $GOPATH environment variable or its default -// value if not set. -func Gopath() string { - if r := os.Getenv("GOPATH"); r != "" { - return r - } - - // go1.8: https://github.com/golang/go/blob/74628a8b9f102bddd5078ee426efe0fd57033115/doc/code.html#L122 - switch runtime.GOOS { - case "plan9": - return os.Getenv("home") - case "windows": - return filepath.Join(os.Getenv("USERPROFILE"), "go") - default: - return filepath.Join(os.Getenv("HOME"), "go") - } -} - -// Homepath returns the user's home directory path. -func Homepath() string { - // go1.8: https://github.com/golang/go/blob/74628a8b9f102bddd5078ee426efe0fd57033115/doc/code.html#L122 - switch runtime.GOOS { - case "plan9": - return os.Getenv("home") - case "windows": - return os.Getenv("USERPROFILE") - default: - return os.Getenv("HOME") - } -} - -// ImportPath returns the import path of the caller or an error, if any. -func ImportPath() (string, error) { - _, file, _, ok := runtime.Caller(1) - if !ok { - return "", fmt.Errorf("runtime.Caller failed") - } - - gopath := Gopath() - for _, v := range filepath.SplitList(gopath) { - gp := filepath.Join(v, "src") - path, err := filepath.Rel(gp, file) - if err != nil { - continue - } - - return filepath.Dir(path), nil - } - - return "", fmt.Errorf("cannot determine import path using GOPATH=%s", gopath) -} diff --git a/vendor/github.com/cznic/zappy/LICENSE b/vendor/github.com/cznic/zappy/LICENSE deleted file mode 100644 index bc67059c5..000000000 --- a/vendor/github.com/cznic/zappy/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014 The zappy Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the names of the authors nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cznic/zappy/decode.go b/vendor/github.com/cznic/zappy/decode.go deleted file mode 100644 index 867c8deea..000000000 --- a/vendor/github.com/cznic/zappy/decode.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2014 The zappy Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Copyright 2011 The Snappy-Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the SNAPPY-GO-LICENSE file. - -package zappy - -import ( - "encoding/binary" - "errors" -) - -// ErrCorrupt reports that the input is invalid. -var ErrCorrupt = errors.New("zappy: corrupt input") - -// DecodedLen returns the length of the decoded block. -func DecodedLen(src []byte) (int, error) { - v, _, err := decodedLen(src) - return v, err -} - -// decodedLen returns the length of the decoded block and the number of bytes -// that the length header occupied. -func decodedLen(src []byte) (blockLen, headerLen int, err error) { - v, n := binary.Uvarint(src) - if n == 0 { - return 0, 0, ErrCorrupt - } - - if uint64(int(v)) != v { - return 0, 0, errors.New("zappy: decoded block is too large") - } - - return int(v), n, nil -} diff --git a/vendor/github.com/cznic/zappy/decode_cgo.go b/vendor/github.com/cznic/zappy/decode_cgo.go deleted file mode 100644 index e5fff17f5..000000000 --- a/vendor/github.com/cznic/zappy/decode_cgo.go +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2014 The zappy Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Copyright 2011 The Snappy-Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the SNAPPY-GO-LICENSE file. - -// +build cgo,!purego - -package zappy - -import ( - "github.com/cznic/internal/buffer" -) - -/* - -#include -#include - -// supports only uint32 encoded values -int uvarint(unsigned int* n, uint8_t* src, int len) { - int r = 0; - unsigned int v = 0; - unsigned int s = 0; - while ((len-- != 0) && (++r <= 5)) { - uint8_t b = *src++; - v = v | ((b&0x7f)<>1; - if ((u&1) != 0) - x = ~x; - *n = x; - return i; -} - -int decode(int s, int len_src, uint8_t* src, int len_dst, uint8_t* dst) { - int d = 0; - int length; - while (s < len_src) { - int n, i = varint(&n, src+s, len_src-s); - if (i <= 0) { - return -1; - } - - s += i; - if (n >= 0) { - length = n+1; - if ((length > len_dst-d) || (length > len_src-s)) - return -1; - - memcpy(dst+d, src+s, length); - d += length; - s += length; - continue; - } - - - length = -n; - int offset; - i = uvarint((unsigned int*)(&offset), src+s, len_src-s); - if (i <= 0) - return -1; - - s += i; - if (s > len_src) - return -1; - - int end = d+length; - if ((offset > d) || (end > len_dst)) - return -1; - - for( ; d < end; d++) - *(dst+d) = *(dst+d-offset); - } - return d; -} - -*/ -import "C" - -func puregoDecode() bool { return false } - -// Decode returns the decoded form of src. The returned slice may be a sub- -// slice of buf if buf was large enough to hold the entire decoded block. -// Otherwise, a newly allocated slice will be returned. -// It is valid to pass a nil buf. -func Decode(buf, src []byte) ([]byte, error) { - dLen, s, err := decodedLen(src) - if err != nil { - return nil, err - } - - if dLen == 0 { - if len(src) == 1 { - return nil, nil - } - - return nil, ErrCorrupt - } - - if len(buf) < dLen { - buf = *buffer.Get(dLen) - } - - d := int(C.decode(C.int(s), C.int(len(src)), (*C.uint8_t)(&src[0]), C.int(len(buf)), (*C.uint8_t)(&buf[0]))) - if d != dLen { - return nil, ErrCorrupt - } - - return buf[:d], nil -} diff --git a/vendor/github.com/cznic/zappy/decode_nocgo.go b/vendor/github.com/cznic/zappy/decode_nocgo.go deleted file mode 100644 index 2f6d3b1da..000000000 --- a/vendor/github.com/cznic/zappy/decode_nocgo.go +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2014 The zappy Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Copyright 2011 The Snappy-Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the SNAPPY-GO-LICENSE file. - -// +build !cgo purego - -package zappy - -import ( - "encoding/binary" - - "github.com/cznic/internal/buffer" -) - -func puregoDecode() bool { return true } - -// Decode returns the decoded form of src. The returned slice may be a sub- -// slice of buf if buf was large enough to hold the entire decoded block. -// Otherwise, a newly allocated slice will be returned. -// It is valid to pass a nil buf. -func Decode(buf, src []byte) ([]byte, error) { - dLen, s, err := decodedLen(src) - if err != nil { - return nil, err - } - - if dLen == 0 { - if len(src) == 1 { - return nil, nil - } - - return nil, ErrCorrupt - } - - if len(buf) < dLen { - buf = *buffer.Get(dLen) - } - - var d, offset, length int - for s < len(src) { - n, i := binary.Varint(src[s:]) - if i <= 0 { - return nil, ErrCorrupt - } - - s += i - if n >= 0 { - length = int(n + 1) - if length > len(buf)-d || length > len(src)-s { - return nil, ErrCorrupt - } - - copy(buf[d:], src[s:s+length]) - d += length - s += length - continue - } - - length = int(-n) - off64, i := binary.Uvarint(src[s:]) - if i <= 0 { - return nil, ErrCorrupt - } - - offset = int(off64) - s += i - if s > len(src) { - return nil, ErrCorrupt - } - - end := d + length - if offset > d || end > len(buf) { - return nil, ErrCorrupt - } - - for s, v := range buf[d-offset : end-offset] { - buf[d+s] = v - } - d = end - - } - if d != dLen { - return nil, ErrCorrupt - } - - return buf[:d], nil -} diff --git a/vendor/github.com/cznic/zappy/encode.go b/vendor/github.com/cznic/zappy/encode.go deleted file mode 100644 index 5b8a20dd4..000000000 --- a/vendor/github.com/cznic/zappy/encode.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 The zappy Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Copyright 2011 The Snappy-Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the SNAPPY-GO-LICENSE file. - -package zappy - -import ( - "encoding/binary" -) - -// We limit how far copy back-references can go, the same as the snappy C++ -// code. -const maxOffset = 1 << 20 - -// emitCopy writes a copy chunk and returns the number of bytes written. -func emitCopy(dst []byte, offset, length int) (n int) { - n = binary.PutVarint(dst, int64(-length)) - n += binary.PutUvarint(dst[n:], uint64(offset)) - return -} - -// emitLiteral writes a literal chunk and returns the number of bytes written. -func emitLiteral(dst, lit []byte) (n int) { - n = binary.PutVarint(dst, int64(len(lit)-1)) - n += copy(dst[n:], lit) - return -} - -// MaxEncodedLen returns the maximum length of a zappy block, given its -// uncompressed length. -func MaxEncodedLen(srcLen int) int { - return 10 + srcLen + (srcLen+1)/2 -} diff --git a/vendor/github.com/cznic/zappy/encode_cgo.go b/vendor/github.com/cznic/zappy/encode_cgo.go deleted file mode 100644 index 0ebccef56..000000000 --- a/vendor/github.com/cznic/zappy/encode_cgo.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2014 The zappy Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Copyright 2011 The Snappy-Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the SNAPPY-GO-LICENSE file. - -// +build cgo,!purego - -package zappy - -/* - -#include -#include - -#define MAXOFFSET 1<<20 - -int putUvarint(uint8_t* buf, unsigned int x) { - int i = 1; - for (; x >= 0x80; i++) { - *buf++ = x|0x80; - x >>= 7; - } - *buf = x; - return i; -} - -int putVarint(uint8_t* buf, int x) { - unsigned int ux = x << 1; - if (x < 0) - ux = ~ux; - return putUvarint(buf, ux); -} - -int emitLiteral(uint8_t* dst, uint8_t* lit, int len_lit) { - int n = putVarint(dst, len_lit-1); - memcpy(dst+n, lit, len_lit); - return n+len_lit; -} - -int emitCopy(uint8_t* dst, int off, int len) { - int n = putVarint(dst, -len); - return n+putUvarint(dst+n, (unsigned int)off); -} - -int encode(int d, uint8_t* dst, uint8_t* src, int len_src) { - int table[1<<12]; - int s = 0; - int t = 0; - int lit = 0; - int lim = 0; - memset(table, 0, sizeof(table)); - for (lim = len_src-3; s < lim; ) { - // Update the hash table. - uint32_t b0 = src[s]; - uint32_t b1 = src[s+1]; - uint32_t b2 = src[s+2]; - uint32_t b3 = src[s+3]; - uint32_t h = b0 | (b1<<8) | (b2<<16) | (b3<<24); - uint32_t i; -more: - i = (h*0x1e35a7bd)>>20; - t = table[i]; - table[i] = s; - // If t is invalid or src[s:s+4] differs from src[t:t+4], accumulate a literal byte. - if ((t == 0) || (s-t >= MAXOFFSET) || (b0 != src[t]) || (b1 != src[t+1]) || (b2 != src[t+2]) || (b3 != src[t+3])) { - s++; - if (s >= lim) - break; - - b0 = b1; - b1 = b2; - b2 = b3; - b3 = src[s+3]; - h = (h>>8) | ((b3)<<24); - goto more; - } - - // Otherwise, we have a match. First, emit any pending literal bytes. - if (lit != s) { - d += emitLiteral(dst+d, src+lit, s-lit); - } - // Extend the match to be as long as possible. - int s0 = s; - s += 4; - t += 4; - while ((s < len_src) && (src[s] == src[t])) { - s++; - t++; - } - d += emitCopy(dst+d, s-t, s-s0); - lit = s; - } - // Emit any final pending literal bytes and return. - if (lit != len_src) { - d += emitLiteral(dst+d, src+lit, len_src-lit); - } - return d; -} - -*/ -import "C" - -import ( - "encoding/binary" - "fmt" - "math" - - "github.com/cznic/internal/buffer" -) - -func puregoEncode() bool { return false } - -// Encode returns the encoded form of src. The returned slice may be a sub- -// slice of buf if buf was large enough to hold the entire encoded block. -// Otherwise, a newly allocated slice will be returned. -// It is valid to pass a nil buf. -func Encode(buf, src []byte) ([]byte, error) { - if n := MaxEncodedLen(len(src)); len(buf) < n { - buf = *buffer.Get(n) - } - - if len(src) > math.MaxInt32 { - return nil, fmt.Errorf("zappy.Encode: too long data: %d bytes", len(src)) - } - - // The block starts with the varint-encoded length of the decompressed bytes. - d := binary.PutUvarint(buf, uint64(len(src))) - - // Return early if src is short. - if len(src) <= 4 { - if len(src) != 0 { - d += emitLiteral(buf[d:], src) - } - return buf[:d], nil - } - - d = int(C.encode(C.int(d), (*C.uint8_t)(&buf[0]), (*C.uint8_t)(&src[0]), C.int(len(src)))) - return buf[:d], nil -} diff --git a/vendor/github.com/cznic/zappy/encode_nocgo.go b/vendor/github.com/cznic/zappy/encode_nocgo.go deleted file mode 100644 index af33eb927..000000000 --- a/vendor/github.com/cznic/zappy/encode_nocgo.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2014 The zappy Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Copyright 2011 The Snappy-Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the SNAPPY-GO-LICENSE file. - -// +build !cgo purego - -package zappy - -import ( - "encoding/binary" - "fmt" - "math" - - "github.com/cznic/internal/buffer" -) - -func puregoEncode() bool { return true } - -// Encode returns the encoded form of src. The returned slice may be a sub- -// slice of buf if buf was large enough to hold the entire encoded block. -// Otherwise, a newly allocated slice will be returned. -// It is valid to pass a nil buf. -func Encode(buf, src []byte) ([]byte, error) { - if n := MaxEncodedLen(len(src)); len(buf) < n { - buf = *buffer.Get(n) - } - - if len(src) > math.MaxInt32 { - return nil, fmt.Errorf("zappy.Encode: too long data: %d bytes", len(src)) - } - - // The block starts with the varint-encoded length of the decompressed bytes. - d := binary.PutUvarint(buf, uint64(len(src))) - - // Return early if src is short. - if len(src) <= 4 { - if len(src) != 0 { - d += emitLiteral(buf[d:], src) - } - return buf[:d], nil - } - - // Iterate over the source bytes. - var ( - table [1 << 12]int // Hash table - s int // The iterator position. - t int // The last position with the same hash as s. - lit int // The start position of any pending literal bytes. - ) - for lim := len(src) - 3; s < lim; { - // Update the hash table. - b0, b1, b2, b3 := src[s], src[s+1], src[s+2], src[s+3] - h := uint32(b0) | uint32(b1)<<8 | uint32(b2)<<16 | uint32(b3)<<24 - more: - p := &table[(h*0x1e35a7bd)>>20] - t, *p = *p, s - // If t is invalid or src[s:s+4] differs from src[t:t+4], accumulate a literal byte. - if t == 0 || s-t >= maxOffset || b0 != src[t] || b1 != src[t+1] || b2 != src[t+2] || b3 != src[t+3] { - s++ - if s >= lim { - break - } - - b0, b1, b2, b3 = b1, b2, b3, src[s+3] - h = h>>8 | uint32(b3)<<24 - goto more - } - - // Otherwise, we have a match. First, emit any pending literal bytes. - if lit != s { - d += emitLiteral(buf[d:], src[lit:s]) - } - // Extend the match to be as long as possible. - s0 := s - s, t = s+4, t+4 - for s < len(src) && src[s] == src[t] { - s++ - t++ - } - // Emit the copied bytes. - d += emitCopy(buf[d:], s-t, s-s0) - lit = s - } - - // Emit any final pending literal bytes and return. - if lit != len(src) { - d += emitLiteral(buf[d:], src[lit:]) - } - return buf[:d], nil -} diff --git a/vendor/github.com/cznic/zappy/zappy.go b/vendor/github.com/cznic/zappy/zappy.go deleted file mode 100644 index 65d9efb12..000000000 --- a/vendor/github.com/cznic/zappy/zappy.go +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2014 The zappy Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Copyright 2011 The Snappy-Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the SNAPPY-GO-LICENSE file. - -/* -Package zappy implements the zappy block-based compression format. It aims for -a combination of good speed and reasonable compression. - -Zappy is a format incompatible, API compatible fork of snappy[1]. The C++ -snappy implementation is at [2]. - -Reasons for the fork - -The snappy compression is pretty good. Yet it has one problem built into its -format definition[3] - the maximum length of a copy "instruction" is 64 bytes. -For some specific usage patterns with long runs of repeated data, it turns out -the compression is suboptimal. For example a 1:1000 "sparseness" 64kB bit index -with only few set bits is compressed to about 3kB (about 1000 of 64B copy, 3 -byte "instructions"). - -Format description - -Zappy uses much less complicated format than snappy. Each encoded block begins -with the uvarint-encoded[4] length of the decoded data, followed by a sequence -of chunks. Chunks begin and end on byte boundaries. The chunk starts with a -varint encoded number N: - - N >= 0: N+1 literal bytes follow. - - N < 0: copy -N bytes, starting at offset M (in the following uvarint). - -Performance issues - -Compression rate is roughly the same as of snappy for the reference data set: - - testdata/html: snappy 23320, zappy 22943, 0.984, orig 102400 - testdata/urls.10K: snappy 334437, zappy 355163, 1.062, orig 702087 - testdata/house.jpg: snappy 126711, zappy 126694, 1.000, orig 126958 - testdata/mapreduce-osdi-1.pdf: snappy 77227, zappy 77646, 1.005, orig 94330 - testdata/html_x_4: snappy 92350, zappy 22956, 0.249, orig 409600 - testdata/cp.html: snappy 11938, zappy 12961, 1.086, orig 24603 - testdata/fields.c: snappy 4825, zappy 5395, 1.118, orig 11150 - testdata/grammar.lsp: snappy 1814, zappy 1933, 1.066, orig 3721 - testdata/kennedy.xls: snappy 423518, zappy 440597, 1.040, orig 1029744 - testdata/alice29.txt: snappy 89550, zappy 104016, 1.162, orig 152089 - testdata/asyoulik.txt: snappy 79583, zappy 91345, 1.148, orig 125179 - testdata/lcet10.txt: snappy 238761, zappy 275488, 1.154, orig 426754 - testdata/plrabn12.txt: snappy 324567, zappy 376885, 1.161, orig 481861 - testdata/ptt5: snappy 96350, zappy 91465, 0.949, orig 513216 - testdata/sum: snappy 18927, zappy 20015, 1.057, orig 38240 - testdata/xargs.1: snappy 2532, zappy 2793, 1.103, orig 4227 - testdata/geo.protodata: snappy 23362, zappy 20759, 0.889, orig 118588 - testdata/kppkn.gtb: snappy 73962, zappy 87200, 1.179, orig 184320 - TOTAL: snappy 2043734, zappy 2136254, 1.045, orig 4549067 - -Zappy has better RLE handling (1/1000+1 non zero bytes in each index): - - Sparse bit index 16 B: snappy 9, zappy 9, 1.000 - Sparse bit index 32 B: snappy 10, zappy 10, 1.000 - Sparse bit index 64 B: snappy 11, zappy 10, 0.909 - Sparse bit index 128 B: snappy 16, zappy 14, 0.875 - Sparse bit index 256 B: snappy 22, zappy 14, 0.636 - Sparse bit index 512 B: snappy 36, zappy 16, 0.444 - Sparse bit index 1024 B: snappy 57, zappy 18, 0.316 - Sparse bit index 2048 B: snappy 111, zappy 32, 0.288 - Sparse bit index 4096 B: snappy 210, zappy 31, 0.148 - Sparse bit index 8192 B: snappy 419, zappy 75, 0.179 - Sparse bit index 16384 B: snappy 821, zappy 138, 0.168 - Sparse bit index 32768 B: snappy 1627, zappy 232, 0.143 - Sparse bit index 65536 B: snappy 3243, zappy 451, 0.139 - -When compiled with CGO_ENABLED=1, zappy is now faster than Go snappy. -Old=Go snappy, new=zappy: - - benchmark old MB/s new MB/s speedup - BenchmarkWordsDecode1e3 148.98 189.04 1.27x - BenchmarkWordsDecode1e4 150.29 182.51 1.21x - BenchmarkWordsDecode1e5 145.79 182.95 1.25x - BenchmarkWordsDecode1e6 167.43 187.69 1.12x - BenchmarkWordsEncode1e3 47.11 145.69 3.09x - BenchmarkWordsEncode1e4 81.47 136.50 1.68x - BenchmarkWordsEncode1e5 78.86 127.93 1.62x - BenchmarkWordsEncode1e6 96.81 142.95 1.48x - Benchmark_UFlat0 316.87 463.19 1.46x - Benchmark_UFlat1 231.56 350.32 1.51x - Benchmark_UFlat2 3656.68 8258.39 2.26x - Benchmark_UFlat3 892.56 1270.09 1.42x - Benchmark_UFlat4 315.84 959.08 3.04x - Benchmark_UFlat5 211.70 301.55 1.42x - Benchmark_UFlat6 211.59 258.29 1.22x - Benchmark_UFlat7 209.80 272.21 1.30x - Benchmark_UFlat8 254.59 301.70 1.19x - Benchmark_UFlat9 163.39 192.66 1.18x - Benchmark_UFlat10 155.46 189.70 1.22x - Benchmark_UFlat11 170.11 198.95 1.17x - Benchmark_UFlat12 148.32 178.78 1.21x - Benchmark_UFlat13 359.25 579.99 1.61x - Benchmark_UFlat14 197.27 291.33 1.48x - Benchmark_UFlat15 185.75 248.07 1.34x - Benchmark_UFlat16 362.74 582.66 1.61x - Benchmark_UFlat17 222.95 240.01 1.08x - Benchmark_ZFlat0 188.66 311.89 1.65x - Benchmark_ZFlat1 101.46 201.34 1.98x - Benchmark_ZFlat2 93.62 244.50 2.61x - Benchmark_ZFlat3 102.79 243.34 2.37x - Benchmark_ZFlat4 191.64 625.32 3.26x - Benchmark_ZFlat5 103.09 169.39 1.64x - Benchmark_ZFlat6 110.35 182.57 1.65x - Benchmark_ZFlat7 89.56 190.53 2.13x - Benchmark_ZFlat8 154.05 235.68 1.53x - Benchmark_ZFlat9 87.58 133.51 1.52x - Benchmark_ZFlat10 82.08 127.51 1.55x - Benchmark_ZFlat11 91.36 138.91 1.52x - Benchmark_ZFlat12 79.24 123.02 1.55x - Benchmark_ZFlat13 217.04 374.26 1.72x - Benchmark_ZFlat14 100.33 168.03 1.67x - Benchmark_ZFlat15 80.79 160.46 1.99x - Benchmark_ZFlat16 213.32 375.79 1.76x - Benchmark_ZFlat17 135.37 197.13 1.46x - -The package builds with CGO_ENABLED=0 as well, but the performance is worse. - - $ CGO_ENABLED=0 go test -test.run=NONE -test.bench=. > old.benchcmp - $ CGO_ENABLED=1 go test -test.run=NONE -test.bench=. > new.benchcmp - $ benchcmp old.benchcmp new.benchcmp - benchmark old ns/op new ns/op delta - BenchmarkWordsDecode1e3 9735 5288 -45.68% - BenchmarkWordsDecode1e4 100229 55369 -44.76% - BenchmarkWordsDecode1e5 1037611 546420 -47.34% - BenchmarkWordsDecode1e6 9559352 5335307 -44.19% - BenchmarkWordsEncode1e3 16206 6629 -59.10% - BenchmarkWordsEncode1e4 140283 73161 -47.85% - BenchmarkWordsEncode1e5 1476657 781756 -47.06% - BenchmarkWordsEncode1e6 12702229 6997656 -44.91% - Benchmark_UFlat0 397307 221198 -44.33% - Benchmark_UFlat1 3890483 2008341 -48.38% - Benchmark_UFlat2 35810 15398 -57.00% - Benchmark_UFlat3 140850 74194 -47.32% - Benchmark_UFlat4 814575 426783 -47.61% - Benchmark_UFlat5 156995 81473 -48.10% - Benchmark_UFlat6 77645 43161 -44.41% - Benchmark_UFlat7 25415 13579 -46.57% - Benchmark_UFlat8 6372440 3412916 -46.44% - Benchmark_UFlat9 1453679 789956 -45.66% - Benchmark_UFlat10 1243146 660747 -46.85% - Benchmark_UFlat11 3903493 2146334 -45.02% - Benchmark_UFlat12 5106250 2696144 -47.20% - Benchmark_UFlat13 1641394 884969 -46.08% - Benchmark_UFlat14 262206 131174 -49.97% - Benchmark_UFlat15 32325 17047 -47.26% - Benchmark_UFlat16 366991 204877 -44.17% - Benchmark_UFlat17 1343988 770907 -42.64% - Benchmark_ZFlat0 579954 329812 -43.13% - Benchmark_ZFlat1 6564692 3504867 -46.61% - Benchmark_ZFlat2 902029 513700 -43.05% - Benchmark_ZFlat3 678722 384312 -43.38% - Benchmark_ZFlat4 1197389 654361 -45.35% - Benchmark_ZFlat5 262677 144939 -44.82% - Benchmark_ZFlat6 111249 60876 -45.28% - Benchmark_ZFlat7 39024 19420 -50.24% - Benchmark_ZFlat8 8046106 4387928 -45.47% - Benchmark_ZFlat9 2043167 1143139 -44.05% - Benchmark_ZFlat10 1781604 980528 -44.96% - Benchmark_ZFlat11 5478647 3078585 -43.81% - Benchmark_ZFlat12 7245995 3929863 -45.77% - Benchmark_ZFlat13 2432529 1371606 -43.61% - Benchmark_ZFlat14 420315 227494 -45.88% - Benchmark_ZFlat15 52378 26564 -49.28% - Benchmark_ZFlat16 567047 316196 -44.24% - Benchmark_ZFlat17 1630820 937310 -42.53% - - benchmark old MB/s new MB/s speedup - BenchmarkWordsDecode1e3 102.71 189.08 1.84x - BenchmarkWordsDecode1e4 99.77 180.60 1.81x - BenchmarkWordsDecode1e5 96.38 183.01 1.90x - BenchmarkWordsDecode1e6 104.61 187.43 1.79x - BenchmarkWordsEncode1e3 61.70 150.85 2.44x - BenchmarkWordsEncode1e4 71.28 136.68 1.92x - BenchmarkWordsEncode1e5 67.72 127.92 1.89x - BenchmarkWordsEncode1e6 78.73 142.90 1.82x - Benchmark_UFlat0 257.73 462.93 1.80x - Benchmark_UFlat1 180.46 349.59 1.94x - Benchmark_UFlat2 3545.30 8244.61 2.33x - Benchmark_UFlat3 669.72 1271.39 1.90x - Benchmark_UFlat4 502.84 959.74 1.91x - Benchmark_UFlat5 156.71 301.98 1.93x - Benchmark_UFlat6 143.60 258.33 1.80x - Benchmark_UFlat7 146.41 274.01 1.87x - Benchmark_UFlat8 161.59 301.72 1.87x - Benchmark_UFlat9 104.62 192.53 1.84x - Benchmark_UFlat10 100.70 189.45 1.88x - Benchmark_UFlat11 109.33 198.83 1.82x - Benchmark_UFlat12 94.37 178.72 1.89x - Benchmark_UFlat13 312.67 579.93 1.85x - Benchmark_UFlat14 145.84 291.52 2.00x - Benchmark_UFlat15 130.77 247.95 1.90x - Benchmark_UFlat16 323.14 578.82 1.79x - Benchmark_UFlat17 137.14 239.09 1.74x - Benchmark_ZFlat0 176.57 310.48 1.76x - Benchmark_ZFlat1 106.95 200.32 1.87x - Benchmark_ZFlat2 140.75 247.14 1.76x - Benchmark_ZFlat3 138.98 245.45 1.77x - Benchmark_ZFlat4 342.08 625.95 1.83x - Benchmark_ZFlat5 93.66 169.75 1.81x - Benchmark_ZFlat6 100.23 183.16 1.83x - Benchmark_ZFlat7 95.35 191.60 2.01x - Benchmark_ZFlat8 127.98 234.68 1.83x - Benchmark_ZFlat9 74.44 133.04 1.79x - Benchmark_ZFlat10 70.26 127.66 1.82x - Benchmark_ZFlat11 77.89 138.62 1.78x - Benchmark_ZFlat12 66.50 122.62 1.84x - Benchmark_ZFlat13 210.98 374.17 1.77x - Benchmark_ZFlat14 90.98 168.09 1.85x - Benchmark_ZFlat15 80.70 159.12 1.97x - Benchmark_ZFlat16 209.13 375.04 1.79x - Benchmark_ZFlat17 113.02 196.65 1.74x - $ - -Build tags - -If a constraint 'purego' appears in the build constraints [5] then a pure Go -version is built regardless of the $CGO_ENABLED value. - - $ touch zappy.go ; go install -tags purego github.com/cznic/zappy # for example - -Information sources - -... referenced from the above documentation. - - [1]: http://github.com/golang/snappy - [2]: http://code.google.com/p/snappy/ - [3]: http://code.google.com/p/snappy/source/browse/trunk/format_description.txt - [4]: http://golang.org/pkg/encoding/binary/ - [5]: http://golang.org/pkg/go/build/#hdr-Build_Constraints -*/ -package zappy diff --git a/vendor/github.com/dustin/go-humanize/LICENSE b/vendor/github.com/dustin/go-humanize/LICENSE new file mode 100644 index 000000000..8d9a94a90 --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/LICENSE @@ -0,0 +1,21 @@ +Copyright (c) 2005-2008 Dustin Sallings + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/vendor/github.com/dustin/go-humanize/big.go b/vendor/github.com/dustin/go-humanize/big.go new file mode 100644 index 000000000..f49dc337d --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/big.go @@ -0,0 +1,31 @@ +package humanize + +import ( + "math/big" +) + +// order of magnitude (to a max order) +func oomm(n, b *big.Int, maxmag int) (float64, int) { + mag := 0 + m := &big.Int{} + for n.Cmp(b) >= 0 { + n.DivMod(n, b, m) + mag++ + if mag == maxmag && maxmag >= 0 { + break + } + } + return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag +} + +// total order of magnitude +// (same as above, but with no upper limit) +func oom(n, b *big.Int) (float64, int) { + mag := 0 + m := &big.Int{} + for n.Cmp(b) >= 0 { + n.DivMod(n, b, m) + mag++ + } + return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag +} diff --git a/vendor/github.com/dustin/go-humanize/bigbytes.go b/vendor/github.com/dustin/go-humanize/bigbytes.go new file mode 100644 index 000000000..1a2bf6172 --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/bigbytes.go @@ -0,0 +1,173 @@ +package humanize + +import ( + "fmt" + "math/big" + "strings" + "unicode" +) + +var ( + bigIECExp = big.NewInt(1024) + + // BigByte is one byte in bit.Ints + BigByte = big.NewInt(1) + // BigKiByte is 1,024 bytes in bit.Ints + BigKiByte = (&big.Int{}).Mul(BigByte, bigIECExp) + // BigMiByte is 1,024 k bytes in bit.Ints + BigMiByte = (&big.Int{}).Mul(BigKiByte, bigIECExp) + // BigGiByte is 1,024 m bytes in bit.Ints + BigGiByte = (&big.Int{}).Mul(BigMiByte, bigIECExp) + // BigTiByte is 1,024 g bytes in bit.Ints + BigTiByte = (&big.Int{}).Mul(BigGiByte, bigIECExp) + // BigPiByte is 1,024 t bytes in bit.Ints + BigPiByte = (&big.Int{}).Mul(BigTiByte, bigIECExp) + // BigEiByte is 1,024 p bytes in bit.Ints + BigEiByte = (&big.Int{}).Mul(BigPiByte, bigIECExp) + // BigZiByte is 1,024 e bytes in bit.Ints + BigZiByte = (&big.Int{}).Mul(BigEiByte, bigIECExp) + // BigYiByte is 1,024 z bytes in bit.Ints + BigYiByte = (&big.Int{}).Mul(BigZiByte, bigIECExp) +) + +var ( + bigSIExp = big.NewInt(1000) + + // BigSIByte is one SI byte in big.Ints + BigSIByte = big.NewInt(1) + // BigKByte is 1,000 SI bytes in big.Ints + BigKByte = (&big.Int{}).Mul(BigSIByte, bigSIExp) + // BigMByte is 1,000 SI k bytes in big.Ints + BigMByte = (&big.Int{}).Mul(BigKByte, bigSIExp) + // BigGByte is 1,000 SI m bytes in big.Ints + BigGByte = (&big.Int{}).Mul(BigMByte, bigSIExp) + // BigTByte is 1,000 SI g bytes in big.Ints + BigTByte = (&big.Int{}).Mul(BigGByte, bigSIExp) + // BigPByte is 1,000 SI t bytes in big.Ints + BigPByte = (&big.Int{}).Mul(BigTByte, bigSIExp) + // BigEByte is 1,000 SI p bytes in big.Ints + BigEByte = (&big.Int{}).Mul(BigPByte, bigSIExp) + // BigZByte is 1,000 SI e bytes in big.Ints + BigZByte = (&big.Int{}).Mul(BigEByte, bigSIExp) + // BigYByte is 1,000 SI z bytes in big.Ints + BigYByte = (&big.Int{}).Mul(BigZByte, bigSIExp) +) + +var bigBytesSizeTable = map[string]*big.Int{ + "b": BigByte, + "kib": BigKiByte, + "kb": BigKByte, + "mib": BigMiByte, + "mb": BigMByte, + "gib": BigGiByte, + "gb": BigGByte, + "tib": BigTiByte, + "tb": BigTByte, + "pib": BigPiByte, + "pb": BigPByte, + "eib": BigEiByte, + "eb": BigEByte, + "zib": BigZiByte, + "zb": BigZByte, + "yib": BigYiByte, + "yb": BigYByte, + // Without suffix + "": BigByte, + "ki": BigKiByte, + "k": BigKByte, + "mi": BigMiByte, + "m": BigMByte, + "gi": BigGiByte, + "g": BigGByte, + "ti": BigTiByte, + "t": BigTByte, + "pi": BigPiByte, + "p": BigPByte, + "ei": BigEiByte, + "e": BigEByte, + "z": BigZByte, + "zi": BigZiByte, + "y": BigYByte, + "yi": BigYiByte, +} + +var ten = big.NewInt(10) + +func humanateBigBytes(s, base *big.Int, sizes []string) string { + if s.Cmp(ten) < 0 { + return fmt.Sprintf("%d B", s) + } + c := (&big.Int{}).Set(s) + val, mag := oomm(c, base, len(sizes)-1) + suffix := sizes[mag] + f := "%.0f %s" + if val < 10 { + f = "%.1f %s" + } + + return fmt.Sprintf(f, val, suffix) + +} + +// BigBytes produces a human readable representation of an SI size. +// +// See also: ParseBigBytes. +// +// BigBytes(82854982) -> 83 MB +func BigBytes(s *big.Int) string { + sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} + return humanateBigBytes(s, bigSIExp, sizes) +} + +// BigIBytes produces a human readable representation of an IEC size. +// +// See also: ParseBigBytes. +// +// BigIBytes(82854982) -> 79 MiB +func BigIBytes(s *big.Int) string { + sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"} + return humanateBigBytes(s, bigIECExp, sizes) +} + +// ParseBigBytes parses a string representation of bytes into the number +// of bytes it represents. +// +// See also: BigBytes, BigIBytes. +// +// ParseBigBytes("42 MB") -> 42000000, nil +// ParseBigBytes("42 mib") -> 44040192, nil +func ParseBigBytes(s string) (*big.Int, error) { + lastDigit := 0 + hasComma := false + for _, r := range s { + if !(unicode.IsDigit(r) || r == '.' || r == ',') { + break + } + if r == ',' { + hasComma = true + } + lastDigit++ + } + + num := s[:lastDigit] + if hasComma { + num = strings.Replace(num, ",", "", -1) + } + + val := &big.Rat{} + _, err := fmt.Sscanf(num, "%f", val) + if err != nil { + return nil, err + } + + extra := strings.ToLower(strings.TrimSpace(s[lastDigit:])) + if m, ok := bigBytesSizeTable[extra]; ok { + mv := (&big.Rat{}).SetInt(m) + val.Mul(val, mv) + rv := &big.Int{} + rv.Div(val.Num(), val.Denom()) + return rv, nil + } + + return nil, fmt.Errorf("unhandled size name: %v", extra) +} diff --git a/vendor/github.com/dustin/go-humanize/bytes.go b/vendor/github.com/dustin/go-humanize/bytes.go new file mode 100644 index 000000000..0b498f488 --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/bytes.go @@ -0,0 +1,143 @@ +package humanize + +import ( + "fmt" + "math" + "strconv" + "strings" + "unicode" +) + +// IEC Sizes. +// kibis of bits +const ( + Byte = 1 << (iota * 10) + KiByte + MiByte + GiByte + TiByte + PiByte + EiByte +) + +// SI Sizes. +const ( + IByte = 1 + KByte = IByte * 1000 + MByte = KByte * 1000 + GByte = MByte * 1000 + TByte = GByte * 1000 + PByte = TByte * 1000 + EByte = PByte * 1000 +) + +var bytesSizeTable = map[string]uint64{ + "b": Byte, + "kib": KiByte, + "kb": KByte, + "mib": MiByte, + "mb": MByte, + "gib": GiByte, + "gb": GByte, + "tib": TiByte, + "tb": TByte, + "pib": PiByte, + "pb": PByte, + "eib": EiByte, + "eb": EByte, + // Without suffix + "": Byte, + "ki": KiByte, + "k": KByte, + "mi": MiByte, + "m": MByte, + "gi": GiByte, + "g": GByte, + "ti": TiByte, + "t": TByte, + "pi": PiByte, + "p": PByte, + "ei": EiByte, + "e": EByte, +} + +func logn(n, b float64) float64 { + return math.Log(n) / math.Log(b) +} + +func humanateBytes(s uint64, base float64, sizes []string) string { + if s < 10 { + return fmt.Sprintf("%d B", s) + } + e := math.Floor(logn(float64(s), base)) + suffix := sizes[int(e)] + val := math.Floor(float64(s)/math.Pow(base, e)*10+0.5) / 10 + f := "%.0f %s" + if val < 10 { + f = "%.1f %s" + } + + return fmt.Sprintf(f, val, suffix) +} + +// Bytes produces a human readable representation of an SI size. +// +// See also: ParseBytes. +// +// Bytes(82854982) -> 83 MB +func Bytes(s uint64) string { + sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"} + return humanateBytes(s, 1000, sizes) +} + +// IBytes produces a human readable representation of an IEC size. +// +// See also: ParseBytes. +// +// IBytes(82854982) -> 79 MiB +func IBytes(s uint64) string { + sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"} + return humanateBytes(s, 1024, sizes) +} + +// ParseBytes parses a string representation of bytes into the number +// of bytes it represents. +// +// See Also: Bytes, IBytes. +// +// ParseBytes("42 MB") -> 42000000, nil +// ParseBytes("42 mib") -> 44040192, nil +func ParseBytes(s string) (uint64, error) { + lastDigit := 0 + hasComma := false + for _, r := range s { + if !(unicode.IsDigit(r) || r == '.' || r == ',') { + break + } + if r == ',' { + hasComma = true + } + lastDigit++ + } + + num := s[:lastDigit] + if hasComma { + num = strings.Replace(num, ",", "", -1) + } + + f, err := strconv.ParseFloat(num, 64) + if err != nil { + return 0, err + } + + extra := strings.ToLower(strings.TrimSpace(s[lastDigit:])) + if m, ok := bytesSizeTable[extra]; ok { + f *= float64(m) + if f >= math.MaxUint64 { + return 0, fmt.Errorf("too large: %v", s) + } + return uint64(f), nil + } + + return 0, fmt.Errorf("unhandled size name: %v", extra) +} diff --git a/vendor/github.com/dustin/go-humanize/comma.go b/vendor/github.com/dustin/go-humanize/comma.go new file mode 100644 index 000000000..13611aaab --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/comma.go @@ -0,0 +1,108 @@ +package humanize + +import ( + "bytes" + "math" + "math/big" + "strconv" + "strings" +) + +// Comma produces a string form of the given number in base 10 with +// commas after every three orders of magnitude. +// +// e.g. Comma(834142) -> 834,142 +func Comma(v int64) string { + sign := "" + + // Min int64 can't be negated to a usable value, so it has to be special cased. + if v == math.MinInt64 { + return "-9,223,372,036,854,775,808" + } + + if v < 0 { + sign = "-" + v = 0 - v + } + + parts := []string{"", "", "", "", "", "", ""} + j := len(parts) - 1 + + for v > 999 { + parts[j] = strconv.FormatInt(v%1000, 10) + switch len(parts[j]) { + case 2: + parts[j] = "0" + parts[j] + case 1: + parts[j] = "00" + parts[j] + } + v = v / 1000 + j-- + } + parts[j] = strconv.Itoa(int(v)) + return sign + strings.Join(parts[j:], ",") +} + +// Commaf produces a string form of the given number in base 10 with +// commas after every three orders of magnitude. +// +// e.g. Commaf(834142.32) -> 834,142.32 +func Commaf(v float64) string { + buf := &bytes.Buffer{} + if v < 0 { + buf.Write([]byte{'-'}) + v = 0 - v + } + + comma := []byte{','} + + parts := strings.Split(strconv.FormatFloat(v, 'f', -1, 64), ".") + pos := 0 + if len(parts[0])%3 != 0 { + pos += len(parts[0]) % 3 + buf.WriteString(parts[0][:pos]) + buf.Write(comma) + } + for ; pos < len(parts[0]); pos += 3 { + buf.WriteString(parts[0][pos : pos+3]) + buf.Write(comma) + } + buf.Truncate(buf.Len() - 1) + + if len(parts) > 1 { + buf.Write([]byte{'.'}) + buf.WriteString(parts[1]) + } + return buf.String() +} + +// BigComma produces a string form of the given big.Int in base 10 +// with commas after every three orders of magnitude. +func BigComma(b *big.Int) string { + sign := "" + if b.Sign() < 0 { + sign = "-" + b.Abs(b) + } + + athousand := big.NewInt(1000) + c := (&big.Int{}).Set(b) + _, m := oom(c, athousand) + parts := make([]string, m+1) + j := len(parts) - 1 + + mod := &big.Int{} + for b.Cmp(athousand) >= 0 { + b.DivMod(b, athousand, mod) + parts[j] = strconv.FormatInt(mod.Int64(), 10) + switch len(parts[j]) { + case 2: + parts[j] = "0" + parts[j] + case 1: + parts[j] = "00" + parts[j] + } + j-- + } + parts[j] = strconv.Itoa(int(b.Int64())) + return sign + strings.Join(parts[j:], ",") +} diff --git a/vendor/github.com/dustin/go-humanize/commaf.go b/vendor/github.com/dustin/go-humanize/commaf.go new file mode 100644 index 000000000..620690dec --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/commaf.go @@ -0,0 +1,40 @@ +// +build go1.6 + +package humanize + +import ( + "bytes" + "math/big" + "strings" +) + +// BigCommaf produces a string form of the given big.Float in base 10 +// with commas after every three orders of magnitude. +func BigCommaf(v *big.Float) string { + buf := &bytes.Buffer{} + if v.Sign() < 0 { + buf.Write([]byte{'-'}) + v.Abs(v) + } + + comma := []byte{','} + + parts := strings.Split(v.Text('f', -1), ".") + pos := 0 + if len(parts[0])%3 != 0 { + pos += len(parts[0]) % 3 + buf.WriteString(parts[0][:pos]) + buf.Write(comma) + } + for ; pos < len(parts[0]); pos += 3 { + buf.WriteString(parts[0][pos : pos+3]) + buf.Write(comma) + } + buf.Truncate(buf.Len() - 1) + + if len(parts) > 1 { + buf.Write([]byte{'.'}) + buf.WriteString(parts[1]) + } + return buf.String() +} diff --git a/vendor/github.com/dustin/go-humanize/english/words.go b/vendor/github.com/dustin/go-humanize/english/words.go new file mode 100644 index 000000000..26e9918bd --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/english/words.go @@ -0,0 +1,96 @@ +// Package english provides utilities to generate more user-friendly English output. +package english + +import ( + "fmt" + "strings" +) + +// These are included because they are common technical terms. +var specialPlurals = map[string]string{ + "index": "indices", + "matrix": "matrices", + "vertex": "vertices", +} + +var sibilantEndings = []string{"s", "sh", "tch", "x"} + +var isVowel = map[byte]bool{ + 'A': true, 'E': true, 'I': true, 'O': true, 'U': true, + 'a': true, 'e': true, 'i': true, 'o': true, 'u': true, +} + +// PluralWord builds the plural form of an English word. +// The simple English rules of regular pluralization will be used +// if the plural form is an empty string (i.e. not explicitly given). +// The special cases are not guaranteed to work for strings outside ASCII. +func PluralWord(quantity int, singular, plural string) string { + if quantity == 1 { + return singular + } + if plural != "" { + return plural + } + if plural = specialPlurals[singular]; plural != "" { + return plural + } + + // We need to guess what the English plural might be. Keep this + // function simple! It doesn't need to know about every possiblity; + // only regular rules and the most common special cases. + // + // Reference: http://en.wikipedia.org/wiki/English_plural + + for _, ending := range sibilantEndings { + if strings.HasSuffix(singular, ending) { + return singular + "es" + } + } + l := len(singular) + if l >= 2 && singular[l-1] == 'o' && !isVowel[singular[l-2]] { + return singular + "es" + } + if l >= 2 && singular[l-1] == 'y' && !isVowel[singular[l-2]] { + return singular[:l-1] + "ies" + } + + return singular + "s" +} + +// Plural formats an integer and a string into a single pluralized string. +// The simple English rules of regular pluralization will be used +// if the plural form is an empty string (i.e. not explicitly given). +func Plural(quantity int, singular, plural string) string { + return fmt.Sprintf("%d %s", quantity, PluralWord(quantity, singular, plural)) +} + +// WordSeries converts a list of words into a word series in English. +// It returns a string containing all the given words separated by commas, +// the coordinating conjunction, and a serial comma, as appropriate. +func WordSeries(words []string, conjunction string) string { + switch len(words) { + case 0: + return "" + case 1: + return words[0] + default: + return fmt.Sprintf("%s %s %s", strings.Join(words[:len(words)-1], ", "), conjunction, words[len(words)-1]) + } +} + +// OxfordWordSeries converts a list of words into a word series in English, +// using an Oxford comma (https://en.wikipedia.org/wiki/Serial_comma). It +// returns a string containing all the given words separated by commas, the +// coordinating conjunction, and a serial comma, as appropriate. +func OxfordWordSeries(words []string, conjunction string) string { + switch len(words) { + case 0: + return "" + case 1: + return words[0] + case 2: + return strings.Join(words, fmt.Sprintf(" %s ", conjunction)) + default: + return fmt.Sprintf("%s, %s %s", strings.Join(words[:len(words)-1], ", "), conjunction, words[len(words)-1]) + } +} diff --git a/vendor/github.com/dustin/go-humanize/ftoa.go b/vendor/github.com/dustin/go-humanize/ftoa.go new file mode 100644 index 000000000..c76190b10 --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/ftoa.go @@ -0,0 +1,23 @@ +package humanize + +import "strconv" + +func stripTrailingZeros(s string) string { + offset := len(s) - 1 + for offset > 0 { + if s[offset] == '.' { + offset-- + break + } + if s[offset] != '0' { + break + } + offset-- + } + return s[:offset+1] +} + +// Ftoa converts a float to a string with no trailing zeros. +func Ftoa(num float64) string { + return stripTrailingZeros(strconv.FormatFloat(num, 'f', 6, 64)) +} diff --git a/vendor/github.com/dustin/go-humanize/humanize.go b/vendor/github.com/dustin/go-humanize/humanize.go new file mode 100644 index 000000000..a2c2da31e --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/humanize.go @@ -0,0 +1,8 @@ +/* +Package humanize converts boring ugly numbers to human-friendly strings and back. + +Durations can be turned into strings such as "3 days ago", numbers +representing sizes like 82854982 into useful strings like, "83 MB" or +"79 MiB" (whichever you prefer). +*/ +package humanize diff --git a/vendor/github.com/dustin/go-humanize/number.go b/vendor/github.com/dustin/go-humanize/number.go new file mode 100644 index 000000000..dec618659 --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/number.go @@ -0,0 +1,192 @@ +package humanize + +/* +Slightly adapted from the source to fit go-humanize. + +Author: https://github.com/gorhill +Source: https://gist.github.com/gorhill/5285193 + +*/ + +import ( + "math" + "strconv" +) + +var ( + renderFloatPrecisionMultipliers = [...]float64{ + 1, + 10, + 100, + 1000, + 10000, + 100000, + 1000000, + 10000000, + 100000000, + 1000000000, + } + + renderFloatPrecisionRounders = [...]float64{ + 0.5, + 0.05, + 0.005, + 0.0005, + 0.00005, + 0.000005, + 0.0000005, + 0.00000005, + 0.000000005, + 0.0000000005, + } +) + +// FormatFloat produces a formatted number as string based on the following user-specified criteria: +// * thousands separator +// * decimal separator +// * decimal precision +// +// Usage: s := RenderFloat(format, n) +// The format parameter tells how to render the number n. +// +// See examples: http://play.golang.org/p/LXc1Ddm1lJ +// +// Examples of format strings, given n = 12345.6789: +// "#,###.##" => "12,345.67" +// "#,###." => "12,345" +// "#,###" => "12345,678" +// "#\u202F###,##" => "12 345,68" +// "#.###,###### => 12.345,678900 +// "" (aka default format) => 12,345.67 +// +// The highest precision allowed is 9 digits after the decimal symbol. +// There is also a version for integer number, FormatInteger(), +// which is convenient for calls within template. +func FormatFloat(format string, n float64) string { + // Special cases: + // NaN = "NaN" + // +Inf = "+Infinity" + // -Inf = "-Infinity" + if math.IsNaN(n) { + return "NaN" + } + if n > math.MaxFloat64 { + return "Infinity" + } + if n < -math.MaxFloat64 { + return "-Infinity" + } + + // default format + precision := 2 + decimalStr := "." + thousandStr := "," + positiveStr := "" + negativeStr := "-" + + if len(format) > 0 { + format := []rune(format) + + // If there is an explicit format directive, + // then default values are these: + precision = 9 + thousandStr = "" + + // collect indices of meaningful formatting directives + formatIndx := []int{} + for i, char := range format { + if char != '#' && char != '0' { + formatIndx = append(formatIndx, i) + } + } + + if len(formatIndx) > 0 { + // Directive at index 0: + // Must be a '+' + // Raise an error if not the case + // index: 0123456789 + // +0.000,000 + // +000,000.0 + // +0000.00 + // +0000 + if formatIndx[0] == 0 { + if format[formatIndx[0]] != '+' { + panic("RenderFloat(): invalid positive sign directive") + } + positiveStr = "+" + formatIndx = formatIndx[1:] + } + + // Two directives: + // First is thousands separator + // Raise an error if not followed by 3-digit + // 0123456789 + // 0.000,000 + // 000,000.00 + if len(formatIndx) == 2 { + if (formatIndx[1] - formatIndx[0]) != 4 { + panic("RenderFloat(): thousands separator directive must be followed by 3 digit-specifiers") + } + thousandStr = string(format[formatIndx[0]]) + formatIndx = formatIndx[1:] + } + + // One directive: + // Directive is decimal separator + // The number of digit-specifier following the separator indicates wanted precision + // 0123456789 + // 0.00 + // 000,0000 + if len(formatIndx) == 1 { + decimalStr = string(format[formatIndx[0]]) + precision = len(format) - formatIndx[0] - 1 + } + } + } + + // generate sign part + var signStr string + if n >= 0.000000001 { + signStr = positiveStr + } else if n <= -0.000000001 { + signStr = negativeStr + n = -n + } else { + signStr = "" + n = 0.0 + } + + // split number into integer and fractional parts + intf, fracf := math.Modf(n + renderFloatPrecisionRounders[precision]) + + // generate integer part string + intStr := strconv.FormatInt(int64(intf), 10) + + // add thousand separator if required + if len(thousandStr) > 0 { + for i := len(intStr); i > 3; { + i -= 3 + intStr = intStr[:i] + thousandStr + intStr[i:] + } + } + + // no fractional part, we can leave now + if precision == 0 { + return signStr + intStr + } + + // generate fractional part + fracStr := strconv.Itoa(int(fracf * renderFloatPrecisionMultipliers[precision])) + // may need padding + if len(fracStr) < precision { + fracStr = "000000000000000"[:precision-len(fracStr)] + fracStr + } + + return signStr + intStr + decimalStr + fracStr +} + +// FormatInteger produces a formatted number as string. +// See FormatFloat. +func FormatInteger(format string, n int) string { + return FormatFloat(format, float64(n)) +} diff --git a/vendor/github.com/dustin/go-humanize/ordinals.go b/vendor/github.com/dustin/go-humanize/ordinals.go new file mode 100644 index 000000000..43d88a861 --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/ordinals.go @@ -0,0 +1,25 @@ +package humanize + +import "strconv" + +// Ordinal gives you the input number in a rank/ordinal format. +// +// Ordinal(3) -> 3rd +func Ordinal(x int) string { + suffix := "th" + switch x % 10 { + case 1: + if x%100 != 11 { + suffix = "st" + } + case 2: + if x%100 != 12 { + suffix = "nd" + } + case 3: + if x%100 != 13 { + suffix = "rd" + } + } + return strconv.Itoa(x) + suffix +} diff --git a/vendor/github.com/dustin/go-humanize/si.go b/vendor/github.com/dustin/go-humanize/si.go new file mode 100644 index 000000000..b24e48169 --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/si.go @@ -0,0 +1,113 @@ +package humanize + +import ( + "errors" + "math" + "regexp" + "strconv" +) + +var siPrefixTable = map[float64]string{ + -24: "y", // yocto + -21: "z", // zepto + -18: "a", // atto + -15: "f", // femto + -12: "p", // pico + -9: "n", // nano + -6: "µ", // micro + -3: "m", // milli + 0: "", + 3: "k", // kilo + 6: "M", // mega + 9: "G", // giga + 12: "T", // tera + 15: "P", // peta + 18: "E", // exa + 21: "Z", // zetta + 24: "Y", // yotta +} + +var revSIPrefixTable = revfmap(siPrefixTable) + +// revfmap reverses the map and precomputes the power multiplier +func revfmap(in map[float64]string) map[string]float64 { + rv := map[string]float64{} + for k, v := range in { + rv[v] = math.Pow(10, k) + } + return rv +} + +var riParseRegex *regexp.Regexp + +func init() { + ri := `^([\-0-9.]+)\s?([` + for _, v := range siPrefixTable { + ri += v + } + ri += `]?)(.*)` + + riParseRegex = regexp.MustCompile(ri) +} + +// ComputeSI finds the most appropriate SI prefix for the given number +// and returns the prefix along with the value adjusted to be within +// that prefix. +// +// See also: SI, ParseSI. +// +// e.g. ComputeSI(2.2345e-12) -> (2.2345, "p") +func ComputeSI(input float64) (float64, string) { + if input == 0 { + return 0, "" + } + mag := math.Abs(input) + exponent := math.Floor(logn(mag, 10)) + exponent = math.Floor(exponent/3) * 3 + + value := mag / math.Pow(10, exponent) + + // Handle special case where value is exactly 1000.0 + // Should return 1 M instead of 1000 k + if value == 1000.0 { + exponent += 3 + value = mag / math.Pow(10, exponent) + } + + value = math.Copysign(value, input) + + prefix := siPrefixTable[exponent] + return value, prefix +} + +// SI returns a string with default formatting. +// +// SI uses Ftoa to format float value, removing trailing zeros. +// +// See also: ComputeSI, ParseSI. +// +// e.g. SI(1000000, "B") -> 1 MB +// e.g. SI(2.2345e-12, "F") -> 2.2345 pF +func SI(input float64, unit string) string { + value, prefix := ComputeSI(input) + return Ftoa(value) + " " + prefix + unit +} + +var errInvalid = errors.New("invalid input") + +// ParseSI parses an SI string back into the number and unit. +// +// See also: SI, ComputeSI. +// +// e.g. ParseSI("2.2345 pF") -> (2.2345e-12, "F", nil) +func ParseSI(input string) (float64, string, error) { + found := riParseRegex.FindStringSubmatch(input) + if len(found) != 4 { + return 0, "", errInvalid + } + mag := revSIPrefixTable[found[2]] + unit := found[3] + + base, err := strconv.ParseFloat(found[1], 64) + return base * mag, unit, err +} diff --git a/vendor/github.com/dustin/go-humanize/times.go b/vendor/github.com/dustin/go-humanize/times.go new file mode 100644 index 000000000..dd3fbf5ef --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/times.go @@ -0,0 +1,117 @@ +package humanize + +import ( + "fmt" + "math" + "sort" + "time" +) + +// Seconds-based time units +const ( + Day = 24 * time.Hour + Week = 7 * Day + Month = 30 * Day + Year = 12 * Month + LongTime = 37 * Year +) + +// Time formats a time into a relative string. +// +// Time(someT) -> "3 weeks ago" +func Time(then time.Time) string { + return RelTime(then, time.Now(), "ago", "from now") +} + +// A RelTimeMagnitude struct contains a relative time point at which +// the relative format of time will switch to a new format string. A +// slice of these in ascending order by their "D" field is passed to +// CustomRelTime to format durations. +// +// The Format field is a string that may contain a "%s" which will be +// replaced with the appropriate signed label (e.g. "ago" or "from +// now") and a "%d" that will be replaced by the quantity. +// +// The DivBy field is the amount of time the time difference must be +// divided by in order to display correctly. +// +// e.g. if D is 2*time.Minute and you want to display "%d minutes %s" +// DivBy should be time.Minute so whatever the duration is will be +// expressed in minutes. +type RelTimeMagnitude struct { + D time.Duration + Format string + DivBy time.Duration +} + +var defaultMagnitudes = []RelTimeMagnitude{ + {time.Second, "now", time.Second}, + {2 * time.Second, "1 second %s", 1}, + {time.Minute, "%d seconds %s", time.Second}, + {2 * time.Minute, "1 minute %s", 1}, + {time.Hour, "%d minutes %s", time.Minute}, + {2 * time.Hour, "1 hour %s", 1}, + {Day, "%d hours %s", time.Hour}, + {2 * Day, "1 day %s", 1}, + {Week, "%d days %s", Day}, + {2 * Week, "1 week %s", 1}, + {Month, "%d weeks %s", Week}, + {2 * Month, "1 month %s", 1}, + {Year, "%d months %s", Month}, + {18 * Month, "1 year %s", 1}, + {2 * Year, "2 years %s", 1}, + {LongTime, "%d years %s", Year}, + {math.MaxInt64, "a long while %s", 1}, +} + +// RelTime formats a time into a relative string. +// +// It takes two times and two labels. In addition to the generic time +// delta string (e.g. 5 minutes), the labels are used applied so that +// the label corresponding to the smaller time is applied. +// +// RelTime(timeInPast, timeInFuture, "earlier", "later") -> "3 weeks earlier" +func RelTime(a, b time.Time, albl, blbl string) string { + return CustomRelTime(a, b, albl, blbl, defaultMagnitudes) +} + +// CustomRelTime formats a time into a relative string. +// +// It takes two times two labels and a table of relative time formats. +// In addition to the generic time delta string (e.g. 5 minutes), the +// labels are used applied so that the label corresponding to the +// smaller time is applied. +func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string { + lbl := albl + diff := b.Sub(a) + + if a.After(b) { + lbl = blbl + diff = a.Sub(b) + } + + n := sort.Search(len(magnitudes), func(i int) bool { + return magnitudes[i].D > diff + }) + + if n >= len(magnitudes) { + n = len(magnitudes) - 1 + } + mag := magnitudes[n] + args := []interface{}{} + escaped := false + for _, ch := range mag.Format { + if escaped { + switch ch { + case 's': + args = append(args, lbl) + case 'd': + args = append(args, diff/mag.DivBy) + } + escaped = false + } else { + escaped = ch == '%' + } + } + return fmt.Sprintf(mag.Format, args...) +} diff --git a/vendor/github.com/gernest/wow/LICENSE b/vendor/github.com/gernest/wow/LICENSE new file mode 100644 index 000000000..ec1701e53 --- /dev/null +++ b/vendor/github.com/gernest/wow/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Geofrey Ernest + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/gernest/wow/example/all/main.go b/vendor/github.com/gernest/wow/example/all/main.go new file mode 100644 index 000000000..93955d930 --- /dev/null +++ b/vendor/github.com/gernest/wow/example/all/main.go @@ -0,0 +1,21 @@ +//DO NOT EDIT : this file was automatically generated. +package main + +import ( + "os" + "time" + + "github.com/gernest/wow" + "github.com/gernest/wow/spin" +) + +var all = []spin.Name{spin.Toggle6, spin.BouncingBall, spin.Balloon, spin.Toggle, spin.Toggle12, spin.Dots5, spin.Dots6, spin.Dots7, spin.GrowVertical, spin.Noise, spin.Toggle8, spin.SimpleDots, spin.BoxBounce2, spin.Arc, spin.BouncingBar, spin.Christmas, spin.Squish, spin.Triangle, spin.Arrow3, spin.Hearts, spin.Earth, spin.Dqpb, spin.Line2, spin.SquareCorners, spin.Toggle3, spin.Toggle5, spin.Monkey, spin.Clock, spin.Shark, spin.Weather, spin.Dots2, spin.Dots3, spin.Dots12, spin.CircleHalves, spin.Arrow, spin.Moon, spin.Flip, spin.Hamburger, spin.Bounce, spin.Circle, spin.Toggle9, spin.Toggle13, spin.Toggle10, spin.Runner, spin.Dots9, spin.Line, spin.Star, spin.CircleQuarters, spin.Arrow2, spin.Smiley, spin.Dots, spin.Dots4, spin.Pipe, spin.Balloon2, spin.Dots10, spin.Dots11, spin.SimpleDotsScrolling, spin.BoxBounce, spin.Toggle4, spin.Dots8, spin.Toggle2, spin.Toggle7, spin.Toggle11, spin.Pong, spin.Star2, spin.GrowHorizontal} + +func main() { + for _, v := range all { + w := wow.New(os.Stdout, spin.Get(v), " "+v.String(), wow.ForceOutput) + w.Start() + time.Sleep(2) + w.Persist() + } +} diff --git a/vendor/github.com/gernest/wow/example/doge/main.go b/vendor/github.com/gernest/wow/example/doge/main.go new file mode 100644 index 000000000..8451c86d3 --- /dev/null +++ b/vendor/github.com/gernest/wow/example/doge/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "os" + "time" + + "github.com/gernest/wow" + "github.com/gernest/wow/spin" +) + +func main() { + w := wow.New(os.Stdout, spin.Get(spin.Dots), "Such Spins") + w.Start() + time.Sleep(2 * time.Second) + w.Text("Very emojis").Spinner(spin.Get(spin.Hearts)) + time.Sleep(2 * time.Second) + w.PersistWith(spin.Spinner{Frames: []string{"👍"}}, " Wow!") +} diff --git a/vendor/github.com/gernest/wow/magefile.go b/vendor/github.com/gernest/wow/magefile.go new file mode 100644 index 000000000..c9a1eb5dc --- /dev/null +++ b/vendor/github.com/gernest/wow/magefile.go @@ -0,0 +1,228 @@ +// +build mage + +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "go/format" + "io/ioutil" + "os" + "path/filepath" + "strings" + "text/template" + + "github.com/magefile/mage/sh" + + "github.com/magefile/mage/mg" +) + +// Spinners generates easy/accessible Go types for spinners from +// cli-spinners/spinners.json. +func Spinners() error { + pkg := "spin" + mg.Deps(func() error { + _, err := os.Stat(pkg) + if err != nil { + if os.IsNotExist(err) { + return os.Mkdir(pkg, 0777) + } + return err + } + return nil + }) + b, err := ioutil.ReadFile("cli-spinners/spinners.json") + if err != nil { + return err + } + o := make(map[string]interface{}) + err = json.Unmarshal(b, &o) + if err != nil { + return err + } + tpl, err := template.New("spinner").Funcs(helpers()).Parse(spinnersTpl) + if err != nil { + return err + } + var buf bytes.Buffer + err = tpl.Execute(&buf, o) + if err != nil { + return err + } + bo, err := format.Source(buf.Bytes()) + if err != nil { + return err + } + return ioutil.WriteFile(filepath.Join(pkg, "spinners.go"), bo, 0600) +} + +// ExampleAll generates example executable file to demo all spinners +func ExampleAll() error { + b, err := ioutil.ReadFile("cli-spinners/spinners.json") + if err != nil { + return err + } + o := make(map[string]interface{}) + err = json.Unmarshal(b, &o) + if err != nil { + return err + } + + // Generate example/all/main.go + tpl, err := template.New("example-all").Funcs(helpers()).Parse(exampleAllTpl) + if err != nil { + return err + } + var buf bytes.Buffer + err = tpl.Execute(&buf, o) + if err != nil { + return err + } + bo, err := format.Source(buf.Bytes()) + if err != nil { + return err + } + return ioutil.WriteFile("example/all/main.go", bo, 0600) +} + +func helpers() template.FuncMap { + return template.FuncMap{ + "title": strings.Title, + "stringify": func(a []interface{}) string { + o := "" + switch len(a) { + case 0: + return "" + case 1: + return fmt.Sprintf("\"%s\"", a[0]) + default: + for k, v := range a { + if k == 0 { + o += fmt.Sprintf("`%s`", v) + } else { + if v == "`" { + o += fmt.Sprintf(",\"%s\"", v) + + } else { + o += fmt.Sprintf(",`%s`", v) + } + + } + } + + return fmt.Sprintf("[]string{ %v }", o) + } + }, + "all": func(a map[string]interface{}) string { + o := "" + for k := range a { + if o == "" { + o += fmt.Sprintf("%s", strings.Title(k)) + } else { + o += fmt.Sprintf(",%s", strings.Title(k)) + } + } + return fmt.Sprintf("[]Name{%s}", o) + }, + "allwithpkg": func(a map[string]interface{}) string { + o := "" + for k := range a { + if o == "" { + o += fmt.Sprintf("spin.%s", strings.Title(k)) + } else { + o += fmt.Sprintf(",spin.%s", strings.Title(k)) + } + } + return fmt.Sprintf("[]spin.Name{%s}", o) + }, + } +} + +const spinnersTpl = `//DO NOT EDIT : this file was automatically generated. +package spin + +// Spinner defines a spinner widget +type Spinner struct{ + Name Name + Interval int + Frames []string +} + +// Name represents a name for a spinner item. +type Name uint + +// available spinners +const( + Unknown Name=iota + {{range $k,$v:= .}} + {{- $k|title}} + {{end}} +) + +func (s Name)String()string{ + switch s{ + {{- range $k,$v:=.}} + case {{$k|title}} : + return "{{$k}}" + {{- end}} + default: + return "" + } +} + +func Get( name Name)Spinner{ + switch name{ + {{- range $k,$v:=.}} + case {{$k|title}} : + return Spinner{ + Name: {{$k|title}}, + Interval: {{$v.interval}}, + Frames: {{$v.frames|stringify }}, + } + {{- end}} + default: + return Spinner{} + } +} +` + +const exampleAllTpl = `//DO NOT EDIT : this file was automatically generated. +package main + +import ( + "os" + "time" + + "github.com/gernest/wow" + "github.com/gernest/wow/spin" +) + +var all = {{allwithpkg .}} + +func main() { + for _, v := range all { + w := wow.New(os.Stdout, spin.Get(v), " "+v.String()) + w.Start() + time.Sleep(2) + w.Persist() + } +} + +` + +// Update updates cli-spinners to get latest changes to the spinners.json file. +func Update() error { + return sh.Run("git", "submodule", "update", "--remote", "cli-spinners") +} + +//Setup prepares the project for local development. +// +// This runs git submodule init && git submodule update +func Setup() error { + err := sh.Run("git", "submodule", "init") + if err != nil { + return err + } + return sh.Run("git", "submodule", "update") +} diff --git a/vendor/github.com/gernest/wow/spin/spinners.go b/vendor/github.com/gernest/wow/spin/spinners.go new file mode 100644 index 000000000..7534c0b8d --- /dev/null +++ b/vendor/github.com/gernest/wow/spin/spinners.go @@ -0,0 +1,625 @@ +//DO NOT EDIT : this file was automatically generated. +package spin + +// Spinner defines a spinner widget +type Spinner struct { + Name Name + Interval int + Frames []string +} + +// Name represents a name for a spinner item. +type Name uint + +// available spinners +const ( + Unknown Name = iota + Arc + Arrow + Arrow2 + Arrow3 + Balloon + Balloon2 + Bounce + BouncingBall + BouncingBar + BoxBounce + BoxBounce2 + Christmas + Circle + CircleHalves + CircleQuarters + Clock + Dots + Dots10 + Dots11 + Dots12 + Dots2 + Dots3 + Dots4 + Dots5 + Dots6 + Dots7 + Dots8 + Dots9 + Dqpb + Earth + Flip + GrowHorizontal + GrowVertical + Hamburger + Hearts + Line + Line2 + Monkey + Moon + Noise + Pipe + Pong + Runner + Shark + SimpleDots + SimpleDotsScrolling + Smiley + SquareCorners + Squish + Star + Star2 + Toggle + Toggle10 + Toggle11 + Toggle12 + Toggle13 + Toggle2 + Toggle3 + Toggle4 + Toggle5 + Toggle6 + Toggle7 + Toggle8 + Toggle9 + Triangle + Weather +) + +func (s Name) String() string { + switch s { + case Arc: + return "arc" + case Arrow: + return "arrow" + case Arrow2: + return "arrow2" + case Arrow3: + return "arrow3" + case Balloon: + return "balloon" + case Balloon2: + return "balloon2" + case Bounce: + return "bounce" + case BouncingBall: + return "bouncingBall" + case BouncingBar: + return "bouncingBar" + case BoxBounce: + return "boxBounce" + case BoxBounce2: + return "boxBounce2" + case Christmas: + return "christmas" + case Circle: + return "circle" + case CircleHalves: + return "circleHalves" + case CircleQuarters: + return "circleQuarters" + case Clock: + return "clock" + case Dots: + return "dots" + case Dots10: + return "dots10" + case Dots11: + return "dots11" + case Dots12: + return "dots12" + case Dots2: + return "dots2" + case Dots3: + return "dots3" + case Dots4: + return "dots4" + case Dots5: + return "dots5" + case Dots6: + return "dots6" + case Dots7: + return "dots7" + case Dots8: + return "dots8" + case Dots9: + return "dots9" + case Dqpb: + return "dqpb" + case Earth: + return "earth" + case Flip: + return "flip" + case GrowHorizontal: + return "growHorizontal" + case GrowVertical: + return "growVertical" + case Hamburger: + return "hamburger" + case Hearts: + return "hearts" + case Line: + return "line" + case Line2: + return "line2" + case Monkey: + return "monkey" + case Moon: + return "moon" + case Noise: + return "noise" + case Pipe: + return "pipe" + case Pong: + return "pong" + case Runner: + return "runner" + case Shark: + return "shark" + case SimpleDots: + return "simpleDots" + case SimpleDotsScrolling: + return "simpleDotsScrolling" + case Smiley: + return "smiley" + case SquareCorners: + return "squareCorners" + case Squish: + return "squish" + case Star: + return "star" + case Star2: + return "star2" + case Toggle: + return "toggle" + case Toggle10: + return "toggle10" + case Toggle11: + return "toggle11" + case Toggle12: + return "toggle12" + case Toggle13: + return "toggle13" + case Toggle2: + return "toggle2" + case Toggle3: + return "toggle3" + case Toggle4: + return "toggle4" + case Toggle5: + return "toggle5" + case Toggle6: + return "toggle6" + case Toggle7: + return "toggle7" + case Toggle8: + return "toggle8" + case Toggle9: + return "toggle9" + case Triangle: + return "triangle" + case Weather: + return "weather" + default: + return "" + } +} + +func Get(name Name) Spinner { + switch name { + case Arc: + return Spinner{ + Name: Arc, + Interval: 100, + Frames: []string{`◜`, `◠`, `◝`, `◞`, `◡`, `◟`}, + } + case Arrow: + return Spinner{ + Name: Arrow, + Interval: 100, + Frames: []string{`←`, `↖`, `↑`, `↗`, `→`, `↘`, `↓`, `↙`}, + } + case Arrow2: + return Spinner{ + Name: Arrow2, + Interval: 80, + Frames: []string{`⬆️ `, `↗️ `, `➡️ `, `↘️ `, `⬇️ `, `↙️ `, `⬅️ `, `↖️ `}, + } + case Arrow3: + return Spinner{ + Name: Arrow3, + Interval: 120, + Frames: []string{`▹▹▹▹▹`, `▸▹▹▹▹`, `▹▸▹▹▹`, `▹▹▸▹▹`, `▹▹▹▸▹`, `▹▹▹▹▸`}, + } + case Balloon: + return Spinner{ + Name: Balloon, + Interval: 140, + Frames: []string{` `, `.`, `o`, `O`, `@`, `*`, ` `}, + } + case Balloon2: + return Spinner{ + Name: Balloon2, + Interval: 120, + Frames: []string{`.`, `o`, `O`, `°`, `O`, `o`, `.`}, + } + case Bounce: + return Spinner{ + Name: Bounce, + Interval: 120, + Frames: []string{`⠁`, `⠂`, `⠄`, `⠂`}, + } + case BouncingBall: + return Spinner{ + Name: BouncingBall, + Interval: 80, + Frames: []string{`( ● )`, `( ● )`, `( ● )`, `( ● )`, `( ●)`, `( ● )`, `( ● )`, `( ● )`, `( ● )`, `(● )`}, + } + case BouncingBar: + return Spinner{ + Name: BouncingBar, + Interval: 80, + Frames: []string{`[ ]`, `[= ]`, `[== ]`, `[=== ]`, `[ ===]`, `[ ==]`, `[ =]`, `[ ]`, `[ =]`, `[ ==]`, `[ ===]`, `[====]`, `[=== ]`, `[== ]`, `[= ]`}, + } + case BoxBounce: + return Spinner{ + Name: BoxBounce, + Interval: 120, + Frames: []string{`▖`, `▘`, `▝`, `▗`}, + } + case BoxBounce2: + return Spinner{ + Name: BoxBounce2, + Interval: 100, + Frames: []string{`▌`, `▀`, `▐`, `▄`}, + } + case Christmas: + return Spinner{ + Name: Christmas, + Interval: 400, + Frames: []string{`🌲`, `🎄`}, + } + case Circle: + return Spinner{ + Name: Circle, + Interval: 120, + Frames: []string{`◡`, `⊙`, `◠`}, + } + case CircleHalves: + return Spinner{ + Name: CircleHalves, + Interval: 50, + Frames: []string{`◐`, `◓`, `◑`, `◒`}, + } + case CircleQuarters: + return Spinner{ + Name: CircleQuarters, + Interval: 120, + Frames: []string{`◴`, `◷`, `◶`, `◵`}, + } + case Clock: + return Spinner{ + Name: Clock, + Interval: 100, + Frames: []string{`🕐 `, `🕑 `, `🕒 `, `🕓 `, `🕔 `, `🕕 `, `🕖 `, `🕗 `, `🕘 `, `🕙 `, `🕚 `}, + } + case Dots: + return Spinner{ + Name: Dots, + Interval: 80, + Frames: []string{`⠋`, `⠙`, `⠹`, `⠸`, `⠼`, `⠴`, `⠦`, `⠧`, `⠇`, `⠏`}, + } + case Dots10: + return Spinner{ + Name: Dots10, + Interval: 80, + Frames: []string{`⢄`, `⢂`, `⢁`, `⡁`, `⡈`, `⡐`, `⡠`}, + } + case Dots11: + return Spinner{ + Name: Dots11, + Interval: 100, + Frames: []string{`⠁`, `⠂`, `⠄`, `⡀`, `⢀`, `⠠`, `⠐`, `⠈`}, + } + case Dots12: + return Spinner{ + Name: Dots12, + Interval: 80, + Frames: []string{`⢀⠀`, `⡀⠀`, `⠄⠀`, `⢂⠀`, `⡂⠀`, `⠅⠀`, `⢃⠀`, `⡃⠀`, `⠍⠀`, `⢋⠀`, `⡋⠀`, `⠍⠁`, `⢋⠁`, `⡋⠁`, `⠍⠉`, `⠋⠉`, `⠋⠉`, `⠉⠙`, `⠉⠙`, `⠉⠩`, `⠈⢙`, `⠈⡙`, `⢈⠩`, `⡀⢙`, `⠄⡙`, `⢂⠩`, `⡂⢘`, `⠅⡘`, `⢃⠨`, `⡃⢐`, `⠍⡐`, `⢋⠠`, `⡋⢀`, `⠍⡁`, `⢋⠁`, `⡋⠁`, `⠍⠉`, `⠋⠉`, `⠋⠉`, `⠉⠙`, `⠉⠙`, `⠉⠩`, `⠈⢙`, `⠈⡙`, `⠈⠩`, `⠀⢙`, `⠀⡙`, `⠀⠩`, `⠀⢘`, `⠀⡘`, `⠀⠨`, `⠀⢐`, `⠀⡐`, `⠀⠠`, `⠀⢀`, `⠀⡀`}, + } + case Dots2: + return Spinner{ + Name: Dots2, + Interval: 80, + Frames: []string{`⣾`, `⣽`, `⣻`, `⢿`, `⡿`, `⣟`, `⣯`, `⣷`}, + } + case Dots3: + return Spinner{ + Name: Dots3, + Interval: 80, + Frames: []string{`⠋`, `⠙`, `⠚`, `⠞`, `⠖`, `⠦`, `⠴`, `⠲`, `⠳`, `⠓`}, + } + case Dots4: + return Spinner{ + Name: Dots4, + Interval: 80, + Frames: []string{`⠄`, `⠆`, `⠇`, `⠋`, `⠙`, `⠸`, `⠰`, `⠠`, `⠰`, `⠸`, `⠙`, `⠋`, `⠇`, `⠆`}, + } + case Dots5: + return Spinner{ + Name: Dots5, + Interval: 80, + Frames: []string{`⠋`, `⠙`, `⠚`, `⠒`, `⠂`, `⠂`, `⠒`, `⠲`, `⠴`, `⠦`, `⠖`, `⠒`, `⠐`, `⠐`, `⠒`, `⠓`, `⠋`}, + } + case Dots6: + return Spinner{ + Name: Dots6, + Interval: 80, + Frames: []string{`⠁`, `⠉`, `⠙`, `⠚`, `⠒`, `⠂`, `⠂`, `⠒`, `⠲`, `⠴`, `⠤`, `⠄`, `⠄`, `⠤`, `⠴`, `⠲`, `⠒`, `⠂`, `⠂`, `⠒`, `⠚`, `⠙`, `⠉`, `⠁`}, + } + case Dots7: + return Spinner{ + Name: Dots7, + Interval: 80, + Frames: []string{`⠈`, `⠉`, `⠋`, `⠓`, `⠒`, `⠐`, `⠐`, `⠒`, `⠖`, `⠦`, `⠤`, `⠠`, `⠠`, `⠤`, `⠦`, `⠖`, `⠒`, `⠐`, `⠐`, `⠒`, `⠓`, `⠋`, `⠉`, `⠈`}, + } + case Dots8: + return Spinner{ + Name: Dots8, + Interval: 80, + Frames: []string{`⠁`, `⠁`, `⠉`, `⠙`, `⠚`, `⠒`, `⠂`, `⠂`, `⠒`, `⠲`, `⠴`, `⠤`, `⠄`, `⠄`, `⠤`, `⠠`, `⠠`, `⠤`, `⠦`, `⠖`, `⠒`, `⠐`, `⠐`, `⠒`, `⠓`, `⠋`, `⠉`, `⠈`, `⠈`}, + } + case Dots9: + return Spinner{ + Name: Dots9, + Interval: 80, + Frames: []string{`⢹`, `⢺`, `⢼`, `⣸`, `⣇`, `⡧`, `⡗`, `⡏`}, + } + case Dqpb: + return Spinner{ + Name: Dqpb, + Interval: 100, + Frames: []string{`d`, `q`, `p`, `b`}, + } + case Earth: + return Spinner{ + Name: Earth, + Interval: 180, + Frames: []string{`🌍 `, `🌎 `, `🌏 `}, + } + case Flip: + return Spinner{ + Name: Flip, + Interval: 70, + Frames: []string{`_`, `_`, `_`, `-`, "`", "`", `'`, `´`, `-`, `_`, `_`, `_`}, + } + case GrowHorizontal: + return Spinner{ + Name: GrowHorizontal, + Interval: 120, + Frames: []string{`▏`, `▎`, `▍`, `▌`, `▋`, `▊`, `▉`, `▊`, `▋`, `▌`, `▍`, `▎`}, + } + case GrowVertical: + return Spinner{ + Name: GrowVertical, + Interval: 120, + Frames: []string{`▁`, `▃`, `▄`, `▅`, `▆`, `▇`, `▆`, `▅`, `▄`, `▃`}, + } + case Hamburger: + return Spinner{ + Name: Hamburger, + Interval: 100, + Frames: []string{`☱`, `☲`, `☴`}, + } + case Hearts: + return Spinner{ + Name: Hearts, + Interval: 100, + Frames: []string{`💛 `, `💙 `, `💜 `, `💚 `, `❤️ `}, + } + case Line: + return Spinner{ + Name: Line, + Interval: 130, + Frames: []string{`-`, `\`, `|`, `/`}, + } + case Line2: + return Spinner{ + Name: Line2, + Interval: 100, + Frames: []string{`⠂`, `-`, `–`, `—`, `–`, `-`}, + } + case Monkey: + return Spinner{ + Name: Monkey, + Interval: 300, + Frames: []string{`🙈 `, `🙈 `, `🙉 `, `🙊 `}, + } + case Moon: + return Spinner{ + Name: Moon, + Interval: 80, + Frames: []string{`🌑 `, `🌒 `, `🌓 `, `🌔 `, `🌕 `, `🌖 `, `🌗 `, `🌘 `}, + } + case Noise: + return Spinner{ + Name: Noise, + Interval: 100, + Frames: []string{`▓`, `▒`, `░`}, + } + case Pipe: + return Spinner{ + Name: Pipe, + Interval: 100, + Frames: []string{`┤`, `┘`, `┴`, `└`, `├`, `┌`, `┬`, `┐`}, + } + case Pong: + return Spinner{ + Name: Pong, + Interval: 80, + Frames: []string{`▐⠂ ▌`, `▐⠈ ▌`, `▐ ⠂ ▌`, `▐ ⠠ ▌`, `▐ ⡀ ▌`, `▐ ⠠ ▌`, `▐ ⠂ ▌`, `▐ ⠈ ▌`, `▐ ⠂ ▌`, `▐ ⠠ ▌`, `▐ ⡀ ▌`, `▐ ⠠ ▌`, `▐ ⠂ ▌`, `▐ ⠈ ▌`, `▐ ⠂▌`, `▐ ⠠▌`, `▐ ⡀▌`, `▐ ⠠ ▌`, `▐ ⠂ ▌`, `▐ ⠈ ▌`, `▐ ⠂ ▌`, `▐ ⠠ ▌`, `▐ ⡀ ▌`, `▐ ⠠ ▌`, `▐ ⠂ ▌`, `▐ ⠈ ▌`, `▐ ⠂ ▌`, `▐ ⠠ ▌`, `▐ ⡀ ▌`, `▐⠠ ▌`}, + } + case Runner: + return Spinner{ + Name: Runner, + Interval: 140, + Frames: []string{`🚶 `, `🏃 `}, + } + case Shark: + return Spinner{ + Name: Shark, + Interval: 120, + Frames: []string{`▐|\____________▌`, `▐_|\___________▌`, `▐__|\__________▌`, `▐___|\_________▌`, `▐____|\________▌`, `▐_____|\_______▌`, `▐______|\______▌`, `▐_______|\_____▌`, `▐________|\____▌`, `▐_________|\___▌`, `▐__________|\__▌`, `▐___________|\_▌`, `▐____________|\▌`, `▐____________/|▌`, `▐___________/|_▌`, `▐__________/|__▌`, `▐_________/|___▌`, `▐________/|____▌`, `▐_______/|_____▌`, `▐______/|______▌`, `▐_____/|_______▌`, `▐____/|________▌`, `▐___/|_________▌`, `▐__/|__________▌`, `▐_/|___________▌`, `▐/|____________▌`}, + } + case SimpleDots: + return Spinner{ + Name: SimpleDots, + Interval: 400, + Frames: []string{`. `, `.. `, `...`, ` `}, + } + case SimpleDotsScrolling: + return Spinner{ + Name: SimpleDotsScrolling, + Interval: 200, + Frames: []string{`. `, `.. `, `...`, ` ..`, ` .`, ` `}, + } + case Smiley: + return Spinner{ + Name: Smiley, + Interval: 200, + Frames: []string{`😄 `, `😝 `}, + } + case SquareCorners: + return Spinner{ + Name: SquareCorners, + Interval: 180, + Frames: []string{`◰`, `◳`, `◲`, `◱`}, + } + case Squish: + return Spinner{ + Name: Squish, + Interval: 100, + Frames: []string{`╫`, `╪`}, + } + case Star: + return Spinner{ + Name: Star, + Interval: 70, + Frames: []string{`✶`, `✸`, `✹`, `✺`, `✹`, `✷`}, + } + case Star2: + return Spinner{ + Name: Star2, + Interval: 80, + Frames: []string{`+`, `x`, `*`}, + } + case Toggle: + return Spinner{ + Name: Toggle, + Interval: 250, + Frames: []string{`⊶`, `⊷`}, + } + case Toggle10: + return Spinner{ + Name: Toggle10, + Interval: 100, + Frames: []string{`㊂`, `㊀`, `㊁`}, + } + case Toggle11: + return Spinner{ + Name: Toggle11, + Interval: 50, + Frames: []string{`⧇`, `⧆`}, + } + case Toggle12: + return Spinner{ + Name: Toggle12, + Interval: 120, + Frames: []string{`☗`, `☖`}, + } + case Toggle13: + return Spinner{ + Name: Toggle13, + Interval: 80, + Frames: []string{`=`, `*`, `-`}, + } + case Toggle2: + return Spinner{ + Name: Toggle2, + Interval: 80, + Frames: []string{`▫`, `▪`}, + } + case Toggle3: + return Spinner{ + Name: Toggle3, + Interval: 120, + Frames: []string{`□`, `■`}, + } + case Toggle4: + return Spinner{ + Name: Toggle4, + Interval: 100, + Frames: []string{`■`, `□`, `▪`, `▫`}, + } + case Toggle5: + return Spinner{ + Name: Toggle5, + Interval: 100, + Frames: []string{`▮`, `▯`}, + } + case Toggle6: + return Spinner{ + Name: Toggle6, + Interval: 300, + Frames: []string{`ဝ`, `၀`}, + } + case Toggle7: + return Spinner{ + Name: Toggle7, + Interval: 80, + Frames: []string{`⦾`, `⦿`}, + } + case Toggle8: + return Spinner{ + Name: Toggle8, + Interval: 100, + Frames: []string{`◍`, `◌`}, + } + case Toggle9: + return Spinner{ + Name: Toggle9, + Interval: 100, + Frames: []string{`◉`, `◎`}, + } + case Triangle: + return Spinner{ + Name: Triangle, + Interval: 50, + Frames: []string{`◢`, `◣`, `◤`, `◥`}, + } + case Weather: + return Spinner{ + Name: Weather, + Interval: 100, + Frames: []string{`☀️ `, `☀️ `, `☀️ `, `🌤 `, `⛅️ `, `🌥 `, `☁️ `, `🌧 `, `🌨 `, `🌧 `, `🌨 `, `🌧 `, `🌨 `, `⛈ `, `🌨 `, `🌧 `, `🌨 `, `☁️ `, `🌥 `, `⛅️ `, `🌤 `, `☀️ `, `☀️ `}, + } + default: + return Spinner{} + } +} diff --git a/vendor/github.com/gernest/wow/symbols.go b/vendor/github.com/gernest/wow/symbols.go new file mode 100644 index 000000000..cf98acea5 --- /dev/null +++ b/vendor/github.com/gernest/wow/symbols.go @@ -0,0 +1,41 @@ +package wow + +import "runtime" + +// LogSymbol is a log severity level +type LogSymbol uint + +// common log symbos +const ( + INFO LogSymbol = iota + SUCCESS + WARNING + ERROR +) + +func (s LogSymbol) String() string { + if runtime.GOOS != "windows" { + switch s { + case INFO: + return "ℹ" + case SUCCESS: + return "✔" + case WARNING: + return "⚠" + case ERROR: + return "✖" + } + } else { + switch s { + case INFO: + return "i" + case SUCCESS: + return "v" + case WARNING: + return "!!" + case ERROR: + return "x" + } + } + return "" +} diff --git a/vendor/github.com/gernest/wow/wow.go b/vendor/github.com/gernest/wow/wow.go new file mode 100644 index 000000000..e10f3d69b --- /dev/null +++ b/vendor/github.com/gernest/wow/wow.go @@ -0,0 +1,122 @@ +package wow + +import ( + "context" + "fmt" + "io" + "os" + "sync" + "time" + + "github.com/gernest/wow/spin" + "golang.org/x/crypto/ssh/terminal" +) + +const erase = "\033[2K\r" + +// Wow writes beautiful spinners on the terminal. +type Wow struct { + txt string + s spin.Spinner + out io.Writer + running bool + done func() + mu sync.RWMutex + IsTerminal bool +} + +// New creates a new wow instance ready to start spinning. +func New(o io.Writer, s spin.Spinner, text string, options ...func(*Wow)) *Wow { + isTerminal := terminal.IsTerminal(int(os.Stdout.Fd())) + + wow := Wow{out: o, s: s, txt: text, IsTerminal: isTerminal} + + for _, option := range options { + option(&wow) + } + + return &wow +} + +// Start starts the spinner. The frames are written based on the spinner +// interval. +func (w *Wow) Start() { + if !w.running { + ctx, done := context.WithCancel(context.Background()) + t := time.NewTicker(time.Duration(w.s.Interval) * time.Millisecond) + w.done = done + w.running = true + go func() { + at := 0 + for { + select { + case <-ctx.Done(): + t.Stop() + break + case <-t.C: + txt := erase + w.s.Frames[at%len(w.s.Frames)] + w.txt + if w.IsTerminal { + fmt.Fprint(w.out, txt) + } + at++ + } + } + }() + } +} + +// Stop stops the spinner +func (w *Wow) Stop() { + if w.done != nil { + w.done() + } + w.running = false +} + +// Spinner sets s to the current spinner +func (w *Wow) Spinner(s spin.Spinner) *Wow { + w.Stop() + w.s = s + w.Start() + return w +} + +// Text adds text to the current spinner +func (w *Wow) Text(txt string) *Wow { + w.mu.Lock() + w.txt = txt + w.mu.Unlock() + return w +} + +// Persist writes the last character of the currect spinner frames together with +// the text on stdout. +// +// A new line is added at the end to ensure the text stay that way. +func (w *Wow) Persist() { + w.Stop() + at := len(w.s.Frames) - 1 + txt := erase + w.s.Frames[at] + w.txt + "\n" + if w.IsTerminal { + fmt.Fprint(w.out, txt) + } +} + +// PersistWith writes the last frame of s together with text with a new line +// added to make it stick. +func (w *Wow) PersistWith(s spin.Spinner, text string) { + w.Stop() + var a string + if len(s.Frames) > 0 { + a = s.Frames[len(s.Frames)-1] + } + txt := erase + a + text + "\n" + if w.IsTerminal { + fmt.Fprint(w.out, txt) + } +} + +// ForceOutput forces all output even if not not outputting directly to a terminal +func ForceOutput(w *Wow) { + w.IsTerminal = true +} diff --git a/vendor/github.com/go-ini/ini/LICENSE b/vendor/github.com/go-ini/ini/LICENSE new file mode 100644 index 000000000..d361bbcdf --- /dev/null +++ b/vendor/github.com/go-ini/ini/LICENSE @@ -0,0 +1,191 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, "control" means (i) the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +"Object" form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +"submitted" means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work + +To apply the Apache License to your work, attach the following boilerplate +notice, with the fields enclosed by brackets "[]" replaced with your own +identifying information. (Don't include the brackets!) The text should be +enclosed in the appropriate comment syntax for the file format. We also +recommend that a file or class name and description of purpose be included on +the same "printed page" as the copyright notice for easier identification within +third-party archives. + + Copyright 2014 Unknwon + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/go-ini/ini/error.go b/vendor/github.com/go-ini/ini/error.go new file mode 100644 index 000000000..80afe7431 --- /dev/null +++ b/vendor/github.com/go-ini/ini/error.go @@ -0,0 +1,32 @@ +// Copyright 2016 Unknwon +// +// Licensed under the Apache License, Version 2.0 (the "License"): you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +package ini + +import ( + "fmt" +) + +type ErrDelimiterNotFound struct { + Line string +} + +func IsErrDelimiterNotFound(err error) bool { + _, ok := err.(ErrDelimiterNotFound) + return ok +} + +func (err ErrDelimiterNotFound) Error() string { + return fmt.Sprintf("key-value delimiter not found: %s", err.Line) +} diff --git a/vendor/github.com/go-ini/ini/file.go b/vendor/github.com/go-ini/ini/file.go new file mode 100644 index 000000000..ce26c3b31 --- /dev/null +++ b/vendor/github.com/go-ini/ini/file.go @@ -0,0 +1,398 @@ +// Copyright 2017 Unknwon +// +// Licensed under the Apache License, Version 2.0 (the "License"): you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +package ini + +import ( + "bytes" + "errors" + "fmt" + "io" + "io/ioutil" + "os" + "strings" + "sync" +) + +// File represents a combination of a or more INI file(s) in memory. +type File struct { + options LoadOptions + dataSources []dataSource + + // Should make things safe, but sometimes doesn't matter. + BlockMode bool + lock sync.RWMutex + + // To keep data in order. + sectionList []string + // Actual data is stored here. + sections map[string]*Section + + NameMapper + ValueMapper +} + +// newFile initializes File object with given data sources. +func newFile(dataSources []dataSource, opts LoadOptions) *File { + return &File{ + BlockMode: true, + dataSources: dataSources, + sections: make(map[string]*Section), + sectionList: make([]string, 0, 10), + options: opts, + } +} + +// Empty returns an empty file object. +func Empty() *File { + // Ignore error here, we sure our data is good. + f, _ := Load([]byte("")) + return f +} + +// NewSection creates a new section. +func (f *File) NewSection(name string) (*Section, error) { + if len(name) == 0 { + return nil, errors.New("error creating new section: empty section name") + } else if f.options.Insensitive && name != DEFAULT_SECTION { + name = strings.ToLower(name) + } + + if f.BlockMode { + f.lock.Lock() + defer f.lock.Unlock() + } + + if inSlice(name, f.sectionList) { + return f.sections[name], nil + } + + f.sectionList = append(f.sectionList, name) + f.sections[name] = newSection(f, name) + return f.sections[name], nil +} + +// NewRawSection creates a new section with an unparseable body. +func (f *File) NewRawSection(name, body string) (*Section, error) { + section, err := f.NewSection(name) + if err != nil { + return nil, err + } + + section.isRawSection = true + section.rawBody = body + return section, nil +} + +// NewSections creates a list of sections. +func (f *File) NewSections(names ...string) (err error) { + for _, name := range names { + if _, err = f.NewSection(name); err != nil { + return err + } + } + return nil +} + +// GetSection returns section by given name. +func (f *File) GetSection(name string) (*Section, error) { + if len(name) == 0 { + name = DEFAULT_SECTION + } + if f.options.Insensitive { + name = strings.ToLower(name) + } + + if f.BlockMode { + f.lock.RLock() + defer f.lock.RUnlock() + } + + sec := f.sections[name] + if sec == nil { + return nil, fmt.Errorf("section '%s' does not exist", name) + } + return sec, nil +} + +// Section assumes named section exists and returns a zero-value when not. +func (f *File) Section(name string) *Section { + sec, err := f.GetSection(name) + if err != nil { + // Note: It's OK here because the only possible error is empty section name, + // but if it's empty, this piece of code won't be executed. + sec, _ = f.NewSection(name) + return sec + } + return sec +} + +// Section returns list of Section. +func (f *File) Sections() []*Section { + sections := make([]*Section, len(f.sectionList)) + for i := range f.sectionList { + sections[i] = f.Section(f.sectionList[i]) + } + return sections +} + +// ChildSections returns a list of child sections of given section name. +func (f *File) ChildSections(name string) []*Section { + return f.Section(name).ChildSections() +} + +// SectionStrings returns list of section names. +func (f *File) SectionStrings() []string { + list := make([]string, len(f.sectionList)) + copy(list, f.sectionList) + return list +} + +// DeleteSection deletes a section. +func (f *File) DeleteSection(name string) { + if f.BlockMode { + f.lock.Lock() + defer f.lock.Unlock() + } + + if len(name) == 0 { + name = DEFAULT_SECTION + } + + for i, s := range f.sectionList { + if s == name { + f.sectionList = append(f.sectionList[:i], f.sectionList[i+1:]...) + delete(f.sections, name) + return + } + } +} + +func (f *File) reload(s dataSource) error { + r, err := s.ReadCloser() + if err != nil { + return err + } + defer r.Close() + + return f.parse(r) +} + +// Reload reloads and parses all data sources. +func (f *File) Reload() (err error) { + for _, s := range f.dataSources { + if err = f.reload(s); err != nil { + // In loose mode, we create an empty default section for nonexistent files. + if os.IsNotExist(err) && f.options.Loose { + f.parse(bytes.NewBuffer(nil)) + continue + } + return err + } + } + return nil +} + +// Append appends one or more data sources and reloads automatically. +func (f *File) Append(source interface{}, others ...interface{}) error { + ds, err := parseDataSource(source) + if err != nil { + return err + } + f.dataSources = append(f.dataSources, ds) + for _, s := range others { + ds, err = parseDataSource(s) + if err != nil { + return err + } + f.dataSources = append(f.dataSources, ds) + } + return f.Reload() +} + +func (f *File) writeToBuffer(indent string) (*bytes.Buffer, error) { + equalSign := "=" + if PrettyFormat { + equalSign = " = " + } + + // Use buffer to make sure target is safe until finish encoding. + buf := bytes.NewBuffer(nil) + for i, sname := range f.sectionList { + sec := f.Section(sname) + if len(sec.Comment) > 0 { + if sec.Comment[0] != '#' && sec.Comment[0] != ';' { + sec.Comment = "; " + sec.Comment + } else { + sec.Comment = sec.Comment[:1] + " " + strings.TrimSpace(sec.Comment[1:]) + } + if _, err := buf.WriteString(sec.Comment + LineBreak); err != nil { + return nil, err + } + } + + if i > 0 || DefaultHeader { + if _, err := buf.WriteString("[" + sname + "]" + LineBreak); err != nil { + return nil, err + } + } else { + // Write nothing if default section is empty + if len(sec.keyList) == 0 { + continue + } + } + + if sec.isRawSection { + if _, err := buf.WriteString(sec.rawBody); err != nil { + return nil, err + } + + if PrettySection { + // Put a line between sections + if _, err := buf.WriteString(LineBreak); err != nil { + return nil, err + } + } + continue + } + + // Count and generate alignment length and buffer spaces using the + // longest key. Keys may be modifed if they contain certain characters so + // we need to take that into account in our calculation. + alignLength := 0 + if PrettyFormat { + for _, kname := range sec.keyList { + keyLength := len(kname) + // First case will surround key by ` and second by """ + if strings.ContainsAny(kname, "\"=:") { + keyLength += 2 + } else if strings.Contains(kname, "`") { + keyLength += 6 + } + + if keyLength > alignLength { + alignLength = keyLength + } + } + } + alignSpaces := bytes.Repeat([]byte(" "), alignLength) + + KEY_LIST: + for _, kname := range sec.keyList { + key := sec.Key(kname) + if len(key.Comment) > 0 { + if len(indent) > 0 && sname != DEFAULT_SECTION { + buf.WriteString(indent) + } + if key.Comment[0] != '#' && key.Comment[0] != ';' { + key.Comment = "; " + key.Comment + } else { + key.Comment = key.Comment[:1] + " " + strings.TrimSpace(key.Comment[1:]) + } + if _, err := buf.WriteString(key.Comment + LineBreak); err != nil { + return nil, err + } + } + + if len(indent) > 0 && sname != DEFAULT_SECTION { + buf.WriteString(indent) + } + + switch { + case key.isAutoIncrement: + kname = "-" + case strings.ContainsAny(kname, "\"=:"): + kname = "`" + kname + "`" + case strings.Contains(kname, "`"): + kname = `"""` + kname + `"""` + } + + for _, val := range key.ValueWithShadows() { + if _, err := buf.WriteString(kname); err != nil { + return nil, err + } + + if key.isBooleanType { + if kname != sec.keyList[len(sec.keyList)-1] { + buf.WriteString(LineBreak) + } + continue KEY_LIST + } + + // Write out alignment spaces before "=" sign + if PrettyFormat { + buf.Write(alignSpaces[:alignLength-len(kname)]) + } + + // In case key value contains "\n", "`", "\"", "#" or ";" + if strings.ContainsAny(val, "\n`") { + val = `"""` + val + `"""` + } else if !f.options.IgnoreInlineComment && strings.ContainsAny(val, "#;") { + val = "`" + val + "`" + } + if _, err := buf.WriteString(equalSign + val + LineBreak); err != nil { + return nil, err + } + } + + for _, val := range key.nestedValues { + if _, err := buf.WriteString(indent + " " + val + LineBreak); err != nil { + return nil, err + } + } + } + + if PrettySection { + // Put a line between sections + if _, err := buf.WriteString(LineBreak); err != nil { + return nil, err + } + } + } + + return buf, nil +} + +// WriteToIndent writes content into io.Writer with given indention. +// If PrettyFormat has been set to be true, +// it will align "=" sign with spaces under each section. +func (f *File) WriteToIndent(w io.Writer, indent string) (int64, error) { + buf, err := f.writeToBuffer(indent) + if err != nil { + return 0, err + } + return buf.WriteTo(w) +} + +// WriteTo writes file content into io.Writer. +func (f *File) WriteTo(w io.Writer) (int64, error) { + return f.WriteToIndent(w, "") +} + +// SaveToIndent writes content to file system with given value indention. +func (f *File) SaveToIndent(filename, indent string) error { + // Note: Because we are truncating with os.Create, + // so it's safer to save to a temporary file location and rename afte done. + buf, err := f.writeToBuffer(indent) + if err != nil { + return err + } + + return ioutil.WriteFile(filename, buf.Bytes(), 0666) +} + +// SaveTo writes content to file system. +func (f *File) SaveTo(filename string) error { + return f.SaveToIndent(filename, "") +} diff --git a/vendor/github.com/go-ini/ini/ini.go b/vendor/github.com/go-ini/ini/ini.go new file mode 100644 index 000000000..535d3588a --- /dev/null +++ b/vendor/github.com/go-ini/ini/ini.go @@ -0,0 +1,194 @@ +// Copyright 2014 Unknwon +// +// Licensed under the Apache License, Version 2.0 (the "License"): you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +// Package ini provides INI file read and write functionality in Go. +package ini + +import ( + "bytes" + "fmt" + "io" + "io/ioutil" + "os" + "regexp" + "runtime" +) + +const ( + // Name for default section. You can use this constant or the string literal. + // In most of cases, an empty string is all you need to access the section. + DEFAULT_SECTION = "DEFAULT" + + // Maximum allowed depth when recursively substituing variable names. + _DEPTH_VALUES = 99 + _VERSION = "1.32.0" +) + +// Version returns current package version literal. +func Version() string { + return _VERSION +} + +var ( + // Delimiter to determine or compose a new line. + // This variable will be changed to "\r\n" automatically on Windows + // at package init time. + LineBreak = "\n" + + // Variable regexp pattern: %(variable)s + varPattern = regexp.MustCompile(`%\(([^\)]+)\)s`) + + // Indicate whether to align "=" sign with spaces to produce pretty output + // or reduce all possible spaces for compact format. + PrettyFormat = true + + // Explicitly write DEFAULT section header + DefaultHeader = false + + // Indicate whether to put a line between sections + PrettySection = true +) + +func init() { + if runtime.GOOS == "windows" { + LineBreak = "\r\n" + } +} + +func inSlice(str string, s []string) bool { + for _, v := range s { + if str == v { + return true + } + } + return false +} + +// dataSource is an interface that returns object which can be read and closed. +type dataSource interface { + ReadCloser() (io.ReadCloser, error) +} + +// sourceFile represents an object that contains content on the local file system. +type sourceFile struct { + name string +} + +func (s sourceFile) ReadCloser() (_ io.ReadCloser, err error) { + return os.Open(s.name) +} + +// sourceData represents an object that contains content in memory. +type sourceData struct { + data []byte +} + +func (s *sourceData) ReadCloser() (io.ReadCloser, error) { + return ioutil.NopCloser(bytes.NewReader(s.data)), nil +} + +// sourceReadCloser represents an input stream with Close method. +type sourceReadCloser struct { + reader io.ReadCloser +} + +func (s *sourceReadCloser) ReadCloser() (io.ReadCloser, error) { + return s.reader, nil +} + +func parseDataSource(source interface{}) (dataSource, error) { + switch s := source.(type) { + case string: + return sourceFile{s}, nil + case []byte: + return &sourceData{s}, nil + case io.ReadCloser: + return &sourceReadCloser{s}, nil + default: + return nil, fmt.Errorf("error parsing data source: unknown type '%s'", s) + } +} + +type LoadOptions struct { + // Loose indicates whether the parser should ignore nonexistent files or return error. + Loose bool + // Insensitive indicates whether the parser forces all section and key names to lowercase. + Insensitive bool + // IgnoreContinuation indicates whether to ignore continuation lines while parsing. + IgnoreContinuation bool + // IgnoreInlineComment indicates whether to ignore comments at the end of value and treat it as part of value. + IgnoreInlineComment bool + // AllowBooleanKeys indicates whether to allow boolean type keys or treat as value is missing. + // This type of keys are mostly used in my.cnf. + AllowBooleanKeys bool + // AllowShadows indicates whether to keep track of keys with same name under same section. + AllowShadows bool + // AllowNestedValues indicates whether to allow AWS-like nested values. + // Docs: http://docs.aws.amazon.com/cli/latest/topic/config-vars.html#nested-values + AllowNestedValues bool + // UnescapeValueDoubleQuotes indicates whether to unescape double quotes inside value to regular format + // when value is surrounded by double quotes, e.g. key="a \"value\"" => key=a "value" + UnescapeValueDoubleQuotes bool + // UnescapeValueCommentSymbols indicates to unescape comment symbols (\# and \;) inside value to regular format + // when value is NOT surrounded by any quotes. + // Note: UNSTABLE, behavior might change to only unescape inside double quotes but may noy necessary at all. + UnescapeValueCommentSymbols bool + // Some INI formats allow group blocks that store a block of raw content that doesn't otherwise + // conform to key/value pairs. Specify the names of those blocks here. + UnparseableSections []string +} + +func LoadSources(opts LoadOptions, source interface{}, others ...interface{}) (_ *File, err error) { + sources := make([]dataSource, len(others)+1) + sources[0], err = parseDataSource(source) + if err != nil { + return nil, err + } + for i := range others { + sources[i+1], err = parseDataSource(others[i]) + if err != nil { + return nil, err + } + } + f := newFile(sources, opts) + if err = f.Reload(); err != nil { + return nil, err + } + return f, nil +} + +// Load loads and parses from INI data sources. +// Arguments can be mixed of file name with string type, or raw data in []byte. +// It will return error if list contains nonexistent files. +func Load(source interface{}, others ...interface{}) (*File, error) { + return LoadSources(LoadOptions{}, source, others...) +} + +// LooseLoad has exactly same functionality as Load function +// except it ignores nonexistent files instead of returning error. +func LooseLoad(source interface{}, others ...interface{}) (*File, error) { + return LoadSources(LoadOptions{Loose: true}, source, others...) +} + +// InsensitiveLoad has exactly same functionality as Load function +// except it forces all section and key names to be lowercased. +func InsensitiveLoad(source interface{}, others ...interface{}) (*File, error) { + return LoadSources(LoadOptions{Insensitive: true}, source, others...) +} + +// InsensitiveLoad has exactly same functionality as Load function +// except it allows have shadow keys. +func ShadowLoad(source interface{}, others ...interface{}) (*File, error) { + return LoadSources(LoadOptions{AllowShadows: true}, source, others...) +} diff --git a/vendor/github.com/go-ini/ini/key.go b/vendor/github.com/go-ini/ini/key.go new file mode 100644 index 000000000..7c8566a1b --- /dev/null +++ b/vendor/github.com/go-ini/ini/key.go @@ -0,0 +1,751 @@ +// Copyright 2014 Unknwon +// +// Licensed under the Apache License, Version 2.0 (the "License"): you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +package ini + +import ( + "bytes" + "errors" + "fmt" + "strconv" + "strings" + "time" +) + +// Key represents a key under a section. +type Key struct { + s *Section + Comment string + name string + value string + isAutoIncrement bool + isBooleanType bool + + isShadow bool + shadows []*Key + + nestedValues []string +} + +// newKey simply return a key object with given values. +func newKey(s *Section, name, val string) *Key { + return &Key{ + s: s, + name: name, + value: val, + } +} + +func (k *Key) addShadow(val string) error { + if k.isShadow { + return errors.New("cannot add shadow to another shadow key") + } else if k.isAutoIncrement || k.isBooleanType { + return errors.New("cannot add shadow to auto-increment or boolean key") + } + + shadow := newKey(k.s, k.name, val) + shadow.isShadow = true + k.shadows = append(k.shadows, shadow) + return nil +} + +// AddShadow adds a new shadow key to itself. +func (k *Key) AddShadow(val string) error { + if !k.s.f.options.AllowShadows { + return errors.New("shadow key is not allowed") + } + return k.addShadow(val) +} + +func (k *Key) addNestedValue(val string) error { + if k.isAutoIncrement || k.isBooleanType { + return errors.New("cannot add nested value to auto-increment or boolean key") + } + + k.nestedValues = append(k.nestedValues, val) + return nil +} + +func (k *Key) AddNestedValue(val string) error { + if !k.s.f.options.AllowNestedValues { + return errors.New("nested value is not allowed") + } + return k.addNestedValue(val) +} + +// ValueMapper represents a mapping function for values, e.g. os.ExpandEnv +type ValueMapper func(string) string + +// Name returns name of key. +func (k *Key) Name() string { + return k.name +} + +// Value returns raw value of key for performance purpose. +func (k *Key) Value() string { + return k.value +} + +// ValueWithShadows returns raw values of key and its shadows if any. +func (k *Key) ValueWithShadows() []string { + if len(k.shadows) == 0 { + return []string{k.value} + } + vals := make([]string, len(k.shadows)+1) + vals[0] = k.value + for i := range k.shadows { + vals[i+1] = k.shadows[i].value + } + return vals +} + +// NestedValues returns nested values stored in the key. +// It is possible returned value is nil if no nested values stored in the key. +func (k *Key) NestedValues() []string { + return k.nestedValues +} + +// transformValue takes a raw value and transforms to its final string. +func (k *Key) transformValue(val string) string { + if k.s.f.ValueMapper != nil { + val = k.s.f.ValueMapper(val) + } + + // Fail-fast if no indicate char found for recursive value + if !strings.Contains(val, "%") { + return val + } + for i := 0; i < _DEPTH_VALUES; i++ { + vr := varPattern.FindString(val) + if len(vr) == 0 { + break + } + + // Take off leading '%(' and trailing ')s'. + noption := strings.TrimLeft(vr, "%(") + noption = strings.TrimRight(noption, ")s") + + // Search in the same section. + nk, err := k.s.GetKey(noption) + if err != nil || k == nk { + // Search again in default section. + nk, _ = k.s.f.Section("").GetKey(noption) + } + + // Substitute by new value and take off leading '%(' and trailing ')s'. + val = strings.Replace(val, vr, nk.value, -1) + } + return val +} + +// String returns string representation of value. +func (k *Key) String() string { + return k.transformValue(k.value) +} + +// Validate accepts a validate function which can +// return modifed result as key value. +func (k *Key) Validate(fn func(string) string) string { + return fn(k.String()) +} + +// parseBool returns the boolean value represented by the string. +// +// It accepts 1, t, T, TRUE, true, True, YES, yes, Yes, y, ON, on, On, +// 0, f, F, FALSE, false, False, NO, no, No, n, OFF, off, Off. +// Any other value returns an error. +func parseBool(str string) (value bool, err error) { + switch str { + case "1", "t", "T", "true", "TRUE", "True", "YES", "yes", "Yes", "y", "ON", "on", "On": + return true, nil + case "0", "f", "F", "false", "FALSE", "False", "NO", "no", "No", "n", "OFF", "off", "Off": + return false, nil + } + return false, fmt.Errorf("parsing \"%s\": invalid syntax", str) +} + +// Bool returns bool type value. +func (k *Key) Bool() (bool, error) { + return parseBool(k.String()) +} + +// Float64 returns float64 type value. +func (k *Key) Float64() (float64, error) { + return strconv.ParseFloat(k.String(), 64) +} + +// Int returns int type value. +func (k *Key) Int() (int, error) { + return strconv.Atoi(k.String()) +} + +// Int64 returns int64 type value. +func (k *Key) Int64() (int64, error) { + return strconv.ParseInt(k.String(), 10, 64) +} + +// Uint returns uint type valued. +func (k *Key) Uint() (uint, error) { + u, e := strconv.ParseUint(k.String(), 10, 64) + return uint(u), e +} + +// Uint64 returns uint64 type value. +func (k *Key) Uint64() (uint64, error) { + return strconv.ParseUint(k.String(), 10, 64) +} + +// Duration returns time.Duration type value. +func (k *Key) Duration() (time.Duration, error) { + return time.ParseDuration(k.String()) +} + +// TimeFormat parses with given format and returns time.Time type value. +func (k *Key) TimeFormat(format string) (time.Time, error) { + return time.Parse(format, k.String()) +} + +// Time parses with RFC3339 format and returns time.Time type value. +func (k *Key) Time() (time.Time, error) { + return k.TimeFormat(time.RFC3339) +} + +// MustString returns default value if key value is empty. +func (k *Key) MustString(defaultVal string) string { + val := k.String() + if len(val) == 0 { + k.value = defaultVal + return defaultVal + } + return val +} + +// MustBool always returns value without error, +// it returns false if error occurs. +func (k *Key) MustBool(defaultVal ...bool) bool { + val, err := k.Bool() + if len(defaultVal) > 0 && err != nil { + k.value = strconv.FormatBool(defaultVal[0]) + return defaultVal[0] + } + return val +} + +// MustFloat64 always returns value without error, +// it returns 0.0 if error occurs. +func (k *Key) MustFloat64(defaultVal ...float64) float64 { + val, err := k.Float64() + if len(defaultVal) > 0 && err != nil { + k.value = strconv.FormatFloat(defaultVal[0], 'f', -1, 64) + return defaultVal[0] + } + return val +} + +// MustInt always returns value without error, +// it returns 0 if error occurs. +func (k *Key) MustInt(defaultVal ...int) int { + val, err := k.Int() + if len(defaultVal) > 0 && err != nil { + k.value = strconv.FormatInt(int64(defaultVal[0]), 10) + return defaultVal[0] + } + return val +} + +// MustInt64 always returns value without error, +// it returns 0 if error occurs. +func (k *Key) MustInt64(defaultVal ...int64) int64 { + val, err := k.Int64() + if len(defaultVal) > 0 && err != nil { + k.value = strconv.FormatInt(defaultVal[0], 10) + return defaultVal[0] + } + return val +} + +// MustUint always returns value without error, +// it returns 0 if error occurs. +func (k *Key) MustUint(defaultVal ...uint) uint { + val, err := k.Uint() + if len(defaultVal) > 0 && err != nil { + k.value = strconv.FormatUint(uint64(defaultVal[0]), 10) + return defaultVal[0] + } + return val +} + +// MustUint64 always returns value without error, +// it returns 0 if error occurs. +func (k *Key) MustUint64(defaultVal ...uint64) uint64 { + val, err := k.Uint64() + if len(defaultVal) > 0 && err != nil { + k.value = strconv.FormatUint(defaultVal[0], 10) + return defaultVal[0] + } + return val +} + +// MustDuration always returns value without error, +// it returns zero value if error occurs. +func (k *Key) MustDuration(defaultVal ...time.Duration) time.Duration { + val, err := k.Duration() + if len(defaultVal) > 0 && err != nil { + k.value = defaultVal[0].String() + return defaultVal[0] + } + return val +} + +// MustTimeFormat always parses with given format and returns value without error, +// it returns zero value if error occurs. +func (k *Key) MustTimeFormat(format string, defaultVal ...time.Time) time.Time { + val, err := k.TimeFormat(format) + if len(defaultVal) > 0 && err != nil { + k.value = defaultVal[0].Format(format) + return defaultVal[0] + } + return val +} + +// MustTime always parses with RFC3339 format and returns value without error, +// it returns zero value if error occurs. +func (k *Key) MustTime(defaultVal ...time.Time) time.Time { + return k.MustTimeFormat(time.RFC3339, defaultVal...) +} + +// In always returns value without error, +// it returns default value if error occurs or doesn't fit into candidates. +func (k *Key) In(defaultVal string, candidates []string) string { + val := k.String() + for _, cand := range candidates { + if val == cand { + return val + } + } + return defaultVal +} + +// InFloat64 always returns value without error, +// it returns default value if error occurs or doesn't fit into candidates. +func (k *Key) InFloat64(defaultVal float64, candidates []float64) float64 { + val := k.MustFloat64() + for _, cand := range candidates { + if val == cand { + return val + } + } + return defaultVal +} + +// InInt always returns value without error, +// it returns default value if error occurs or doesn't fit into candidates. +func (k *Key) InInt(defaultVal int, candidates []int) int { + val := k.MustInt() + for _, cand := range candidates { + if val == cand { + return val + } + } + return defaultVal +} + +// InInt64 always returns value without error, +// it returns default value if error occurs or doesn't fit into candidates. +func (k *Key) InInt64(defaultVal int64, candidates []int64) int64 { + val := k.MustInt64() + for _, cand := range candidates { + if val == cand { + return val + } + } + return defaultVal +} + +// InUint always returns value without error, +// it returns default value if error occurs or doesn't fit into candidates. +func (k *Key) InUint(defaultVal uint, candidates []uint) uint { + val := k.MustUint() + for _, cand := range candidates { + if val == cand { + return val + } + } + return defaultVal +} + +// InUint64 always returns value without error, +// it returns default value if error occurs or doesn't fit into candidates. +func (k *Key) InUint64(defaultVal uint64, candidates []uint64) uint64 { + val := k.MustUint64() + for _, cand := range candidates { + if val == cand { + return val + } + } + return defaultVal +} + +// InTimeFormat always parses with given format and returns value without error, +// it returns default value if error occurs or doesn't fit into candidates. +func (k *Key) InTimeFormat(format string, defaultVal time.Time, candidates []time.Time) time.Time { + val := k.MustTimeFormat(format) + for _, cand := range candidates { + if val == cand { + return val + } + } + return defaultVal +} + +// InTime always parses with RFC3339 format and returns value without error, +// it returns default value if error occurs or doesn't fit into candidates. +func (k *Key) InTime(defaultVal time.Time, candidates []time.Time) time.Time { + return k.InTimeFormat(time.RFC3339, defaultVal, candidates) +} + +// RangeFloat64 checks if value is in given range inclusively, +// and returns default value if it's not. +func (k *Key) RangeFloat64(defaultVal, min, max float64) float64 { + val := k.MustFloat64() + if val < min || val > max { + return defaultVal + } + return val +} + +// RangeInt checks if value is in given range inclusively, +// and returns default value if it's not. +func (k *Key) RangeInt(defaultVal, min, max int) int { + val := k.MustInt() + if val < min || val > max { + return defaultVal + } + return val +} + +// RangeInt64 checks if value is in given range inclusively, +// and returns default value if it's not. +func (k *Key) RangeInt64(defaultVal, min, max int64) int64 { + val := k.MustInt64() + if val < min || val > max { + return defaultVal + } + return val +} + +// RangeTimeFormat checks if value with given format is in given range inclusively, +// and returns default value if it's not. +func (k *Key) RangeTimeFormat(format string, defaultVal, min, max time.Time) time.Time { + val := k.MustTimeFormat(format) + if val.Unix() < min.Unix() || val.Unix() > max.Unix() { + return defaultVal + } + return val +} + +// RangeTime checks if value with RFC3339 format is in given range inclusively, +// and returns default value if it's not. +func (k *Key) RangeTime(defaultVal, min, max time.Time) time.Time { + return k.RangeTimeFormat(time.RFC3339, defaultVal, min, max) +} + +// Strings returns list of string divided by given delimiter. +func (k *Key) Strings(delim string) []string { + str := k.String() + if len(str) == 0 { + return []string{} + } + + runes := []rune(str) + vals := make([]string, 0, 2) + var buf bytes.Buffer + escape := false + idx := 0 + for { + if escape { + escape = false + if runes[idx] != '\\' && !strings.HasPrefix(string(runes[idx:]), delim) { + buf.WriteRune('\\') + } + buf.WriteRune(runes[idx]) + } else { + if runes[idx] == '\\' { + escape = true + } else if strings.HasPrefix(string(runes[idx:]), delim) { + idx += len(delim) - 1 + vals = append(vals, strings.TrimSpace(buf.String())) + buf.Reset() + } else { + buf.WriteRune(runes[idx]) + } + } + idx += 1 + if idx == len(runes) { + break + } + } + + if buf.Len() > 0 { + vals = append(vals, strings.TrimSpace(buf.String())) + } + + return vals +} + +// StringsWithShadows returns list of string divided by given delimiter. +// Shadows will also be appended if any. +func (k *Key) StringsWithShadows(delim string) []string { + vals := k.ValueWithShadows() + results := make([]string, 0, len(vals)*2) + for i := range vals { + if len(vals) == 0 { + continue + } + + results = append(results, strings.Split(vals[i], delim)...) + } + + for i := range results { + results[i] = k.transformValue(strings.TrimSpace(results[i])) + } + return results +} + +// Float64s returns list of float64 divided by given delimiter. Any invalid input will be treated as zero value. +func (k *Key) Float64s(delim string) []float64 { + vals, _ := k.parseFloat64s(k.Strings(delim), true, false) + return vals +} + +// Ints returns list of int divided by given delimiter. Any invalid input will be treated as zero value. +func (k *Key) Ints(delim string) []int { + vals, _ := k.parseInts(k.Strings(delim), true, false) + return vals +} + +// Int64s returns list of int64 divided by given delimiter. Any invalid input will be treated as zero value. +func (k *Key) Int64s(delim string) []int64 { + vals, _ := k.parseInt64s(k.Strings(delim), true, false) + return vals +} + +// Uints returns list of uint divided by given delimiter. Any invalid input will be treated as zero value. +func (k *Key) Uints(delim string) []uint { + vals, _ := k.parseUints(k.Strings(delim), true, false) + return vals +} + +// Uint64s returns list of uint64 divided by given delimiter. Any invalid input will be treated as zero value. +func (k *Key) Uint64s(delim string) []uint64 { + vals, _ := k.parseUint64s(k.Strings(delim), true, false) + return vals +} + +// TimesFormat parses with given format and returns list of time.Time divided by given delimiter. +// Any invalid input will be treated as zero value (0001-01-01 00:00:00 +0000 UTC). +func (k *Key) TimesFormat(format, delim string) []time.Time { + vals, _ := k.parseTimesFormat(format, k.Strings(delim), true, false) + return vals +} + +// Times parses with RFC3339 format and returns list of time.Time divided by given delimiter. +// Any invalid input will be treated as zero value (0001-01-01 00:00:00 +0000 UTC). +func (k *Key) Times(delim string) []time.Time { + return k.TimesFormat(time.RFC3339, delim) +} + +// ValidFloat64s returns list of float64 divided by given delimiter. If some value is not float, then +// it will not be included to result list. +func (k *Key) ValidFloat64s(delim string) []float64 { + vals, _ := k.parseFloat64s(k.Strings(delim), false, false) + return vals +} + +// ValidInts returns list of int divided by given delimiter. If some value is not integer, then it will +// not be included to result list. +func (k *Key) ValidInts(delim string) []int { + vals, _ := k.parseInts(k.Strings(delim), false, false) + return vals +} + +// ValidInt64s returns list of int64 divided by given delimiter. If some value is not 64-bit integer, +// then it will not be included to result list. +func (k *Key) ValidInt64s(delim string) []int64 { + vals, _ := k.parseInt64s(k.Strings(delim), false, false) + return vals +} + +// ValidUints returns list of uint divided by given delimiter. If some value is not unsigned integer, +// then it will not be included to result list. +func (k *Key) ValidUints(delim string) []uint { + vals, _ := k.parseUints(k.Strings(delim), false, false) + return vals +} + +// ValidUint64s returns list of uint64 divided by given delimiter. If some value is not 64-bit unsigned +// integer, then it will not be included to result list. +func (k *Key) ValidUint64s(delim string) []uint64 { + vals, _ := k.parseUint64s(k.Strings(delim), false, false) + return vals +} + +// ValidTimesFormat parses with given format and returns list of time.Time divided by given delimiter. +func (k *Key) ValidTimesFormat(format, delim string) []time.Time { + vals, _ := k.parseTimesFormat(format, k.Strings(delim), false, false) + return vals +} + +// ValidTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter. +func (k *Key) ValidTimes(delim string) []time.Time { + return k.ValidTimesFormat(time.RFC3339, delim) +} + +// StrictFloat64s returns list of float64 divided by given delimiter or error on first invalid input. +func (k *Key) StrictFloat64s(delim string) ([]float64, error) { + return k.parseFloat64s(k.Strings(delim), false, true) +} + +// StrictInts returns list of int divided by given delimiter or error on first invalid input. +func (k *Key) StrictInts(delim string) ([]int, error) { + return k.parseInts(k.Strings(delim), false, true) +} + +// StrictInt64s returns list of int64 divided by given delimiter or error on first invalid input. +func (k *Key) StrictInt64s(delim string) ([]int64, error) { + return k.parseInt64s(k.Strings(delim), false, true) +} + +// StrictUints returns list of uint divided by given delimiter or error on first invalid input. +func (k *Key) StrictUints(delim string) ([]uint, error) { + return k.parseUints(k.Strings(delim), false, true) +} + +// StrictUint64s returns list of uint64 divided by given delimiter or error on first invalid input. +func (k *Key) StrictUint64s(delim string) ([]uint64, error) { + return k.parseUint64s(k.Strings(delim), false, true) +} + +// StrictTimesFormat parses with given format and returns list of time.Time divided by given delimiter +// or error on first invalid input. +func (k *Key) StrictTimesFormat(format, delim string) ([]time.Time, error) { + return k.parseTimesFormat(format, k.Strings(delim), false, true) +} + +// StrictTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter +// or error on first invalid input. +func (k *Key) StrictTimes(delim string) ([]time.Time, error) { + return k.StrictTimesFormat(time.RFC3339, delim) +} + +// parseFloat64s transforms strings to float64s. +func (k *Key) parseFloat64s(strs []string, addInvalid, returnOnInvalid bool) ([]float64, error) { + vals := make([]float64, 0, len(strs)) + for _, str := range strs { + val, err := strconv.ParseFloat(str, 64) + if err != nil && returnOnInvalid { + return nil, err + } + if err == nil || addInvalid { + vals = append(vals, val) + } + } + return vals, nil +} + +// parseInts transforms strings to ints. +func (k *Key) parseInts(strs []string, addInvalid, returnOnInvalid bool) ([]int, error) { + vals := make([]int, 0, len(strs)) + for _, str := range strs { + val, err := strconv.Atoi(str) + if err != nil && returnOnInvalid { + return nil, err + } + if err == nil || addInvalid { + vals = append(vals, val) + } + } + return vals, nil +} + +// parseInt64s transforms strings to int64s. +func (k *Key) parseInt64s(strs []string, addInvalid, returnOnInvalid bool) ([]int64, error) { + vals := make([]int64, 0, len(strs)) + for _, str := range strs { + val, err := strconv.ParseInt(str, 10, 64) + if err != nil && returnOnInvalid { + return nil, err + } + if err == nil || addInvalid { + vals = append(vals, val) + } + } + return vals, nil +} + +// parseUints transforms strings to uints. +func (k *Key) parseUints(strs []string, addInvalid, returnOnInvalid bool) ([]uint, error) { + vals := make([]uint, 0, len(strs)) + for _, str := range strs { + val, err := strconv.ParseUint(str, 10, 0) + if err != nil && returnOnInvalid { + return nil, err + } + if err == nil || addInvalid { + vals = append(vals, uint(val)) + } + } + return vals, nil +} + +// parseUint64s transforms strings to uint64s. +func (k *Key) parseUint64s(strs []string, addInvalid, returnOnInvalid bool) ([]uint64, error) { + vals := make([]uint64, 0, len(strs)) + for _, str := range strs { + val, err := strconv.ParseUint(str, 10, 64) + if err != nil && returnOnInvalid { + return nil, err + } + if err == nil || addInvalid { + vals = append(vals, val) + } + } + return vals, nil +} + +// parseTimesFormat transforms strings to times in given format. +func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnOnInvalid bool) ([]time.Time, error) { + vals := make([]time.Time, 0, len(strs)) + for _, str := range strs { + val, err := time.Parse(format, str) + if err != nil && returnOnInvalid { + return nil, err + } + if err == nil || addInvalid { + vals = append(vals, val) + } + } + return vals, nil +} + +// SetValue changes key value. +func (k *Key) SetValue(v string) { + if k.s.f.BlockMode { + k.s.f.lock.Lock() + defer k.s.f.lock.Unlock() + } + + k.value = v + k.s.keysHash[k.name] = v +} diff --git a/vendor/github.com/go-ini/ini/parser.go b/vendor/github.com/go-ini/ini/parser.go new file mode 100644 index 000000000..db3af8f00 --- /dev/null +++ b/vendor/github.com/go-ini/ini/parser.go @@ -0,0 +1,401 @@ +// Copyright 2015 Unknwon +// +// Licensed under the Apache License, Version 2.0 (the "License"): you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +package ini + +import ( + "bufio" + "bytes" + "fmt" + "io" + "strconv" + "strings" + "unicode" +) + +type tokenType int + +const ( + _TOKEN_INVALID tokenType = iota + _TOKEN_COMMENT + _TOKEN_SECTION + _TOKEN_KEY +) + +type parser struct { + buf *bufio.Reader + isEOF bool + count int + comment *bytes.Buffer +} + +func newParser(r io.Reader) *parser { + return &parser{ + buf: bufio.NewReader(r), + count: 1, + comment: &bytes.Buffer{}, + } +} + +// BOM handles header of UTF-8, UTF-16 LE and UTF-16 BE's BOM format. +// http://en.wikipedia.org/wiki/Byte_order_mark#Representations_of_byte_order_marks_by_encoding +func (p *parser) BOM() error { + mask, err := p.buf.Peek(2) + if err != nil && err != io.EOF { + return err + } else if len(mask) < 2 { + return nil + } + + switch { + case mask[0] == 254 && mask[1] == 255: + fallthrough + case mask[0] == 255 && mask[1] == 254: + p.buf.Read(mask) + case mask[0] == 239 && mask[1] == 187: + mask, err := p.buf.Peek(3) + if err != nil && err != io.EOF { + return err + } else if len(mask) < 3 { + return nil + } + if mask[2] == 191 { + p.buf.Read(mask) + } + } + return nil +} + +func (p *parser) readUntil(delim byte) ([]byte, error) { + data, err := p.buf.ReadBytes(delim) + if err != nil { + if err == io.EOF { + p.isEOF = true + } else { + return nil, err + } + } + return data, nil +} + +func cleanComment(in []byte) ([]byte, bool) { + i := bytes.IndexAny(in, "#;") + if i == -1 { + return nil, false + } + return in[i:], true +} + +func readKeyName(in []byte) (string, int, error) { + line := string(in) + + // Check if key name surrounded by quotes. + var keyQuote string + if line[0] == '"' { + if len(line) > 6 && string(line[0:3]) == `"""` { + keyQuote = `"""` + } else { + keyQuote = `"` + } + } else if line[0] == '`' { + keyQuote = "`" + } + + // Get out key name + endIdx := -1 + if len(keyQuote) > 0 { + startIdx := len(keyQuote) + // FIXME: fail case -> """"""name"""=value + pos := strings.Index(line[startIdx:], keyQuote) + if pos == -1 { + return "", -1, fmt.Errorf("missing closing key quote: %s", line) + } + pos += startIdx + + // Find key-value delimiter + i := strings.IndexAny(line[pos+startIdx:], "=:") + if i < 0 { + return "", -1, ErrDelimiterNotFound{line} + } + endIdx = pos + i + return strings.TrimSpace(line[startIdx:pos]), endIdx + startIdx + 1, nil + } + + endIdx = strings.IndexAny(line, "=:") + if endIdx < 0 { + return "", -1, ErrDelimiterNotFound{line} + } + return strings.TrimSpace(line[0:endIdx]), endIdx + 1, nil +} + +func (p *parser) readMultilines(line, val, valQuote string) (string, error) { + for { + data, err := p.readUntil('\n') + if err != nil { + return "", err + } + next := string(data) + + pos := strings.LastIndex(next, valQuote) + if pos > -1 { + val += next[:pos] + + comment, has := cleanComment([]byte(next[pos:])) + if has { + p.comment.Write(bytes.TrimSpace(comment)) + } + break + } + val += next + if p.isEOF { + return "", fmt.Errorf("missing closing key quote from '%s' to '%s'", line, next) + } + } + return val, nil +} + +func (p *parser) readContinuationLines(val string) (string, error) { + for { + data, err := p.readUntil('\n') + if err != nil { + return "", err + } + next := strings.TrimSpace(string(data)) + + if len(next) == 0 { + break + } + val += next + if val[len(val)-1] != '\\' { + break + } + val = val[:len(val)-1] + } + return val, nil +} + +// hasSurroundedQuote check if and only if the first and last characters +// are quotes \" or \'. +// It returns false if any other parts also contain same kind of quotes. +func hasSurroundedQuote(in string, quote byte) bool { + return len(in) >= 2 && in[0] == quote && in[len(in)-1] == quote && + strings.IndexByte(in[1:], quote) == len(in)-2 +} + +func (p *parser) readValue(in []byte, + ignoreContinuation, ignoreInlineComment, unescapeValueDoubleQuotes, unescapeValueCommentSymbols bool) (string, error) { + + line := strings.TrimLeftFunc(string(in), unicode.IsSpace) + if len(line) == 0 { + return "", nil + } + + var valQuote string + if len(line) > 3 && string(line[0:3]) == `"""` { + valQuote = `"""` + } else if line[0] == '`' { + valQuote = "`" + } else if unescapeValueDoubleQuotes && line[0] == '"' { + valQuote = `"` + } + + if len(valQuote) > 0 { + startIdx := len(valQuote) + pos := strings.LastIndex(line[startIdx:], valQuote) + // Check for multi-line value + if pos == -1 { + return p.readMultilines(line, line[startIdx:], valQuote) + } + + if unescapeValueDoubleQuotes && valQuote == `"` { + return strings.Replace(line[startIdx:pos+startIdx], `\"`, `"`, -1), nil + } + return line[startIdx : pos+startIdx], nil + } + + // Won't be able to reach here if value only contains whitespace + line = strings.TrimSpace(line) + + // Check continuation lines when desired + if !ignoreContinuation && line[len(line)-1] == '\\' { + return p.readContinuationLines(line[:len(line)-1]) + } + + // Check if ignore inline comment + if !ignoreInlineComment { + i := strings.IndexAny(line, "#;") + if i > -1 { + p.comment.WriteString(line[i:]) + line = strings.TrimSpace(line[:i]) + } + } + + // Trim single and double quotes + if hasSurroundedQuote(line, '\'') || + hasSurroundedQuote(line, '"') { + line = line[1 : len(line)-1] + } else if len(valQuote) == 0 && unescapeValueCommentSymbols { + if strings.Contains(line, `\;`) { + line = strings.Replace(line, `\;`, ";", -1) + } + if strings.Contains(line, `\#`) { + line = strings.Replace(line, `\#`, "#", -1) + } + } + return line, nil +} + +// parse parses data through an io.Reader. +func (f *File) parse(reader io.Reader) (err error) { + p := newParser(reader) + if err = p.BOM(); err != nil { + return fmt.Errorf("BOM: %v", err) + } + + // Ignore error because default section name is never empty string. + name := DEFAULT_SECTION + if f.options.Insensitive { + name = strings.ToLower(DEFAULT_SECTION) + } + section, _ := f.NewSection(name) + + // This "last" is not strictly equivalent to "previous one" if current key is not the first nested key + var isLastValueEmpty bool + var lastRegularKey *Key + + var line []byte + var inUnparseableSection bool + for !p.isEOF { + line, err = p.readUntil('\n') + if err != nil { + return err + } + + if f.options.AllowNestedValues && + isLastValueEmpty && len(line) > 0 { + if line[0] == ' ' || line[0] == '\t' { + lastRegularKey.addNestedValue(string(bytes.TrimSpace(line))) + continue + } + } + + line = bytes.TrimLeftFunc(line, unicode.IsSpace) + if len(line) == 0 { + continue + } + + // Comments + if line[0] == '#' || line[0] == ';' { + // Note: we do not care ending line break, + // it is needed for adding second line, + // so just clean it once at the end when set to value. + p.comment.Write(line) + continue + } + + // Section + if line[0] == '[' { + // Read to the next ']' (TODO: support quoted strings) + // TODO(unknwon): use LastIndexByte when stop supporting Go1.4 + closeIdx := bytes.LastIndex(line, []byte("]")) + if closeIdx == -1 { + return fmt.Errorf("unclosed section: %s", line) + } + + name := string(line[1:closeIdx]) + section, err = f.NewSection(name) + if err != nil { + return err + } + + comment, has := cleanComment(line[closeIdx+1:]) + if has { + p.comment.Write(comment) + } + + section.Comment = strings.TrimSpace(p.comment.String()) + + // Reset aotu-counter and comments + p.comment.Reset() + p.count = 1 + + inUnparseableSection = false + for i := range f.options.UnparseableSections { + if f.options.UnparseableSections[i] == name || + (f.options.Insensitive && strings.ToLower(f.options.UnparseableSections[i]) == strings.ToLower(name)) { + inUnparseableSection = true + continue + } + } + continue + } + + if inUnparseableSection { + section.isRawSection = true + section.rawBody += string(line) + continue + } + + kname, offset, err := readKeyName(line) + if err != nil { + // Treat as boolean key when desired, and whole line is key name. + if IsErrDelimiterNotFound(err) && f.options.AllowBooleanKeys { + kname, err := p.readValue(line, + f.options.IgnoreContinuation, + f.options.IgnoreInlineComment, + f.options.UnescapeValueDoubleQuotes, + f.options.UnescapeValueCommentSymbols) + if err != nil { + return err + } + key, err := section.NewBooleanKey(kname) + if err != nil { + return err + } + key.Comment = strings.TrimSpace(p.comment.String()) + p.comment.Reset() + continue + } + return err + } + + // Auto increment. + isAutoIncr := false + if kname == "-" { + isAutoIncr = true + kname = "#" + strconv.Itoa(p.count) + p.count++ + } + + value, err := p.readValue(line[offset:], + f.options.IgnoreContinuation, + f.options.IgnoreInlineComment, + f.options.UnescapeValueDoubleQuotes, + f.options.UnescapeValueCommentSymbols) + if err != nil { + return err + } + isLastValueEmpty = len(value) == 0 + + key, err := section.NewKey(kname, value) + if err != nil { + return err + } + key.isAutoIncrement = isAutoIncr + key.Comment = strings.TrimSpace(p.comment.String()) + p.comment.Reset() + lastRegularKey = key + } + return nil +} diff --git a/vendor/github.com/go-ini/ini/section.go b/vendor/github.com/go-ini/ini/section.go new file mode 100644 index 000000000..d8a402619 --- /dev/null +++ b/vendor/github.com/go-ini/ini/section.go @@ -0,0 +1,257 @@ +// Copyright 2014 Unknwon +// +// Licensed under the Apache License, Version 2.0 (the "License"): you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +package ini + +import ( + "errors" + "fmt" + "strings" +) + +// Section represents a config section. +type Section struct { + f *File + Comment string + name string + keys map[string]*Key + keyList []string + keysHash map[string]string + + isRawSection bool + rawBody string +} + +func newSection(f *File, name string) *Section { + return &Section{ + f: f, + name: name, + keys: make(map[string]*Key), + keyList: make([]string, 0, 10), + keysHash: make(map[string]string), + } +} + +// Name returns name of Section. +func (s *Section) Name() string { + return s.name +} + +// Body returns rawBody of Section if the section was marked as unparseable. +// It still follows the other rules of the INI format surrounding leading/trailing whitespace. +func (s *Section) Body() string { + return strings.TrimSpace(s.rawBody) +} + +// SetBody updates body content only if section is raw. +func (s *Section) SetBody(body string) { + if !s.isRawSection { + return + } + s.rawBody = body +} + +// NewKey creates a new key to given section. +func (s *Section) NewKey(name, val string) (*Key, error) { + if len(name) == 0 { + return nil, errors.New("error creating new key: empty key name") + } else if s.f.options.Insensitive { + name = strings.ToLower(name) + } + + if s.f.BlockMode { + s.f.lock.Lock() + defer s.f.lock.Unlock() + } + + if inSlice(name, s.keyList) { + if s.f.options.AllowShadows { + if err := s.keys[name].addShadow(val); err != nil { + return nil, err + } + } else { + s.keys[name].value = val + } + return s.keys[name], nil + } + + s.keyList = append(s.keyList, name) + s.keys[name] = newKey(s, name, val) + s.keysHash[name] = val + return s.keys[name], nil +} + +// NewBooleanKey creates a new boolean type key to given section. +func (s *Section) NewBooleanKey(name string) (*Key, error) { + key, err := s.NewKey(name, "true") + if err != nil { + return nil, err + } + + key.isBooleanType = true + return key, nil +} + +// GetKey returns key in section by given name. +func (s *Section) GetKey(name string) (*Key, error) { + // FIXME: change to section level lock? + if s.f.BlockMode { + s.f.lock.RLock() + } + if s.f.options.Insensitive { + name = strings.ToLower(name) + } + key := s.keys[name] + if s.f.BlockMode { + s.f.lock.RUnlock() + } + + if key == nil { + // Check if it is a child-section. + sname := s.name + for { + if i := strings.LastIndex(sname, "."); i > -1 { + sname = sname[:i] + sec, err := s.f.GetSection(sname) + if err != nil { + continue + } + return sec.GetKey(name) + } else { + break + } + } + return nil, fmt.Errorf("error when getting key of section '%s': key '%s' not exists", s.name, name) + } + return key, nil +} + +// HasKey returns true if section contains a key with given name. +func (s *Section) HasKey(name string) bool { + key, _ := s.GetKey(name) + return key != nil +} + +// Haskey is a backwards-compatible name for HasKey. +// TODO: delete me in v2 +func (s *Section) Haskey(name string) bool { + return s.HasKey(name) +} + +// HasValue returns true if section contains given raw value. +func (s *Section) HasValue(value string) bool { + if s.f.BlockMode { + s.f.lock.RLock() + defer s.f.lock.RUnlock() + } + + for _, k := range s.keys { + if value == k.value { + return true + } + } + return false +} + +// Key assumes named Key exists in section and returns a zero-value when not. +func (s *Section) Key(name string) *Key { + key, err := s.GetKey(name) + if err != nil { + // It's OK here because the only possible error is empty key name, + // but if it's empty, this piece of code won't be executed. + key, _ = s.NewKey(name, "") + return key + } + return key +} + +// Keys returns list of keys of section. +func (s *Section) Keys() []*Key { + keys := make([]*Key, len(s.keyList)) + for i := range s.keyList { + keys[i] = s.Key(s.keyList[i]) + } + return keys +} + +// ParentKeys returns list of keys of parent section. +func (s *Section) ParentKeys() []*Key { + var parentKeys []*Key + sname := s.name + for { + if i := strings.LastIndex(sname, "."); i > -1 { + sname = sname[:i] + sec, err := s.f.GetSection(sname) + if err != nil { + continue + } + parentKeys = append(parentKeys, sec.Keys()...) + } else { + break + } + + } + return parentKeys +} + +// KeyStrings returns list of key names of section. +func (s *Section) KeyStrings() []string { + list := make([]string, len(s.keyList)) + copy(list, s.keyList) + return list +} + +// KeysHash returns keys hash consisting of names and values. +func (s *Section) KeysHash() map[string]string { + if s.f.BlockMode { + s.f.lock.RLock() + defer s.f.lock.RUnlock() + } + + hash := map[string]string{} + for key, value := range s.keysHash { + hash[key] = value + } + return hash +} + +// DeleteKey deletes a key from section. +func (s *Section) DeleteKey(name string) { + if s.f.BlockMode { + s.f.lock.Lock() + defer s.f.lock.Unlock() + } + + for i, k := range s.keyList { + if k == name { + s.keyList = append(s.keyList[:i], s.keyList[i+1:]...) + delete(s.keys, name) + return + } + } +} + +// ChildSections returns a list of child sections of current section. +// For example, "[parent.child1]" and "[parent.child12]" are child sections +// of section "[parent]". +func (s *Section) ChildSections() []*Section { + prefix := s.name + "." + children := make([]*Section, 0, 3) + for _, name := range s.f.sectionList { + if strings.HasPrefix(name, prefix) { + children = append(children, s.f.sections[name]) + } + } + return children +} diff --git a/vendor/github.com/go-ini/ini/struct.go b/vendor/github.com/go-ini/ini/struct.go new file mode 100644 index 000000000..9719dc698 --- /dev/null +++ b/vendor/github.com/go-ini/ini/struct.go @@ -0,0 +1,512 @@ +// Copyright 2014 Unknwon +// +// Licensed under the Apache License, Version 2.0 (the "License"): you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +package ini + +import ( + "bytes" + "errors" + "fmt" + "reflect" + "strings" + "time" + "unicode" +) + +// NameMapper represents a ini tag name mapper. +type NameMapper func(string) string + +// Built-in name getters. +var ( + // AllCapsUnderscore converts to format ALL_CAPS_UNDERSCORE. + AllCapsUnderscore NameMapper = func(raw string) string { + newstr := make([]rune, 0, len(raw)) + for i, chr := range raw { + if isUpper := 'A' <= chr && chr <= 'Z'; isUpper { + if i > 0 { + newstr = append(newstr, '_') + } + } + newstr = append(newstr, unicode.ToUpper(chr)) + } + return string(newstr) + } + // TitleUnderscore converts to format title_underscore. + TitleUnderscore NameMapper = func(raw string) string { + newstr := make([]rune, 0, len(raw)) + for i, chr := range raw { + if isUpper := 'A' <= chr && chr <= 'Z'; isUpper { + if i > 0 { + newstr = append(newstr, '_') + } + chr -= ('A' - 'a') + } + newstr = append(newstr, chr) + } + return string(newstr) + } +) + +func (s *Section) parseFieldName(raw, actual string) string { + if len(actual) > 0 { + return actual + } + if s.f.NameMapper != nil { + return s.f.NameMapper(raw) + } + return raw +} + +func parseDelim(actual string) string { + if len(actual) > 0 { + return actual + } + return "," +} + +var reflectTime = reflect.TypeOf(time.Now()).Kind() + +// setSliceWithProperType sets proper values to slice based on its type. +func setSliceWithProperType(key *Key, field reflect.Value, delim string, allowShadow, isStrict bool) error { + var strs []string + if allowShadow { + strs = key.StringsWithShadows(delim) + } else { + strs = key.Strings(delim) + } + + numVals := len(strs) + if numVals == 0 { + return nil + } + + var vals interface{} + var err error + + sliceOf := field.Type().Elem().Kind() + switch sliceOf { + case reflect.String: + vals = strs + case reflect.Int: + vals, err = key.parseInts(strs, true, false) + case reflect.Int64: + vals, err = key.parseInt64s(strs, true, false) + case reflect.Uint: + vals, err = key.parseUints(strs, true, false) + case reflect.Uint64: + vals, err = key.parseUint64s(strs, true, false) + case reflect.Float64: + vals, err = key.parseFloat64s(strs, true, false) + case reflectTime: + vals, err = key.parseTimesFormat(time.RFC3339, strs, true, false) + default: + return fmt.Errorf("unsupported type '[]%s'", sliceOf) + } + if err != nil && isStrict { + return err + } + + slice := reflect.MakeSlice(field.Type(), numVals, numVals) + for i := 0; i < numVals; i++ { + switch sliceOf { + case reflect.String: + slice.Index(i).Set(reflect.ValueOf(vals.([]string)[i])) + case reflect.Int: + slice.Index(i).Set(reflect.ValueOf(vals.([]int)[i])) + case reflect.Int64: + slice.Index(i).Set(reflect.ValueOf(vals.([]int64)[i])) + case reflect.Uint: + slice.Index(i).Set(reflect.ValueOf(vals.([]uint)[i])) + case reflect.Uint64: + slice.Index(i).Set(reflect.ValueOf(vals.([]uint64)[i])) + case reflect.Float64: + slice.Index(i).Set(reflect.ValueOf(vals.([]float64)[i])) + case reflectTime: + slice.Index(i).Set(reflect.ValueOf(vals.([]time.Time)[i])) + } + } + field.Set(slice) + return nil +} + +func wrapStrictError(err error, isStrict bool) error { + if isStrict { + return err + } + return nil +} + +// setWithProperType sets proper value to field based on its type, +// but it does not return error for failing parsing, +// because we want to use default value that is already assigned to strcut. +func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string, allowShadow, isStrict bool) error { + switch t.Kind() { + case reflect.String: + if len(key.String()) == 0 { + return nil + } + field.SetString(key.String()) + case reflect.Bool: + boolVal, err := key.Bool() + if err != nil { + return wrapStrictError(err, isStrict) + } + field.SetBool(boolVal) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + durationVal, err := key.Duration() + // Skip zero value + if err == nil && int64(durationVal) > 0 { + field.Set(reflect.ValueOf(durationVal)) + return nil + } + + intVal, err := key.Int64() + if err != nil { + return wrapStrictError(err, isStrict) + } + field.SetInt(intVal) + // byte is an alias for uint8, so supporting uint8 breaks support for byte + case reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64: + durationVal, err := key.Duration() + // Skip zero value + if err == nil && int(durationVal) > 0 { + field.Set(reflect.ValueOf(durationVal)) + return nil + } + + uintVal, err := key.Uint64() + if err != nil { + return wrapStrictError(err, isStrict) + } + field.SetUint(uintVal) + + case reflect.Float32, reflect.Float64: + floatVal, err := key.Float64() + if err != nil { + return wrapStrictError(err, isStrict) + } + field.SetFloat(floatVal) + case reflectTime: + timeVal, err := key.Time() + if err != nil { + return wrapStrictError(err, isStrict) + } + field.Set(reflect.ValueOf(timeVal)) + case reflect.Slice: + return setSliceWithProperType(key, field, delim, allowShadow, isStrict) + default: + return fmt.Errorf("unsupported type '%s'", t) + } + return nil +} + +func parseTagOptions(tag string) (rawName string, omitEmpty bool, allowShadow bool) { + opts := strings.SplitN(tag, ",", 3) + rawName = opts[0] + if len(opts) > 1 { + omitEmpty = opts[1] == "omitempty" + } + if len(opts) > 2 { + allowShadow = opts[2] == "allowshadow" + } + return rawName, omitEmpty, allowShadow +} + +func (s *Section) mapTo(val reflect.Value, isStrict bool) error { + if val.Kind() == reflect.Ptr { + val = val.Elem() + } + typ := val.Type() + + for i := 0; i < typ.NumField(); i++ { + field := val.Field(i) + tpField := typ.Field(i) + + tag := tpField.Tag.Get("ini") + if tag == "-" { + continue + } + + rawName, _, allowShadow := parseTagOptions(tag) + fieldName := s.parseFieldName(tpField.Name, rawName) + if len(fieldName) == 0 || !field.CanSet() { + continue + } + + isAnonymous := tpField.Type.Kind() == reflect.Ptr && tpField.Anonymous + isStruct := tpField.Type.Kind() == reflect.Struct + if isAnonymous { + field.Set(reflect.New(tpField.Type.Elem())) + } + + if isAnonymous || isStruct { + if sec, err := s.f.GetSection(fieldName); err == nil { + if err = sec.mapTo(field, isStrict); err != nil { + return fmt.Errorf("error mapping field(%s): %v", fieldName, err) + } + continue + } + } + + if key, err := s.GetKey(fieldName); err == nil { + delim := parseDelim(tpField.Tag.Get("delim")) + if err = setWithProperType(tpField.Type, key, field, delim, allowShadow, isStrict); err != nil { + return fmt.Errorf("error mapping field(%s): %v", fieldName, err) + } + } + } + return nil +} + +// MapTo maps section to given struct. +func (s *Section) MapTo(v interface{}) error { + typ := reflect.TypeOf(v) + val := reflect.ValueOf(v) + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + val = val.Elem() + } else { + return errors.New("cannot map to non-pointer struct") + } + + return s.mapTo(val, false) +} + +// MapTo maps section to given struct in strict mode, +// which returns all possible error including value parsing error. +func (s *Section) StrictMapTo(v interface{}) error { + typ := reflect.TypeOf(v) + val := reflect.ValueOf(v) + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + val = val.Elem() + } else { + return errors.New("cannot map to non-pointer struct") + } + + return s.mapTo(val, true) +} + +// MapTo maps file to given struct. +func (f *File) MapTo(v interface{}) error { + return f.Section("").MapTo(v) +} + +// MapTo maps file to given struct in strict mode, +// which returns all possible error including value parsing error. +func (f *File) StrictMapTo(v interface{}) error { + return f.Section("").StrictMapTo(v) +} + +// MapTo maps data sources to given struct with name mapper. +func MapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error { + cfg, err := Load(source, others...) + if err != nil { + return err + } + cfg.NameMapper = mapper + return cfg.MapTo(v) +} + +// StrictMapToWithMapper maps data sources to given struct with name mapper in strict mode, +// which returns all possible error including value parsing error. +func StrictMapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error { + cfg, err := Load(source, others...) + if err != nil { + return err + } + cfg.NameMapper = mapper + return cfg.StrictMapTo(v) +} + +// MapTo maps data sources to given struct. +func MapTo(v, source interface{}, others ...interface{}) error { + return MapToWithMapper(v, nil, source, others...) +} + +// StrictMapTo maps data sources to given struct in strict mode, +// which returns all possible error including value parsing error. +func StrictMapTo(v, source interface{}, others ...interface{}) error { + return StrictMapToWithMapper(v, nil, source, others...) +} + +// reflectSliceWithProperType does the opposite thing as setSliceWithProperType. +func reflectSliceWithProperType(key *Key, field reflect.Value, delim string) error { + slice := field.Slice(0, field.Len()) + if field.Len() == 0 { + return nil + } + + var buf bytes.Buffer + sliceOf := field.Type().Elem().Kind() + for i := 0; i < field.Len(); i++ { + switch sliceOf { + case reflect.String: + buf.WriteString(slice.Index(i).String()) + case reflect.Int, reflect.Int64: + buf.WriteString(fmt.Sprint(slice.Index(i).Int())) + case reflect.Uint, reflect.Uint64: + buf.WriteString(fmt.Sprint(slice.Index(i).Uint())) + case reflect.Float64: + buf.WriteString(fmt.Sprint(slice.Index(i).Float())) + case reflectTime: + buf.WriteString(slice.Index(i).Interface().(time.Time).Format(time.RFC3339)) + default: + return fmt.Errorf("unsupported type '[]%s'", sliceOf) + } + buf.WriteString(delim) + } + key.SetValue(buf.String()[:buf.Len()-1]) + return nil +} + +// reflectWithProperType does the opposite thing as setWithProperType. +func reflectWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string) error { + switch t.Kind() { + case reflect.String: + key.SetValue(field.String()) + case reflect.Bool: + key.SetValue(fmt.Sprint(field.Bool())) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + key.SetValue(fmt.Sprint(field.Int())) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + key.SetValue(fmt.Sprint(field.Uint())) + case reflect.Float32, reflect.Float64: + key.SetValue(fmt.Sprint(field.Float())) + case reflectTime: + key.SetValue(fmt.Sprint(field.Interface().(time.Time).Format(time.RFC3339))) + case reflect.Slice: + return reflectSliceWithProperType(key, field, delim) + default: + return fmt.Errorf("unsupported type '%s'", t) + } + return nil +} + +// CR: copied from encoding/json/encode.go with modifications of time.Time support. +// TODO: add more test coverage. +func isEmptyValue(v reflect.Value) bool { + switch v.Kind() { + case reflect.Array, reflect.Map, reflect.Slice, reflect.String: + return v.Len() == 0 + case reflect.Bool: + return !v.Bool() + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return v.Int() == 0 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + return v.Uint() == 0 + case reflect.Float32, reflect.Float64: + return v.Float() == 0 + case reflect.Interface, reflect.Ptr: + return v.IsNil() + case reflectTime: + t, ok := v.Interface().(time.Time) + return ok && t.IsZero() + } + return false +} + +func (s *Section) reflectFrom(val reflect.Value) error { + if val.Kind() == reflect.Ptr { + val = val.Elem() + } + typ := val.Type() + + for i := 0; i < typ.NumField(); i++ { + field := val.Field(i) + tpField := typ.Field(i) + + tag := tpField.Tag.Get("ini") + if tag == "-" { + continue + } + + opts := strings.SplitN(tag, ",", 2) + if len(opts) == 2 && opts[1] == "omitempty" && isEmptyValue(field) { + continue + } + + fieldName := s.parseFieldName(tpField.Name, opts[0]) + if len(fieldName) == 0 || !field.CanSet() { + continue + } + + if (tpField.Type.Kind() == reflect.Ptr && tpField.Anonymous) || + (tpField.Type.Kind() == reflect.Struct && tpField.Type.Name() != "Time") { + // Note: The only error here is section doesn't exist. + sec, err := s.f.GetSection(fieldName) + if err != nil { + // Note: fieldName can never be empty here, ignore error. + sec, _ = s.f.NewSection(fieldName) + } + + // Add comment from comment tag + if len(sec.Comment) == 0 { + sec.Comment = tpField.Tag.Get("comment") + } + + if err = sec.reflectFrom(field); err != nil { + return fmt.Errorf("error reflecting field (%s): %v", fieldName, err) + } + continue + } + + // Note: Same reason as secion. + key, err := s.GetKey(fieldName) + if err != nil { + key, _ = s.NewKey(fieldName, "") + } + + // Add comment from comment tag + if len(key.Comment) == 0 { + key.Comment = tpField.Tag.Get("comment") + } + + if err = reflectWithProperType(tpField.Type, key, field, parseDelim(tpField.Tag.Get("delim"))); err != nil { + return fmt.Errorf("error reflecting field (%s): %v", fieldName, err) + } + + } + return nil +} + +// ReflectFrom reflects secion from given struct. +func (s *Section) ReflectFrom(v interface{}) error { + typ := reflect.TypeOf(v) + val := reflect.ValueOf(v) + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + val = val.Elem() + } else { + return errors.New("cannot reflect from non-pointer struct") + } + + return s.reflectFrom(val) +} + +// ReflectFrom reflects file from given struct. +func (f *File) ReflectFrom(v interface{}) error { + return f.Section("").ReflectFrom(v) +} + +// ReflectFrom reflects data sources from given struct with name mapper. +func ReflectFromWithMapper(cfg *File, v interface{}, mapper NameMapper) error { + cfg.NameMapper = mapper + return cfg.ReflectFrom(v) +} + +// ReflectFrom reflects data sources from given struct. +func ReflectFrom(cfg *File, v interface{}) error { + return ReflectFromWithMapper(cfg, v, nil) +} diff --git a/vendor/github.com/gogo/protobuf/.gitignore b/vendor/github.com/gogo/protobuf/.gitignore new file mode 100644 index 000000000..76009479d --- /dev/null +++ b/vendor/github.com/gogo/protobuf/.gitignore @@ -0,0 +1,3 @@ +._* +*.js +*.js.map diff --git a/vendor/github.com/gogo/protobuf/.mailmap b/vendor/github.com/gogo/protobuf/.mailmap new file mode 100644 index 000000000..bc0010219 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/.mailmap @@ -0,0 +1,8 @@ +Walter Schulze Walter Schulze +Walter Schulze +Walter Schulze awalterschulze +Walter Schulze awalterschulze@gmail.com +John Tuley +Anton Povarov +Denis Smirnov dennwc +DongYun Kang \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/.travis.yml b/vendor/github.com/gogo/protobuf/.travis.yml new file mode 100644 index 000000000..12302e006 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/.travis.yml @@ -0,0 +1,20 @@ +env: + - PROTOBUF_VERSION=2.6.1 + - PROTOBUF_VERSION=3.0.2 + - PROTOBUF_VERSION=3.5.1 + +before_install: + - ./install-protobuf.sh + - PATH=/home/travis/bin:$PATH protoc --version + +script: + - PATH=/home/travis/bin:$PATH make buildserverall + - echo $TRAVIS_GO_VERSION + - if [[ "$PROTOBUF_VERSION" == "3.5.1" ]] && [[ "$TRAVIS_GO_VERSION" =~ ^1\.9\.[0-9]+$ ]]; then ! git status --porcelain | read || (git status; git diff; exit 1); fi + +language: go + +go: + - 1.8.x + - 1.9.x + - 1.10beta1 diff --git a/vendor/github.com/gogo/protobuf/AUTHORS b/vendor/github.com/gogo/protobuf/AUTHORS new file mode 100644 index 000000000..3d97fc7a2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/AUTHORS @@ -0,0 +1,15 @@ +# This is the official list of GoGo authors for copyright purposes. +# This file is distinct from the CONTRIBUTORS file, which +# lists people. For example, employees are listed in CONTRIBUTORS, +# but not in AUTHORS, because the employer holds the copyright. + +# Names should be added to this file as one of +# Organization's name +# Individual's name +# Individual's name + +# Please keep the list sorted. + +Sendgrid, Inc +Vastech SA (PTY) LTD +Walter Schulze diff --git a/vendor/github.com/gogo/protobuf/CONTRIBUTORS b/vendor/github.com/gogo/protobuf/CONTRIBUTORS new file mode 100644 index 000000000..1b4f6c208 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/CONTRIBUTORS @@ -0,0 +1,23 @@ +Anton Povarov +Brian Goff +Clayton Coleman +Denis Smirnov +DongYun Kang +Dwayne Schultz +Georg Apitz +Gustav Paul +Johan Brandhorst +John Shahid +John Tuley +Laurent +Patrick Lee +Peter Edge +Roger Johansson +Sam Nguyen +Sergio Arbeo +Stephen J Day +Tamir Duberstein +Todd Eisenberger +Tormod Erevik Lea +Vyacheslav Kim +Walter Schulze diff --git a/vendor/github.com/gogo/protobuf/GOLANG_CONTRIBUTORS b/vendor/github.com/gogo/protobuf/GOLANG_CONTRIBUTORS new file mode 100644 index 000000000..b368efb7f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/GOLANG_CONTRIBUTORS @@ -0,0 +1,5 @@ +The contributors to the Go protobuf repository: + +# This source code was written by the Go contributors. +# The master list of contributors is in the main Go distribution, +# visible at http://tip.golang.org/CONTRIBUTORS. \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/Makefile b/vendor/github.com/gogo/protobuf/Makefile new file mode 100644 index 000000000..1d9ad1f56 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/Makefile @@ -0,0 +1,162 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +GO_VERSION:=$(shell go version) + +.PHONY: nuke regenerate tests clean install gofmt vet contributors + +all: clean install regenerate install tests errcheck vet + +buildserverall: clean install regenerate install tests vet js + +install: + go install ./proto + go install ./gogoproto + go install ./jsonpb + go install ./protoc-gen-gogo + go install ./protoc-gen-gofast + go install ./protoc-gen-gogofast + go install ./protoc-gen-gogofaster + go install ./protoc-gen-gogoslick + go install ./protoc-gen-gostring + go install ./protoc-min-version + go install ./protoc-gen-combo + go install ./gogoreplace + +clean: + go clean ./... + +nuke: + go clean -i ./... + +gofmt: + gofmt -l -s -w . + +regenerate: + make -C protoc-gen-gogo/descriptor regenerate + make -C protoc-gen-gogo/plugin regenerate + make -C protoc-gen-gogo/testdata regenerate + make -C gogoproto regenerate + make -C proto/testdata regenerate + make -C jsonpb/jsonpb_test_proto regenerate + make -C _conformance regenerate + make -C types regenerate + make -C test regenerate + make -C test/example regenerate + make -C test/unrecognized regenerate + make -C test/group regenerate + make -C test/unrecognizedgroup regenerate + make -C test/enumstringer regenerate + make -C test/unmarshalmerge regenerate + make -C test/moredefaults regenerate + make -C test/issue8 regenerate + make -C test/enumprefix regenerate + make -C test/enumcustomname regenerate + make -C test/packed regenerate + make -C test/protosize regenerate + make -C test/tags regenerate + make -C test/oneof regenerate + make -C test/oneof3 regenerate + make -C test/theproto3 regenerate + make -C test/mapdefaults regenerate + make -C test/mapsproto2 regenerate + make -C test/issue42order regenerate + make -C proto generate-test-pbs + make -C test/importdedup regenerate + make -C test/importduplicate regenerate + make -C test/custombytesnonstruct regenerate + make -C test/required regenerate + make -C test/casttype regenerate + make -C test/castvalue regenerate + make -C vanity/test regenerate + make -C test/sizeunderscore regenerate + make -C test/issue34 regenerate + make -C test/empty-issue70 regenerate + make -C test/indeximport-issue72 regenerate + make -C test/fuzztests regenerate + make -C test/oneofembed regenerate + make -C test/asymetric-issue125 regenerate + make -C test/filedotname regenerate + make -C test/nopackage regenerate + make -C test/types regenerate + make -C test/proto3extension regenerate + make -C test/stdtypes regenerate + make -C test/data regenerate + make -C test/typedecl regenerate + make -C test/issue260 regenerate + make -C test/issue261 regenerate + make -C test/issue262 regenerate + make -C test/issue312 regenerate + make -C test/enumdecl regenerate + make -C test/typedecl_all regenerate + make -C test/enumdecl_all regenerate + make -C test/int64support regenerate + make -C test/issue322 regenerate + make -C test/issue330 regenerate + make gofmt + +tests: + go build ./test/enumprefix + go test ./... + (cd test/stdtypes && make test) + +vet: + go vet ./... + go tool vet --shadow . + +errcheck: + go get github.com/kisielk/errcheck + errcheck ./test/... + +drone: + sudo apt-get install protobuf-compiler + (cd $(GOPATH)/src/github.com/gogo/protobuf && make buildserverall) + +testall: + go get -u github.com/golang/protobuf/proto + make -C protoc-gen-gogo/testdata test + make -C vanity/test test + make -C test/registration test + make tests + +bench: + go get golang.org/x/tools/cmd/benchcmp + (cd test/mixbench && go build .) + ./test/mixbench/mixbench + +contributors: + git log --format='%aN <%aE>' | sort -fu > CONTRIBUTORS + +js: +ifeq (go1.9, $(findstring go1.9, $(GO_VERSION))) + go get -u github.com/gopherjs/gopherjs + gopherjs build github.com/gogo/protobuf/protoc-gen-gogo +endif + +update: + (cd protobuf && make update) diff --git a/vendor/github.com/gogo/protobuf/README b/vendor/github.com/gogo/protobuf/README new file mode 100644 index 000000000..035426df5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/README @@ -0,0 +1,258 @@ +GoGoProtobuf http://github.com/gogo/protobuf extends +GoProtobuf http://github.com/golang/protobuf + +# Go support for Protocol Buffers + +Google's data interchange format. +Copyright 2010 The Go Authors. +https://github.com/golang/protobuf + +This package and the code it generates requires at least Go 1.4. + +This software implements Go bindings for protocol buffers. For +information about protocol buffers themselves, see + https://developers.google.com/protocol-buffers/ + +## Installation ## + +To use this software, you must: +- Install the standard C++ implementation of protocol buffers from + https://developers.google.com/protocol-buffers/ +- Of course, install the Go compiler and tools from + https://golang.org/ + See + https://golang.org/doc/install + for details or, if you are using gccgo, follow the instructions at + https://golang.org/doc/install/gccgo +- Grab the code from the repository and install the proto package. + The simplest way is to run `go get -u github.com/golang/protobuf/protoc-gen-go`. + The compiler plugin, protoc-gen-go, will be installed in $GOBIN, + defaulting to $GOPATH/bin. It must be in your $PATH for the protocol + compiler, protoc, to find it. + +This software has two parts: a 'protocol compiler plugin' that +generates Go source files that, once compiled, can access and manage +protocol buffers; and a library that implements run-time support for +encoding (marshaling), decoding (unmarshaling), and accessing protocol +buffers. + +There is support for gRPC in Go using protocol buffers. +See the note at the bottom of this file for details. + +There are no insertion points in the plugin. + +GoGoProtobuf provides extensions for protocol buffers and GoProtobuf +see http://github.com/gogo/protobuf/gogoproto/doc.go + +## Using protocol buffers with Go ## + +Once the software is installed, there are two steps to using it. +First you must compile the protocol buffer definitions and then import +them, with the support library, into your program. + +To compile the protocol buffer definition, run protoc with the --gogo_out +parameter set to the directory you want to output the Go code to. + + protoc --gogo_out=. *.proto + +The generated files will be suffixed .pb.go. See the Test code below +for an example using such a file. + +The package comment for the proto library contains text describing +the interface provided in Go for protocol buffers. Here is an edited +version. + +If you are using any gogo.proto extensions you will need to specify the +proto_path to include the descriptor.proto and gogo.proto. +gogo.proto is located in github.com/gogo/protobuf/gogoproto +This should be fine, since your import is the same. +descriptor.proto is located in either github.com/gogo/protobuf/protobuf +or code.google.com/p/protobuf/trunk/src/ +Its import is google/protobuf/descriptor.proto so it might need some help. + + protoc --gogo_out=. -I=.:github.com/gogo/protobuf/protobuf *.proto + +========== + +The proto package converts data structures to and from the +wire format of protocol buffers. It works in concert with the +Go source code generated for .proto files by the protocol compiler. + +A summary of the properties of the protocol buffer interface +for a protocol buffer variable v: + + - Names are turned from camel_case to CamelCase for export. + - There are no methods on v to set fields; just treat + them as structure fields. + - There are getters that return a field's value if set, + and return the field's default value if unset. + The getters work even if the receiver is a nil message. + - The zero value for a struct is its correct initialization state. + All desired fields must be set before marshaling. + - A Reset() method will restore a protobuf struct to its zero state. + - Non-repeated fields are pointers to the values; nil means unset. + That is, optional or required field int32 f becomes F *int32. + - Repeated fields are slices. + - Helper functions are available to aid the setting of fields. + Helpers for getting values are superseded by the + GetFoo methods and their use is deprecated. + msg.Foo = proto.String("hello") // set field + - Constants are defined to hold the default values of all fields that + have them. They have the form Default_StructName_FieldName. + Because the getter methods handle defaulted values, + direct use of these constants should be rare. + - Enums are given type names and maps from names to values. + Enum values are prefixed with the enum's type name. Enum types have + a String method, and a Enum method to assist in message construction. + - Nested groups and enums have type names prefixed with the name of + the surrounding message type. + - Extensions are given descriptor names that start with E_, + followed by an underscore-delimited list of the nested messages + that contain it (if any) followed by the CamelCased name of the + extension field itself. HasExtension, ClearExtension, GetExtension + and SetExtension are functions for manipulating extensions. + - Oneof field sets are given a single field in their message, + with distinguished wrapper types for each possible field value. + - Marshal and Unmarshal are functions to encode and decode the wire format. + +When the .proto file specifies `syntax="proto3"`, there are some differences: + + - Non-repeated fields of non-message type are values instead of pointers. + - Enum types do not get an Enum method. + +Consider file test.proto, containing + +```proto + syntax = "proto2"; + package example; + + enum FOO { X = 17; }; + + message Test { + required string label = 1; + optional int32 type = 2 [default=77]; + repeated int64 reps = 3; + optional group OptionalGroup = 4 { + required string RequiredField = 5; + } + } +``` + +To create and play with a Test object from the example package, + +```go + package main + + import ( + "log" + + "github.com/gogo/protobuf/proto" + "path/to/example" + ) + + func main() { + test := &example.Test { + Label: proto.String("hello"), + Type: proto.Int32(17), + Reps: []int64{1, 2, 3}, + Optionalgroup: &example.Test_OptionalGroup { + RequiredField: proto.String("good bye"), + }, + } + data, err := proto.Marshal(test) + if err != nil { + log.Fatal("marshaling error: ", err) + } + newTest := &example.Test{} + err = proto.Unmarshal(data, newTest) + if err != nil { + log.Fatal("unmarshaling error: ", err) + } + // Now test and newTest contain the same data. + if test.GetLabel() != newTest.GetLabel() { + log.Fatalf("data mismatch %q != %q", test.GetLabel(), newTest.GetLabel()) + } + // etc. + } +``` + + +## Parameters ## + +To pass extra parameters to the plugin, use a comma-separated +parameter list separated from the output directory by a colon: + + + protoc --gogo_out=plugins=grpc,import_path=mypackage:. *.proto + + +- `import_prefix=xxx` - a prefix that is added onto the beginning of + all imports. Useful for things like generating protos in a + subdirectory, or regenerating vendored protobufs in-place. +- `import_path=foo/bar` - used as the package if no input files + declare `go_package`. If it contains slashes, everything up to the + rightmost slash is ignored. +- `plugins=plugin1+plugin2` - specifies the list of sub-plugins to + load. The only plugin in this repo is `grpc`. +- `Mfoo/bar.proto=quux/shme` - declares that foo/bar.proto is + associated with Go package quux/shme. This is subject to the + import_prefix parameter. + +## gRPC Support ## + +If a proto file specifies RPC services, protoc-gen-go can be instructed to +generate code compatible with gRPC (http://www.grpc.io/). To do this, pass +the `plugins` parameter to protoc-gen-go; the usual way is to insert it into +the --go_out argument to protoc: + + protoc --gogo_out=plugins=grpc:. *.proto + +## Compatibility ## + +The library and the generated code are expected to be stable over time. +However, we reserve the right to make breaking changes without notice for the +following reasons: + +- Security. A security issue in the specification or implementation may come to + light whose resolution requires breaking compatibility. We reserve the right + to address such security issues. +- Unspecified behavior. There are some aspects of the Protocol Buffers + specification that are undefined. Programs that depend on such unspecified + behavior may break in future releases. +- Specification errors or changes. If it becomes necessary to address an + inconsistency, incompleteness, or change in the Protocol Buffers + specification, resolving the issue could affect the meaning or legality of + existing programs. We reserve the right to address such issues, including + updating the implementations. +- Bugs. If the library has a bug that violates the specification, a program + that depends on the buggy behavior may break if the bug is fixed. We reserve + the right to fix such bugs. +- Adding methods or fields to generated structs. These may conflict with field + names that already exist in a schema, causing applications to break. When the + code generator encounters a field in the schema that would collide with a + generated field or method name, the code generator will append an underscore + to the generated field or method name. +- Adding, removing, or changing methods or fields in generated structs that + start with `XXX`. These parts of the generated code are exported out of + necessity, but should not be considered part of the public API. +- Adding, removing, or changing unexported symbols in generated code. + +Any breaking changes outside of these will be announced 6 months in advance to +protobuf@googlegroups.com. + +You should, whenever possible, use generated code created by the `protoc-gen-go` +tool built at the same commit as the `proto` package. The `proto` package +declares package-level constants in the form `ProtoPackageIsVersionX`. +Application code and generated code may depend on one of these constants to +ensure that compilation will fail if the available version of the proto library +is too old. Whenever we make a change to the generated code that requires newer +library support, in the same commit we will increment the version number of the +generated code and declare a new package-level constant whose name incorporates +the latest version number. Removing a compatibility constant is considered a +breaking change and would be subject to the announcement policy stated above. + +## Plugins ## + +The `protoc-gen-go/generator` package exposes a plugin interface, +which is used by the gRPC code generation. This interface is not +supported and is subject to incompatible changes without notice. diff --git a/vendor/github.com/gogo/protobuf/Readme.md b/vendor/github.com/gogo/protobuf/Readme.md new file mode 100644 index 000000000..bb0dbb5d4 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/Readme.md @@ -0,0 +1,129 @@ +# Protocol Buffers for Go with Gadgets + +[![Build Status](https://travis-ci.org/gogo/protobuf.svg?branch=master)](https://travis-ci.org/gogo/protobuf) + +gogoprotobuf is a fork of golang/protobuf with extra code generation features. + +This code generation is used to achieve: + + - fast marshalling and unmarshalling + - more canonical Go structures + - goprotobuf compatibility + - less typing by optionally generating extra helper code + - peace of mind by optionally generating test and benchmark code + - other serialization formats + +Keeping track of how up to date gogoprotobuf is relative to golang/protobuf is done in this +issue + +## Users + +These projects use gogoprotobuf: + + - etcd - blog - sample proto file + - spacemonkey - blog + - badoo - sample proto file + - mesos-go - sample proto file + - heka - the switch from golang/protobuf to gogo/protobuf when it was still on code.google.com + - cockroachdb - sample proto file + - go-ipfs - sample proto file + - rkive-go - sample proto file + - dropbox + - srclib - sample proto file + - adyoulike + - cloudfoundry - sample proto file + - kubernetes - go2idl built on top of gogoprotobuf + - dgraph - release notes - benchmarks + - centrifugo - release notes - blog + - docker swarmkit - sample proto file + - nats.io - go-nats-streaming + - tidb - Communication between tidb and tikv + - protoactor-go - vanity command that also generates actors from service definitions + - containerd - vanity command with custom field names that conforms to the golang convention. + - nakama + - proteus + - carbonzipper stack + - sendgrid + - zero-os/0-stor + +Please let us know if you are using gogoprotobuf by posting on our GoogleGroup. + +### Mentioned + + - Cloudflare - go serialization talk - Albert Strasheim + - GopherCon 2014 Writing High Performance Databases in Go by Ben Johnson + - alecthomas' go serialization benchmarks + +## Getting Started + +There are several ways to use gogoprotobuf, but for all you need to install go and protoc. +After that you can choose: + + - Speed + - More Speed and more generated code + - Most Speed and most customization + +### Installation + +To install it, you must first have Go (at least version 1.6.3) installed (see [http://golang.org/doc/install](http://golang.org/doc/install)). Latest patch versions of Go 1.8, 1.9 and 1.10 are continuously tested. + +Next, install the standard protocol buffer implementation from [https://github.com/google/protobuf](https://github.com/google/protobuf). +Most versions from 2.3.1 should not give any problems, but 2.6.1, 3.0.2 and 3.5.1 are continuously tested. + +### Speed + +Install the protoc-gen-gofast binary + + go get github.com/gogo/protobuf/protoc-gen-gofast + +Use it to generate faster marshaling and unmarshaling go code for your protocol buffers. + + protoc --gofast_out=. myproto.proto + +This does not allow you to use any of the other gogoprotobuf [extensions](https://github.com/gogo/protobuf/blob/master/extensions.md). + +### More Speed and more generated code + +Fields without pointers cause less time in the garbage collector. +More code generation results in more convenient methods. + +Other binaries are also included: + + protoc-gen-gogofast (same as gofast, but imports gogoprotobuf) + protoc-gen-gogofaster (same as gogofast, without XXX_unrecognized, less pointer fields) + protoc-gen-gogoslick (same as gogofaster, but with generated string, gostring and equal methods) + +Installing any of these binaries is easy. Simply run: + + go get github.com/gogo/protobuf/proto + go get github.com/gogo/protobuf/{binary} + go get github.com/gogo/protobuf/gogoproto + +These binaries allow you to use gogoprotobuf [extensions](https://github.com/gogo/protobuf/blob/master/extensions.md). You can also use your own binary. + +To generate the code, you also need to set the include path properly. + + protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/gogo/protobuf/protobuf --{binary}_out=. myproto.proto + +Note that in the protoc command, {binary} does not contain the initial prefix of "protoc-gen". + +### Most Speed and most customization + +Customizing the fields of the messages to be the fields that you actually want to use removes the need to copy between the structs you use and structs you use to serialize. +gogoprotobuf also offers more serialization formats and generation of tests and even more methods. + +Please visit the [extensions](https://github.com/gogo/protobuf/blob/master/extensions.md) page for more documentation. + +Install protoc-gen-gogo: + + go get github.com/gogo/protobuf/proto + go get github.com/gogo/protobuf/jsonpb + go get github.com/gogo/protobuf/protoc-gen-gogo + go get github.com/gogo/protobuf/gogoproto + +## GRPC + +It works the same as golang/protobuf, simply specify the plugin. +Here is an example using gofast: + + protoc --gofast_out=plugins=grpc:. my.proto diff --git a/vendor/github.com/gogo/protobuf/_conformance/Makefile b/vendor/github.com/gogo/protobuf/_conformance/Makefile new file mode 100644 index 000000000..74aa200ef --- /dev/null +++ b/vendor/github.com/gogo/protobuf/_conformance/Makefile @@ -0,0 +1,40 @@ +# Go support for Protocol Buffers - Google's data interchange format +# +# Copyright 2016 The Go Authors. All rights reserved. +# https://github.com/golang/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + protoc-min-version --version="3.0.0" --proto_path=$(GOPATH)/src:$(GOPATH)/src/github.com/gogo/protobuf/protobuf:. --gogo_out=\ + Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types\ + :. conformance_proto/conformance.proto diff --git a/vendor/github.com/gogo/protobuf/_conformance/conformance.go b/vendor/github.com/gogo/protobuf/_conformance/conformance.go new file mode 100644 index 000000000..45b37881b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/_conformance/conformance.go @@ -0,0 +1,161 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// conformance implements the conformance test subprocess protocol as +// documented in conformance.proto. +package main + +import ( + "encoding/binary" + "fmt" + "io" + "os" + + pb "github.com/gogo/protobuf/_conformance/conformance_proto" + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" +) + +func main() { + var sizeBuf [4]byte + inbuf := make([]byte, 0, 4096) + outbuf := proto.NewBuffer(nil) + for { + if _, err := io.ReadFull(os.Stdin, sizeBuf[:]); err == io.EOF { + break + } else if err != nil { + fmt.Fprintln(os.Stderr, "go conformance: read request:", err) + os.Exit(1) + } + size := binary.LittleEndian.Uint32(sizeBuf[:]) + if int(size) > cap(inbuf) { + inbuf = make([]byte, size) + } + inbuf = inbuf[:size] + if _, err := io.ReadFull(os.Stdin, inbuf); err != nil { + fmt.Fprintln(os.Stderr, "go conformance: read request:", err) + os.Exit(1) + } + + req := new(pb.ConformanceRequest) + if err := proto.Unmarshal(inbuf, req); err != nil { + fmt.Fprintln(os.Stderr, "go conformance: parse request:", err) + os.Exit(1) + } + res := handle(req) + + if err := outbuf.Marshal(res); err != nil { + fmt.Fprintln(os.Stderr, "go conformance: marshal response:", err) + os.Exit(1) + } + binary.LittleEndian.PutUint32(sizeBuf[:], uint32(len(outbuf.Bytes()))) + if _, err := os.Stdout.Write(sizeBuf[:]); err != nil { + fmt.Fprintln(os.Stderr, "go conformance: write response:", err) + os.Exit(1) + } + if _, err := os.Stdout.Write(outbuf.Bytes()); err != nil { + fmt.Fprintln(os.Stderr, "go conformance: write response:", err) + os.Exit(1) + } + outbuf.Reset() + } +} + +var jsonMarshaler = jsonpb.Marshaler{ + OrigName: true, +} + +func handle(req *pb.ConformanceRequest) *pb.ConformanceResponse { + var err error + var msg pb.TestAllTypes + switch p := req.Payload.(type) { + case *pb.ConformanceRequest_ProtobufPayload: + err = proto.Unmarshal(p.ProtobufPayload, &msg) + case *pb.ConformanceRequest_JsonPayload: + err = jsonpb.UnmarshalString(p.JsonPayload, &msg) + if err != nil && err.Error() == "unmarshaling Any not supported yet" { + return &pb.ConformanceResponse{ + Result: &pb.ConformanceResponse_Skipped{ + Skipped: err.Error(), + }, + } + } + default: + return &pb.ConformanceResponse{ + Result: &pb.ConformanceResponse_RuntimeError{ + RuntimeError: "unknown request payload type", + }, + } + } + if err != nil { + return &pb.ConformanceResponse{ + Result: &pb.ConformanceResponse_ParseError{ + ParseError: err.Error(), + }, + } + } + switch req.RequestedOutputFormat { + case pb.WireFormat_PROTOBUF: + p, err := proto.Marshal(&msg) + if err != nil { + return &pb.ConformanceResponse{ + Result: &pb.ConformanceResponse_SerializeError{ + SerializeError: err.Error(), + }, + } + } + return &pb.ConformanceResponse{ + Result: &pb.ConformanceResponse_ProtobufPayload{ + ProtobufPayload: p, + }, + } + case pb.WireFormat_JSON: + p, err := jsonMarshaler.MarshalToString(&msg) + if err != nil { + return &pb.ConformanceResponse{ + Result: &pb.ConformanceResponse_SerializeError{ + SerializeError: err.Error(), + }, + } + } + return &pb.ConformanceResponse{ + Result: &pb.ConformanceResponse_JsonPayload{ + JsonPayload: p, + }, + } + default: + return &pb.ConformanceResponse{ + Result: &pb.ConformanceResponse_RuntimeError{ + RuntimeError: "unknown output format", + }, + } + } +} diff --git a/vendor/github.com/gogo/protobuf/_conformance/conformance_proto/conformance.pb.go b/vendor/github.com/gogo/protobuf/_conformance/conformance_proto/conformance.pb.go new file mode 100644 index 000000000..49c6fb329 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/_conformance/conformance_proto/conformance.pb.go @@ -0,0 +1,1889 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: conformance_proto/conformance.proto + +/* +Package conformance is a generated protocol buffer package. + +It is generated from these files: + conformance_proto/conformance.proto + +It has these top-level messages: + ConformanceRequest + ConformanceResponse + TestAllTypes + ForeignMessage +*/ +package conformance + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import google_protobuf "github.com/gogo/protobuf/types" +import google_protobuf1 "github.com/gogo/protobuf/types" +import google_protobuf2 "github.com/gogo/protobuf/types" +import google_protobuf3 "github.com/gogo/protobuf/types" +import google_protobuf4 "github.com/gogo/protobuf/types" +import google_protobuf5 "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type WireFormat int32 + +const ( + WireFormat_UNSPECIFIED WireFormat = 0 + WireFormat_PROTOBUF WireFormat = 1 + WireFormat_JSON WireFormat = 2 +) + +var WireFormat_name = map[int32]string{ + 0: "UNSPECIFIED", + 1: "PROTOBUF", + 2: "JSON", +} +var WireFormat_value = map[string]int32{ + "UNSPECIFIED": 0, + "PROTOBUF": 1, + "JSON": 2, +} + +func (x WireFormat) String() string { + return proto.EnumName(WireFormat_name, int32(x)) +} +func (WireFormat) EnumDescriptor() ([]byte, []int) { return fileDescriptorConformance, []int{0} } + +type ForeignEnum int32 + +const ( + ForeignEnum_FOREIGN_FOO ForeignEnum = 0 + ForeignEnum_FOREIGN_BAR ForeignEnum = 1 + ForeignEnum_FOREIGN_BAZ ForeignEnum = 2 +) + +var ForeignEnum_name = map[int32]string{ + 0: "FOREIGN_FOO", + 1: "FOREIGN_BAR", + 2: "FOREIGN_BAZ", +} +var ForeignEnum_value = map[string]int32{ + "FOREIGN_FOO": 0, + "FOREIGN_BAR": 1, + "FOREIGN_BAZ": 2, +} + +func (x ForeignEnum) String() string { + return proto.EnumName(ForeignEnum_name, int32(x)) +} +func (ForeignEnum) EnumDescriptor() ([]byte, []int) { return fileDescriptorConformance, []int{1} } + +type TestAllTypes_NestedEnum int32 + +const ( + TestAllTypes_FOO TestAllTypes_NestedEnum = 0 + TestAllTypes_BAR TestAllTypes_NestedEnum = 1 + TestAllTypes_BAZ TestAllTypes_NestedEnum = 2 + TestAllTypes_NEG TestAllTypes_NestedEnum = -1 +) + +var TestAllTypes_NestedEnum_name = map[int32]string{ + 0: "FOO", + 1: "BAR", + 2: "BAZ", + -1: "NEG", +} +var TestAllTypes_NestedEnum_value = map[string]int32{ + "FOO": 0, + "BAR": 1, + "BAZ": 2, + "NEG": -1, +} + +func (x TestAllTypes_NestedEnum) String() string { + return proto.EnumName(TestAllTypes_NestedEnum_name, int32(x)) +} +func (TestAllTypes_NestedEnum) EnumDescriptor() ([]byte, []int) { + return fileDescriptorConformance, []int{2, 0} +} + +// Represents a single test case's input. The testee should: +// +// 1. parse this proto (which should always succeed) +// 2. parse the protobuf or JSON payload in "payload" (which may fail) +// 3. if the parse succeeded, serialize the message in the requested format. +type ConformanceRequest struct { + // The payload (whether protobuf of JSON) is always for a TestAllTypes proto + // (see below). + // + // Types that are valid to be assigned to Payload: + // *ConformanceRequest_ProtobufPayload + // *ConformanceRequest_JsonPayload + Payload isConformanceRequest_Payload `protobuf_oneof:"payload"` + // Which format should the testee serialize its message to? + RequestedOutputFormat WireFormat `protobuf:"varint,3,opt,name=requested_output_format,json=requestedOutputFormat,proto3,enum=conformance.WireFormat" json:"requested_output_format,omitempty"` +} + +func (m *ConformanceRequest) Reset() { *m = ConformanceRequest{} } +func (m *ConformanceRequest) String() string { return proto.CompactTextString(m) } +func (*ConformanceRequest) ProtoMessage() {} +func (*ConformanceRequest) Descriptor() ([]byte, []int) { return fileDescriptorConformance, []int{0} } + +type isConformanceRequest_Payload interface { + isConformanceRequest_Payload() +} + +type ConformanceRequest_ProtobufPayload struct { + ProtobufPayload []byte `protobuf:"bytes,1,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof"` +} +type ConformanceRequest_JsonPayload struct { + JsonPayload string `protobuf:"bytes,2,opt,name=json_payload,json=jsonPayload,proto3,oneof"` +} + +func (*ConformanceRequest_ProtobufPayload) isConformanceRequest_Payload() {} +func (*ConformanceRequest_JsonPayload) isConformanceRequest_Payload() {} + +func (m *ConformanceRequest) GetPayload() isConformanceRequest_Payload { + if m != nil { + return m.Payload + } + return nil +} + +func (m *ConformanceRequest) GetProtobufPayload() []byte { + if x, ok := m.GetPayload().(*ConformanceRequest_ProtobufPayload); ok { + return x.ProtobufPayload + } + return nil +} + +func (m *ConformanceRequest) GetJsonPayload() string { + if x, ok := m.GetPayload().(*ConformanceRequest_JsonPayload); ok { + return x.JsonPayload + } + return "" +} + +func (m *ConformanceRequest) GetRequestedOutputFormat() WireFormat { + if m != nil { + return m.RequestedOutputFormat + } + return WireFormat_UNSPECIFIED +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*ConformanceRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _ConformanceRequest_OneofMarshaler, _ConformanceRequest_OneofUnmarshaler, _ConformanceRequest_OneofSizer, []interface{}{ + (*ConformanceRequest_ProtobufPayload)(nil), + (*ConformanceRequest_JsonPayload)(nil), + } +} + +func _ConformanceRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*ConformanceRequest) + // payload + switch x := m.Payload.(type) { + case *ConformanceRequest_ProtobufPayload: + _ = b.EncodeVarint(1<<3 | proto.WireBytes) + _ = b.EncodeRawBytes(x.ProtobufPayload) + case *ConformanceRequest_JsonPayload: + _ = b.EncodeVarint(2<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.JsonPayload) + case nil: + default: + return fmt.Errorf("ConformanceRequest.Payload has unexpected type %T", x) + } + return nil +} + +func _ConformanceRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*ConformanceRequest) + switch tag { + case 1: // payload.protobuf_payload + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeRawBytes(true) + m.Payload = &ConformanceRequest_ProtobufPayload{x} + return true, err + case 2: // payload.json_payload + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Payload = &ConformanceRequest_JsonPayload{x} + return true, err + default: + return false, nil + } +} + +func _ConformanceRequest_OneofSizer(msg proto.Message) (n int) { + m := msg.(*ConformanceRequest) + // payload + switch x := m.Payload.(type) { + case *ConformanceRequest_ProtobufPayload: + n += proto.SizeVarint(1<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.ProtobufPayload))) + n += len(x.ProtobufPayload) + case *ConformanceRequest_JsonPayload: + n += proto.SizeVarint(2<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.JsonPayload))) + n += len(x.JsonPayload) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +// Represents a single test case's output. +type ConformanceResponse struct { + // Types that are valid to be assigned to Result: + // *ConformanceResponse_ParseError + // *ConformanceResponse_SerializeError + // *ConformanceResponse_RuntimeError + // *ConformanceResponse_ProtobufPayload + // *ConformanceResponse_JsonPayload + // *ConformanceResponse_Skipped + Result isConformanceResponse_Result `protobuf_oneof:"result"` +} + +func (m *ConformanceResponse) Reset() { *m = ConformanceResponse{} } +func (m *ConformanceResponse) String() string { return proto.CompactTextString(m) } +func (*ConformanceResponse) ProtoMessage() {} +func (*ConformanceResponse) Descriptor() ([]byte, []int) { return fileDescriptorConformance, []int{1} } + +type isConformanceResponse_Result interface { + isConformanceResponse_Result() +} + +type ConformanceResponse_ParseError struct { + ParseError string `protobuf:"bytes,1,opt,name=parse_error,json=parseError,proto3,oneof"` +} +type ConformanceResponse_SerializeError struct { + SerializeError string `protobuf:"bytes,6,opt,name=serialize_error,json=serializeError,proto3,oneof"` +} +type ConformanceResponse_RuntimeError struct { + RuntimeError string `protobuf:"bytes,2,opt,name=runtime_error,json=runtimeError,proto3,oneof"` +} +type ConformanceResponse_ProtobufPayload struct { + ProtobufPayload []byte `protobuf:"bytes,3,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof"` +} +type ConformanceResponse_JsonPayload struct { + JsonPayload string `protobuf:"bytes,4,opt,name=json_payload,json=jsonPayload,proto3,oneof"` +} +type ConformanceResponse_Skipped struct { + Skipped string `protobuf:"bytes,5,opt,name=skipped,proto3,oneof"` +} + +func (*ConformanceResponse_ParseError) isConformanceResponse_Result() {} +func (*ConformanceResponse_SerializeError) isConformanceResponse_Result() {} +func (*ConformanceResponse_RuntimeError) isConformanceResponse_Result() {} +func (*ConformanceResponse_ProtobufPayload) isConformanceResponse_Result() {} +func (*ConformanceResponse_JsonPayload) isConformanceResponse_Result() {} +func (*ConformanceResponse_Skipped) isConformanceResponse_Result() {} + +func (m *ConformanceResponse) GetResult() isConformanceResponse_Result { + if m != nil { + return m.Result + } + return nil +} + +func (m *ConformanceResponse) GetParseError() string { + if x, ok := m.GetResult().(*ConformanceResponse_ParseError); ok { + return x.ParseError + } + return "" +} + +func (m *ConformanceResponse) GetSerializeError() string { + if x, ok := m.GetResult().(*ConformanceResponse_SerializeError); ok { + return x.SerializeError + } + return "" +} + +func (m *ConformanceResponse) GetRuntimeError() string { + if x, ok := m.GetResult().(*ConformanceResponse_RuntimeError); ok { + return x.RuntimeError + } + return "" +} + +func (m *ConformanceResponse) GetProtobufPayload() []byte { + if x, ok := m.GetResult().(*ConformanceResponse_ProtobufPayload); ok { + return x.ProtobufPayload + } + return nil +} + +func (m *ConformanceResponse) GetJsonPayload() string { + if x, ok := m.GetResult().(*ConformanceResponse_JsonPayload); ok { + return x.JsonPayload + } + return "" +} + +func (m *ConformanceResponse) GetSkipped() string { + if x, ok := m.GetResult().(*ConformanceResponse_Skipped); ok { + return x.Skipped + } + return "" +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*ConformanceResponse) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _ConformanceResponse_OneofMarshaler, _ConformanceResponse_OneofUnmarshaler, _ConformanceResponse_OneofSizer, []interface{}{ + (*ConformanceResponse_ParseError)(nil), + (*ConformanceResponse_SerializeError)(nil), + (*ConformanceResponse_RuntimeError)(nil), + (*ConformanceResponse_ProtobufPayload)(nil), + (*ConformanceResponse_JsonPayload)(nil), + (*ConformanceResponse_Skipped)(nil), + } +} + +func _ConformanceResponse_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*ConformanceResponse) + // result + switch x := m.Result.(type) { + case *ConformanceResponse_ParseError: + _ = b.EncodeVarint(1<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.ParseError) + case *ConformanceResponse_SerializeError: + _ = b.EncodeVarint(6<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.SerializeError) + case *ConformanceResponse_RuntimeError: + _ = b.EncodeVarint(2<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.RuntimeError) + case *ConformanceResponse_ProtobufPayload: + _ = b.EncodeVarint(3<<3 | proto.WireBytes) + _ = b.EncodeRawBytes(x.ProtobufPayload) + case *ConformanceResponse_JsonPayload: + _ = b.EncodeVarint(4<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.JsonPayload) + case *ConformanceResponse_Skipped: + _ = b.EncodeVarint(5<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.Skipped) + case nil: + default: + return fmt.Errorf("ConformanceResponse.Result has unexpected type %T", x) + } + return nil +} + +func _ConformanceResponse_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*ConformanceResponse) + switch tag { + case 1: // result.parse_error + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Result = &ConformanceResponse_ParseError{x} + return true, err + case 6: // result.serialize_error + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Result = &ConformanceResponse_SerializeError{x} + return true, err + case 2: // result.runtime_error + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Result = &ConformanceResponse_RuntimeError{x} + return true, err + case 3: // result.protobuf_payload + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeRawBytes(true) + m.Result = &ConformanceResponse_ProtobufPayload{x} + return true, err + case 4: // result.json_payload + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Result = &ConformanceResponse_JsonPayload{x} + return true, err + case 5: // result.skipped + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Result = &ConformanceResponse_Skipped{x} + return true, err + default: + return false, nil + } +} + +func _ConformanceResponse_OneofSizer(msg proto.Message) (n int) { + m := msg.(*ConformanceResponse) + // result + switch x := m.Result.(type) { + case *ConformanceResponse_ParseError: + n += proto.SizeVarint(1<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.ParseError))) + n += len(x.ParseError) + case *ConformanceResponse_SerializeError: + n += proto.SizeVarint(6<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.SerializeError))) + n += len(x.SerializeError) + case *ConformanceResponse_RuntimeError: + n += proto.SizeVarint(2<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.RuntimeError))) + n += len(x.RuntimeError) + case *ConformanceResponse_ProtobufPayload: + n += proto.SizeVarint(3<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.ProtobufPayload))) + n += len(x.ProtobufPayload) + case *ConformanceResponse_JsonPayload: + n += proto.SizeVarint(4<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.JsonPayload))) + n += len(x.JsonPayload) + case *ConformanceResponse_Skipped: + n += proto.SizeVarint(5<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.Skipped))) + n += len(x.Skipped) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +// This proto includes every type of field in both singular and repeated +// forms. +type TestAllTypes struct { + // Singular + OptionalInt32 int32 `protobuf:"varint,1,opt,name=optional_int32,json=optionalInt32,proto3" json:"optional_int32,omitempty"` + OptionalInt64 int64 `protobuf:"varint,2,opt,name=optional_int64,json=optionalInt64,proto3" json:"optional_int64,omitempty"` + OptionalUint32 uint32 `protobuf:"varint,3,opt,name=optional_uint32,json=optionalUint32,proto3" json:"optional_uint32,omitempty"` + OptionalUint64 uint64 `protobuf:"varint,4,opt,name=optional_uint64,json=optionalUint64,proto3" json:"optional_uint64,omitempty"` + OptionalSint32 int32 `protobuf:"zigzag32,5,opt,name=optional_sint32,json=optionalSint32,proto3" json:"optional_sint32,omitempty"` + OptionalSint64 int64 `protobuf:"zigzag64,6,opt,name=optional_sint64,json=optionalSint64,proto3" json:"optional_sint64,omitempty"` + OptionalFixed32 uint32 `protobuf:"fixed32,7,opt,name=optional_fixed32,json=optionalFixed32,proto3" json:"optional_fixed32,omitempty"` + OptionalFixed64 uint64 `protobuf:"fixed64,8,opt,name=optional_fixed64,json=optionalFixed64,proto3" json:"optional_fixed64,omitempty"` + OptionalSfixed32 int32 `protobuf:"fixed32,9,opt,name=optional_sfixed32,json=optionalSfixed32,proto3" json:"optional_sfixed32,omitempty"` + OptionalSfixed64 int64 `protobuf:"fixed64,10,opt,name=optional_sfixed64,json=optionalSfixed64,proto3" json:"optional_sfixed64,omitempty"` + OptionalFloat float32 `protobuf:"fixed32,11,opt,name=optional_float,json=optionalFloat,proto3" json:"optional_float,omitempty"` + OptionalDouble float64 `protobuf:"fixed64,12,opt,name=optional_double,json=optionalDouble,proto3" json:"optional_double,omitempty"` + OptionalBool bool `protobuf:"varint,13,opt,name=optional_bool,json=optionalBool,proto3" json:"optional_bool,omitempty"` + OptionalString string `protobuf:"bytes,14,opt,name=optional_string,json=optionalString,proto3" json:"optional_string,omitempty"` + OptionalBytes []byte `protobuf:"bytes,15,opt,name=optional_bytes,json=optionalBytes,proto3" json:"optional_bytes,omitempty"` + OptionalNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,18,opt,name=optional_nested_message,json=optionalNestedMessage" json:"optional_nested_message,omitempty"` + OptionalForeignMessage *ForeignMessage `protobuf:"bytes,19,opt,name=optional_foreign_message,json=optionalForeignMessage" json:"optional_foreign_message,omitempty"` + OptionalNestedEnum TestAllTypes_NestedEnum `protobuf:"varint,21,opt,name=optional_nested_enum,json=optionalNestedEnum,proto3,enum=conformance.TestAllTypes_NestedEnum" json:"optional_nested_enum,omitempty"` + OptionalForeignEnum ForeignEnum `protobuf:"varint,22,opt,name=optional_foreign_enum,json=optionalForeignEnum,proto3,enum=conformance.ForeignEnum" json:"optional_foreign_enum,omitempty"` + OptionalStringPiece string `protobuf:"bytes,24,opt,name=optional_string_piece,json=optionalStringPiece,proto3" json:"optional_string_piece,omitempty"` + OptionalCord string `protobuf:"bytes,25,opt,name=optional_cord,json=optionalCord,proto3" json:"optional_cord,omitempty"` + RecursiveMessage *TestAllTypes `protobuf:"bytes,27,opt,name=recursive_message,json=recursiveMessage" json:"recursive_message,omitempty"` + // Repeated + RepeatedInt32 []int32 `protobuf:"varint,31,rep,packed,name=repeated_int32,json=repeatedInt32" json:"repeated_int32,omitempty"` + RepeatedInt64 []int64 `protobuf:"varint,32,rep,packed,name=repeated_int64,json=repeatedInt64" json:"repeated_int64,omitempty"` + RepeatedUint32 []uint32 `protobuf:"varint,33,rep,packed,name=repeated_uint32,json=repeatedUint32" json:"repeated_uint32,omitempty"` + RepeatedUint64 []uint64 `protobuf:"varint,34,rep,packed,name=repeated_uint64,json=repeatedUint64" json:"repeated_uint64,omitempty"` + RepeatedSint32 []int32 `protobuf:"zigzag32,35,rep,packed,name=repeated_sint32,json=repeatedSint32" json:"repeated_sint32,omitempty"` + RepeatedSint64 []int64 `protobuf:"zigzag64,36,rep,packed,name=repeated_sint64,json=repeatedSint64" json:"repeated_sint64,omitempty"` + RepeatedFixed32 []uint32 `protobuf:"fixed32,37,rep,packed,name=repeated_fixed32,json=repeatedFixed32" json:"repeated_fixed32,omitempty"` + RepeatedFixed64 []uint64 `protobuf:"fixed64,38,rep,packed,name=repeated_fixed64,json=repeatedFixed64" json:"repeated_fixed64,omitempty"` + RepeatedSfixed32 []int32 `protobuf:"fixed32,39,rep,packed,name=repeated_sfixed32,json=repeatedSfixed32" json:"repeated_sfixed32,omitempty"` + RepeatedSfixed64 []int64 `protobuf:"fixed64,40,rep,packed,name=repeated_sfixed64,json=repeatedSfixed64" json:"repeated_sfixed64,omitempty"` + RepeatedFloat []float32 `protobuf:"fixed32,41,rep,packed,name=repeated_float,json=repeatedFloat" json:"repeated_float,omitempty"` + RepeatedDouble []float64 `protobuf:"fixed64,42,rep,packed,name=repeated_double,json=repeatedDouble" json:"repeated_double,omitempty"` + RepeatedBool []bool `protobuf:"varint,43,rep,packed,name=repeated_bool,json=repeatedBool" json:"repeated_bool,omitempty"` + RepeatedString []string `protobuf:"bytes,44,rep,name=repeated_string,json=repeatedString" json:"repeated_string,omitempty"` + RepeatedBytes [][]byte `protobuf:"bytes,45,rep,name=repeated_bytes,json=repeatedBytes" json:"repeated_bytes,omitempty"` + RepeatedNestedMessage []*TestAllTypes_NestedMessage `protobuf:"bytes,48,rep,name=repeated_nested_message,json=repeatedNestedMessage" json:"repeated_nested_message,omitempty"` + RepeatedForeignMessage []*ForeignMessage `protobuf:"bytes,49,rep,name=repeated_foreign_message,json=repeatedForeignMessage" json:"repeated_foreign_message,omitempty"` + RepeatedNestedEnum []TestAllTypes_NestedEnum `protobuf:"varint,51,rep,packed,name=repeated_nested_enum,json=repeatedNestedEnum,enum=conformance.TestAllTypes_NestedEnum" json:"repeated_nested_enum,omitempty"` + RepeatedForeignEnum []ForeignEnum `protobuf:"varint,52,rep,packed,name=repeated_foreign_enum,json=repeatedForeignEnum,enum=conformance.ForeignEnum" json:"repeated_foreign_enum,omitempty"` + RepeatedStringPiece []string `protobuf:"bytes,54,rep,name=repeated_string_piece,json=repeatedStringPiece" json:"repeated_string_piece,omitempty"` + RepeatedCord []string `protobuf:"bytes,55,rep,name=repeated_cord,json=repeatedCord" json:"repeated_cord,omitempty"` + // Map + MapInt32Int32 map[int32]int32 `protobuf:"bytes,56,rep,name=map_int32_int32,json=mapInt32Int32" json:"map_int32_int32,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + MapInt64Int64 map[int64]int64 `protobuf:"bytes,57,rep,name=map_int64_int64,json=mapInt64Int64" json:"map_int64_int64,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + MapUint32Uint32 map[uint32]uint32 `protobuf:"bytes,58,rep,name=map_uint32_uint32,json=mapUint32Uint32" json:"map_uint32_uint32,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + MapUint64Uint64 map[uint64]uint64 `protobuf:"bytes,59,rep,name=map_uint64_uint64,json=mapUint64Uint64" json:"map_uint64_uint64,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + MapSint32Sint32 map[int32]int32 `protobuf:"bytes,60,rep,name=map_sint32_sint32,json=mapSint32Sint32" json:"map_sint32_sint32,omitempty" protobuf_key:"zigzag32,1,opt,name=key,proto3" protobuf_val:"zigzag32,2,opt,name=value,proto3"` + MapSint64Sint64 map[int64]int64 `protobuf:"bytes,61,rep,name=map_sint64_sint64,json=mapSint64Sint64" json:"map_sint64_sint64,omitempty" protobuf_key:"zigzag64,1,opt,name=key,proto3" protobuf_val:"zigzag64,2,opt,name=value,proto3"` + MapFixed32Fixed32 map[uint32]uint32 `protobuf:"bytes,62,rep,name=map_fixed32_fixed32,json=mapFixed32Fixed32" json:"map_fixed32_fixed32,omitempty" protobuf_key:"fixed32,1,opt,name=key,proto3" protobuf_val:"fixed32,2,opt,name=value,proto3"` + MapFixed64Fixed64 map[uint64]uint64 `protobuf:"bytes,63,rep,name=map_fixed64_fixed64,json=mapFixed64Fixed64" json:"map_fixed64_fixed64,omitempty" protobuf_key:"fixed64,1,opt,name=key,proto3" protobuf_val:"fixed64,2,opt,name=value,proto3"` + MapSfixed32Sfixed32 map[int32]int32 `protobuf:"bytes,64,rep,name=map_sfixed32_sfixed32,json=mapSfixed32Sfixed32" json:"map_sfixed32_sfixed32,omitempty" protobuf_key:"fixed32,1,opt,name=key,proto3" protobuf_val:"fixed32,2,opt,name=value,proto3"` + MapSfixed64Sfixed64 map[int64]int64 `protobuf:"bytes,65,rep,name=map_sfixed64_sfixed64,json=mapSfixed64Sfixed64" json:"map_sfixed64_sfixed64,omitempty" protobuf_key:"fixed64,1,opt,name=key,proto3" protobuf_val:"fixed64,2,opt,name=value,proto3"` + MapInt32Float map[int32]float32 `protobuf:"bytes,66,rep,name=map_int32_float,json=mapInt32Float" json:"map_int32_float,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"fixed32,2,opt,name=value,proto3"` + MapInt32Double map[int32]float64 `protobuf:"bytes,67,rep,name=map_int32_double,json=mapInt32Double" json:"map_int32_double,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"fixed64,2,opt,name=value,proto3"` + MapBoolBool map[bool]bool `protobuf:"bytes,68,rep,name=map_bool_bool,json=mapBoolBool" json:"map_bool_bool,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + MapStringString map[string]string `protobuf:"bytes,69,rep,name=map_string_string,json=mapStringString" json:"map_string_string,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + MapStringBytes map[string][]byte `protobuf:"bytes,70,rep,name=map_string_bytes,json=mapStringBytes" json:"map_string_bytes,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + MapStringNestedMessage map[string]*TestAllTypes_NestedMessage `protobuf:"bytes,71,rep,name=map_string_nested_message,json=mapStringNestedMessage" json:"map_string_nested_message,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value"` + MapStringForeignMessage map[string]*ForeignMessage `protobuf:"bytes,72,rep,name=map_string_foreign_message,json=mapStringForeignMessage" json:"map_string_foreign_message,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value"` + MapStringNestedEnum map[string]TestAllTypes_NestedEnum `protobuf:"bytes,73,rep,name=map_string_nested_enum,json=mapStringNestedEnum" json:"map_string_nested_enum,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=conformance.TestAllTypes_NestedEnum"` + MapStringForeignEnum map[string]ForeignEnum `protobuf:"bytes,74,rep,name=map_string_foreign_enum,json=mapStringForeignEnum" json:"map_string_foreign_enum,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=conformance.ForeignEnum"` + // Types that are valid to be assigned to OneofField: + // *TestAllTypes_OneofUint32 + // *TestAllTypes_OneofNestedMessage + // *TestAllTypes_OneofString + // *TestAllTypes_OneofBytes + // *TestAllTypes_OneofBool + // *TestAllTypes_OneofUint64 + // *TestAllTypes_OneofFloat + // *TestAllTypes_OneofDouble + // *TestAllTypes_OneofEnum + OneofField isTestAllTypes_OneofField `protobuf_oneof:"oneof_field"` + // Well-known types + OptionalBoolWrapper *google_protobuf5.BoolValue `protobuf:"bytes,201,opt,name=optional_bool_wrapper,json=optionalBoolWrapper" json:"optional_bool_wrapper,omitempty"` + OptionalInt32Wrapper *google_protobuf5.Int32Value `protobuf:"bytes,202,opt,name=optional_int32_wrapper,json=optionalInt32Wrapper" json:"optional_int32_wrapper,omitempty"` + OptionalInt64Wrapper *google_protobuf5.Int64Value `protobuf:"bytes,203,opt,name=optional_int64_wrapper,json=optionalInt64Wrapper" json:"optional_int64_wrapper,omitempty"` + OptionalUint32Wrapper *google_protobuf5.UInt32Value `protobuf:"bytes,204,opt,name=optional_uint32_wrapper,json=optionalUint32Wrapper" json:"optional_uint32_wrapper,omitempty"` + OptionalUint64Wrapper *google_protobuf5.UInt64Value `protobuf:"bytes,205,opt,name=optional_uint64_wrapper,json=optionalUint64Wrapper" json:"optional_uint64_wrapper,omitempty"` + OptionalFloatWrapper *google_protobuf5.FloatValue `protobuf:"bytes,206,opt,name=optional_float_wrapper,json=optionalFloatWrapper" json:"optional_float_wrapper,omitempty"` + OptionalDoubleWrapper *google_protobuf5.DoubleValue `protobuf:"bytes,207,opt,name=optional_double_wrapper,json=optionalDoubleWrapper" json:"optional_double_wrapper,omitempty"` + OptionalStringWrapper *google_protobuf5.StringValue `protobuf:"bytes,208,opt,name=optional_string_wrapper,json=optionalStringWrapper" json:"optional_string_wrapper,omitempty"` + OptionalBytesWrapper *google_protobuf5.BytesValue `protobuf:"bytes,209,opt,name=optional_bytes_wrapper,json=optionalBytesWrapper" json:"optional_bytes_wrapper,omitempty"` + RepeatedBoolWrapper []*google_protobuf5.BoolValue `protobuf:"bytes,211,rep,name=repeated_bool_wrapper,json=repeatedBoolWrapper" json:"repeated_bool_wrapper,omitempty"` + RepeatedInt32Wrapper []*google_protobuf5.Int32Value `protobuf:"bytes,212,rep,name=repeated_int32_wrapper,json=repeatedInt32Wrapper" json:"repeated_int32_wrapper,omitempty"` + RepeatedInt64Wrapper []*google_protobuf5.Int64Value `protobuf:"bytes,213,rep,name=repeated_int64_wrapper,json=repeatedInt64Wrapper" json:"repeated_int64_wrapper,omitempty"` + RepeatedUint32Wrapper []*google_protobuf5.UInt32Value `protobuf:"bytes,214,rep,name=repeated_uint32_wrapper,json=repeatedUint32Wrapper" json:"repeated_uint32_wrapper,omitempty"` + RepeatedUint64Wrapper []*google_protobuf5.UInt64Value `protobuf:"bytes,215,rep,name=repeated_uint64_wrapper,json=repeatedUint64Wrapper" json:"repeated_uint64_wrapper,omitempty"` + RepeatedFloatWrapper []*google_protobuf5.FloatValue `protobuf:"bytes,216,rep,name=repeated_float_wrapper,json=repeatedFloatWrapper" json:"repeated_float_wrapper,omitempty"` + RepeatedDoubleWrapper []*google_protobuf5.DoubleValue `protobuf:"bytes,217,rep,name=repeated_double_wrapper,json=repeatedDoubleWrapper" json:"repeated_double_wrapper,omitempty"` + RepeatedStringWrapper []*google_protobuf5.StringValue `protobuf:"bytes,218,rep,name=repeated_string_wrapper,json=repeatedStringWrapper" json:"repeated_string_wrapper,omitempty"` + RepeatedBytesWrapper []*google_protobuf5.BytesValue `protobuf:"bytes,219,rep,name=repeated_bytes_wrapper,json=repeatedBytesWrapper" json:"repeated_bytes_wrapper,omitempty"` + OptionalDuration *google_protobuf1.Duration `protobuf:"bytes,301,opt,name=optional_duration,json=optionalDuration" json:"optional_duration,omitempty"` + OptionalTimestamp *google_protobuf4.Timestamp `protobuf:"bytes,302,opt,name=optional_timestamp,json=optionalTimestamp" json:"optional_timestamp,omitempty"` + OptionalFieldMask *google_protobuf2.FieldMask `protobuf:"bytes,303,opt,name=optional_field_mask,json=optionalFieldMask" json:"optional_field_mask,omitempty"` + OptionalStruct *google_protobuf3.Struct `protobuf:"bytes,304,opt,name=optional_struct,json=optionalStruct" json:"optional_struct,omitempty"` + OptionalAny *google_protobuf.Any `protobuf:"bytes,305,opt,name=optional_any,json=optionalAny" json:"optional_any,omitempty"` + OptionalValue *google_protobuf3.Value `protobuf:"bytes,306,opt,name=optional_value,json=optionalValue" json:"optional_value,omitempty"` + RepeatedDuration []*google_protobuf1.Duration `protobuf:"bytes,311,rep,name=repeated_duration,json=repeatedDuration" json:"repeated_duration,omitempty"` + RepeatedTimestamp []*google_protobuf4.Timestamp `protobuf:"bytes,312,rep,name=repeated_timestamp,json=repeatedTimestamp" json:"repeated_timestamp,omitempty"` + RepeatedFieldmask []*google_protobuf2.FieldMask `protobuf:"bytes,313,rep,name=repeated_fieldmask,json=repeatedFieldmask" json:"repeated_fieldmask,omitempty"` + RepeatedStruct []*google_protobuf3.Struct `protobuf:"bytes,324,rep,name=repeated_struct,json=repeatedStruct" json:"repeated_struct,omitempty"` + RepeatedAny []*google_protobuf.Any `protobuf:"bytes,315,rep,name=repeated_any,json=repeatedAny" json:"repeated_any,omitempty"` + RepeatedValue []*google_protobuf3.Value `protobuf:"bytes,316,rep,name=repeated_value,json=repeatedValue" json:"repeated_value,omitempty"` + // Test field-name-to-JSON-name convention. + // (protobuf says names can be any valid C/C++ identifier.) + Fieldname1 int32 `protobuf:"varint,401,opt,name=fieldname1,proto3" json:"fieldname1,omitempty"` + FieldName2 int32 `protobuf:"varint,402,opt,name=field_name2,json=fieldName2,proto3" json:"field_name2,omitempty"` + XFieldName3 int32 `protobuf:"varint,403,opt,name=_field_name3,json=FieldName3,proto3" json:"_field_name3,omitempty"` + Field_Name4_ int32 `protobuf:"varint,404,opt,name=field__name4_,json=fieldName4,proto3" json:"field__name4_,omitempty"` + Field0Name5 int32 `protobuf:"varint,405,opt,name=field0name5,proto3" json:"field0name5,omitempty"` + Field_0Name6 int32 `protobuf:"varint,406,opt,name=field_0_name6,json=field0Name6,proto3" json:"field_0_name6,omitempty"` + FieldName7 int32 `protobuf:"varint,407,opt,name=fieldName7,proto3" json:"fieldName7,omitempty"` + FieldName8 int32 `protobuf:"varint,408,opt,name=FieldName8,proto3" json:"FieldName8,omitempty"` + Field_Name9 int32 `protobuf:"varint,409,opt,name=field_Name9,json=fieldName9,proto3" json:"field_Name9,omitempty"` + Field_Name10 int32 `protobuf:"varint,410,opt,name=Field_Name10,json=FieldName10,proto3" json:"Field_Name10,omitempty"` + FIELD_NAME11 int32 `protobuf:"varint,411,opt,name=FIELD_NAME11,json=FIELDNAME11,proto3" json:"FIELD_NAME11,omitempty"` + FIELDName12 int32 `protobuf:"varint,412,opt,name=FIELD_name12,json=FIELDName12,proto3" json:"FIELD_name12,omitempty"` + XFieldName13 int32 `protobuf:"varint,413,opt,name=__field_name13,json=FieldName13,proto3" json:"__field_name13,omitempty"` + X_FieldName14 int32 `protobuf:"varint,414,opt,name=__Field_name14,json=FieldName14,proto3" json:"__Field_name14,omitempty"` + Field_Name15 int32 `protobuf:"varint,415,opt,name=field__name15,json=fieldName15,proto3" json:"field__name15,omitempty"` + Field__Name16 int32 `protobuf:"varint,416,opt,name=field__Name16,json=fieldName16,proto3" json:"field__Name16,omitempty"` + FieldName17__ int32 `protobuf:"varint,417,opt,name=field_name17__,json=fieldName17,proto3" json:"field_name17__,omitempty"` + FieldName18__ int32 `protobuf:"varint,418,opt,name=Field_name18__,json=FieldName18,proto3" json:"Field_name18__,omitempty"` +} + +func (m *TestAllTypes) Reset() { *m = TestAllTypes{} } +func (m *TestAllTypes) String() string { return proto.CompactTextString(m) } +func (*TestAllTypes) ProtoMessage() {} +func (*TestAllTypes) Descriptor() ([]byte, []int) { return fileDescriptorConformance, []int{2} } + +type isTestAllTypes_OneofField interface { + isTestAllTypes_OneofField() +} + +type TestAllTypes_OneofUint32 struct { + OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,proto3,oneof"` +} +type TestAllTypes_OneofNestedMessage struct { + OneofNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,oneof"` +} +type TestAllTypes_OneofString struct { + OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,proto3,oneof"` +} +type TestAllTypes_OneofBytes struct { + OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,proto3,oneof"` +} +type TestAllTypes_OneofBool struct { + OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,proto3,oneof"` +} +type TestAllTypes_OneofUint64 struct { + OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,proto3,oneof"` +} +type TestAllTypes_OneofFloat struct { + OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,proto3,oneof"` +} +type TestAllTypes_OneofDouble struct { + OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,proto3,oneof"` +} +type TestAllTypes_OneofEnum struct { + OneofEnum TestAllTypes_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,proto3,enum=conformance.TestAllTypes_NestedEnum,oneof"` +} + +func (*TestAllTypes_OneofUint32) isTestAllTypes_OneofField() {} +func (*TestAllTypes_OneofNestedMessage) isTestAllTypes_OneofField() {} +func (*TestAllTypes_OneofString) isTestAllTypes_OneofField() {} +func (*TestAllTypes_OneofBytes) isTestAllTypes_OneofField() {} +func (*TestAllTypes_OneofBool) isTestAllTypes_OneofField() {} +func (*TestAllTypes_OneofUint64) isTestAllTypes_OneofField() {} +func (*TestAllTypes_OneofFloat) isTestAllTypes_OneofField() {} +func (*TestAllTypes_OneofDouble) isTestAllTypes_OneofField() {} +func (*TestAllTypes_OneofEnum) isTestAllTypes_OneofField() {} + +func (m *TestAllTypes) GetOneofField() isTestAllTypes_OneofField { + if m != nil { + return m.OneofField + } + return nil +} + +func (m *TestAllTypes) GetOptionalInt32() int32 { + if m != nil { + return m.OptionalInt32 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalInt64() int64 { + if m != nil { + return m.OptionalInt64 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalUint32() uint32 { + if m != nil { + return m.OptionalUint32 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalUint64() uint64 { + if m != nil { + return m.OptionalUint64 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalSint32() int32 { + if m != nil { + return m.OptionalSint32 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalSint64() int64 { + if m != nil { + return m.OptionalSint64 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalFixed32() uint32 { + if m != nil { + return m.OptionalFixed32 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalFixed64() uint64 { + if m != nil { + return m.OptionalFixed64 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalSfixed32() int32 { + if m != nil { + return m.OptionalSfixed32 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalSfixed64() int64 { + if m != nil { + return m.OptionalSfixed64 + } + return 0 +} + +func (m *TestAllTypes) GetOptionalFloat() float32 { + if m != nil { + return m.OptionalFloat + } + return 0 +} + +func (m *TestAllTypes) GetOptionalDouble() float64 { + if m != nil { + return m.OptionalDouble + } + return 0 +} + +func (m *TestAllTypes) GetOptionalBool() bool { + if m != nil { + return m.OptionalBool + } + return false +} + +func (m *TestAllTypes) GetOptionalString() string { + if m != nil { + return m.OptionalString + } + return "" +} + +func (m *TestAllTypes) GetOptionalBytes() []byte { + if m != nil { + return m.OptionalBytes + } + return nil +} + +func (m *TestAllTypes) GetOptionalNestedMessage() *TestAllTypes_NestedMessage { + if m != nil { + return m.OptionalNestedMessage + } + return nil +} + +func (m *TestAllTypes) GetOptionalForeignMessage() *ForeignMessage { + if m != nil { + return m.OptionalForeignMessage + } + return nil +} + +func (m *TestAllTypes) GetOptionalNestedEnum() TestAllTypes_NestedEnum { + if m != nil { + return m.OptionalNestedEnum + } + return TestAllTypes_FOO +} + +func (m *TestAllTypes) GetOptionalForeignEnum() ForeignEnum { + if m != nil { + return m.OptionalForeignEnum + } + return ForeignEnum_FOREIGN_FOO +} + +func (m *TestAllTypes) GetOptionalStringPiece() string { + if m != nil { + return m.OptionalStringPiece + } + return "" +} + +func (m *TestAllTypes) GetOptionalCord() string { + if m != nil { + return m.OptionalCord + } + return "" +} + +func (m *TestAllTypes) GetRecursiveMessage() *TestAllTypes { + if m != nil { + return m.RecursiveMessage + } + return nil +} + +func (m *TestAllTypes) GetRepeatedInt32() []int32 { + if m != nil { + return m.RepeatedInt32 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedInt64() []int64 { + if m != nil { + return m.RepeatedInt64 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedUint32() []uint32 { + if m != nil { + return m.RepeatedUint32 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedUint64() []uint64 { + if m != nil { + return m.RepeatedUint64 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedSint32() []int32 { + if m != nil { + return m.RepeatedSint32 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedSint64() []int64 { + if m != nil { + return m.RepeatedSint64 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedFixed32() []uint32 { + if m != nil { + return m.RepeatedFixed32 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedFixed64() []uint64 { + if m != nil { + return m.RepeatedFixed64 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedSfixed32() []int32 { + if m != nil { + return m.RepeatedSfixed32 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedSfixed64() []int64 { + if m != nil { + return m.RepeatedSfixed64 + } + return nil +} + +func (m *TestAllTypes) GetRepeatedFloat() []float32 { + if m != nil { + return m.RepeatedFloat + } + return nil +} + +func (m *TestAllTypes) GetRepeatedDouble() []float64 { + if m != nil { + return m.RepeatedDouble + } + return nil +} + +func (m *TestAllTypes) GetRepeatedBool() []bool { + if m != nil { + return m.RepeatedBool + } + return nil +} + +func (m *TestAllTypes) GetRepeatedString() []string { + if m != nil { + return m.RepeatedString + } + return nil +} + +func (m *TestAllTypes) GetRepeatedBytes() [][]byte { + if m != nil { + return m.RepeatedBytes + } + return nil +} + +func (m *TestAllTypes) GetRepeatedNestedMessage() []*TestAllTypes_NestedMessage { + if m != nil { + return m.RepeatedNestedMessage + } + return nil +} + +func (m *TestAllTypes) GetRepeatedForeignMessage() []*ForeignMessage { + if m != nil { + return m.RepeatedForeignMessage + } + return nil +} + +func (m *TestAllTypes) GetRepeatedNestedEnum() []TestAllTypes_NestedEnum { + if m != nil { + return m.RepeatedNestedEnum + } + return nil +} + +func (m *TestAllTypes) GetRepeatedForeignEnum() []ForeignEnum { + if m != nil { + return m.RepeatedForeignEnum + } + return nil +} + +func (m *TestAllTypes) GetRepeatedStringPiece() []string { + if m != nil { + return m.RepeatedStringPiece + } + return nil +} + +func (m *TestAllTypes) GetRepeatedCord() []string { + if m != nil { + return m.RepeatedCord + } + return nil +} + +func (m *TestAllTypes) GetMapInt32Int32() map[int32]int32 { + if m != nil { + return m.MapInt32Int32 + } + return nil +} + +func (m *TestAllTypes) GetMapInt64Int64() map[int64]int64 { + if m != nil { + return m.MapInt64Int64 + } + return nil +} + +func (m *TestAllTypes) GetMapUint32Uint32() map[uint32]uint32 { + if m != nil { + return m.MapUint32Uint32 + } + return nil +} + +func (m *TestAllTypes) GetMapUint64Uint64() map[uint64]uint64 { + if m != nil { + return m.MapUint64Uint64 + } + return nil +} + +func (m *TestAllTypes) GetMapSint32Sint32() map[int32]int32 { + if m != nil { + return m.MapSint32Sint32 + } + return nil +} + +func (m *TestAllTypes) GetMapSint64Sint64() map[int64]int64 { + if m != nil { + return m.MapSint64Sint64 + } + return nil +} + +func (m *TestAllTypes) GetMapFixed32Fixed32() map[uint32]uint32 { + if m != nil { + return m.MapFixed32Fixed32 + } + return nil +} + +func (m *TestAllTypes) GetMapFixed64Fixed64() map[uint64]uint64 { + if m != nil { + return m.MapFixed64Fixed64 + } + return nil +} + +func (m *TestAllTypes) GetMapSfixed32Sfixed32() map[int32]int32 { + if m != nil { + return m.MapSfixed32Sfixed32 + } + return nil +} + +func (m *TestAllTypes) GetMapSfixed64Sfixed64() map[int64]int64 { + if m != nil { + return m.MapSfixed64Sfixed64 + } + return nil +} + +func (m *TestAllTypes) GetMapInt32Float() map[int32]float32 { + if m != nil { + return m.MapInt32Float + } + return nil +} + +func (m *TestAllTypes) GetMapInt32Double() map[int32]float64 { + if m != nil { + return m.MapInt32Double + } + return nil +} + +func (m *TestAllTypes) GetMapBoolBool() map[bool]bool { + if m != nil { + return m.MapBoolBool + } + return nil +} + +func (m *TestAllTypes) GetMapStringString() map[string]string { + if m != nil { + return m.MapStringString + } + return nil +} + +func (m *TestAllTypes) GetMapStringBytes() map[string][]byte { + if m != nil { + return m.MapStringBytes + } + return nil +} + +func (m *TestAllTypes) GetMapStringNestedMessage() map[string]*TestAllTypes_NestedMessage { + if m != nil { + return m.MapStringNestedMessage + } + return nil +} + +func (m *TestAllTypes) GetMapStringForeignMessage() map[string]*ForeignMessage { + if m != nil { + return m.MapStringForeignMessage + } + return nil +} + +func (m *TestAllTypes) GetMapStringNestedEnum() map[string]TestAllTypes_NestedEnum { + if m != nil { + return m.MapStringNestedEnum + } + return nil +} + +func (m *TestAllTypes) GetMapStringForeignEnum() map[string]ForeignEnum { + if m != nil { + return m.MapStringForeignEnum + } + return nil +} + +func (m *TestAllTypes) GetOneofUint32() uint32 { + if x, ok := m.GetOneofField().(*TestAllTypes_OneofUint32); ok { + return x.OneofUint32 + } + return 0 +} + +func (m *TestAllTypes) GetOneofNestedMessage() *TestAllTypes_NestedMessage { + if x, ok := m.GetOneofField().(*TestAllTypes_OneofNestedMessage); ok { + return x.OneofNestedMessage + } + return nil +} + +func (m *TestAllTypes) GetOneofString() string { + if x, ok := m.GetOneofField().(*TestAllTypes_OneofString); ok { + return x.OneofString + } + return "" +} + +func (m *TestAllTypes) GetOneofBytes() []byte { + if x, ok := m.GetOneofField().(*TestAllTypes_OneofBytes); ok { + return x.OneofBytes + } + return nil +} + +func (m *TestAllTypes) GetOneofBool() bool { + if x, ok := m.GetOneofField().(*TestAllTypes_OneofBool); ok { + return x.OneofBool + } + return false +} + +func (m *TestAllTypes) GetOneofUint64() uint64 { + if x, ok := m.GetOneofField().(*TestAllTypes_OneofUint64); ok { + return x.OneofUint64 + } + return 0 +} + +func (m *TestAllTypes) GetOneofFloat() float32 { + if x, ok := m.GetOneofField().(*TestAllTypes_OneofFloat); ok { + return x.OneofFloat + } + return 0 +} + +func (m *TestAllTypes) GetOneofDouble() float64 { + if x, ok := m.GetOneofField().(*TestAllTypes_OneofDouble); ok { + return x.OneofDouble + } + return 0 +} + +func (m *TestAllTypes) GetOneofEnum() TestAllTypes_NestedEnum { + if x, ok := m.GetOneofField().(*TestAllTypes_OneofEnum); ok { + return x.OneofEnum + } + return TestAllTypes_FOO +} + +func (m *TestAllTypes) GetOptionalBoolWrapper() *google_protobuf5.BoolValue { + if m != nil { + return m.OptionalBoolWrapper + } + return nil +} + +func (m *TestAllTypes) GetOptionalInt32Wrapper() *google_protobuf5.Int32Value { + if m != nil { + return m.OptionalInt32Wrapper + } + return nil +} + +func (m *TestAllTypes) GetOptionalInt64Wrapper() *google_protobuf5.Int64Value { + if m != nil { + return m.OptionalInt64Wrapper + } + return nil +} + +func (m *TestAllTypes) GetOptionalUint32Wrapper() *google_protobuf5.UInt32Value { + if m != nil { + return m.OptionalUint32Wrapper + } + return nil +} + +func (m *TestAllTypes) GetOptionalUint64Wrapper() *google_protobuf5.UInt64Value { + if m != nil { + return m.OptionalUint64Wrapper + } + return nil +} + +func (m *TestAllTypes) GetOptionalFloatWrapper() *google_protobuf5.FloatValue { + if m != nil { + return m.OptionalFloatWrapper + } + return nil +} + +func (m *TestAllTypes) GetOptionalDoubleWrapper() *google_protobuf5.DoubleValue { + if m != nil { + return m.OptionalDoubleWrapper + } + return nil +} + +func (m *TestAllTypes) GetOptionalStringWrapper() *google_protobuf5.StringValue { + if m != nil { + return m.OptionalStringWrapper + } + return nil +} + +func (m *TestAllTypes) GetOptionalBytesWrapper() *google_protobuf5.BytesValue { + if m != nil { + return m.OptionalBytesWrapper + } + return nil +} + +func (m *TestAllTypes) GetRepeatedBoolWrapper() []*google_protobuf5.BoolValue { + if m != nil { + return m.RepeatedBoolWrapper + } + return nil +} + +func (m *TestAllTypes) GetRepeatedInt32Wrapper() []*google_protobuf5.Int32Value { + if m != nil { + return m.RepeatedInt32Wrapper + } + return nil +} + +func (m *TestAllTypes) GetRepeatedInt64Wrapper() []*google_protobuf5.Int64Value { + if m != nil { + return m.RepeatedInt64Wrapper + } + return nil +} + +func (m *TestAllTypes) GetRepeatedUint32Wrapper() []*google_protobuf5.UInt32Value { + if m != nil { + return m.RepeatedUint32Wrapper + } + return nil +} + +func (m *TestAllTypes) GetRepeatedUint64Wrapper() []*google_protobuf5.UInt64Value { + if m != nil { + return m.RepeatedUint64Wrapper + } + return nil +} + +func (m *TestAllTypes) GetRepeatedFloatWrapper() []*google_protobuf5.FloatValue { + if m != nil { + return m.RepeatedFloatWrapper + } + return nil +} + +func (m *TestAllTypes) GetRepeatedDoubleWrapper() []*google_protobuf5.DoubleValue { + if m != nil { + return m.RepeatedDoubleWrapper + } + return nil +} + +func (m *TestAllTypes) GetRepeatedStringWrapper() []*google_protobuf5.StringValue { + if m != nil { + return m.RepeatedStringWrapper + } + return nil +} + +func (m *TestAllTypes) GetRepeatedBytesWrapper() []*google_protobuf5.BytesValue { + if m != nil { + return m.RepeatedBytesWrapper + } + return nil +} + +func (m *TestAllTypes) GetOptionalDuration() *google_protobuf1.Duration { + if m != nil { + return m.OptionalDuration + } + return nil +} + +func (m *TestAllTypes) GetOptionalTimestamp() *google_protobuf4.Timestamp { + if m != nil { + return m.OptionalTimestamp + } + return nil +} + +func (m *TestAllTypes) GetOptionalFieldMask() *google_protobuf2.FieldMask { + if m != nil { + return m.OptionalFieldMask + } + return nil +} + +func (m *TestAllTypes) GetOptionalStruct() *google_protobuf3.Struct { + if m != nil { + return m.OptionalStruct + } + return nil +} + +func (m *TestAllTypes) GetOptionalAny() *google_protobuf.Any { + if m != nil { + return m.OptionalAny + } + return nil +} + +func (m *TestAllTypes) GetOptionalValue() *google_protobuf3.Value { + if m != nil { + return m.OptionalValue + } + return nil +} + +func (m *TestAllTypes) GetRepeatedDuration() []*google_protobuf1.Duration { + if m != nil { + return m.RepeatedDuration + } + return nil +} + +func (m *TestAllTypes) GetRepeatedTimestamp() []*google_protobuf4.Timestamp { + if m != nil { + return m.RepeatedTimestamp + } + return nil +} + +func (m *TestAllTypes) GetRepeatedFieldmask() []*google_protobuf2.FieldMask { + if m != nil { + return m.RepeatedFieldmask + } + return nil +} + +func (m *TestAllTypes) GetRepeatedStruct() []*google_protobuf3.Struct { + if m != nil { + return m.RepeatedStruct + } + return nil +} + +func (m *TestAllTypes) GetRepeatedAny() []*google_protobuf.Any { + if m != nil { + return m.RepeatedAny + } + return nil +} + +func (m *TestAllTypes) GetRepeatedValue() []*google_protobuf3.Value { + if m != nil { + return m.RepeatedValue + } + return nil +} + +func (m *TestAllTypes) GetFieldname1() int32 { + if m != nil { + return m.Fieldname1 + } + return 0 +} + +func (m *TestAllTypes) GetFieldName2() int32 { + if m != nil { + return m.FieldName2 + } + return 0 +} + +func (m *TestAllTypes) GetXFieldName3() int32 { + if m != nil { + return m.XFieldName3 + } + return 0 +} + +func (m *TestAllTypes) GetField_Name4_() int32 { + if m != nil { + return m.Field_Name4_ + } + return 0 +} + +func (m *TestAllTypes) GetField0Name5() int32 { + if m != nil { + return m.Field0Name5 + } + return 0 +} + +func (m *TestAllTypes) GetField_0Name6() int32 { + if m != nil { + return m.Field_0Name6 + } + return 0 +} + +func (m *TestAllTypes) GetFieldName7() int32 { + if m != nil { + return m.FieldName7 + } + return 0 +} + +func (m *TestAllTypes) GetFieldName8() int32 { + if m != nil { + return m.FieldName8 + } + return 0 +} + +func (m *TestAllTypes) GetField_Name9() int32 { + if m != nil { + return m.Field_Name9 + } + return 0 +} + +func (m *TestAllTypes) GetField_Name10() int32 { + if m != nil { + return m.Field_Name10 + } + return 0 +} + +func (m *TestAllTypes) GetFIELD_NAME11() int32 { + if m != nil { + return m.FIELD_NAME11 + } + return 0 +} + +func (m *TestAllTypes) GetFIELDName12() int32 { + if m != nil { + return m.FIELDName12 + } + return 0 +} + +func (m *TestAllTypes) GetXFieldName13() int32 { + if m != nil { + return m.XFieldName13 + } + return 0 +} + +func (m *TestAllTypes) GetX_FieldName14() int32 { + if m != nil { + return m.X_FieldName14 + } + return 0 +} + +func (m *TestAllTypes) GetField_Name15() int32 { + if m != nil { + return m.Field_Name15 + } + return 0 +} + +func (m *TestAllTypes) GetField__Name16() int32 { + if m != nil { + return m.Field__Name16 + } + return 0 +} + +func (m *TestAllTypes) GetFieldName17__() int32 { + if m != nil { + return m.FieldName17__ + } + return 0 +} + +func (m *TestAllTypes) GetFieldName18__() int32 { + if m != nil { + return m.FieldName18__ + } + return 0 +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*TestAllTypes) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _TestAllTypes_OneofMarshaler, _TestAllTypes_OneofUnmarshaler, _TestAllTypes_OneofSizer, []interface{}{ + (*TestAllTypes_OneofUint32)(nil), + (*TestAllTypes_OneofNestedMessage)(nil), + (*TestAllTypes_OneofString)(nil), + (*TestAllTypes_OneofBytes)(nil), + (*TestAllTypes_OneofBool)(nil), + (*TestAllTypes_OneofUint64)(nil), + (*TestAllTypes_OneofFloat)(nil), + (*TestAllTypes_OneofDouble)(nil), + (*TestAllTypes_OneofEnum)(nil), + } +} + +func _TestAllTypes_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*TestAllTypes) + // oneof_field + switch x := m.OneofField.(type) { + case *TestAllTypes_OneofUint32: + _ = b.EncodeVarint(111<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.OneofUint32)) + case *TestAllTypes_OneofNestedMessage: + _ = b.EncodeVarint(112<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.OneofNestedMessage); err != nil { + return err + } + case *TestAllTypes_OneofString: + _ = b.EncodeVarint(113<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.OneofString) + case *TestAllTypes_OneofBytes: + _ = b.EncodeVarint(114<<3 | proto.WireBytes) + _ = b.EncodeRawBytes(x.OneofBytes) + case *TestAllTypes_OneofBool: + t := uint64(0) + if x.OneofBool { + t = 1 + } + _ = b.EncodeVarint(115<<3 | proto.WireVarint) + _ = b.EncodeVarint(t) + case *TestAllTypes_OneofUint64: + _ = b.EncodeVarint(116<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.OneofUint64)) + case *TestAllTypes_OneofFloat: + _ = b.EncodeVarint(117<<3 | proto.WireFixed32) + _ = b.EncodeFixed32(uint64(math.Float32bits(x.OneofFloat))) + case *TestAllTypes_OneofDouble: + _ = b.EncodeVarint(118<<3 | proto.WireFixed64) + _ = b.EncodeFixed64(math.Float64bits(x.OneofDouble)) + case *TestAllTypes_OneofEnum: + _ = b.EncodeVarint(119<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.OneofEnum)) + case nil: + default: + return fmt.Errorf("TestAllTypes.OneofField has unexpected type %T", x) + } + return nil +} + +func _TestAllTypes_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*TestAllTypes) + switch tag { + case 111: // oneof_field.oneof_uint32 + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.OneofField = &TestAllTypes_OneofUint32{uint32(x)} + return true, err + case 112: // oneof_field.oneof_nested_message + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(TestAllTypes_NestedMessage) + err := b.DecodeMessage(msg) + m.OneofField = &TestAllTypes_OneofNestedMessage{msg} + return true, err + case 113: // oneof_field.oneof_string + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.OneofField = &TestAllTypes_OneofString{x} + return true, err + case 114: // oneof_field.oneof_bytes + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeRawBytes(true) + m.OneofField = &TestAllTypes_OneofBytes{x} + return true, err + case 115: // oneof_field.oneof_bool + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.OneofField = &TestAllTypes_OneofBool{x != 0} + return true, err + case 116: // oneof_field.oneof_uint64 + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.OneofField = &TestAllTypes_OneofUint64{x} + return true, err + case 117: // oneof_field.oneof_float + if wire != proto.WireFixed32 { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeFixed32() + m.OneofField = &TestAllTypes_OneofFloat{math.Float32frombits(uint32(x))} + return true, err + case 118: // oneof_field.oneof_double + if wire != proto.WireFixed64 { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeFixed64() + m.OneofField = &TestAllTypes_OneofDouble{math.Float64frombits(x)} + return true, err + case 119: // oneof_field.oneof_enum + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.OneofField = &TestAllTypes_OneofEnum{TestAllTypes_NestedEnum(x)} + return true, err + default: + return false, nil + } +} + +func _TestAllTypes_OneofSizer(msg proto.Message) (n int) { + m := msg.(*TestAllTypes) + // oneof_field + switch x := m.OneofField.(type) { + case *TestAllTypes_OneofUint32: + n += proto.SizeVarint(111<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.OneofUint32)) + case *TestAllTypes_OneofNestedMessage: + s := proto.Size(x.OneofNestedMessage) + n += proto.SizeVarint(112<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(s)) + n += s + case *TestAllTypes_OneofString: + n += proto.SizeVarint(113<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.OneofString))) + n += len(x.OneofString) + case *TestAllTypes_OneofBytes: + n += proto.SizeVarint(114<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.OneofBytes))) + n += len(x.OneofBytes) + case *TestAllTypes_OneofBool: + n += proto.SizeVarint(115<<3 | proto.WireVarint) + n += 1 + case *TestAllTypes_OneofUint64: + n += proto.SizeVarint(116<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.OneofUint64)) + case *TestAllTypes_OneofFloat: + n += proto.SizeVarint(117<<3 | proto.WireFixed32) + n += 4 + case *TestAllTypes_OneofDouble: + n += proto.SizeVarint(118<<3 | proto.WireFixed64) + n += 8 + case *TestAllTypes_OneofEnum: + n += proto.SizeVarint(119<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.OneofEnum)) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type TestAllTypes_NestedMessage struct { + A int32 `protobuf:"varint,1,opt,name=a,proto3" json:"a,omitempty"` + Corecursive *TestAllTypes `protobuf:"bytes,2,opt,name=corecursive" json:"corecursive,omitempty"` +} + +func (m *TestAllTypes_NestedMessage) Reset() { *m = TestAllTypes_NestedMessage{} } +func (m *TestAllTypes_NestedMessage) String() string { return proto.CompactTextString(m) } +func (*TestAllTypes_NestedMessage) ProtoMessage() {} +func (*TestAllTypes_NestedMessage) Descriptor() ([]byte, []int) { + return fileDescriptorConformance, []int{2, 0} +} + +func (m *TestAllTypes_NestedMessage) GetA() int32 { + if m != nil { + return m.A + } + return 0 +} + +func (m *TestAllTypes_NestedMessage) GetCorecursive() *TestAllTypes { + if m != nil { + return m.Corecursive + } + return nil +} + +type ForeignMessage struct { + C int32 `protobuf:"varint,1,opt,name=c,proto3" json:"c,omitempty"` +} + +func (m *ForeignMessage) Reset() { *m = ForeignMessage{} } +func (m *ForeignMessage) String() string { return proto.CompactTextString(m) } +func (*ForeignMessage) ProtoMessage() {} +func (*ForeignMessage) Descriptor() ([]byte, []int) { return fileDescriptorConformance, []int{3} } + +func (m *ForeignMessage) GetC() int32 { + if m != nil { + return m.C + } + return 0 +} + +func init() { + proto.RegisterType((*ConformanceRequest)(nil), "conformance.ConformanceRequest") + proto.RegisterType((*ConformanceResponse)(nil), "conformance.ConformanceResponse") + proto.RegisterType((*TestAllTypes)(nil), "conformance.TestAllTypes") + proto.RegisterType((*TestAllTypes_NestedMessage)(nil), "conformance.TestAllTypes.NestedMessage") + proto.RegisterType((*ForeignMessage)(nil), "conformance.ForeignMessage") + proto.RegisterEnum("conformance.WireFormat", WireFormat_name, WireFormat_value) + proto.RegisterEnum("conformance.ForeignEnum", ForeignEnum_name, ForeignEnum_value) + proto.RegisterEnum("conformance.TestAllTypes_NestedEnum", TestAllTypes_NestedEnum_name, TestAllTypes_NestedEnum_value) +} + +func init() { proto.RegisterFile("conformance_proto/conformance.proto", fileDescriptorConformance) } + +var fileDescriptorConformance = []byte{ + // 2737 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x5a, 0xd9, 0x72, 0xdb, 0xc8, + 0xd5, 0x16, 0x08, 0x59, 0x4b, 0x93, 0x92, 0xa8, 0xd6, 0xd6, 0x96, 0x5d, 0x63, 0x58, 0xb2, 0x7f, + 0xd3, 0xf6, 0x8c, 0xac, 0x05, 0x86, 0x65, 0xcf, 0x3f, 0x8e, 0x45, 0x9b, 0xb4, 0xe4, 0x8c, 0x25, + 0x17, 0x64, 0x8d, 0xab, 0x9c, 0x0b, 0x06, 0xa6, 0x20, 0x15, 0xc7, 0x24, 0xc1, 0x01, 0x48, 0x4f, + 0x94, 0xcb, 0xbc, 0x41, 0xf6, 0x7d, 0xbd, 0xcf, 0x7a, 0x93, 0xa4, 0x92, 0xab, 0x54, 0x6e, 0xb2, + 0x27, 0x95, 0x3d, 0x79, 0x85, 0xbc, 0x43, 0x52, 0xbd, 0xa2, 0xbb, 0x01, 0x50, 0xf4, 0x54, 0x0d, + 0x25, 0x1e, 0x7c, 0xfd, 0x9d, 0xd3, 0xe7, 0x1c, 0x7c, 0x2d, 0x1c, 0x18, 0x2c, 0xd7, 0x83, 0xf6, + 0x51, 0x10, 0xb6, 0xbc, 0x76, 0xdd, 0xaf, 0x75, 0xc2, 0xa0, 0x1b, 0xdc, 0x90, 0x2c, 0x2b, 0xc4, + 0x02, 0xf3, 0x92, 0x69, 0xf1, 0xec, 0x71, 0x10, 0x1c, 0x37, 0xfd, 0x1b, 0xe4, 0xd2, 0x8b, 0xde, + 0xd1, 0x0d, 0xaf, 0x7d, 0x42, 0x71, 0x8b, 0x6f, 0xe8, 0x97, 0x0e, 0x7b, 0xa1, 0xd7, 0x6d, 0x04, + 0x6d, 0x76, 0xdd, 0xd2, 0xaf, 0x1f, 0x35, 0xfc, 0xe6, 0x61, 0xad, 0xe5, 0x45, 0x2f, 0x19, 0xe2, + 0xbc, 0x8e, 0x88, 0xba, 0x61, 0xaf, 0xde, 0x65, 0x57, 0x2f, 0xe8, 0x57, 0xbb, 0x8d, 0x96, 0x1f, + 0x75, 0xbd, 0x56, 0x27, 0x2b, 0x80, 0x0f, 0x43, 0xaf, 0xd3, 0xf1, 0xc3, 0x88, 0x5e, 0x5f, 0xfa, + 0x85, 0x01, 0xe0, 0xfd, 0x78, 0x2f, 0xae, 0xff, 0x41, 0xcf, 0x8f, 0xba, 0xf0, 0x3a, 0x28, 0xf2, + 0x15, 0xb5, 0x8e, 0x77, 0xd2, 0x0c, 0xbc, 0x43, 0x64, 0x58, 0x46, 0xa9, 0xb0, 0x3d, 0xe4, 0x4e, + 0xf1, 0x2b, 0x4f, 0xe8, 0x05, 0xb8, 0x0c, 0x0a, 0xef, 0x47, 0x41, 0x5b, 0x00, 0x73, 0x96, 0x51, + 0x1a, 0xdf, 0x1e, 0x72, 0xf3, 0xd8, 0xca, 0x41, 0x7b, 0x60, 0x21, 0xa4, 0xe4, 0xfe, 0x61, 0x2d, + 0xe8, 0x75, 0x3b, 0xbd, 0x6e, 0x8d, 0x78, 0xed, 0x22, 0xd3, 0x32, 0x4a, 0x93, 0xeb, 0x0b, 0x2b, + 0x72, 0x9a, 0x9f, 0x35, 0x42, 0xbf, 0x4a, 0x2e, 0xbb, 0x73, 0x62, 0xdd, 0x1e, 0x59, 0x46, 0xcd, + 0xe5, 0x71, 0x30, 0xca, 0x1c, 0x2e, 0x7d, 0x2a, 0x07, 0x66, 0x94, 0x4d, 0x44, 0x9d, 0xa0, 0x1d, + 0xf9, 0xf0, 0x22, 0xc8, 0x77, 0xbc, 0x30, 0xf2, 0x6b, 0x7e, 0x18, 0x06, 0x21, 0xd9, 0x00, 0x8e, + 0x0b, 0x10, 0x63, 0x05, 0xdb, 0xe0, 0x55, 0x30, 0x15, 0xf9, 0x61, 0xc3, 0x6b, 0x36, 0x3e, 0xc9, + 0x61, 0x23, 0x0c, 0x36, 0x29, 0x2e, 0x50, 0xe8, 0x65, 0x30, 0x11, 0xf6, 0xda, 0x38, 0xc1, 0x0c, + 0xc8, 0xf7, 0x59, 0x60, 0x66, 0x0a, 0x4b, 0x4b, 0x9d, 0x39, 0x68, 0xea, 0x86, 0xd3, 0x52, 0xb7, + 0x08, 0x46, 0xa3, 0x97, 0x8d, 0x4e, 0xc7, 0x3f, 0x44, 0x67, 0xd8, 0x75, 0x6e, 0x28, 0x8f, 0x81, + 0x91, 0xd0, 0x8f, 0x7a, 0xcd, 0xee, 0xd2, 0x7f, 0xaa, 0xa0, 0xf0, 0xd4, 0x8f, 0xba, 0x5b, 0xcd, + 0xe6, 0xd3, 0x93, 0x8e, 0x1f, 0xc1, 0xcb, 0x60, 0x32, 0xe8, 0xe0, 0x5e, 0xf3, 0x9a, 0xb5, 0x46, + 0xbb, 0xbb, 0xb1, 0x4e, 0x12, 0x70, 0xc6, 0x9d, 0xe0, 0xd6, 0x1d, 0x6c, 0xd4, 0x61, 0x8e, 0x4d, + 0xf6, 0x65, 0x2a, 0x30, 0xc7, 0x86, 0x57, 0xc0, 0x94, 0x80, 0xf5, 0x28, 0x1d, 0xde, 0xd5, 0x84, + 0x2b, 0x56, 0x1f, 0x10, 0x6b, 0x02, 0xe8, 0xd8, 0x64, 0x57, 0xc3, 0x2a, 0x50, 0x63, 0x8c, 0x28, + 0x23, 0xde, 0xde, 0x74, 0x0c, 0xdc, 0x4f, 0x32, 0x46, 0x94, 0x11, 0xd7, 0x08, 0xaa, 0x40, 0xc7, + 0x86, 0x57, 0x41, 0x51, 0x00, 0x8f, 0x1a, 0x9f, 0xf0, 0x0f, 0x37, 0xd6, 0xd1, 0xa8, 0x65, 0x94, + 0x46, 0x5d, 0x41, 0x50, 0xa5, 0xe6, 0x24, 0xd4, 0xb1, 0xd1, 0x98, 0x65, 0x94, 0x46, 0x34, 0xa8, + 0x63, 0xc3, 0xeb, 0x60, 0x3a, 0x76, 0xcf, 0x69, 0xc7, 0x2d, 0xa3, 0x34, 0xe5, 0x0a, 0x8e, 0x7d, + 0x66, 0x4f, 0x01, 0x3b, 0x36, 0x02, 0x96, 0x51, 0x2a, 0xea, 0x60, 0xc7, 0x56, 0x52, 0x7f, 0xd4, + 0x0c, 0xbc, 0x2e, 0xca, 0x5b, 0x46, 0x29, 0x17, 0xa7, 0xbe, 0x8a, 0x8d, 0xca, 0xfe, 0x0f, 0x83, + 0xde, 0x8b, 0xa6, 0x8f, 0x0a, 0x96, 0x51, 0x32, 0xe2, 0xfd, 0x3f, 0x20, 0x56, 0xb8, 0x0c, 0xc4, + 0xca, 0xda, 0x8b, 0x20, 0x68, 0xa2, 0x09, 0xcb, 0x28, 0x8d, 0xb9, 0x05, 0x6e, 0x2c, 0x07, 0x41, + 0x53, 0xcd, 0x66, 0x37, 0x6c, 0xb4, 0x8f, 0xd1, 0x24, 0xee, 0x2a, 0x29, 0x9b, 0xc4, 0xaa, 0x44, + 0xf7, 0xe2, 0xa4, 0xeb, 0x47, 0x68, 0x0a, 0xb7, 0x71, 0x1c, 0x5d, 0x19, 0x1b, 0x61, 0x0d, 0x2c, + 0x08, 0x58, 0x9b, 0xde, 0xde, 0x2d, 0x3f, 0x8a, 0xbc, 0x63, 0x1f, 0x41, 0xcb, 0x28, 0xe5, 0xd7, + 0xaf, 0x28, 0x37, 0xb6, 0xdc, 0xa2, 0x2b, 0xbb, 0x04, 0xff, 0x98, 0xc2, 0xdd, 0x39, 0xce, 0xa3, + 0x98, 0xe1, 0x01, 0x40, 0x71, 0x96, 0x82, 0xd0, 0x6f, 0x1c, 0xb7, 0x85, 0x87, 0x19, 0xe2, 0xe1, + 0x9c, 0xe2, 0xa1, 0x4a, 0x31, 0x9c, 0x75, 0x5e, 0x24, 0x53, 0xb1, 0xc3, 0xf7, 0xc0, 0xac, 0x1e, + 0xb7, 0xdf, 0xee, 0xb5, 0xd0, 0x1c, 0x51, 0xa3, 0x4b, 0xa7, 0x05, 0x5d, 0x69, 0xf7, 0x5a, 0x2e, + 0x54, 0x23, 0xc6, 0x36, 0xf8, 0x2e, 0x98, 0x4b, 0x84, 0x4b, 0x88, 0xe7, 0x09, 0x31, 0x4a, 0x8b, + 0x95, 0x90, 0xcd, 0x68, 0x81, 0x12, 0x36, 0x47, 0x62, 0xa3, 0xd5, 0xaa, 0x75, 0x1a, 0x7e, 0xdd, + 0x47, 0x08, 0xd7, 0xac, 0x9c, 0x1b, 0xcb, 0xc5, 0xeb, 0x68, 0xdd, 0x9e, 0xe0, 0xcb, 0xf0, 0x8a, + 0xd4, 0x0a, 0xf5, 0x20, 0x3c, 0x44, 0x67, 0x19, 0xde, 0x88, 0xdb, 0xe1, 0x7e, 0x10, 0x1e, 0xc2, + 0x2a, 0x98, 0x0e, 0xfd, 0x7a, 0x2f, 0x8c, 0x1a, 0xaf, 0x7c, 0x91, 0xd6, 0x73, 0x24, 0xad, 0x67, + 0x33, 0x73, 0xe0, 0x16, 0xc5, 0x1a, 0x9e, 0xce, 0xcb, 0x60, 0x32, 0xf4, 0x3b, 0xbe, 0x87, 0xf3, + 0x48, 0x6f, 0xe6, 0x0b, 0x96, 0x89, 0xd5, 0x86, 0x5b, 0x85, 0xda, 0xc8, 0x30, 0xc7, 0x46, 0x96, + 0x65, 0x62, 0xb5, 0x91, 0x60, 0x54, 0x1b, 0x04, 0x8c, 0xa9, 0xcd, 0x45, 0xcb, 0xc4, 0x6a, 0xc3, + 0xcd, 0xb1, 0xda, 0x28, 0x40, 0xc7, 0x46, 0x4b, 0x96, 0x89, 0xd5, 0x46, 0x06, 0x6a, 0x8c, 0x4c, + 0x6d, 0x96, 0x2d, 0x13, 0xab, 0x0d, 0x37, 0xef, 0x27, 0x19, 0x99, 0xda, 0x5c, 0xb2, 0x4c, 0xac, + 0x36, 0x32, 0x90, 0xaa, 0x8d, 0x00, 0x72, 0x59, 0xb8, 0x6c, 0x99, 0x58, 0x6d, 0xb8, 0x5d, 0x52, + 0x1b, 0x15, 0xea, 0xd8, 0xe8, 0xff, 0x2c, 0x13, 0xab, 0x8d, 0x02, 0xa5, 0x6a, 0x13, 0xbb, 0xe7, + 0xb4, 0x57, 0x2c, 0x13, 0xab, 0x8d, 0x08, 0x40, 0x52, 0x1b, 0x0d, 0xec, 0xd8, 0xa8, 0x64, 0x99, + 0x58, 0x6d, 0x54, 0x30, 0x55, 0x9b, 0x38, 0x08, 0xa2, 0x36, 0x57, 0x2d, 0x13, 0xab, 0x8d, 0x08, + 0x81, 0xab, 0x8d, 0x80, 0x31, 0xb5, 0xb9, 0x66, 0x99, 0x58, 0x6d, 0xb8, 0x39, 0x56, 0x1b, 0x01, + 0x24, 0x6a, 0x73, 0xdd, 0x32, 0xb1, 0xda, 0x70, 0x23, 0x57, 0x9b, 0x38, 0x42, 0xaa, 0x36, 0x6f, + 0x5a, 0x26, 0x56, 0x1b, 0x11, 0x9f, 0x50, 0x9b, 0x98, 0x8d, 0xa8, 0xcd, 0x5b, 0x96, 0x89, 0xd5, + 0x46, 0xd0, 0x71, 0xb5, 0x11, 0x30, 0x4d, 0x6d, 0x56, 0x2d, 0xf3, 0xb5, 0xd4, 0x86, 0xf3, 0x24, + 0xd4, 0x26, 0xce, 0x92, 0xa6, 0x36, 0x6b, 0xc4, 0x43, 0x7f, 0xb5, 0x11, 0xc9, 0x4c, 0xa8, 0x8d, + 0x1e, 0x37, 0x11, 0x85, 0x0d, 0xcb, 0x1c, 0x5c, 0x6d, 0xd4, 0x88, 0xb9, 0xda, 0x24, 0xc2, 0x25, + 0xc4, 0x36, 0x21, 0xee, 0xa3, 0x36, 0x5a, 0xa0, 0x5c, 0x6d, 0xb4, 0x6a, 0x31, 0xb5, 0x71, 0x70, + 0xcd, 0xa8, 0xda, 0xa8, 0x75, 0x13, 0x6a, 0x23, 0xd6, 0x11, 0xb5, 0xb9, 0xc5, 0xf0, 0x46, 0xdc, + 0x0e, 0x44, 0x6d, 0x9e, 0x82, 0xa9, 0x96, 0xd7, 0xa1, 0x02, 0xc1, 0x64, 0x62, 0x93, 0x24, 0xf5, + 0xcd, 0xec, 0x0c, 0x3c, 0xf6, 0x3a, 0x44, 0x3b, 0xc8, 0x47, 0xa5, 0xdd, 0x0d, 0x4f, 0xdc, 0x89, + 0x96, 0x6c, 0x93, 0x58, 0x1d, 0x9b, 0xa9, 0xca, 0xed, 0xc1, 0x58, 0x1d, 0x9b, 0x7c, 0x28, 0xac, + 0xcc, 0x06, 0x9f, 0x83, 0x69, 0xcc, 0x4a, 0xe5, 0x87, 0xab, 0xd0, 0x1d, 0xc2, 0xbb, 0xd2, 0x97, + 0x97, 0x4a, 0x13, 0xfd, 0xa4, 0xcc, 0x38, 0x3c, 0xd9, 0x2a, 0x73, 0x3b, 0x36, 0x17, 0xae, 0xb7, + 0x07, 0xe4, 0x76, 0x6c, 0xfa, 0xa9, 0x72, 0x73, 0x2b, 0xe7, 0xa6, 0x22, 0xc7, 0xb5, 0xee, 0xff, + 0x07, 0xe0, 0xa6, 0x02, 0xb8, 0xaf, 0xc5, 0x2d, 0x5b, 0x65, 0x6e, 0xc7, 0xe6, 0xf2, 0xf8, 0xce, + 0x80, 0xdc, 0x8e, 0xbd, 0xaf, 0xc5, 0x2d, 0x5b, 0xe1, 0xc7, 0xc1, 0x0c, 0xe6, 0x66, 0xda, 0x26, + 0x24, 0xf5, 0x2e, 0x61, 0x5f, 0xed, 0xcb, 0xce, 0x74, 0x96, 0xfd, 0xa0, 0xfc, 0x38, 0x50, 0xd5, + 0xae, 0x78, 0x70, 0x6c, 0xa1, 0xc4, 0x1f, 0x19, 0xd4, 0x83, 0x63, 0xb3, 0x1f, 0x9a, 0x07, 0x61, + 0x87, 0x47, 0x60, 0x8e, 0xe4, 0x87, 0x6f, 0x42, 0x28, 0xf8, 0x3d, 0xe2, 0x63, 0xbd, 0x7f, 0x8e, + 0x18, 0x98, 0xff, 0xa4, 0x5e, 0x70, 0xc8, 0xfa, 0x15, 0xd5, 0x0f, 0xae, 0x04, 0xdf, 0xcb, 0xd6, + 0xc0, 0x7e, 0x1c, 0x9b, 0xff, 0xd4, 0xfd, 0xc4, 0x57, 0xd4, 0xfb, 0x95, 0x1e, 0x1a, 0xe5, 0x41, + 0xef, 0x57, 0x72, 0x9c, 0x68, 0xf7, 0x2b, 0x3d, 0x62, 0x9e, 0x81, 0x62, 0xcc, 0xca, 0xce, 0x98, + 0xfb, 0x84, 0xf6, 0xad, 0xd3, 0x69, 0xe9, 0xe9, 0x43, 0x79, 0x27, 0x5b, 0x8a, 0x11, 0xee, 0x02, + 0xec, 0x89, 0x9c, 0x46, 0xf4, 0x48, 0x7a, 0x40, 0x58, 0xaf, 0xf5, 0x65, 0xc5, 0xe7, 0x14, 0xfe, + 0x9f, 0x52, 0xe6, 0x5b, 0xb1, 0x45, 0xb4, 0x3b, 0x95, 0x42, 0x76, 0x7e, 0x55, 0x06, 0x69, 0x77, + 0x02, 0xa5, 0x9f, 0x52, 0xbb, 0x4b, 0x56, 0x9e, 0x04, 0xc6, 0x4d, 0x8f, 0xbc, 0xea, 0x00, 0x49, + 0xa0, 0xcb, 0xc9, 0x69, 0x18, 0x27, 0x41, 0x32, 0xc2, 0x0e, 0x38, 0x2b, 0x11, 0x6b, 0x87, 0xe4, + 0x43, 0xe2, 0xe1, 0xe6, 0x00, 0x1e, 0x94, 0x63, 0x91, 0x7a, 0x9a, 0x6f, 0xa5, 0x5e, 0x84, 0x11, + 0x58, 0x94, 0x3c, 0xea, 0xa7, 0xe6, 0x36, 0x71, 0xe9, 0x0c, 0xe0, 0x52, 0x3d, 0x33, 0xa9, 0xcf, + 0x85, 0x56, 0xfa, 0x55, 0x78, 0x0c, 0xe6, 0x93, 0xdb, 0x24, 0x47, 0xdf, 0xce, 0x20, 0xf7, 0x80, + 0xb4, 0x0d, 0x7c, 0xf4, 0x49, 0xf7, 0x80, 0x76, 0x05, 0xbe, 0x0f, 0x16, 0x52, 0x76, 0x47, 0x3c, + 0x3d, 0x22, 0x9e, 0x36, 0x06, 0xdf, 0x5a, 0xec, 0x6a, 0xb6, 0x95, 0x72, 0x09, 0x2e, 0x83, 0x42, + 0xd0, 0xf6, 0x83, 0x23, 0x7e, 0xdc, 0x04, 0xf8, 0x11, 0x7b, 0x7b, 0xc8, 0xcd, 0x13, 0x2b, 0x3b, + 0x3c, 0x3e, 0x06, 0x66, 0x29, 0x48, 0xab, 0x6d, 0xe7, 0xb5, 0x1e, 0xb7, 0xb6, 0x87, 0x5c, 0x48, + 0x68, 0xd4, 0x5a, 0x8a, 0x08, 0x58, 0xb7, 0x7f, 0xc0, 0x27, 0x12, 0xc4, 0xca, 0x7a, 0xf7, 0x22, + 0xa0, 0x5f, 0x59, 0xdb, 0x86, 0x6c, 0xbc, 0x01, 0x88, 0x91, 0x76, 0xe1, 0x05, 0x00, 0x18, 0x04, + 0xdf, 0x87, 0x11, 0x7e, 0x10, 0xdd, 0x1e, 0x72, 0xc7, 0x29, 0x02, 0xdf, 0x5b, 0xca, 0x56, 0x1d, + 0x1b, 0x75, 0x2d, 0xa3, 0x34, 0xac, 0x6c, 0xd5, 0xb1, 0x63, 0x47, 0x54, 0x7b, 0x7a, 0xf8, 0xf1, + 0x58, 0x38, 0xa2, 0x62, 0x22, 0x78, 0x98, 0x90, 0xbc, 0xc2, 0x8f, 0xc6, 0x82, 0x87, 0x09, 0x43, + 0x85, 0x47, 0x43, 0xca, 0xf6, 0xe1, 0xe0, 0x8f, 0x78, 0x22, 0x66, 0x52, 0x9e, 0x3d, 0xe9, 0x69, + 0x8c, 0x88, 0x0c, 0x9b, 0xa6, 0xa1, 0x5f, 0x19, 0x24, 0xf7, 0x8b, 0x2b, 0x74, 0xdc, 0xb6, 0xc2, + 0xe7, 0x3c, 0x2b, 0x78, 0xab, 0xef, 0x79, 0xcd, 0x9e, 0x1f, 0x3f, 0xa6, 0x61, 0xd3, 0x33, 0xba, + 0x0e, 0xba, 0x60, 0x5e, 0x9d, 0xd1, 0x08, 0xc6, 0x5f, 0x1b, 0xec, 0xd1, 0x56, 0x67, 0x24, 0x7a, + 0x47, 0x29, 0x67, 0x95, 0x49, 0x4e, 0x06, 0xa7, 0x63, 0x0b, 0xce, 0xdf, 0xf4, 0xe1, 0x74, 0xec, + 0x24, 0xa7, 0x63, 0x73, 0xce, 0x03, 0xe9, 0x21, 0xbf, 0xa7, 0x06, 0xfa, 0x5b, 0x4a, 0x7a, 0x3e, + 0x41, 0x7a, 0x20, 0x45, 0x3a, 0xa7, 0x0e, 0x89, 0xb2, 0x68, 0xa5, 0x58, 0x7f, 0xd7, 0x8f, 0x96, + 0x07, 0x3b, 0xa7, 0x8e, 0x94, 0xd2, 0x32, 0x40, 0x1a, 0x47, 0xb0, 0xfe, 0x3e, 0x2b, 0x03, 0xa4, + 0x97, 0xb4, 0x0c, 0x10, 0x5b, 0x5a, 0xa8, 0xb4, 0xd3, 0x04, 0xe9, 0x1f, 0xb2, 0x42, 0xa5, 0xcd, + 0xa7, 0x85, 0x4a, 0x8d, 0x69, 0xb4, 0x4c, 0x61, 0x38, 0xed, 0x1f, 0xb3, 0x68, 0xe9, 0x4d, 0xa8, + 0xd1, 0x52, 0x63, 0x5a, 0x06, 0xc8, 0x3d, 0x2a, 0x58, 0xff, 0x94, 0x95, 0x01, 0x72, 0xdb, 0x6a, + 0x19, 0x20, 0x36, 0xce, 0xb9, 0x27, 0x3d, 0x1c, 0x28, 0xcd, 0xff, 0x67, 0x83, 0xc8, 0x60, 0xdf, + 0xe6, 0x97, 0x1f, 0x0a, 0xa5, 0x20, 0xd5, 0x91, 0x81, 0x60, 0xfc, 0x8b, 0xc1, 0x9e, 0xb4, 0xfa, + 0x35, 0xbf, 0x32, 0x58, 0xc8, 0xe0, 0x94, 0x1a, 0xea, 0xaf, 0x7d, 0x38, 0x45, 0xf3, 0x2b, 0x53, + 0x08, 0xa9, 0x46, 0xda, 0x30, 0x42, 0x90, 0xfe, 0x8d, 0x92, 0x9e, 0xd2, 0xfc, 0xea, 0xcc, 0x22, + 0x8b, 0x56, 0x8a, 0xf5, 0xef, 0xfd, 0x68, 0x45, 0xf3, 0xab, 0x13, 0x8e, 0xb4, 0x0c, 0xa8, 0xcd, + 0xff, 0x8f, 0xac, 0x0c, 0xc8, 0xcd, 0xaf, 0x0c, 0x03, 0xd2, 0x42, 0xd5, 0x9a, 0xff, 0x9f, 0x59, + 0xa1, 0x2a, 0xcd, 0xaf, 0x8e, 0x0e, 0xd2, 0x68, 0xb5, 0xe6, 0xff, 0x57, 0x16, 0xad, 0xd2, 0xfc, + 0xea, 0xb3, 0x68, 0x5a, 0x06, 0xd4, 0xe6, 0xff, 0x77, 0x56, 0x06, 0xe4, 0xe6, 0x57, 0x06, 0x0e, + 0x9c, 0xf3, 0xa1, 0x34, 0xd7, 0xe5, 0xef, 0x70, 0xd0, 0x77, 0x73, 0x6c, 0x4e, 0x96, 0xd8, 0x3b, + 0x43, 0xc4, 0x33, 0x5f, 0x6e, 0x81, 0x8f, 0x80, 0x18, 0x1a, 0xd6, 0xc4, 0xcb, 0x1a, 0xf4, 0xbd, + 0x5c, 0xc6, 0xf9, 0xf1, 0x94, 0x43, 0x5c, 0xe1, 0x5f, 0x98, 0xe0, 0x47, 0xc1, 0x8c, 0x34, 0xc4, + 0xe6, 0x2f, 0x8e, 0xd0, 0xf7, 0xb3, 0xc8, 0xaa, 0x18, 0xf3, 0xd8, 0x8b, 0x5e, 0xc6, 0x64, 0xc2, + 0x04, 0xb7, 0xd4, 0xb9, 0x70, 0xaf, 0xde, 0x45, 0x3f, 0xa0, 0x44, 0x0b, 0x69, 0x45, 0xe8, 0xd5, + 0xbb, 0xca, 0xc4, 0xb8, 0x57, 0xef, 0xc2, 0x4d, 0x20, 0x66, 0x8b, 0x35, 0xaf, 0x7d, 0x82, 0x7e, + 0x48, 0xd7, 0xcf, 0x26, 0xd6, 0x6f, 0xb5, 0x4f, 0xdc, 0x3c, 0x87, 0x6e, 0xb5, 0x4f, 0xe0, 0x5d, + 0x69, 0xd6, 0xfc, 0x0a, 0x97, 0x01, 0xfd, 0x88, 0xae, 0x9d, 0x4f, 0xac, 0xa5, 0x55, 0x12, 0xd3, + 0x4d, 0xf2, 0x15, 0x97, 0x27, 0x6e, 0x50, 0x5e, 0x9e, 0x1f, 0xe7, 0x48, 0xb5, 0xfb, 0x95, 0x47, + 0xf4, 0xa5, 0x54, 0x1e, 0x41, 0x14, 0x97, 0xe7, 0x27, 0xb9, 0x0c, 0x85, 0x93, 0xca, 0xc3, 0x97, + 0xc5, 0xe5, 0x91, 0xb9, 0x48, 0x79, 0x48, 0x75, 0x7e, 0x9a, 0xc5, 0x25, 0x55, 0x27, 0x1e, 0x0a, + 0xb2, 0x55, 0xb8, 0x3a, 0xf2, 0xad, 0x82, 0xab, 0xf3, 0x4b, 0x4a, 0x94, 0x5d, 0x1d, 0xe9, 0xee, + 0x60, 0xd5, 0x11, 0x14, 0xb8, 0x3a, 0x3f, 0xa3, 0xeb, 0x33, 0xaa, 0xc3, 0xa1, 0xac, 0x3a, 0x62, + 0x25, 0xad, 0xce, 0xcf, 0xe9, 0xda, 0xcc, 0xea, 0x70, 0x38, 0xad, 0xce, 0x05, 0x00, 0xc8, 0xfe, + 0xdb, 0x5e, 0xcb, 0x5f, 0x43, 0x9f, 0x36, 0xc9, 0x6b, 0x28, 0xc9, 0x04, 0x2d, 0x90, 0xa7, 0xfd, + 0x8b, 0xbf, 0xae, 0xa3, 0xcf, 0xc8, 0x88, 0x5d, 0x6c, 0x82, 0x17, 0x41, 0xa1, 0x16, 0x43, 0x36, + 0xd0, 0x67, 0x19, 0xa4, 0xca, 0x21, 0x1b, 0x70, 0x09, 0x4c, 0x50, 0x04, 0x81, 0xd8, 0x35, 0xf4, + 0x39, 0x9d, 0x86, 0xfc, 0x3d, 0x49, 0xbe, 0xad, 0x62, 0xc8, 0x4d, 0xf4, 0x79, 0x8a, 0x90, 0x6d, + 0x70, 0x99, 0xd3, 0xac, 0x12, 0x1e, 0x07, 0x7d, 0x41, 0x01, 0x61, 0x1e, 0x47, 0xec, 0x08, 0x7f, + 0xbb, 0x85, 0xbe, 0xa8, 0x3b, 0xba, 0x85, 0x01, 0x22, 0xb4, 0x4d, 0xf4, 0x25, 0x3d, 0xda, 0xcd, + 0x78, 0xcb, 0xf8, 0xeb, 0x6d, 0xf4, 0x65, 0x9d, 0xe2, 0x36, 0x5c, 0x02, 0x85, 0xaa, 0x40, 0xac, + 0xad, 0xa2, 0xaf, 0xb0, 0x38, 0x04, 0xc9, 0xda, 0x2a, 0xc1, 0xec, 0x54, 0xde, 0x7d, 0x50, 0xdb, + 0xdd, 0x7a, 0x5c, 0x59, 0x5b, 0x43, 0x5f, 0xe5, 0x18, 0x6c, 0xa4, 0xb6, 0x18, 0x43, 0x72, 0xbd, + 0x8e, 0xbe, 0xa6, 0x60, 0x88, 0x0d, 0x5e, 0x02, 0x93, 0x35, 0x29, 0xbf, 0x6b, 0x1b, 0xe8, 0xeb, + 0x09, 0x6f, 0x1b, 0x14, 0x55, 0x8d, 0x51, 0x36, 0xfa, 0x46, 0x02, 0x65, 0xc7, 0x09, 0xa4, 0xa0, + 0x9b, 0xe8, 0x9b, 0x72, 0x02, 0x09, 0x48, 0xca, 0x32, 0xdd, 0x9d, 0x83, 0xbe, 0x95, 0x00, 0x39, + 0xd8, 0x9f, 0x14, 0xd3, 0xad, 0x5a, 0x0d, 0x7d, 0x3b, 0x81, 0xba, 0x85, 0x51, 0x52, 0x4c, 0x9b, + 0xb5, 0x1a, 0xfa, 0x4e, 0x22, 0xaa, 0xcd, 0xc5, 0xe7, 0x60, 0x42, 0x7d, 0xd0, 0x29, 0x00, 0xc3, + 0x63, 0x6f, 0x44, 0x0d, 0x0f, 0xbe, 0x0d, 0xf2, 0xf5, 0x40, 0xbc, 0xd4, 0x40, 0xb9, 0xd3, 0x5e, + 0x80, 0xc8, 0xe8, 0xc5, 0x7b, 0x00, 0x26, 0x87, 0x94, 0xb0, 0x08, 0xcc, 0x97, 0xfe, 0x09, 0x73, + 0x81, 0x7f, 0x85, 0xb3, 0xe0, 0x0c, 0xbd, 0x7d, 0x72, 0xc4, 0x46, 0xbf, 0xdc, 0xc9, 0x6d, 0x1a, + 0x31, 0x83, 0x3c, 0x90, 0x94, 0x19, 0xcc, 0x14, 0x06, 0x53, 0x66, 0x28, 0x83, 0xd9, 0xb4, 0xd1, + 0xa3, 0xcc, 0x31, 0x91, 0xc2, 0x31, 0x91, 0xce, 0xa1, 0x8c, 0x18, 0x65, 0x8e, 0xe1, 0x14, 0x8e, + 0xe1, 0x24, 0x47, 0x62, 0x94, 0x28, 0x73, 0x4c, 0xa7, 0x70, 0x4c, 0xa7, 0x73, 0x28, 0x23, 0x43, + 0x99, 0x03, 0xa6, 0x70, 0x40, 0x99, 0xe3, 0x01, 0x98, 0x4f, 0x1f, 0x0c, 0xca, 0x2c, 0xa3, 0x29, + 0x2c, 0xa3, 0x19, 0x2c, 0xea, 0xf0, 0x4f, 0x66, 0x19, 0x49, 0x61, 0x19, 0x91, 0x59, 0xaa, 0x00, + 0x65, 0x8d, 0xf7, 0x64, 0x9e, 0xa9, 0x14, 0x9e, 0xa9, 0x2c, 0x1e, 0x6d, 0x7c, 0x27, 0xf3, 0x14, + 0x53, 0x78, 0x8a, 0xa9, 0xdd, 0x26, 0x0f, 0xe9, 0x4e, 0xeb, 0xd7, 0x9c, 0xcc, 0xb0, 0x05, 0x66, + 0x52, 0xe6, 0x71, 0xa7, 0x51, 0x18, 0x32, 0xc5, 0x5d, 0x50, 0xd4, 0x87, 0x6f, 0xf2, 0xfa, 0xb1, + 0x94, 0xf5, 0x63, 0x29, 0x4d, 0xa2, 0x0f, 0xda, 0x64, 0x8e, 0xf1, 0x14, 0x8e, 0xf1, 0xe4, 0x36, + 0xf4, 0x89, 0xda, 0x69, 0x14, 0x05, 0x99, 0x22, 0x04, 0xe7, 0xfa, 0x8c, 0xcc, 0x52, 0xa8, 0xde, + 0x91, 0xa9, 0x5e, 0xe3, 0x7d, 0x95, 0xe4, 0xf3, 0x18, 0x9c, 0xef, 0x37, 0x33, 0x4b, 0x71, 0xba, + 0xa6, 0x3a, 0xed, 0xfb, 0x0a, 0x4b, 0x72, 0xd4, 0xa4, 0x0d, 0x97, 0x36, 0x2b, 0x4b, 0x71, 0x72, + 0x47, 0x76, 0x32, 0xe8, 0x4b, 0x2d, 0xc9, 0x9b, 0x07, 0xce, 0x66, 0xce, 0xcb, 0x52, 0xdc, 0xad, + 0xa8, 0xee, 0xb2, 0x5f, 0x75, 0xc5, 0x2e, 0x96, 0x6e, 0x03, 0x20, 0x4d, 0xf6, 0x46, 0x81, 0x59, + 0xdd, 0xdb, 0x2b, 0x0e, 0xe1, 0x5f, 0xca, 0x5b, 0x6e, 0xd1, 0xa0, 0xbf, 0x3c, 0x2f, 0xe6, 0xb0, + 0xbb, 0xdd, 0xca, 0xc3, 0xe2, 0x7f, 0xf9, 0x7f, 0x46, 0x79, 0x42, 0x8c, 0xa2, 0xf0, 0xa9, 0xb2, + 0xf4, 0x06, 0x98, 0xd4, 0x06, 0x92, 0x05, 0x60, 0xd4, 0xf9, 0x81, 0x52, 0xbf, 0x76, 0x13, 0x80, + 0xf8, 0xdf, 0x30, 0xc1, 0x29, 0x90, 0x3f, 0xd8, 0xdd, 0x7f, 0x52, 0xb9, 0xbf, 0x53, 0xdd, 0xa9, + 0x3c, 0x28, 0x0e, 0xc1, 0x02, 0x18, 0x7b, 0xe2, 0xee, 0x3d, 0xdd, 0x2b, 0x1f, 0x54, 0x8b, 0x06, + 0x1c, 0x03, 0xc3, 0x8f, 0xf6, 0xf7, 0x76, 0x8b, 0xb9, 0x6b, 0xf7, 0x40, 0x5e, 0x9e, 0x07, 0x4e, + 0x81, 0x7c, 0x75, 0xcf, 0xad, 0xec, 0x3c, 0xdc, 0xad, 0xd1, 0x48, 0x25, 0x03, 0x8d, 0x58, 0x31, + 0x3c, 0x2f, 0xe6, 0xca, 0x17, 0xc1, 0x85, 0x7a, 0xd0, 0x4a, 0xfc, 0x61, 0x26, 0x25, 0xe7, 0xc5, + 0x08, 0xb1, 0x6e, 0xfc, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x33, 0xc2, 0x0c, 0xb6, 0xeb, 0x26, 0x00, + 0x00, +} diff --git a/vendor/github.com/gogo/protobuf/_conformance/conformance_proto/conformance.proto b/vendor/github.com/gogo/protobuf/_conformance/conformance_proto/conformance.proto new file mode 100644 index 000000000..95a8fd135 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/_conformance/conformance_proto/conformance.proto @@ -0,0 +1,285 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package conformance; +option java_package = "com.google.protobuf.conformance"; + +import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/field_mask.proto"; +import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +// This defines the conformance testing protocol. This protocol exists between +// the conformance test suite itself and the code being tested. For each test, +// the suite will send a ConformanceRequest message and expect a +// ConformanceResponse message. +// +// You can either run the tests in two different ways: +// +// 1. in-process (using the interface in conformance_test.h). +// +// 2. as a sub-process communicating over a pipe. Information about how to +// do this is in conformance_test_runner.cc. +// +// Pros/cons of the two approaches: +// +// - running as a sub-process is much simpler for languages other than C/C++. +// +// - running as a sub-process may be more tricky in unusual environments like +// iOS apps, where fork/stdin/stdout are not available. + +enum WireFormat { + UNSPECIFIED = 0; + PROTOBUF = 1; + JSON = 2; +} + +// Represents a single test case's input. The testee should: +// +// 1. parse this proto (which should always succeed) +// 2. parse the protobuf or JSON payload in "payload" (which may fail) +// 3. if the parse succeeded, serialize the message in the requested format. +message ConformanceRequest { + // The payload (whether protobuf of JSON) is always for a TestAllTypes proto + // (see below). + oneof payload { + bytes protobuf_payload = 1; + string json_payload = 2; + } + + // Which format should the testee serialize its message to? + WireFormat requested_output_format = 3; +} + +// Represents a single test case's output. +message ConformanceResponse { + oneof result { + // This string should be set to indicate parsing failed. The string can + // provide more information about the parse error if it is available. + // + // Setting this string does not necessarily mean the testee failed the + // test. Some of the test cases are intentionally invalid input. + string parse_error = 1; + + // If the input was successfully parsed but errors occurred when + // serializing it to the requested output format, set the error message in + // this field. + string serialize_error = 6; + + // This should be set if some other error occurred. This will always + // indicate that the test failed. The string can provide more information + // about the failure. + string runtime_error = 2; + + // If the input was successfully parsed and the requested output was + // protobuf, serialize it to protobuf and set it in this field. + bytes protobuf_payload = 3; + + // If the input was successfully parsed and the requested output was JSON, + // serialize to JSON and set it in this field. + string json_payload = 4; + + // For when the testee skipped the test, likely because a certain feature + // wasn't supported, like JSON input/output. + string skipped = 5; + } +} + +// This proto includes every type of field in both singular and repeated +// forms. +message TestAllTypes { + message NestedMessage { + int32 a = 1; + TestAllTypes corecursive = 2; + } + + enum NestedEnum { + FOO = 0; + BAR = 1; + BAZ = 2; + NEG = -1; // Intentionally negative. + } + + // Singular + int32 optional_int32 = 1; + int64 optional_int64 = 2; + uint32 optional_uint32 = 3; + uint64 optional_uint64 = 4; + sint32 optional_sint32 = 5; + sint64 optional_sint64 = 6; + fixed32 optional_fixed32 = 7; + fixed64 optional_fixed64 = 8; + sfixed32 optional_sfixed32 = 9; + sfixed64 optional_sfixed64 = 10; + float optional_float = 11; + double optional_double = 12; + bool optional_bool = 13; + string optional_string = 14; + bytes optional_bytes = 15; + + NestedMessage optional_nested_message = 18; + ForeignMessage optional_foreign_message = 19; + + NestedEnum optional_nested_enum = 21; + ForeignEnum optional_foreign_enum = 22; + + string optional_string_piece = 24 [ctype=STRING_PIECE]; + string optional_cord = 25 [ctype=CORD]; + + TestAllTypes recursive_message = 27; + + // Repeated + repeated int32 repeated_int32 = 31; + repeated int64 repeated_int64 = 32; + repeated uint32 repeated_uint32 = 33; + repeated uint64 repeated_uint64 = 34; + repeated sint32 repeated_sint32 = 35; + repeated sint64 repeated_sint64 = 36; + repeated fixed32 repeated_fixed32 = 37; + repeated fixed64 repeated_fixed64 = 38; + repeated sfixed32 repeated_sfixed32 = 39; + repeated sfixed64 repeated_sfixed64 = 40; + repeated float repeated_float = 41; + repeated double repeated_double = 42; + repeated bool repeated_bool = 43; + repeated string repeated_string = 44; + repeated bytes repeated_bytes = 45; + + repeated NestedMessage repeated_nested_message = 48; + repeated ForeignMessage repeated_foreign_message = 49; + + repeated NestedEnum repeated_nested_enum = 51; + repeated ForeignEnum repeated_foreign_enum = 52; + + repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; + repeated string repeated_cord = 55 [ctype=CORD]; + + // Map + map < int32, int32> map_int32_int32 = 56; + map < int64, int64> map_int64_int64 = 57; + map < uint32, uint32> map_uint32_uint32 = 58; + map < uint64, uint64> map_uint64_uint64 = 59; + map < sint32, sint32> map_sint32_sint32 = 60; + map < sint64, sint64> map_sint64_sint64 = 61; + map < fixed32, fixed32> map_fixed32_fixed32 = 62; + map < fixed64, fixed64> map_fixed64_fixed64 = 63; + map map_sfixed32_sfixed32 = 64; + map map_sfixed64_sfixed64 = 65; + map < int32, float> map_int32_float = 66; + map < int32, double> map_int32_double = 67; + map < bool, bool> map_bool_bool = 68; + map < string, string> map_string_string = 69; + map < string, bytes> map_string_bytes = 70; + map < string, NestedMessage> map_string_nested_message = 71; + map < string, ForeignMessage> map_string_foreign_message = 72; + map < string, NestedEnum> map_string_nested_enum = 73; + map < string, ForeignEnum> map_string_foreign_enum = 74; + + oneof oneof_field { + uint32 oneof_uint32 = 111; + NestedMessage oneof_nested_message = 112; + string oneof_string = 113; + bytes oneof_bytes = 114; + bool oneof_bool = 115; + uint64 oneof_uint64 = 116; + float oneof_float = 117; + double oneof_double = 118; + NestedEnum oneof_enum = 119; + } + + // Well-known types + google.protobuf.BoolValue optional_bool_wrapper = 201; + google.protobuf.Int32Value optional_int32_wrapper = 202; + google.protobuf.Int64Value optional_int64_wrapper = 203; + google.protobuf.UInt32Value optional_uint32_wrapper = 204; + google.protobuf.UInt64Value optional_uint64_wrapper = 205; + google.protobuf.FloatValue optional_float_wrapper = 206; + google.protobuf.DoubleValue optional_double_wrapper = 207; + google.protobuf.StringValue optional_string_wrapper = 208; + google.protobuf.BytesValue optional_bytes_wrapper = 209; + + repeated google.protobuf.BoolValue repeated_bool_wrapper = 211; + repeated google.protobuf.Int32Value repeated_int32_wrapper = 212; + repeated google.protobuf.Int64Value repeated_int64_wrapper = 213; + repeated google.protobuf.UInt32Value repeated_uint32_wrapper = 214; + repeated google.protobuf.UInt64Value repeated_uint64_wrapper = 215; + repeated google.protobuf.FloatValue repeated_float_wrapper = 216; + repeated google.protobuf.DoubleValue repeated_double_wrapper = 217; + repeated google.protobuf.StringValue repeated_string_wrapper = 218; + repeated google.protobuf.BytesValue repeated_bytes_wrapper = 219; + + google.protobuf.Duration optional_duration = 301; + google.protobuf.Timestamp optional_timestamp = 302; + google.protobuf.FieldMask optional_field_mask = 303; + google.protobuf.Struct optional_struct = 304; + google.protobuf.Any optional_any = 305; + google.protobuf.Value optional_value = 306; + + repeated google.protobuf.Duration repeated_duration = 311; + repeated google.protobuf.Timestamp repeated_timestamp = 312; + repeated google.protobuf.FieldMask repeated_fieldmask = 313; + repeated google.protobuf.Struct repeated_struct = 324; + repeated google.protobuf.Any repeated_any = 315; + repeated google.protobuf.Value repeated_value = 316; + + // Test field-name-to-JSON-name convention. + // (protobuf says names can be any valid C/C++ identifier.) + int32 fieldname1 = 401; + int32 field_name2 = 402; + int32 _field_name3 = 403; + int32 field__name4_ = 404; + int32 field0name5 = 405; + int32 field_0_name6 = 406; + int32 fieldName7 = 407; + int32 FieldName8 = 408; + int32 field_Name9 = 409; + int32 Field_Name10 = 410; + int32 FIELD_NAME11 = 411; + int32 FIELD_name12 = 412; + int32 __field_name13 = 413; + int32 __Field_name14 = 414; + int32 field__name15 = 415; + int32 field__Name16 = 416; + int32 field_name17__ = 417; + int32 Field_name18__ = 418; +} + +message ForeignMessage { + int32 c = 1; +} + +enum ForeignEnum { + FOREIGN_FOO = 0; + FOREIGN_BAR = 1; + FOREIGN_BAZ = 2; +} diff --git a/vendor/github.com/gogo/protobuf/bench.md b/vendor/github.com/gogo/protobuf/bench.md new file mode 100644 index 000000000..16da66ad2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/bench.md @@ -0,0 +1,190 @@ +# Benchmarks + +## How to reproduce + +For a comparison run: + + make bench + +followed by [benchcmp](http://code.google.com/p/go/source/browse/misc/benchcmp benchcmp) on the resulting files: + + $GOROOT/misc/benchcmp $GOPATH/src/github.com/gogo/protobuf/test/mixbench/marshal.txt $GOPATH/src/github.com/gogo/protobuf/test/mixbench/marshaler.txt + $GOROOT/misc/benchcmp $GOPATH/src/github.com/gogo/protobuf/test/mixbench/unmarshal.txt $GOPATH/src/github.com/gogo/protobuf/test/mixbench/unmarshaler.txt + +Benchmarks ran on Revision: 11c56be39364 + +June 2013 + +Processor 2,66 GHz Intel Core i7 + +Memory 8 GB 1067 MHz DDR3 + +## Marshaler + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
benchmarkold ns/opnew ns/opdelta
BenchmarkNidOptNativeProtoMarshal2656889-66.53%
BenchmarkNinOptNativeProtoMarshal26511015-61.71%
BenchmarkNidRepNativeProtoMarshal4266112519-70.65%
BenchmarkNinRepNativeProtoMarshal4230612354-70.80%
BenchmarkNidRepPackedNativeProtoMarshal3414811902-65.15%
BenchmarkNinRepPackedNativeProtoMarshal3337511969-64.14%
BenchmarkNidOptStructProtoMarshal71483727-47.86%
BenchmarkNinOptStructProtoMarshal69563481-49.96%
BenchmarkNidRepStructProtoMarshal4655119492-58.13%
BenchmarkNinRepStructProtoMarshal4671519043-59.24%
BenchmarkNidEmbeddedStructProtoMarshal52312050-60.81%
BenchmarkNinEmbeddedStructProtoMarshal46652000-57.13%
BenchmarkNidNestedStructProtoMarshal181106103604-42.79%
BenchmarkNinNestedStructProtoMarshal182053102069-43.93%
BenchmarkNidOptCustomProtoMarshal1209310-74.36%
BenchmarkNinOptCustomProtoMarshal1435277-80.70%
BenchmarkNidRepCustomProtoMarshal4126763-81.51%
BenchmarkNinRepCustomProtoMarshal3972769-80.64%
BenchmarkNinOptNativeUnionProtoMarshal973303-68.86%
BenchmarkNinOptStructUnionProtoMarshal1536521-66.08%
BenchmarkNinEmbeddedStructUnionProtoMarshal2327884-62.01%
BenchmarkNinNestedStructUnionProtoMarshal2070743-64.11%
BenchmarkTreeProtoMarshal1554838-46.07%
BenchmarkOrBranchProtoMarshal31562012-36.25%
BenchmarkAndBranchProtoMarshal31831996-37.29%
BenchmarkLeafProtoMarshal965606-37.20%
BenchmarkDeepTreeProtoMarshal23161283-44.60%
BenchmarkADeepBranchProtoMarshal27191492-45.13%
BenchmarkAndDeepBranchProtoMarshal46632922-37.34%
BenchmarkDeepLeafProtoMarshal18491016-45.05%
BenchmarkNilProtoMarshal43976-82.53%
BenchmarkNidOptEnumProtoMarshal514152-70.43%
BenchmarkNinOptEnumProtoMarshal550158-71.27%
BenchmarkNidRepEnumProtoMarshal647207-68.01%
BenchmarkNinRepEnumProtoMarshal662213-67.82%
BenchmarkTimerProtoMarshal934271-70.99%
BenchmarkMyExtendableProtoMarshal608185-69.57%
BenchmarkOtherExtenableProtoMarshal1112332-70.14%
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
benchmarkold MB/snew MB/sspeedup
BenchmarkNidOptNativeProtoMarshal126.86378.862.99x
BenchmarkNinOptNativeProtoMarshal114.27298.422.61x
BenchmarkNidRepNativeProtoMarshal164.25561.203.42x
BenchmarkNinRepNativeProtoMarshal166.10568.233.42x
BenchmarkNidRepPackedNativeProtoMarshal99.10283.972.87x
BenchmarkNinRepPackedNativeProtoMarshal101.30282.312.79x
BenchmarkNidOptStructProtoMarshal176.83339.071.92x
BenchmarkNinOptStructProtoMarshal163.59326.572.00x
BenchmarkNidRepStructProtoMarshal178.84427.492.39x
BenchmarkNinRepStructProtoMarshal178.70437.692.45x
BenchmarkNidEmbeddedStructProtoMarshal124.24317.562.56x
BenchmarkNinEmbeddedStructProtoMarshal132.03307.992.33x
BenchmarkNidNestedStructProtoMarshal192.91337.861.75x
BenchmarkNinNestedStructProtoMarshal192.44344.451.79x
BenchmarkNidOptCustomProtoMarshal29.77116.033.90x
BenchmarkNinOptCustomProtoMarshal22.29115.385.18x
BenchmarkNidRepCustomProtoMarshal35.14189.805.40x
BenchmarkNinRepCustomProtoMarshal36.50188.405.16x
BenchmarkNinOptNativeUnionProtoMarshal32.87105.393.21x
BenchmarkNinOptStructUnionProtoMarshal66.40195.762.95x
BenchmarkNinEmbeddedStructUnionProtoMarshal93.24245.262.63x
BenchmarkNinNestedStructUnionProtoMarshal57.49160.062.78x
BenchmarkTreeProtoMarshal137.64255.121.85x
BenchmarkOrBranchProtoMarshal137.80216.101.57x
BenchmarkAndBranchProtoMarshal136.64217.891.59x
BenchmarkLeafProtoMarshal214.48341.531.59x
BenchmarkDeepTreeProtoMarshal95.85173.031.81x
BenchmarkADeepBranchProtoMarshal82.73150.781.82x
BenchmarkAndDeepBranchProtoMarshal96.72153.981.59x
BenchmarkDeepLeafProtoMarshal117.34213.411.82x
BenchmarkNidOptEnumProtoMarshal3.8913.163.38x
BenchmarkNinOptEnumProtoMarshal1.826.303.46x
BenchmarkNidRepEnumProtoMarshal12.3638.503.11x
BenchmarkNinRepEnumProtoMarshal12.0837.533.11x
BenchmarkTimerProtoMarshal73.81253.873.44x
BenchmarkMyExtendableProtoMarshal13.1543.083.28x
BenchmarkOtherExtenableProtoMarshal24.2881.093.34x
+ +## Unmarshaler + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
benchmarkold ns/opnew ns/opdelta
BenchmarkNidOptNativeProtoUnmarshal25211006-60.10%
BenchmarkNinOptNativeProtoUnmarshal25291750-30.80%
BenchmarkNidRepNativeProtoUnmarshal4906735299-28.06%
BenchmarkNinRepNativeProtoUnmarshal4799035456-26.12%
BenchmarkNidRepPackedNativeProtoUnmarshal2645623950-9.47%
BenchmarkNinRepPackedNativeProtoUnmarshal2649924037-9.29%
BenchmarkNidOptStructProtoUnmarshal68033873-43.07%
BenchmarkNinOptStructProtoUnmarshal67864154-38.79%
BenchmarkNidRepStructProtoUnmarshal5627631970-43.19%
BenchmarkNinRepStructProtoUnmarshal4875031832-34.70%
BenchmarkNidEmbeddedStructProtoUnmarshal45561973-56.69%
BenchmarkNinEmbeddedStructProtoUnmarshal44851975-55.96%
BenchmarkNidNestedStructProtoUnmarshal223395135844-39.19%
BenchmarkNinNestedStructProtoUnmarshal226446134022-40.82%
BenchmarkNidOptCustomProtoUnmarshal1859300-83.86%
BenchmarkNinOptCustomProtoUnmarshal1486402-72.95%
BenchmarkNidRepCustomProtoUnmarshal82291669-79.72%
BenchmarkNinRepCustomProtoUnmarshal82531649-80.02%
BenchmarkNinOptNativeUnionProtoUnmarshal840307-63.45%
BenchmarkNinOptStructUnionProtoUnmarshal1395639-54.19%
BenchmarkNinEmbeddedStructUnionProtoUnmarshal22971167-49.19%
BenchmarkNinNestedStructUnionProtoUnmarshal1820889-51.15%
BenchmarkTreeProtoUnmarshal1521720-52.66%
BenchmarkOrBranchProtoUnmarshal26691385-48.11%
BenchmarkAndBranchProtoUnmarshal26671420-46.76%
BenchmarkLeafProtoUnmarshal1171584-50.13%
BenchmarkDeepTreeProtoUnmarshal20651081-47.65%
BenchmarkADeepBranchProtoUnmarshal26951178-56.29%
BenchmarkAndDeepBranchProtoUnmarshal40551918-52.70%
BenchmarkDeepLeafProtoUnmarshal1758865-50.80%
BenchmarkNilProtoUnmarshal56463-88.79%
BenchmarkNidOptEnumProtoUnmarshal76273-90.34%
BenchmarkNinOptEnumProtoUnmarshal764163-78.66%
BenchmarkNidRepEnumProtoUnmarshal1078447-58.53%
BenchmarkNinRepEnumProtoUnmarshal1071479-55.28%
BenchmarkTimerProtoUnmarshal1128362-67.91%
BenchmarkMyExtendableProtoUnmarshal808217-73.14%
BenchmarkOtherExtenableProtoUnmarshal1233517-58.07%
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
benchmarkold MB/snew MB/sspeedup
BenchmarkNidOptNativeProtoUnmarshal133.67334.982.51x
BenchmarkNinOptNativeProtoUnmarshal119.77173.081.45x
BenchmarkNidRepNativeProtoUnmarshal143.23199.121.39x
BenchmarkNinRepNativeProtoUnmarshal146.07198.161.36x
BenchmarkNidRepPackedNativeProtoUnmarshal127.80141.041.10x
BenchmarkNinRepPackedNativeProtoUnmarshal127.55140.781.10x
BenchmarkNidOptStructProtoUnmarshal185.79326.311.76x
BenchmarkNinOptStructProtoUnmarshal167.68273.661.63x
BenchmarkNidRepStructProtoUnmarshal147.88260.391.76x
BenchmarkNinRepStructProtoUnmarshal171.20261.971.53x
BenchmarkNidEmbeddedStructProtoUnmarshal142.86329.422.31x
BenchmarkNinEmbeddedStructProtoUnmarshal137.33311.832.27x
BenchmarkNidNestedStructProtoUnmarshal154.97259.471.67x
BenchmarkNinNestedStructProtoUnmarshal154.32258.421.67x
BenchmarkNidOptCustomProtoUnmarshal19.36119.666.18x
BenchmarkNinOptCustomProtoUnmarshal21.5279.503.69x
BenchmarkNidRepCustomProtoUnmarshal17.6286.864.93x
BenchmarkNinRepCustomProtoUnmarshal17.5787.925.00x
BenchmarkNinOptNativeUnionProtoUnmarshal38.07104.122.73x
BenchmarkNinOptStructUnionProtoUnmarshal73.08159.542.18x
BenchmarkNinEmbeddedStructUnionProtoUnmarshal94.00185.921.98x
BenchmarkNinNestedStructUnionProtoUnmarshal65.35133.752.05x
BenchmarkTreeProtoUnmarshal141.28297.132.10x
BenchmarkOrBranchProtoUnmarshal162.56313.961.93x
BenchmarkAndBranchProtoUnmarshal163.06306.151.88x
BenchmarkLeafProtoUnmarshal176.72354.192.00x
BenchmarkDeepTreeProtoUnmarshal107.50205.301.91x
BenchmarkADeepBranchProtoUnmarshal83.48190.882.29x
BenchmarkAndDeepBranchProtoUnmarshal110.97234.602.11x
BenchmarkDeepLeafProtoUnmarshal123.40250.732.03x
BenchmarkNidOptEnumProtoUnmarshal2.6227.1610.37x
BenchmarkNinOptEnumProtoUnmarshal1.316.114.66x
BenchmarkNidRepEnumProtoUnmarshal7.4217.882.41x
BenchmarkNinRepEnumProtoUnmarshal7.4716.692.23x
BenchmarkTimerProtoUnmarshal61.12190.343.11x
BenchmarkMyExtendableProtoUnmarshal9.9036.713.71x
BenchmarkOtherExtenableProtoUnmarshal21.9052.132.38x
\ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/codec/codec_test.go b/vendor/github.com/gogo/protobuf/codec/codec_test.go new file mode 100644 index 000000000..de2c9bc4b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/codec/codec_test.go @@ -0,0 +1,54 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package codec + +import ( + "github.com/gogo/protobuf/test" + "math/rand" + "testing" + "time" +) + +func TestCodec(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + in := test.NewPopulatedNinOptStruct(r, true) + c := New(r.Intn(1024)) + data, err := c.Marshal(in) + if err != nil { + t.Fatal(err) + } + out := &test.NinOptStruct{} + err = c.Unmarshal(data, out) + if err != nil { + t.Fatal(err) + } + if err := in.VerboseEqual(out); err != nil { + t.Fatal(err) + } +} diff --git a/vendor/github.com/gogo/protobuf/custom_types.md b/vendor/github.com/gogo/protobuf/custom_types.md new file mode 100644 index 000000000..3eed249b5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/custom_types.md @@ -0,0 +1,68 @@ +# Custom types + +Custom types is a gogo protobuf extensions that allows for using a custom +struct type to decorate the underlying structure of the protocol message. + +# How to use + +## Defining the protobuf message + +```proto +message CustomType { + optional ProtoType Field = 1 [(gogoproto.customtype) = "T"]; +} + +message ProtoType { + optional string Field = 1; +} +``` + +or alternatively you can declare the field type in the protocol message to be +`bytes`: + +```proto +message BytesCustomType { + optional bytes Field = 1 [(gogoproto.customtype) = "T"]; +} +``` + +The downside of using `bytes` is that it makes it harder to generate protobuf +code in other languages. In either case, it is the user responsibility to +ensure that the custom type marshals and unmarshals to the expected wire +format. That is, in the first example, gogo protobuf will not attempt to ensure +that the wire format of `ProtoType` and `T` are wire compatible. + +## Custom type method signatures + +The custom type must define the following methods with the given +signatures. Assuming the custom type is called `T`: + +```go +func (t T) Marshal() ([]byte, error) {} +func (t *T) MarshalTo(data []byte) (n int, err error) {} +func (t *T) Unmarshal(data []byte) error {} + +func (t T) MarshalJSON() ([]byte, error) {} +func (t *T) UnmarshalJSON(data []byte) error {} + +// only required if the compare option is set +func (t T) Compare(other T) int {} +// only required if the equal option is set +func (t T) Equal(other T) bool {} +// only required if populate option is set +func NewPopulatedT(r randyThetest) *T {} +``` + +Check [t.go](test/t.go) for a full example + +# Warnings and issues + +`Warning about customtype: It is your responsibility to test all cases of your marshaling, unmarshaling and size methods implemented for your custom type.` + +Issues with customtype include: + * A Bytes method is not allowed. + * Defining a customtype as a fake proto message is broken. + * proto.Clone is broken. + * Using a proto message as a customtype is not allowed. + * cusomtype of type map can not UnmarshalText + * customtype of type struct cannot jsonpb unmarshal diff --git a/vendor/github.com/gogo/protobuf/extensions.md b/vendor/github.com/gogo/protobuf/extensions.md new file mode 100644 index 000000000..35dfee16f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/extensions.md @@ -0,0 +1,162 @@ +# gogoprotobuf Extensions + +Here is an [example.proto](https://github.com/gogo/protobuf/blob/master/test/example/example.proto) which uses most of the gogoprotobuf code generation plugins. + +Please also look at the example [Makefile](https://github.com/gogo/protobuf/blob/master/test/example/Makefile) which shows how to specify the `descriptor.proto` and `gogo.proto` in your proto_path + +The documentation at [http://godoc.org/github.com/gogo/protobuf/gogoproto](http://godoc.org/github.com/gogo/protobuf/gogoproto) describes the extensions made to goprotobuf in more detail. + +Also see [http://godoc.org/github.com/gogo/protobuf/plugin/](http://godoc.org/github.com/gogo/protobuf/plugin/) for documentation of each of the extensions which have their own plugins. + +# Fast Marshalling and Unmarshalling + +Generating a `Marshal`, `MarshalTo`, `Size` (or `ProtoSize`) and `Unmarshal` method for a struct results in faster marshalling and unmarshalling than when using reflect. + +See [BenchComparison](https://github.com/gogo/protobuf/blob/master/bench.md) for a comparison between reflect and generated code used for marshalling and unmarshalling. + + + + + + + + + + + +
NameOptionTypeDescriptionDefault
marshalerMessageboolif true, a Marshal and MarshalTo method is generated for the specific messagefalse
sizerMessageboolif true, a Size method is generated for the specific messagefalse
unmarshaler Message bool if true, an Unmarshal method is generated for the specific message false
protosizerMessageboolif true, a ProtoSize method is generated for the specific messagefalse
unsafe_marshaler (deprecated) Message bool if true, a Marshal and MarshalTo method is generated. false
unsafe_unmarshaler (deprecated) Message bool if true, an Unmarshal method is generated. false
stable_marshaler Message bool if true, a Marshal and MarshalTo method is generated for the specific message, but unlike marshaler the output is guaranteed to be deterministic, at the sacrifice of some speed false
typedecl (beta) Message bool if false, type declaration of the message is excluded from the generated output. Requires the marshaler and unmarshaler to be generated. true
+ +# More Canonical Go Structures + +Lots of times working with a goprotobuf struct will lead you to a place where you create another struct that is easier to work with and then have a function to copy the values between the two structs. + +You might also find that basic structs that started their life as part of an API need to be sent over the wire. With gob, you could just send it. With goprotobuf, you need to make a new struct. + +`gogoprotobuf` tries to fix these problems with the nullable, embed, customtype, customname, casttype, castkey and castvalue field extensions. + + + + + + + + + + + + + + + +
NameOptionTypeDescriptionDefault
nullable Field bool if false, a field is generated without a pointer (see warning below). true
embed Field bool if true, the field is generated as an embedded field. false
customtype Field string It works with the Marshal and Unmarshal methods, to allow you to have your own types in your struct, but marshal to bytes. For example, custom.Uuid or custom.Fixed128. For more information please refer to the CustomTypes document goprotobuf type
customname (beta) Field string Changes the generated fieldname. This is especially useful when generated methods conflict with fieldnames. goprotobuf field name
casttype (beta) Field string Changes the generated field type. It assumes that this type is castable to the original goprotobuf field type. It currently does not support maps, structs or enums. goprotobuf field type
castkey (beta) Field string Changes the generated fieldtype for a map key. All generated code assumes that this type is castable to the protocol buffer field type. Only supported on maps. goprotobuf field type
castvalue (beta) Field string Changes the generated fieldtype for a map value. All generated code assumes that this type is castable to the protocol buffer field type. Only supported on maps. goprotobuf field type
enum_customname (beta) Enum string Sets the type name of an enum. If goproto_enum_prefix is enabled, this value will be used as a prefix when generating enum values.goprotobuf enum type name. Helps with golint issues.
enumdecl (beta) Enum bool if false, type declaration of the enum is excluded from the generated output. Requires the marshaler and unmarshaler to be generated. true
enumvalue_customname (beta) Enum Value string Changes the generated enum name. Helps with golint issues.goprotobuf enum value name
stdtime Timestamp Field bool Changes the Well Known Timestamp Type to time.TimeTimestamp
stdduration Duration Field bool Changes the Well Known Duration Type to time.DurationDuration
+ +`Warning about nullable: according to the Protocol Buffer specification, you should be able to tell whether a field is set or unset. With the option nullable=false this feature is lost, since your non-nullable fields will always be set.` + +# Goprotobuf Compatibility + +Gogoprotobuf is compatible with Goprotobuf, because it is compatible with protocol buffers (see the section on tests below). + +Gogoprotobuf generates the same code as goprotobuf if no extensions are used. + +The enumprefix, getters and stringer extensions can be used to remove some of the unnecessary code generated by goprotobuf. + + + + + + + + + + + +
NameOptionTypeDescriptionDefault
gogoproto_import File bool if false, the generated code imports github.com/golang/protobuf/proto instead of github.com/gogo/protobuf/proto. true
goproto_enum_prefix Enum bool if false, generates the enum constant names without the messagetype prefix true
goproto_getters Message bool if false, the message is generated without get methods, this is useful when you would rather want to use face true
goproto_stringer Message bool if false, the message is generated without the default string method, this is useful for rather using stringer true
goproto_enum_stringer (experimental) Enum bool if false, the enum is generated without the default string method, this is useful for rather using enum_stringer true
goproto_extensions_map (beta) Message bool if false, the extensions field is generated as type []byte instead of type map[int32]proto.Extension true
goproto_unrecognized (beta) Message bool if false, XXX_unrecognized field is not generated. This is useful to reduce GC pressure at the cost of losing information about unrecognized fields. true
goproto_registration (beta) File bool if true, the generated files will register all messages and types against both gogo/protobuf and golang/protobuf. This is necessary when using third-party packages which read registrations from golang/protobuf (such as the grpc-gateway). false
+ +# Less Typing + +The Protocol Buffer language is very parseable and extra code can be easily generated for structures. + +Helper methods, functions and interfaces can be generated by triggering certain extensions like gostring. + + + + + + + + + + + + + +
NameOptionTypeDescriptionDefault
gostring Message bool if true, a `GoString` method is generated. This returns a string representing valid go code to reproduce the current state of the struct. false
onlyone Message bool if true, all fields must be nullable and only one of the fields may be set, like a union. Two methods are generated: `GetValue() interface{}` and `SetValue(v interface{}) (set bool)`. These provide easier interaction with a union. false
equal Message bool if true, an Equal method is generated false
compare Message bool if true, a Compare method is generated. This is very useful for quickly implementing sort on a list of protobuf structs false
verbose_equal Message bool if true, a verbose equal method is generated for the message. This returns an error which describes the exact element which is not equal to the exact element in the other struct. false
stringer Message bool if true, a String method is generated for the message. false
face Message bool if true, a function will be generated which can convert a structure which satisfies an interface (face) to the specified structure. This interface contains getters for each of the fields in the struct. The specified struct is also generated with the getters. This allows it to satisfy its own face. false
description (beta) Message bool if true, a Description method is generated for the message. false
populate Message bool if true, a `NewPopulated` function is generated. This is necessary for generated tests. false
enum_stringer (experimental) Enum bool if true, a String method is generated for an Enum false
+ +Issues with Compare include: + * Oneof is not supported yet + * Not all Well Known Types are supported yet + * Maps are not supported + +#Peace of Mind + +Test and Benchmark generation is done with the following extensions: + + + + +
testgen Message bool if true, tests are generated for proto, json and prototext marshalling as well as for some of the other enabled plugins false
benchgen Message bool if true, benchmarks are generated for proto, json and prototext marshalling as well as for some of the other enabled plugins false
+ +# More Serialization Formats + +Other serialization formats like xml and json typically use reflect to marshal and unmarshal structured data. Manipulating these structs into something other than the default Go requires editing tags. The following extensions provide ways of editing these tags for the generated protobuf structs. + + + + +
jsontag (beta) Field string if set, the json tag value between the double quotes is replaced with this string fieldname
moretags (beta) Field string if set, this string is appended to the tag string empty
+ +Here is a longer explanation of jsontag and moretags + +# File Options + +Each of the boolean message and enum extensions also have a file extension: + + * `marshaler_all` + * `sizer_all` + * `protosizer_all` + * `unmarshaler_all` + * `unsafe_marshaler_all` + * `unsafe_unmarshaler_all` + * `stable_marshaler_all` + * `goproto_enum_prefix_all` + * `goproto_getters_all` + * `goproto_stringer_all` + * `goproto_enum_stringer_all` + * `goproto_extensions_map_all` + * `goproto_unrecognized_all` + * `gostring_all` + * `onlyone_all` + * `equal_all` + * `compare_all` + * `verbose_equal_all` + * `stringer_all` + * `enum_stringer_all` + * `face_all` + * `description_all` + * `populate_all` + * `testgen_all` + * `benchgen_all` + * `enumdecl_all` + * `typedecl_all` + +Each of these are the same as their Message Option counterparts, except they apply to all messages in the file. Their Message option counterparts can also be used to overwrite their effect. + +# Tests + + * The normal barrage of tests are run with: `make tests` + * A few weird tests: `make testall` + * Tests for compatibility with [golang/protobuf](https://github.com/golang/protobuf) are handled by a different project [harmonytests](https://github.com/gogo/harmonytests), since it requires goprotobuf. + * Cross version tests are made with [Travis CI](https://travis-ci.org/gogo/protobuf). + * GRPC Tests are also handled by a different project [grpctests](https://github.com/gogo/grpctests), since it depends on a lot of grpc libraries. + * Thanks to [go-fuzz](https://github.com/dvyukov/go-fuzz/) we have proper [fuzztests](https://github.com/gogo/fuzztests). + diff --git a/vendor/github.com/gogo/protobuf/gogoproto/Makefile b/vendor/github.com/gogo/protobuf/gogoproto/Makefile new file mode 100644 index 000000000..0b4659b73 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/gogoproto/Makefile @@ -0,0 +1,37 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc --gogo_out=Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor:../../../../ --proto_path=../../../../:../protobuf/:. *.proto + +restore: + cp gogo.pb.golden gogo.pb.go + +preserve: + cp gogo.pb.go gogo.pb.golden diff --git a/vendor/github.com/gogo/protobuf/gogoproto/gogo.pb.golden b/vendor/github.com/gogo/protobuf/gogoproto/gogo.pb.golden new file mode 100644 index 000000000..f6502e4b9 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/gogoproto/gogo.pb.golden @@ -0,0 +1,45 @@ +// Code generated by protoc-gen-go. +// source: gogo.proto +// DO NOT EDIT! + +package gogoproto + +import proto "github.com/gogo/protobuf/proto" +import json "encoding/json" +import math "math" +import google_protobuf "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" + +// Reference proto, json, and math imports to suppress error if they are not otherwise used. +var _ = proto.Marshal +var _ = &json.SyntaxError{} +var _ = math.Inf + +var E_Nullable = &proto.ExtensionDesc{ + ExtendedType: (*google_protobuf.FieldOptions)(nil), + ExtensionType: (*bool)(nil), + Field: 51235, + Name: "gogoproto.nullable", + Tag: "varint,51235,opt,name=nullable", +} + +var E_Embed = &proto.ExtensionDesc{ + ExtendedType: (*google_protobuf.FieldOptions)(nil), + ExtensionType: (*bool)(nil), + Field: 51236, + Name: "gogoproto.embed", + Tag: "varint,51236,opt,name=embed", +} + +var E_Customtype = &proto.ExtensionDesc{ + ExtendedType: (*google_protobuf.FieldOptions)(nil), + ExtensionType: (*string)(nil), + Field: 51237, + Name: "gogoproto.customtype", + Tag: "bytes,51237,opt,name=customtype", +} + +func init() { + proto.RegisterExtension(E_Nullable) + proto.RegisterExtension(E_Embed) + proto.RegisterExtension(E_Customtype) +} diff --git a/vendor/github.com/gogo/protobuf/gogoproto/gogo.proto b/vendor/github.com/gogo/protobuf/gogoproto/gogo.proto new file mode 100644 index 000000000..7f0997935 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/gogoproto/gogo.proto @@ -0,0 +1,133 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package gogoproto; + +import "google/protobuf/descriptor.proto"; + +option java_package = "com.google.protobuf"; +option java_outer_classname = "GoGoProtos"; +option go_package = "github.com/gogo/protobuf/gogoproto"; + +extend google.protobuf.EnumOptions { + optional bool goproto_enum_prefix = 62001; + optional bool goproto_enum_stringer = 62021; + optional bool enum_stringer = 62022; + optional string enum_customname = 62023; + optional bool enumdecl = 62024; +} + +extend google.protobuf.EnumValueOptions { + optional string enumvalue_customname = 66001; +} + +extend google.protobuf.FileOptions { + optional bool goproto_getters_all = 63001; + optional bool goproto_enum_prefix_all = 63002; + optional bool goproto_stringer_all = 63003; + optional bool verbose_equal_all = 63004; + optional bool face_all = 63005; + optional bool gostring_all = 63006; + optional bool populate_all = 63007; + optional bool stringer_all = 63008; + optional bool onlyone_all = 63009; + + optional bool equal_all = 63013; + optional bool description_all = 63014; + optional bool testgen_all = 63015; + optional bool benchgen_all = 63016; + optional bool marshaler_all = 63017; + optional bool unmarshaler_all = 63018; + optional bool stable_marshaler_all = 63019; + + optional bool sizer_all = 63020; + + optional bool goproto_enum_stringer_all = 63021; + optional bool enum_stringer_all = 63022; + + optional bool unsafe_marshaler_all = 63023; + optional bool unsafe_unmarshaler_all = 63024; + + optional bool goproto_extensions_map_all = 63025; + optional bool goproto_unrecognized_all = 63026; + optional bool gogoproto_import = 63027; + optional bool protosizer_all = 63028; + optional bool compare_all = 63029; + optional bool typedecl_all = 63030; + optional bool enumdecl_all = 63031; + + optional bool goproto_registration = 63032; +} + +extend google.protobuf.MessageOptions { + optional bool goproto_getters = 64001; + optional bool goproto_stringer = 64003; + optional bool verbose_equal = 64004; + optional bool face = 64005; + optional bool gostring = 64006; + optional bool populate = 64007; + optional bool stringer = 67008; + optional bool onlyone = 64009; + + optional bool equal = 64013; + optional bool description = 64014; + optional bool testgen = 64015; + optional bool benchgen = 64016; + optional bool marshaler = 64017; + optional bool unmarshaler = 64018; + optional bool stable_marshaler = 64019; + + optional bool sizer = 64020; + + optional bool unsafe_marshaler = 64023; + optional bool unsafe_unmarshaler = 64024; + + optional bool goproto_extensions_map = 64025; + optional bool goproto_unrecognized = 64026; + + optional bool protosizer = 64028; + optional bool compare = 64029; + + optional bool typedecl = 64030; +} + +extend google.protobuf.FieldOptions { + optional bool nullable = 65001; + optional bool embed = 65002; + optional string customtype = 65003; + optional string customname = 65004; + optional string jsontag = 65005; + optional string moretags = 65006; + optional string casttype = 65007; + optional string castkey = 65008; + optional string castvalue = 65009; + + optional bool stdtime = 65010; + optional bool stdduration = 65011; +} diff --git a/vendor/github.com/gogo/protobuf/install-protobuf.sh b/vendor/github.com/gogo/protobuf/install-protobuf.sh new file mode 100644 index 000000000..f42fc9e63 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/install-protobuf.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -ex + +die() { + echo "$@" >&2 + exit 1 +} + +cd /home/travis + +case "$PROTOBUF_VERSION" in +2*) + basename=protobuf-$PROTOBUF_VERSION + wget https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/$basename.tar.gz + tar xzf $basename.tar.gz + cd protobuf-$PROTOBUF_VERSION + ./configure --prefix=/home/travis && make -j2 && make install + ;; +3*) + basename=protoc-$PROTOBUF_VERSION-linux-x86_64 + wget https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/$basename.zip + unzip $basename.zip + ;; +*) + die "unknown protobuf version: $PROTOBUF_VERSION" + ;; +esac diff --git a/vendor/github.com/gogo/protobuf/io/io_test.go b/vendor/github.com/gogo/protobuf/io/io_test.go new file mode 100644 index 000000000..0b74b3100 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/io/io_test.go @@ -0,0 +1,221 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package io_test + +import ( + "bytes" + "encoding/binary" + "github.com/gogo/protobuf/io" + "github.com/gogo/protobuf/test" + goio "io" + "math/rand" + "testing" + "time" +) + +func iotest(writer io.WriteCloser, reader io.ReadCloser) error { + size := 1000 + msgs := make([]*test.NinOptNative, size) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + for i := range msgs { + msgs[i] = test.NewPopulatedNinOptNative(r, true) + //issue 31 + if i == 5 { + msgs[i] = &test.NinOptNative{} + } + //issue 31 + if i == 999 { + msgs[i] = &test.NinOptNative{} + } + err := writer.WriteMsg(msgs[i]) + if err != nil { + return err + } + } + if err := writer.Close(); err != nil { + return err + } + i := 0 + for { + msg := &test.NinOptNative{} + if err := reader.ReadMsg(msg); err != nil { + if err == goio.EOF { + break + } + return err + } + if err := msg.VerboseEqual(msgs[i]); err != nil { + return err + } + i++ + } + if i != size { + panic("not enough messages read") + } + if err := reader.Close(); err != nil { + return err + } + return nil +} + +type buffer struct { + *bytes.Buffer + closed bool +} + +func (this *buffer) Close() error { + this.closed = true + return nil +} + +func newBuffer() *buffer { + return &buffer{bytes.NewBuffer(nil), false} +} + +func TestBigUint32Normal(t *testing.T) { + buf := newBuffer() + writer := io.NewUint32DelimitedWriter(buf, binary.BigEndian) + reader := io.NewUint32DelimitedReader(buf, binary.BigEndian, 1024*1024) + if err := iotest(writer, reader); err != nil { + t.Error(err) + } + if !buf.closed { + t.Fatalf("did not close buffer") + } +} + +func TestBigUint32MaxSize(t *testing.T) { + buf := newBuffer() + writer := io.NewUint32DelimitedWriter(buf, binary.BigEndian) + reader := io.NewUint32DelimitedReader(buf, binary.BigEndian, 20) + if err := iotest(writer, reader); err != goio.ErrShortBuffer { + t.Error(err) + } else { + t.Logf("%s", err) + } +} + +func TestLittleUint32Normal(t *testing.T) { + buf := newBuffer() + writer := io.NewUint32DelimitedWriter(buf, binary.LittleEndian) + reader := io.NewUint32DelimitedReader(buf, binary.LittleEndian, 1024*1024) + if err := iotest(writer, reader); err != nil { + t.Error(err) + } + if !buf.closed { + t.Fatalf("did not close buffer") + } +} + +func TestLittleUint32MaxSize(t *testing.T) { + buf := newBuffer() + writer := io.NewUint32DelimitedWriter(buf, binary.LittleEndian) + reader := io.NewUint32DelimitedReader(buf, binary.LittleEndian, 20) + if err := iotest(writer, reader); err != goio.ErrShortBuffer { + t.Error(err) + } else { + t.Logf("%s", err) + } +} + +func TestVarintNormal(t *testing.T) { + buf := newBuffer() + writer := io.NewDelimitedWriter(buf) + reader := io.NewDelimitedReader(buf, 1024*1024) + if err := iotest(writer, reader); err != nil { + t.Error(err) + } + if !buf.closed { + t.Fatalf("did not close buffer") + } +} + +func TestVarintNoClose(t *testing.T) { + buf := bytes.NewBuffer(nil) + writer := io.NewDelimitedWriter(buf) + reader := io.NewDelimitedReader(buf, 1024*1024) + if err := iotest(writer, reader); err != nil { + t.Error(err) + } +} + +//issue 32 +func TestVarintMaxSize(t *testing.T) { + buf := newBuffer() + writer := io.NewDelimitedWriter(buf) + reader := io.NewDelimitedReader(buf, 20) + if err := iotest(writer, reader); err != goio.ErrShortBuffer { + t.Error(err) + } else { + t.Logf("%s", err) + } +} + +func TestVarintError(t *testing.T) { + buf := newBuffer() + buf.Write([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}) + reader := io.NewDelimitedReader(buf, 1024*1024) + msg := &test.NinOptNative{} + err := reader.ReadMsg(msg) + if err == nil { + t.Fatalf("Expected error") + } +} + +func TestFull(t *testing.T) { + buf := newBuffer() + writer := io.NewFullWriter(buf) + reader := io.NewFullReader(buf, 1024*1024) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + msgIn := test.NewPopulatedNinOptNative(r, true) + if err := writer.WriteMsg(msgIn); err != nil { + panic(err) + } + if err := writer.Close(); err != nil { + panic(err) + } + msgOut := &test.NinOptNative{} + if err := reader.ReadMsg(msgOut); err != nil { + panic(err) + } + if err := msgIn.VerboseEqual(msgOut); err != nil { + panic(err) + } + if err := reader.ReadMsg(msgOut); err != nil { + if err != goio.EOF { + panic(err) + } + } + if err := reader.Close(); err != nil { + panic(err) + } + if !buf.closed { + t.Fatalf("did not close buffer") + } +} diff --git a/vendor/github.com/gogo/protobuf/io/uint32_test.go b/vendor/github.com/gogo/protobuf/io/uint32_test.go new file mode 100644 index 000000000..d837e4a93 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/io/uint32_test.go @@ -0,0 +1,38 @@ +package io_test + +import ( + "encoding/binary" + "io/ioutil" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/test" + example "github.com/gogo/protobuf/test/example" + + "github.com/gogo/protobuf/io" +) + +func BenchmarkUint32DelimWriterMarshaller(b *testing.B) { + w := io.NewUint32DelimitedWriter(ioutil.Discard, binary.BigEndian) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + msg := example.NewPopulatedA(r, true) + + for i := 0; i < b.N; i++ { + if err := w.WriteMsg(msg); err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkUint32DelimWriterFallback(b *testing.B) { + w := io.NewUint32DelimitedWriter(ioutil.Discard, binary.BigEndian) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + msg := test.NewPopulatedNinOptNative(r, true) + + for i := 0; i < b.N; i++ { + if err := w.WriteMsg(msg); err != nil { + b.Fatal(err) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test.go b/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test.go new file mode 100644 index 000000000..8d585f2ed --- /dev/null +++ b/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test.go @@ -0,0 +1,890 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2015 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package jsonpb + +import ( + "bytes" + "encoding/json" + "io" + "math" + "reflect" + "strings" + "testing" + + pb "github.com/gogo/protobuf/jsonpb/jsonpb_test_proto" + "github.com/gogo/protobuf/proto" + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + "github.com/gogo/protobuf/types" +) + +var ( + marshaler = Marshaler{} + + marshalerAllOptions = Marshaler{ + Indent: " ", + } + + simpleObject = &pb.Simple{ + OInt32: proto.Int32(-32), + OInt64: proto.Int64(-6400000000), + OUint32: proto.Uint32(32), + OUint64: proto.Uint64(6400000000), + OSint32: proto.Int32(-13), + OSint64: proto.Int64(-2600000000), + OFloat: proto.Float32(3.14), + ODouble: proto.Float64(6.02214179e23), + OBool: proto.Bool(true), + OString: proto.String("hello \"there\""), + OBytes: []byte("beep boop"), + OCastBytes: pb.Bytes("wow"), + } + + simpleObjectJSON = `{` + + `"oBool":true,` + + `"oInt32":-32,` + + `"oInt64":"-6400000000",` + + `"oUint32":32,` + + `"oUint64":"6400000000",` + + `"oSint32":-13,` + + `"oSint64":"-2600000000",` + + `"oFloat":3.14,` + + `"oDouble":6.02214179e+23,` + + `"oString":"hello \"there\"",` + + `"oBytes":"YmVlcCBib29w",` + + `"oCastBytes":"d293"` + + `}` + + simpleObjectPrettyJSON = `{ + "oBool": true, + "oInt32": -32, + "oInt64": "-6400000000", + "oUint32": 32, + "oUint64": "6400000000", + "oSint32": -13, + "oSint64": "-2600000000", + "oFloat": 3.14, + "oDouble": 6.02214179e+23, + "oString": "hello \"there\"", + "oBytes": "YmVlcCBib29w", + "oCastBytes": "d293" +}` + + repeatsObject = &pb.Repeats{ + RBool: []bool{true, false, true}, + RInt32: []int32{-3, -4, -5}, + RInt64: []int64{-123456789, -987654321}, + RUint32: []uint32{1, 2, 3}, + RUint64: []uint64{6789012345, 3456789012}, + RSint32: []int32{-1, -2, -3}, + RSint64: []int64{-6789012345, -3456789012}, + RFloat: []float32{3.14, 6.28}, + RDouble: []float64{299792458 * 1e20, 6.62606957e-34}, + RString: []string{"happy", "days"}, + RBytes: [][]byte{[]byte("skittles"), []byte("m&m's")}, + } + + repeatsObjectJSON = `{` + + `"rBool":[true,false,true],` + + `"rInt32":[-3,-4,-5],` + + `"rInt64":["-123456789","-987654321"],` + + `"rUint32":[1,2,3],` + + `"rUint64":["6789012345","3456789012"],` + + `"rSint32":[-1,-2,-3],` + + `"rSint64":["-6789012345","-3456789012"],` + + `"rFloat":[3.14,6.28],` + + `"rDouble":[2.99792458e+28,6.62606957e-34],` + + `"rString":["happy","days"],` + + `"rBytes":["c2tpdHRsZXM=","bSZtJ3M="]` + + `}` + + repeatsObjectPrettyJSON = `{ + "rBool": [ + true, + false, + true + ], + "rInt32": [ + -3, + -4, + -5 + ], + "rInt64": [ + "-123456789", + "-987654321" + ], + "rUint32": [ + 1, + 2, + 3 + ], + "rUint64": [ + "6789012345", + "3456789012" + ], + "rSint32": [ + -1, + -2, + -3 + ], + "rSint64": [ + "-6789012345", + "-3456789012" + ], + "rFloat": [ + 3.14, + 6.28 + ], + "rDouble": [ + 2.99792458e+28, + 6.62606957e-34 + ], + "rString": [ + "happy", + "days" + ], + "rBytes": [ + "c2tpdHRsZXM=", + "bSZtJ3M=" + ] +}` + + innerSimple = &pb.Simple{OInt32: proto.Int32(-32)} + innerSimple2 = &pb.Simple{OInt64: proto.Int64(25)} + innerRepeats = &pb.Repeats{RString: []string{"roses", "red"}} + innerRepeats2 = &pb.Repeats{RString: []string{"violets", "blue"}} + complexObject = &pb.Widget{ + Color: pb.Widget_GREEN.Enum(), + RColor: []pb.Widget_Color{pb.Widget_RED, pb.Widget_GREEN, pb.Widget_BLUE}, + Simple: innerSimple, + RSimple: []*pb.Simple{innerSimple, innerSimple2}, + Repeats: innerRepeats, + RRepeats: []*pb.Repeats{innerRepeats, innerRepeats2}, + } + + complexObjectJSON = `{"color":"GREEN",` + + `"rColor":["RED","GREEN","BLUE"],` + + `"simple":{"oInt32":-32},` + + `"rSimple":[{"oInt32":-32},{"oInt64":"25"}],` + + `"repeats":{"rString":["roses","red"]},` + + `"rRepeats":[{"rString":["roses","red"]},{"rString":["violets","blue"]}]` + + `}` + + complexObjectPrettyJSON = `{ + "color": "GREEN", + "rColor": [ + "RED", + "GREEN", + "BLUE" + ], + "simple": { + "oInt32": -32 + }, + "rSimple": [ + { + "oInt32": -32 + }, + { + "oInt64": "25" + } + ], + "repeats": { + "rString": [ + "roses", + "red" + ] + }, + "rRepeats": [ + { + "rString": [ + "roses", + "red" + ] + }, + { + "rString": [ + "violets", + "blue" + ] + } + ] +}` + + colorPrettyJSON = `{ + "color": 2 +}` + + colorListPrettyJSON = `{ + "color": 1000, + "rColor": [ + "RED" + ] +}` + + nummyPrettyJSON = `{ + "nummy": { + "1": 2, + "3": 4 + } +}` + + objjyPrettyJSON = `{ + "objjy": { + "1": { + "dub": 1 + } + } +}` + realNumber = &pb.Real{Value: proto.Float64(3.14159265359)} + realNumberName = "Pi" + complexNumber = &pb.Complex{Imaginary: proto.Float64(0.5772156649)} + realNumberJSON = `{` + + `"value":3.14159265359,` + + `"[jsonpb.Complex.real_extension]":{"imaginary":0.5772156649},` + + `"[jsonpb.name]":"Pi"` + + `}` + + anySimple = &pb.KnownTypes{ + An: &types.Any{ + TypeUrl: "something.example.com/jsonpb.Simple", + Value: []byte{ + // &pb.Simple{OBool:true} + 1 << 3, 1, + }, + }, + } + anySimpleJSON = `{"an":{"@type":"something.example.com/jsonpb.Simple","oBool":true}}` + anySimplePrettyJSON = `{ + "an": { + "@type": "something.example.com/jsonpb.Simple", + "oBool": true + } +}` + + anyWellKnown = &pb.KnownTypes{ + An: &types.Any{ + TypeUrl: "type.googleapis.com/google.protobuf.Duration", + Value: []byte{ + // &durpb.Duration{Seconds: 1, Nanos: 212000000 } + 1 << 3, 1, // seconds + 2 << 3, 0x80, 0xba, 0x8b, 0x65, // nanos + }, + }, + } + anyWellKnownJSON = `{"an":{"@type":"type.googleapis.com/google.protobuf.Duration","value":"1.212s"}}` + anyWellKnownPrettyJSON = `{ + "an": { + "@type": "type.googleapis.com/google.protobuf.Duration", + "value": "1.212s" + } +}` + + nonFinites = &pb.NonFinites{ + FNan: proto.Float32(float32(math.NaN())), + FPinf: proto.Float32(float32(math.Inf(1))), + FNinf: proto.Float32(float32(math.Inf(-1))), + DNan: proto.Float64(float64(math.NaN())), + DPinf: proto.Float64(float64(math.Inf(1))), + DNinf: proto.Float64(float64(math.Inf(-1))), + } + nonFinitesJSON = `{` + + `"fNan":"NaN",` + + `"fPinf":"Infinity",` + + `"fNinf":"-Infinity",` + + `"dNan":"NaN",` + + `"dPinf":"Infinity",` + + `"dNinf":"-Infinity"` + + `}` +) + +func init() { + if err := proto.SetExtension(realNumber, pb.E_Name, &realNumberName); err != nil { + panic(err) + } + if err := proto.SetExtension(realNumber, pb.E_Complex_RealExtension, complexNumber); err != nil { + panic(err) + } +} + +var marshalingTests = []struct { + desc string + marshaler Marshaler + pb proto.Message + json string +}{ + {"simple flat object", marshaler, simpleObject, simpleObjectJSON}, + {"simple pretty object", marshalerAllOptions, simpleObject, simpleObjectPrettyJSON}, + {"non-finite floats fields object", marshaler, nonFinites, nonFinitesJSON}, + {"repeated fields flat object", marshaler, repeatsObject, repeatsObjectJSON}, + {"repeated fields pretty object", marshalerAllOptions, repeatsObject, repeatsObjectPrettyJSON}, + {"nested message/enum flat object", marshaler, complexObject, complexObjectJSON}, + {"nested message/enum pretty object", marshalerAllOptions, complexObject, complexObjectPrettyJSON}, + {"enum-string flat object", Marshaler{}, + &pb.Widget{Color: pb.Widget_BLUE.Enum()}, `{"color":"BLUE"}`}, + {"enum-value pretty object", Marshaler{EnumsAsInts: true, Indent: " "}, + &pb.Widget{Color: pb.Widget_BLUE.Enum()}, colorPrettyJSON}, + {"unknown enum value object", marshalerAllOptions, + &pb.Widget{Color: pb.Widget_Color(1000).Enum(), RColor: []pb.Widget_Color{pb.Widget_RED}}, colorListPrettyJSON}, + {"repeated proto3 enum", Marshaler{}, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}, + `{"rFunny":["PUNS","SLAPSTICK"]}`}, + {"repeated proto3 enum as int", Marshaler{EnumsAsInts: true}, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}, + `{"rFunny":[1,2]}`}, + {"empty value", marshaler, &pb.Simple3{}, `{}`}, + {"empty value emitted", Marshaler{EmitDefaults: true}, &pb.Simple3{}, `{"dub":0}`}, + {"empty repeated emitted", Marshaler{EmitDefaults: true}, &pb.SimpleSlice3{}, `{"slices":[]}`}, + {"empty map emitted", Marshaler{EmitDefaults: true}, &pb.SimpleMap3{}, `{"stringy":{}}`}, + {"nested struct null", Marshaler{EmitDefaults: true}, &pb.SimpleNull3{}, `{"simple":null}`}, + {"map", marshaler, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, `{"nummy":{"1":2,"3":4}}`}, + {"map", marshalerAllOptions, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, nummyPrettyJSON}, + {"map", marshaler, + &pb.Mappy{Strry: map[string]string{`"one"`: "two", "three": "four"}}, + `{"strry":{"\"one\"":"two","three":"four"}}`}, + {"map", marshaler, + &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: {Dub: 1}}}, `{"objjy":{"1":{"dub":1}}}`}, + {"map", marshalerAllOptions, + &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: {Dub: 1}}}, objjyPrettyJSON}, + {"map", marshaler, &pb.Mappy{Buggy: map[int64]string{1234: "yup"}}, + `{"buggy":{"1234":"yup"}}`}, + {"map", marshaler, &pb.Mappy{Booly: map[bool]bool{false: true}}, `{"booly":{"false":true}}`}, + // TODO: This is broken. + //{"map", marshaler, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}, `{"enumy":{"XIV":"ROMAN"}`}, + {"map", Marshaler{EnumsAsInts: true}, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}, `{"enumy":{"XIV":2}}`}, + {"map", marshaler, &pb.Mappy{S32Booly: map[int32]bool{1: true, 3: false, 10: true, 12: false}}, `{"s32booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"map", marshaler, &pb.Mappy{S64Booly: map[int64]bool{1: true, 3: false, 10: true, 12: false}}, `{"s64booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"map", marshaler, &pb.Mappy{U32Booly: map[uint32]bool{1: true, 3: false, 10: true, 12: false}}, `{"u32booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"map", marshaler, &pb.Mappy{U64Booly: map[uint64]bool{1: true, 3: false, 10: true, 12: false}}, `{"u64booly":{"1":true,"3":false,"10":true,"12":false}}`}, + {"proto2 map", marshaler, &pb.Maps{MInt64Str: map[int64]string{213: "cat"}}, + `{"mInt64Str":{"213":"cat"}}`}, + {"proto2 map", marshaler, + &pb.Maps{MBoolSimple: map[bool]*pb.Simple{true: {OInt32: proto.Int32(1)}}}, + `{"mBoolSimple":{"true":{"oInt32":1}}}`}, + {"oneof, not set", marshaler, &pb.MsgWithOneof{}, `{}`}, + {"oneof, set", marshaler, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Title{Title: "Grand Poobah"}}, `{"title":"Grand Poobah"}`}, + {"force orig_name", Marshaler{OrigName: true}, &pb.Simple{OInt32: proto.Int32(4)}, + `{"o_int32":4}`}, + {"proto2 extension", marshaler, realNumber, realNumberJSON}, + {"Any with message", marshaler, anySimple, anySimpleJSON}, + {"Any with message and indent", marshalerAllOptions, anySimple, anySimplePrettyJSON}, + {"Any with WKT", marshaler, anyWellKnown, anyWellKnownJSON}, + {"Any with WKT and indent", marshalerAllOptions, anyWellKnown, anyWellKnownPrettyJSON}, + {"Duration", marshaler, &pb.KnownTypes{Dur: &types.Duration{Seconds: 3}}, `{"dur":"3.000s"}`}, + {"Struct", marshaler, &pb.KnownTypes{St: &types.Struct{ + Fields: map[string]*types.Value{ + "one": {Kind: &types.Value_StringValue{StringValue: "loneliest number"}}, + "two": {Kind: &types.Value_NullValue{NullValue: types.NULL_VALUE}}, + }, + }}, `{"st":{"one":"loneliest number","two":null}}`}, + {"empty ListValue", marshaler, &pb.KnownTypes{Lv: &types.ListValue{}}, `{"lv":[]}`}, + {"basic ListValue", marshaler, &pb.KnownTypes{Lv: &types.ListValue{Values: []*types.Value{ + {Kind: &types.Value_StringValue{StringValue: "x"}}, + {Kind: &types.Value_NullValue{}}, + {Kind: &types.Value_NumberValue{NumberValue: 3}}, + {Kind: &types.Value_BoolValue{BoolValue: true}}, + }}}, `{"lv":["x",null,3,true]}`}, + {"Timestamp", marshaler, &pb.KnownTypes{Ts: &types.Timestamp{Seconds: 14e8, Nanos: 21e6}}, `{"ts":"2014-05-13T16:53:20.021Z"}`}, + {"number Value", marshaler, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_NumberValue{NumberValue: 1}}}, `{"val":1}`}, + {"null Value", marshaler, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_NullValue{NullValue: types.NULL_VALUE}}}, `{"val":null}`}, + {"string number value", marshaler, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_StringValue{StringValue: "9223372036854775807"}}}, `{"val":"9223372036854775807"}`}, + {"list of lists Value", marshaler, &pb.KnownTypes{Val: &types.Value{ + Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{ + {Kind: &types.Value_StringValue{StringValue: "x"}}, + {Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{ + {Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{{Kind: &types.Value_StringValue{StringValue: "y"}}}, + }}}, + {Kind: &types.Value_StringValue{StringValue: "z"}}, + }, + }}}, + }, + }}, + }}, `{"val":["x",[["y"],"z"]]}`}, + {"DoubleValue", marshaler, &pb.KnownTypes{Dbl: &types.DoubleValue{Value: 1.2}}, `{"dbl":1.2}`}, + {"FloatValue", marshaler, &pb.KnownTypes{Flt: &types.FloatValue{Value: 1.2}}, `{"flt":1.2}`}, + {"Int64Value", marshaler, &pb.KnownTypes{I64: &types.Int64Value{Value: -3}}, `{"i64":"-3"}`}, + {"UInt64Value", marshaler, &pb.KnownTypes{U64: &types.UInt64Value{Value: 3}}, `{"u64":"3"}`}, + {"Int32Value", marshaler, &pb.KnownTypes{I32: &types.Int32Value{Value: -4}}, `{"i32":-4}`}, + {"UInt32Value", marshaler, &pb.KnownTypes{U32: &types.UInt32Value{Value: 4}}, `{"u32":4}`}, + {"BoolValue", marshaler, &pb.KnownTypes{Bool: &types.BoolValue{Value: true}}, `{"bool":true}`}, + {"StringValue", marshaler, &pb.KnownTypes{Str: &types.StringValue{Value: "plush"}}, `{"str":"plush"}`}, + {"BytesValue", marshaler, &pb.KnownTypes{Bytes: &types.BytesValue{Value: []byte("wow")}}, `{"bytes":"d293"}`}, +} + +func TestMarshaling(t *testing.T) { + for _, tt := range marshalingTests { + json, err := tt.marshaler.MarshalToString(tt.pb) + if err != nil { + t.Errorf("%s: marshaling error: %v", tt.desc, err) + } else if tt.json != json { + t.Errorf("%s: got [%v] want [%v]", tt.desc, json, tt.json) + } + } +} + +func TestMarshalJSONPBMarshaler(t *testing.T) { + rawJson := `{ "foo": "bar", "baz": [0, 1, 2, 3] }` + msg := dynamicMessage{rawJson: rawJson} + str, err := new(Marshaler).MarshalToString(&msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshalling JSONPBMarshaler: %v", err) + } + if str != rawJson { + t.Errorf("marshalling JSON produced incorrect output: got %s, wanted %s", str, rawJson) + } +} + +func TestMarshalAnyJSONPBMarshaler(t *testing.T) { + msg := dynamicMessage{rawJson: `{ "foo": "bar", "baz": [0, 1, 2, 3] }`} + a, err := types.MarshalAny(&msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshalling to Any: %v", err) + } + str, err := new(Marshaler).MarshalToString(a) + if err != nil { + t.Errorf("an unexpected error occurred when marshalling Any to JSON: %v", err) + } + // after custom marshaling, it's round-tripped through JSON decoding/encoding already, + // so the keys are sorted, whitespace is compacted, and "@type" key has been added + expected := `{"@type":"type.googleapis.com/` + dynamicMessageName + `","baz":[0,1,2,3],"foo":"bar"}` + if str != expected { + t.Errorf("marshalling JSON produced incorrect output: got %s, wanted %s", str, expected) + } +} + +var unmarshalingTests = []struct { + desc string + unmarshaler Unmarshaler + json string + pb proto.Message +}{ + {"simple flat object", Unmarshaler{}, simpleObjectJSON, simpleObject}, + {"simple pretty object", Unmarshaler{}, simpleObjectPrettyJSON, simpleObject}, + {"repeated fields flat object", Unmarshaler{}, repeatsObjectJSON, repeatsObject}, + {"repeated fields pretty object", Unmarshaler{}, repeatsObjectPrettyJSON, repeatsObject}, + {"nested message/enum flat object", Unmarshaler{}, complexObjectJSON, complexObject}, + {"nested message/enum pretty object", Unmarshaler{}, complexObjectPrettyJSON, complexObject}, + {"enum-string object", Unmarshaler{}, `{"color":"BLUE"}`, &pb.Widget{Color: pb.Widget_BLUE.Enum()}}, + {"enum-value object", Unmarshaler{}, "{\n \"color\": 2\n}", &pb.Widget{Color: pb.Widget_BLUE.Enum()}}, + {"unknown field with allowed option", Unmarshaler{AllowUnknownFields: true}, `{"unknown": "foo"}`, new(pb.Simple)}, + {"proto3 enum string", Unmarshaler{}, `{"hilarity":"PUNS"}`, &proto3pb.Message{Hilarity: proto3pb.Message_PUNS}}, + {"proto3 enum value", Unmarshaler{}, `{"hilarity":1}`, &proto3pb.Message{Hilarity: proto3pb.Message_PUNS}}, + {"unknown enum value object", + Unmarshaler{}, + "{\n \"color\": 1000,\n \"r_color\": [\n \"RED\"\n ]\n}", + &pb.Widget{Color: pb.Widget_Color(1000).Enum(), RColor: []pb.Widget_Color{pb.Widget_RED}}}, + {"repeated proto3 enum", Unmarshaler{}, `{"rFunny":["PUNS","SLAPSTICK"]}`, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}}, + {"repeated proto3 enum as int", Unmarshaler{}, `{"rFunny":[1,2]}`, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}}, + {"repeated proto3 enum as mix of strings and ints", Unmarshaler{}, `{"rFunny":["PUNS",2]}`, + &proto3pb.Message{RFunny: []proto3pb.Message_Humour{ + proto3pb.Message_PUNS, + proto3pb.Message_SLAPSTICK, + }}}, + {"unquoted int64 object", Unmarshaler{}, `{"oInt64":-314}`, &pb.Simple{OInt64: proto.Int64(-314)}}, + {"unquoted uint64 object", Unmarshaler{}, `{"oUint64":123}`, &pb.Simple{OUint64: proto.Uint64(123)}}, + {"NaN", Unmarshaler{}, `{"oDouble":"NaN"}`, &pb.Simple{ODouble: proto.Float64(math.NaN())}}, + {"Inf", Unmarshaler{}, `{"oFloat":"Infinity"}`, &pb.Simple{OFloat: proto.Float32(float32(math.Inf(1)))}}, + {"-Inf", Unmarshaler{}, `{"oDouble":"-Infinity"}`, &pb.Simple{ODouble: proto.Float64(math.Inf(-1))}}, + {"map", Unmarshaler{}, `{"nummy":{"1":2,"3":4}}`, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}}, + {"map", Unmarshaler{}, `{"strry":{"\"one\"":"two","three":"four"}}`, &pb.Mappy{Strry: map[string]string{`"one"`: "two", "three": "four"}}}, + {"map", Unmarshaler{}, `{"objjy":{"1":{"dub":1}}}`, &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: {Dub: 1}}}}, + {"proto2 extension", Unmarshaler{}, realNumberJSON, realNumber}, + // TODO does not work with go version 1.7, but works with go version 1.8 {"Any with message", Unmarshaler{}, anySimpleJSON, anySimple}, + // TODO does not work with go version 1.7, but works with go version 1.8 {"Any with message and indent", Unmarshaler{}, anySimplePrettyJSON, anySimple}, + {"Any with WKT", Unmarshaler{}, anyWellKnownJSON, anyWellKnown}, + {"Any with WKT and indent", Unmarshaler{}, anyWellKnownPrettyJSON, anyWellKnown}, + // TODO: This is broken. + //{"map", Unmarshaler{}, `{"enumy":{"XIV":"ROMAN"}`, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}}, + {"map", Unmarshaler{}, `{"enumy":{"XIV":2}}`, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}}, + {"oneof", Unmarshaler{}, `{"salary":31000}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Salary{Salary: 31000}}}, + {"oneof spec name", Unmarshaler{}, `{"Country":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Country{Country: "Australia"}}}, + {"oneof orig_name", Unmarshaler{}, `{"Country":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Country{Country: "Australia"}}}, + {"oneof spec name2", Unmarshaler{}, `{"homeAddress":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_HomeAddress{HomeAddress: "Australia"}}}, + {"oneof orig_name2", Unmarshaler{}, `{"home_address":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_HomeAddress{HomeAddress: "Australia"}}}, + {"orig_name input", Unmarshaler{}, `{"o_bool":true}`, &pb.Simple{OBool: proto.Bool(true)}}, + {"camelName input", Unmarshaler{}, `{"oBool":true}`, &pb.Simple{OBool: proto.Bool(true)}}, + {"Duration", Unmarshaler{}, `{"dur":"3.000s"}`, &pb.KnownTypes{Dur: &types.Duration{Seconds: 3}}}, + {"null Duration", Unmarshaler{}, `{"dur":null}`, &pb.KnownTypes{Dur: nil}}, + {"Timestamp", Unmarshaler{}, `{"ts":"2014-05-13T16:53:20.021Z"}`, &pb.KnownTypes{Ts: &types.Timestamp{Seconds: 14e8, Nanos: 21e6}}}, + {"PreEpochTimestamp", Unmarshaler{}, `{"ts":"1969-12-31T23:59:58.999999995Z"}`, &pb.KnownTypes{Ts: &types.Timestamp{Seconds: -2, Nanos: 999999995}}}, + {"ZeroTimeTimestamp", Unmarshaler{}, `{"ts":"0001-01-01T00:00:00Z"}`, &pb.KnownTypes{Ts: &types.Timestamp{Seconds: -62135596800, Nanos: 0}}}, + {"null Timestamp", Unmarshaler{}, `{"ts":null}`, &pb.KnownTypes{Ts: nil}}, + {"null Struct", Unmarshaler{}, `{"st": null}`, &pb.KnownTypes{St: nil}}, + {"empty Struct", Unmarshaler{}, `{"st": {}}`, &pb.KnownTypes{St: &types.Struct{}}}, + {"basic Struct", Unmarshaler{}, `{"st": {"a": "x", "b": null, "c": 3, "d": true}}`, &pb.KnownTypes{St: &types.Struct{Fields: map[string]*types.Value{ + "a": {Kind: &types.Value_StringValue{StringValue: "x"}}, + "b": {Kind: &types.Value_NullValue{}}, + "c": {Kind: &types.Value_NumberValue{NumberValue: 3}}, + "d": {Kind: &types.Value_BoolValue{BoolValue: true}}, + }}}}, + {"nested Struct", Unmarshaler{}, `{"st": {"a": {"b": 1, "c": [{"d": true}, "f"]}}}`, &pb.KnownTypes{St: &types.Struct{Fields: map[string]*types.Value{ + "a": {Kind: &types.Value_StructValue{StructValue: &types.Struct{Fields: map[string]*types.Value{ + "b": {Kind: &types.Value_NumberValue{NumberValue: 1}}, + "c": {Kind: &types.Value_ListValue{ListValue: &types.ListValue{Values: []*types.Value{ + {Kind: &types.Value_StructValue{StructValue: &types.Struct{Fields: map[string]*types.Value{"d": {Kind: &types.Value_BoolValue{BoolValue: true}}}}}}, + {Kind: &types.Value_StringValue{StringValue: "f"}}, + }}}}, + }}}}, + }}}}, + {"null ListValue", Unmarshaler{}, `{"lv": null}`, &pb.KnownTypes{Lv: nil}}, + {"empty ListValue", Unmarshaler{}, `{"lv": []}`, &pb.KnownTypes{Lv: &types.ListValue{}}}, + {"basic ListValue", Unmarshaler{}, `{"lv": ["x", null, 3, true]}`, &pb.KnownTypes{Lv: &types.ListValue{Values: []*types.Value{ + {Kind: &types.Value_StringValue{StringValue: "x"}}, + {Kind: &types.Value_NullValue{}}, + {Kind: &types.Value_NumberValue{NumberValue: 3}}, + {Kind: &types.Value_BoolValue{BoolValue: true}}, + }}}}, + {"number Value", Unmarshaler{}, `{"val":1}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_NumberValue{NumberValue: 1}}}}, + {"null Value", Unmarshaler{}, `{"val":null}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_NullValue{NullValue: types.NULL_VALUE}}}}, + {"bool Value", Unmarshaler{}, `{"val":true}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_BoolValue{BoolValue: true}}}}, + {"string Value", Unmarshaler{}, `{"val":"x"}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_StringValue{StringValue: "x"}}}}, + {"string number value", Unmarshaler{}, `{"val":"9223372036854775807"}`, &pb.KnownTypes{Val: &types.Value{Kind: &types.Value_StringValue{StringValue: "9223372036854775807"}}}}, + {"list of lists Value", Unmarshaler{}, `{"val":["x", [["y"], "z"]]}`, &pb.KnownTypes{Val: &types.Value{ + Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{ + {Kind: &types.Value_StringValue{StringValue: "x"}}, + {Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{ + {Kind: &types.Value_ListValue{ListValue: &types.ListValue{ + Values: []*types.Value{{Kind: &types.Value_StringValue{StringValue: "y"}}}, + }}}, + {Kind: &types.Value_StringValue{StringValue: "z"}}, + }, + }}}, + }, + }}}}}, + + {"DoubleValue", Unmarshaler{}, `{"dbl":1.2}`, &pb.KnownTypes{Dbl: &types.DoubleValue{Value: 1.2}}}, + {"FloatValue", Unmarshaler{}, `{"flt":1.2}`, &pb.KnownTypes{Flt: &types.FloatValue{Value: 1.2}}}, + {"Int64Value", Unmarshaler{}, `{"i64":"-3"}`, &pb.KnownTypes{I64: &types.Int64Value{Value: -3}}}, + {"UInt64Value", Unmarshaler{}, `{"u64":"3"}`, &pb.KnownTypes{U64: &types.UInt64Value{Value: 3}}}, + {"Int32Value", Unmarshaler{}, `{"i32":-4}`, &pb.KnownTypes{I32: &types.Int32Value{Value: -4}}}, + {"UInt32Value", Unmarshaler{}, `{"u32":4}`, &pb.KnownTypes{U32: &types.UInt32Value{Value: 4}}}, + {"BoolValue", Unmarshaler{}, `{"bool":true}`, &pb.KnownTypes{Bool: &types.BoolValue{Value: true}}}, + {"StringValue", Unmarshaler{}, `{"str":"plush"}`, &pb.KnownTypes{Str: &types.StringValue{Value: "plush"}}}, + {"BytesValue", Unmarshaler{}, `{"bytes":"d293"}`, &pb.KnownTypes{Bytes: &types.BytesValue{Value: []byte("wow")}}}, + // Ensure that `null` as a value ends up with a nil pointer instead of a [type]Value struct. + {"null DoubleValue", Unmarshaler{}, `{"dbl":null}`, &pb.KnownTypes{Dbl: nil}}, + {"null FloatValue", Unmarshaler{}, `{"flt":null}`, &pb.KnownTypes{Flt: nil}}, + {"null Int64Value", Unmarshaler{}, `{"i64":null}`, &pb.KnownTypes{I64: nil}}, + {"null UInt64Value", Unmarshaler{}, `{"u64":null}`, &pb.KnownTypes{U64: nil}}, + {"null Int32Value", Unmarshaler{}, `{"i32":null}`, &pb.KnownTypes{I32: nil}}, + {"null UInt32Value", Unmarshaler{}, `{"u32":null}`, &pb.KnownTypes{U32: nil}}, + {"null BoolValue", Unmarshaler{}, `{"bool":null}`, &pb.KnownTypes{Bool: nil}}, + {"null StringValue", Unmarshaler{}, `{"str":null}`, &pb.KnownTypes{Str: nil}}, + {"null BytesValue", Unmarshaler{}, `{"bytes":null}`, &pb.KnownTypes{Bytes: nil}}, +} + +func TestUnmarshaling(t *testing.T) { + for _, tt := range unmarshalingTests { + // Make a new instance of the type of our expected object. + p := reflect.New(reflect.TypeOf(tt.pb).Elem()).Interface().(proto.Message) + + err := tt.unmarshaler.Unmarshal(strings.NewReader(tt.json), p) + if err != nil { + t.Errorf("%s: %v", tt.desc, err) + continue + } + + // For easier diffs, compare text strings of the protos. + exp := proto.MarshalTextString(tt.pb) + act := proto.MarshalTextString(p) + if string(exp) != string(act) { + t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp) + } + } +} + +func TestUnmarshalNullArray(t *testing.T) { + var repeats pb.Repeats + if err := UnmarshalString(`{"rBool":null}`, &repeats); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(repeats, pb.Repeats{}) { + t.Errorf("got non-nil fields in [%#v]", repeats) + } +} + +func TestUnmarshalNullObject(t *testing.T) { + var maps pb.Maps + if err := UnmarshalString(`{"mInt64Str":null}`, &maps); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(maps, pb.Maps{}) { + t.Errorf("got non-nil fields in [%#v]", maps) + } +} + +func TestUnmarshalNext(t *testing.T) { + // We only need to check against a few, not all of them. + tests := unmarshalingTests[:5] + + // Create a buffer with many concatenated JSON objects. + var b bytes.Buffer + for _, tt := range tests { + b.WriteString(tt.json) + } + + dec := json.NewDecoder(&b) + for _, tt := range tests { + // Make a new instance of the type of our expected object. + p := reflect.New(reflect.TypeOf(tt.pb).Elem()).Interface().(proto.Message) + + err := tt.unmarshaler.UnmarshalNext(dec, p) + if err != nil { + t.Errorf("%s: %v", tt.desc, err) + continue + } + + // For easier diffs, compare text strings of the protos. + exp := proto.MarshalTextString(tt.pb) + act := proto.MarshalTextString(p) + if string(exp) != string(act) { + t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp) + } + } + + p := &pb.Simple{} + err := new(Unmarshaler).UnmarshalNext(dec, p) + if err != io.EOF { + t.Errorf("eof: got %v, expected io.EOF", err) + } +} + +var unmarshalingShouldError = []struct { + desc string + in string + pb proto.Message +}{ + {"a value", "666", new(pb.Simple)}, + {"gibberish", "{adskja123;l23=-=", new(pb.Simple)}, + {"unknown field", `{"unknown": "foo"}`, new(pb.Simple)}, + {"unknown enum name", `{"hilarity":"DAVE"}`, new(proto3pb.Message)}, +} + +func TestUnmarshalingBadInput(t *testing.T) { + for _, tt := range unmarshalingShouldError { + err := UnmarshalString(tt.in, tt.pb) + if err == nil { + t.Errorf("an error was expected when parsing %q instead of an object", tt.desc) + } + } +} + +type funcResolver func(turl string) (proto.Message, error) + +func (fn funcResolver) Resolve(turl string) (proto.Message, error) { + return fn(turl) +} + +func TestAnyWithCustomResolver(t *testing.T) { + var resolvedTypeUrls []string + resolver := funcResolver(func(turl string) (proto.Message, error) { + resolvedTypeUrls = append(resolvedTypeUrls, turl) + return new(pb.Simple), nil + }) + msg := &pb.Simple{ + OBytes: []byte{1, 2, 3, 4}, + OBool: proto.Bool(true), + OString: proto.String("foobar"), + OInt64: proto.Int64(1020304), + } + msgBytes, err := proto.Marshal(msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshaling message: %v", err) + } + // make an Any with a type URL that won't resolve w/out custom resolver + any := &types.Any{ + TypeUrl: "https://foobar.com/some.random.MessageKind", + Value: msgBytes, + } + + m := Marshaler{AnyResolver: resolver} + js, err := m.MarshalToString(any) + if err != nil { + t.Errorf("an unexpected error occurred when marshaling any to JSON: %v", err) + } + if len(resolvedTypeUrls) != 1 { + t.Errorf("custom resolver was not invoked during marshaling") + } else if resolvedTypeUrls[0] != "https://foobar.com/some.random.MessageKind" { + t.Errorf("custom resolver was invoked with wrong URL: got %q, wanted %q", resolvedTypeUrls[0], "https://foobar.com/some.random.MessageKind") + } + wanted := `{"@type":"https://foobar.com/some.random.MessageKind","oBool":true,"oInt64":"1020304","oString":"foobar","oBytes":"AQIDBA=="}` + if js != wanted { + t.Errorf("marshalling JSON produced incorrect output: got %s, wanted %s", js, wanted) + } + + u := Unmarshaler{AnyResolver: resolver} + roundTrip := &types.Any{} + err = u.Unmarshal(bytes.NewReader([]byte(js)), roundTrip) + if err != nil { + t.Errorf("an unexpected error occurred when unmarshaling any from JSON: %v", err) + } + if len(resolvedTypeUrls) != 2 { + t.Errorf("custom resolver was not invoked during marshaling") + } else if resolvedTypeUrls[1] != "https://foobar.com/some.random.MessageKind" { + t.Errorf("custom resolver was invoked with wrong URL: got %q, wanted %q", resolvedTypeUrls[1], "https://foobar.com/some.random.MessageKind") + } + if !proto.Equal(any, roundTrip) { + t.Errorf("message contents not set correctly after unmarshalling JSON: got %s, wanted %s", roundTrip, any) + } +} + +func TestUnmarshalJSONPBUnmarshaler(t *testing.T) { + rawJson := `{ "foo": "bar", "baz": [0, 1, 2, 3] }` + var msg dynamicMessage + if err := Unmarshal(strings.NewReader(rawJson), &msg); err != nil { + t.Errorf("an unexpected error occurred when parsing into JSONPBUnmarshaler: %v", err) + } + if msg.rawJson != rawJson { + t.Errorf("message contents not set correctly after unmarshalling JSON: got %s, wanted %s", msg.rawJson, rawJson) + } +} + +func TestUnmarshalNullWithJSONPBUnmarshaler(t *testing.T) { + rawJson := `{"stringField":null}` + var ptrFieldMsg ptrFieldMessage + if err := Unmarshal(strings.NewReader(rawJson), &ptrFieldMsg); err != nil { + t.Errorf("unmarshal error: %v", err) + } + + want := ptrFieldMessage{StringField: &stringField{IsSet: true, StringValue: "null"}} + if !proto.Equal(&ptrFieldMsg, &want) { + t.Errorf("unmarshal result StringField: got %v, want %v", ptrFieldMsg, want) + } +} + +func TestUnmarshalAnyJSONPBUnmarshaler(t *testing.T) { + rawJson := `{ "@type": "blah.com/` + dynamicMessageName + `", "foo": "bar", "baz": [0, 1, 2, 3] }` + var got types.Any + if err := Unmarshal(strings.NewReader(rawJson), &got); err != nil { + t.Errorf("an unexpected error occurred when parsing into JSONPBUnmarshaler: %v", err) + } + + dm := &dynamicMessage{rawJson: `{"baz":[0,1,2,3],"foo":"bar"}`} + var want types.Any + if b, err := proto.Marshal(dm); err != nil { + t.Errorf("an unexpected error occurred when marshaling message: %v", err) + } else { + want.TypeUrl = "blah.com/" + dynamicMessageName + want.Value = b + } + + if !proto.Equal(&got, &want) { + t.Errorf("message contents not set correctly after unmarshalling JSON: got %s, wanted %s", got, want) + } +} + +const ( + dynamicMessageName = "google.protobuf.jsonpb.testing.dynamicMessage" +) + +func init() { + // we register the custom type below so that we can use it in Any types + proto.RegisterType((*dynamicMessage)(nil), dynamicMessageName) +} + +type ptrFieldMessage struct { + StringField *stringField `protobuf:"bytes,1,opt,name=stringField"` +} + +func (m *ptrFieldMessage) Reset() { +} + +func (m *ptrFieldMessage) String() string { + return m.StringField.StringValue +} + +func (m *ptrFieldMessage) ProtoMessage() { +} + +type stringField struct { + IsSet bool `protobuf:"varint,1,opt,name=isSet"` + StringValue string `protobuf:"bytes,2,opt,name=stringValue"` +} + +func (s *stringField) Reset() { +} + +func (s *stringField) String() string { + return s.StringValue +} + +func (s *stringField) ProtoMessage() { +} + +func (s *stringField) UnmarshalJSONPB(jum *Unmarshaler, js []byte) error { + s.IsSet = true + s.StringValue = string(js) + return nil +} + +// dynamicMessage implements protobuf.Message but is not a normal generated message type. +// It provides implementations of JSONPBMarshaler and JSONPBUnmarshaler for JSON support. +type dynamicMessage struct { + rawJson string `protobuf:"bytes,1,opt,name=rawJson"` +} + +func (m *dynamicMessage) Reset() { + m.rawJson = "{}" +} + +func (m *dynamicMessage) String() string { + return m.rawJson +} + +func (m *dynamicMessage) ProtoMessage() { +} + +func (m *dynamicMessage) MarshalJSONPB(jm *Marshaler) ([]byte, error) { + return []byte(m.rawJson), nil +} + +func (m *dynamicMessage) UnmarshalJSONPB(jum *Unmarshaler, js []byte) error { + m.rawJson = string(js) + return nil +} diff --git a/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test_proto/Makefile b/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test_proto/Makefile new file mode 100644 index 000000000..e294f68dd --- /dev/null +++ b/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test_proto/Makefile @@ -0,0 +1,33 @@ +# Go support for Protocol Buffers - Google's data interchange format +# +# Copyright 2015 The Go Authors. All rights reserved. +# https://github.com/golang/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + protoc-min-version --version="3.0.0" --gogo_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types:. *.proto -I . -I ../../ -I ../../protobuf/ diff --git a/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test_proto/more_test_objects.proto b/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test_proto/more_test_objects.proto new file mode 100644 index 000000000..d254fa5fa --- /dev/null +++ b/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test_proto/more_test_objects.proto @@ -0,0 +1,69 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2015 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package jsonpb; + +message Simple3 { + double dub = 1; +} + +message SimpleSlice3 { + repeated string slices = 1; +} + +message SimpleMap3 { + map stringy = 1; +} + +message SimpleNull3 { + Simple3 simple = 1; +} + +enum Numeral { + UNKNOWN = 0; + ARABIC = 1; + ROMAN = 2; +} + +message Mappy { + map nummy = 1; + map strry = 2; + map objjy = 3; + map buggy = 4; + map booly = 5; + map enumy = 6; + map s32booly = 7; + map s64booly = 8; + map u32booly = 9; + map u64booly = 10; +} diff --git a/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test_proto/test_objects.proto b/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test_proto/test_objects.proto new file mode 100644 index 000000000..a7bdac63c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/jsonpb/jsonpb_test_proto/test_objects.proto @@ -0,0 +1,151 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2015 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +package jsonpb; + +import weak "gogoproto/gogo.proto"; + +// Test message for holding primitive types. +message Simple { + optional bool o_bool = 1; + optional int32 o_int32 = 2; + optional int64 o_int64 = 3; + optional uint32 o_uint32 = 4; + optional uint64 o_uint64 = 5; + optional sint32 o_sint32 = 6; + optional sint64 o_sint64 = 7; + optional float o_float = 8; + optional double o_double = 9; + optional string o_string = 10; + optional bytes o_bytes = 11; + optional bytes o_cast_bytes = 12 [(gogoproto.casttype) = "Bytes"]; +} + +// Test message for holding special non-finites primitives. +message NonFinites { + optional float f_nan = 1; + optional float f_pinf = 2; + optional float f_ninf = 3; + optional double d_nan = 4; + optional double d_pinf = 5; + optional double d_ninf = 6; +} + + +// Test message for holding repeated primitives. +message Repeats { + repeated bool r_bool = 1; + repeated int32 r_int32 = 2; + repeated int64 r_int64 = 3; + repeated uint32 r_uint32 = 4; + repeated uint64 r_uint64 = 5; + repeated sint32 r_sint32 = 6; + repeated sint64 r_sint64 = 7; + repeated float r_float = 8; + repeated double r_double = 9; + repeated string r_string = 10; + repeated bytes r_bytes = 11; +} + +// Test message for holding enums and nested messages. +message Widget { + enum Color { + RED = 0; + GREEN = 1; + BLUE = 2; + }; + optional Color color = 1; + repeated Color r_color = 2; + + optional Simple simple = 10; + repeated Simple r_simple = 11; + + optional Repeats repeats = 20; + repeated Repeats r_repeats = 21; +} + +message Maps { + map m_int64_str = 1; + map m_bool_simple = 2; +} + +message MsgWithOneof { + oneof union { + string title = 1; + int64 salary = 2; + string Country = 3; + string home_address = 4; + } +} + +message Real { + optional double value = 1; + extensions 100 to max; +} + +extend Real { + optional string name = 124; +} + +message Complex { + extend Real { + optional Complex real_extension = 123; + } + optional double imaginary = 1; + extensions 100 to max; +} + +message KnownTypes { + optional google.protobuf.Any an = 14; + optional google.protobuf.Duration dur = 1; + optional google.protobuf.Struct st = 12; + optional google.protobuf.Timestamp ts = 2; + optional google.protobuf.ListValue lv = 15; + optional google.protobuf.Value val = 16; + + optional google.protobuf.DoubleValue dbl = 3; + optional google.protobuf.FloatValue flt = 4; + optional google.protobuf.Int64Value i64 = 5; + optional google.protobuf.UInt64Value u64 = 6; + optional google.protobuf.Int32Value i32 = 7; + optional google.protobuf.UInt32Value u32 = 8; + optional google.protobuf.BoolValue bool = 9; + optional google.protobuf.StringValue str = 10; + optional google.protobuf.BytesValue bytes = 11; +} diff --git a/vendor/github.com/gogo/protobuf/proto/Makefile b/vendor/github.com/gogo/protobuf/proto/Makefile new file mode 100644 index 000000000..41c717573 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/Makefile @@ -0,0 +1,43 @@ +# Go support for Protocol Buffers - Google's data interchange format +# +# Copyright 2010 The Go Authors. All rights reserved. +# https://github.com/golang/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +install: + go install + +test: install generate-test-pbs + go test + + +generate-test-pbs: + make install + make -C testdata + protoc-min-version --version="3.0.0" --proto_path=.:../../../../:../protobuf --gogo_out=Mtestdata/test.proto=github.com/gogo/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types:. proto3_proto/proto3.proto + make diff --git a/vendor/github.com/gogo/protobuf/proto/all_test.go b/vendor/github.com/gogo/protobuf/proto/all_test.go new file mode 100644 index 000000000..b5f8709d8 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/all_test.go @@ -0,0 +1,2278 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "math" + "math/rand" + "reflect" + "runtime/debug" + "strings" + "testing" + "time" + + . "github.com/gogo/protobuf/proto" + . "github.com/gogo/protobuf/proto/testdata" +) + +var globalO *Buffer + +func old() *Buffer { + if globalO == nil { + globalO = NewBuffer(nil) + } + globalO.Reset() + return globalO +} + +func equalbytes(b1, b2 []byte, t *testing.T) { + if len(b1) != len(b2) { + t.Errorf("wrong lengths: 2*%d != %d", len(b1), len(b2)) + return + } + for i := 0; i < len(b1); i++ { + if b1[i] != b2[i] { + t.Errorf("bad byte[%d]:%x %x: %s %s", i, b1[i], b2[i], b1, b2) + } + } +} + +func initGoTestField() *GoTestField { + f := new(GoTestField) + f.Label = String("label") + f.Type = String("type") + return f +} + +// These are all structurally equivalent but the tag numbers differ. +// (It's remarkable that required, optional, and repeated all have +// 8 letters.) +func initGoTest_RequiredGroup() *GoTest_RequiredGroup { + return &GoTest_RequiredGroup{ + RequiredField: String("required"), + } +} + +func initGoTest_OptionalGroup() *GoTest_OptionalGroup { + return &GoTest_OptionalGroup{ + RequiredField: String("optional"), + } +} + +func initGoTest_RepeatedGroup() *GoTest_RepeatedGroup { + return &GoTest_RepeatedGroup{ + RequiredField: String("repeated"), + } +} + +func initGoTest(setdefaults bool) *GoTest { + pb := new(GoTest) + if setdefaults { + pb.F_BoolDefaulted = Bool(Default_GoTest_F_BoolDefaulted) + pb.F_Int32Defaulted = Int32(Default_GoTest_F_Int32Defaulted) + pb.F_Int64Defaulted = Int64(Default_GoTest_F_Int64Defaulted) + pb.F_Fixed32Defaulted = Uint32(Default_GoTest_F_Fixed32Defaulted) + pb.F_Fixed64Defaulted = Uint64(Default_GoTest_F_Fixed64Defaulted) + pb.F_Uint32Defaulted = Uint32(Default_GoTest_F_Uint32Defaulted) + pb.F_Uint64Defaulted = Uint64(Default_GoTest_F_Uint64Defaulted) + pb.F_FloatDefaulted = Float32(Default_GoTest_F_FloatDefaulted) + pb.F_DoubleDefaulted = Float64(Default_GoTest_F_DoubleDefaulted) + pb.F_StringDefaulted = String(Default_GoTest_F_StringDefaulted) + pb.F_BytesDefaulted = Default_GoTest_F_BytesDefaulted + pb.F_Sint32Defaulted = Int32(Default_GoTest_F_Sint32Defaulted) + pb.F_Sint64Defaulted = Int64(Default_GoTest_F_Sint64Defaulted) + } + + pb.Kind = GoTest_TIME.Enum() + pb.RequiredField = initGoTestField() + pb.F_BoolRequired = Bool(true) + pb.F_Int32Required = Int32(3) + pb.F_Int64Required = Int64(6) + pb.F_Fixed32Required = Uint32(32) + pb.F_Fixed64Required = Uint64(64) + pb.F_Uint32Required = Uint32(3232) + pb.F_Uint64Required = Uint64(6464) + pb.F_FloatRequired = Float32(3232) + pb.F_DoubleRequired = Float64(6464) + pb.F_StringRequired = String("string") + pb.F_BytesRequired = []byte("bytes") + pb.F_Sint32Required = Int32(-32) + pb.F_Sint64Required = Int64(-64) + pb.Requiredgroup = initGoTest_RequiredGroup() + + return pb +} + +func fail(msg string, b *bytes.Buffer, s string, t *testing.T) { + data := b.Bytes() + ld := len(data) + ls := len(s) / 2 + + fmt.Printf("fail %s ld=%d ls=%d\n", msg, ld, ls) + + // find the interesting spot - n + n := ls + if ld < ls { + n = ld + } + j := 0 + for i := 0; i < n; i++ { + bs := hex(s[j])*16 + hex(s[j+1]) + j += 2 + if data[i] == bs { + continue + } + n = i + break + } + l := n - 10 + if l < 0 { + l = 0 + } + h := n + 10 + + // find the interesting spot - n + fmt.Printf("is[%d]:", l) + for i := l; i < h; i++ { + if i >= ld { + fmt.Printf(" --") + continue + } + fmt.Printf(" %.2x", data[i]) + } + fmt.Printf("\n") + + fmt.Printf("sb[%d]:", l) + for i := l; i < h; i++ { + if i >= ls { + fmt.Printf(" --") + continue + } + bs := hex(s[j])*16 + hex(s[j+1]) + j += 2 + fmt.Printf(" %.2x", bs) + } + fmt.Printf("\n") + + t.Fail() + + // t.Errorf("%s: \ngood: %s\nbad: %x", msg, s, b.Bytes()) + // Print the output in a partially-decoded format; can + // be helpful when updating the test. It produces the output + // that is pasted, with minor edits, into the argument to verify(). + // data := b.Bytes() + // nesting := 0 + // for b.Len() > 0 { + // start := len(data) - b.Len() + // var u uint64 + // u, err := DecodeVarint(b) + // if err != nil { + // fmt.Printf("decode error on varint:", err) + // return + // } + // wire := u & 0x7 + // tag := u >> 3 + // switch wire { + // case WireVarint: + // v, err := DecodeVarint(b) + // if err != nil { + // fmt.Printf("decode error on varint:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n", + // data[start:len(data)-b.Len()], tag, wire, v) + // case WireFixed32: + // v, err := DecodeFixed32(b) + // if err != nil { + // fmt.Printf("decode error on fixed32:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n", + // data[start:len(data)-b.Len()], tag, wire, v) + // case WireFixed64: + // v, err := DecodeFixed64(b) + // if err != nil { + // fmt.Printf("decode error on fixed64:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n", + // data[start:len(data)-b.Len()], tag, wire, v) + // case WireBytes: + // nb, err := DecodeVarint(b) + // if err != nil { + // fmt.Printf("decode error on bytes:", err) + // return + // } + // after_tag := len(data) - b.Len() + // str := make([]byte, nb) + // _, err = b.Read(str) + // if err != nil { + // fmt.Printf("decode error on bytes:", err) + // return + // } + // fmt.Printf("\t\t\"%x\" \"%x\" // field %d, encoding %d (FIELD)\n", + // data[start:after_tag], str, tag, wire) + // case WireStartGroup: + // nesting++ + // fmt.Printf("\t\t\"%x\"\t\t// start group field %d level %d\n", + // data[start:len(data)-b.Len()], tag, nesting) + // case WireEndGroup: + // fmt.Printf("\t\t\"%x\"\t\t// end group field %d level %d\n", + // data[start:len(data)-b.Len()], tag, nesting) + // nesting-- + // default: + // fmt.Printf("unrecognized wire type %d\n", wire) + // return + // } + // } +} + +func hex(c uint8) uint8 { + if '0' <= c && c <= '9' { + return c - '0' + } + if 'a' <= c && c <= 'f' { + return 10 + c - 'a' + } + if 'A' <= c && c <= 'F' { + return 10 + c - 'A' + } + return 0 +} + +func equal(b []byte, s string, t *testing.T) bool { + if 2*len(b) != len(s) { + // fail(fmt.Sprintf("wrong lengths: 2*%d != %d", len(b), len(s)), b, s, t) + fmt.Printf("wrong lengths: 2*%d != %d\n", len(b), len(s)) + return false + } + for i, j := 0, 0; i < len(b); i, j = i+1, j+2 { + x := hex(s[j])*16 + hex(s[j+1]) + if b[i] != x { + // fail(fmt.Sprintf("bad byte[%d]:%x %x", i, b[i], x), b, s, t) + fmt.Printf("bad byte[%d]:%x %x", i, b[i], x) + return false + } + } + return true +} + +func overify(t *testing.T, pb *GoTest, expected string) { + o := old() + err := o.Marshal(pb) + if err != nil { + fmt.Printf("overify marshal-1 err = %v", err) + o.DebugPrint("", o.Bytes()) + t.Fatalf("expected = %s", expected) + } + if !equal(o.Bytes(), expected, t) { + o.DebugPrint("overify neq 1", o.Bytes()) + t.Fatalf("expected = %s", expected) + } + + // Now test Unmarshal by recreating the original buffer. + pbd := new(GoTest) + err = o.Unmarshal(pbd) + if err != nil { + t.Fatalf("overify unmarshal err = %v", err) + o.DebugPrint("", o.Bytes()) + t.Fatalf("string = %s", expected) + } + o.Reset() + err = o.Marshal(pbd) + if err != nil { + t.Errorf("overify marshal-2 err = %v", err) + o.DebugPrint("", o.Bytes()) + t.Fatalf("string = %s", expected) + } + if !equal(o.Bytes(), expected, t) { + o.DebugPrint("overify neq 2", o.Bytes()) + t.Fatalf("string = %s", expected) + } +} + +// Simple tests for numeric encode/decode primitives (varint, etc.) +func TestNumericPrimitives(t *testing.T) { + for i := uint64(0); i < 1e6; i += 111 { + o := old() + if o.EncodeVarint(i) != nil { + t.Error("EncodeVarint") + break + } + x, e := o.DecodeVarint() + if e != nil { + t.Fatal("DecodeVarint") + } + if x != i { + t.Fatal("varint decode fail:", i, x) + } + + o = old() + if o.EncodeFixed32(i) != nil { + t.Fatal("encFixed32") + } + x, e = o.DecodeFixed32() + if e != nil { + t.Fatal("decFixed32") + } + if x != i { + t.Fatal("fixed32 decode fail:", i, x) + } + + o = old() + if o.EncodeFixed64(i*1234567) != nil { + t.Error("encFixed64") + break + } + x, e = o.DecodeFixed64() + if e != nil { + t.Error("decFixed64") + break + } + if x != i*1234567 { + t.Error("fixed64 decode fail:", i*1234567, x) + break + } + + o = old() + i32 := int32(i - 12345) + if o.EncodeZigzag32(uint64(i32)) != nil { + t.Fatal("EncodeZigzag32") + } + x, e = o.DecodeZigzag32() + if e != nil { + t.Fatal("DecodeZigzag32") + } + if x != uint64(uint32(i32)) { + t.Fatal("zigzag32 decode fail:", i32, x) + } + + o = old() + i64 := int64(i - 12345) + if o.EncodeZigzag64(uint64(i64)) != nil { + t.Fatal("EncodeZigzag64") + } + x, e = o.DecodeZigzag64() + if e != nil { + t.Fatal("DecodeZigzag64") + } + if x != uint64(i64) { + t.Fatal("zigzag64 decode fail:", i64, x) + } + } +} + +// fakeMarshaler is a simple struct implementing Marshaler and Message interfaces. +type fakeMarshaler struct { + b []byte + err error +} + +func (f *fakeMarshaler) Marshal() ([]byte, error) { return f.b, f.err } +func (f *fakeMarshaler) String() string { return fmt.Sprintf("Bytes: %v Error: %v", f.b, f.err) } +func (f *fakeMarshaler) ProtoMessage() {} +func (f *fakeMarshaler) Reset() {} + +type msgWithFakeMarshaler struct { + M *fakeMarshaler `protobuf:"bytes,1,opt,name=fake"` +} + +func (m *msgWithFakeMarshaler) String() string { return CompactTextString(m) } +func (m *msgWithFakeMarshaler) ProtoMessage() {} +func (m *msgWithFakeMarshaler) Reset() {} + +// Simple tests for proto messages that implement the Marshaler interface. +func TestMarshalerEncoding(t *testing.T) { + tests := []struct { + name string + m Message + want []byte + errType reflect.Type + }{ + { + name: "Marshaler that fails", + m: &fakeMarshaler{ + err: errors.New("some marshal err"), + b: []byte{5, 6, 7}, + }, + // Since the Marshal method returned bytes, they should be written to the + // buffer. (For efficiency, we assume that Marshal implementations are + // always correct w.r.t. RequiredNotSetError and output.) + want: []byte{5, 6, 7}, + errType: reflect.TypeOf(errors.New("some marshal err")), + }, + { + name: "Marshaler that fails with RequiredNotSetError", + m: &msgWithFakeMarshaler{ + M: &fakeMarshaler{ + err: &RequiredNotSetError{}, + b: []byte{5, 6, 7}, + }, + }, + // Since there's an error that can be continued after, + // the buffer should be written. + want: []byte{ + 10, 3, // for &msgWithFakeMarshaler + 5, 6, 7, // for &fakeMarshaler + }, + errType: reflect.TypeOf(&RequiredNotSetError{}), + }, + { + name: "Marshaler that succeeds", + m: &fakeMarshaler{ + b: []byte{0, 1, 2, 3, 4, 127, 255}, + }, + want: []byte{0, 1, 2, 3, 4, 127, 255}, + }, + } + for _, test := range tests { + b := NewBuffer(nil) + err := b.Marshal(test.m) + if reflect.TypeOf(err) != test.errType { + t.Errorf("%s: got err %T(%v) wanted %T", test.name, err, err, test.errType) + } + if !reflect.DeepEqual(test.want, b.Bytes()) { + t.Errorf("%s: got bytes %v wanted %v", test.name, b.Bytes(), test.want) + } + if size := Size(test.m); size != len(b.Bytes()) { + t.Errorf("%s: Size(_) = %v, but marshaled to %v bytes", test.name, size, len(b.Bytes())) + } + + m, mErr := Marshal(test.m) + if !bytes.Equal(b.Bytes(), m) { + t.Errorf("%s: Marshal returned %v, but (*Buffer).Marshal wrote %v", test.name, m, b.Bytes()) + } + if !reflect.DeepEqual(err, mErr) { + t.Errorf("%s: Marshal err = %q, but (*Buffer).Marshal returned %q", + test.name, fmt.Sprint(mErr), fmt.Sprint(err)) + } + } +} + +// Simple tests for bytes +func TestBytesPrimitives(t *testing.T) { + o := old() + bytes := []byte{'n', 'o', 'w', ' ', 'i', 's', ' ', 't', 'h', 'e', ' ', 't', 'i', 'm', 'e'} + if o.EncodeRawBytes(bytes) != nil { + t.Error("EncodeRawBytes") + } + decb, e := o.DecodeRawBytes(false) + if e != nil { + t.Error("DecodeRawBytes") + } + equalbytes(bytes, decb, t) +} + +// Simple tests for strings +func TestStringPrimitives(t *testing.T) { + o := old() + s := "now is the time" + if o.EncodeStringBytes(s) != nil { + t.Error("enc_string") + } + decs, e := o.DecodeStringBytes() + if e != nil { + t.Error("dec_string") + } + if s != decs { + t.Error("string encode/decode fail:", s, decs) + } +} + +// Do we catch the "required bit not set" case? +func TestRequiredBit(t *testing.T) { + o := old() + pb := new(GoTest) + err := o.Marshal(pb) + if err == nil { + t.Error("did not catch missing required fields") + } else if strings.Index(err.Error(), "Kind") < 0 { + t.Error("wrong error type:", err) + } +} + +// Check that all fields are nil. +// Clearly silly, and a residue from a more interesting test with an earlier, +// different initialization property, but it once caught a compiler bug so +// it lives. +func checkInitialized(pb *GoTest, t *testing.T) { + if pb.F_BoolDefaulted != nil { + t.Error("New or Reset did not set boolean:", *pb.F_BoolDefaulted) + } + if pb.F_Int32Defaulted != nil { + t.Error("New or Reset did not set int32:", *pb.F_Int32Defaulted) + } + if pb.F_Int64Defaulted != nil { + t.Error("New or Reset did not set int64:", *pb.F_Int64Defaulted) + } + if pb.F_Fixed32Defaulted != nil { + t.Error("New or Reset did not set fixed32:", *pb.F_Fixed32Defaulted) + } + if pb.F_Fixed64Defaulted != nil { + t.Error("New or Reset did not set fixed64:", *pb.F_Fixed64Defaulted) + } + if pb.F_Uint32Defaulted != nil { + t.Error("New or Reset did not set uint32:", *pb.F_Uint32Defaulted) + } + if pb.F_Uint64Defaulted != nil { + t.Error("New or Reset did not set uint64:", *pb.F_Uint64Defaulted) + } + if pb.F_FloatDefaulted != nil { + t.Error("New or Reset did not set float:", *pb.F_FloatDefaulted) + } + if pb.F_DoubleDefaulted != nil { + t.Error("New or Reset did not set double:", *pb.F_DoubleDefaulted) + } + if pb.F_StringDefaulted != nil { + t.Error("New or Reset did not set string:", *pb.F_StringDefaulted) + } + if pb.F_BytesDefaulted != nil { + t.Error("New or Reset did not set bytes:", string(pb.F_BytesDefaulted)) + } + if pb.F_Sint32Defaulted != nil { + t.Error("New or Reset did not set int32:", *pb.F_Sint32Defaulted) + } + if pb.F_Sint64Defaulted != nil { + t.Error("New or Reset did not set int64:", *pb.F_Sint64Defaulted) + } +} + +// Does Reset() reset? +func TestReset(t *testing.T) { + pb := initGoTest(true) + // muck with some values + pb.F_BoolDefaulted = Bool(false) + pb.F_Int32Defaulted = Int32(237) + pb.F_Int64Defaulted = Int64(12346) + pb.F_Fixed32Defaulted = Uint32(32000) + pb.F_Fixed64Defaulted = Uint64(666) + pb.F_Uint32Defaulted = Uint32(323232) + pb.F_Uint64Defaulted = nil + pb.F_FloatDefaulted = nil + pb.F_DoubleDefaulted = Float64(0) + pb.F_StringDefaulted = String("gotcha") + pb.F_BytesDefaulted = []byte("asdfasdf") + pb.F_Sint32Defaulted = Int32(123) + pb.F_Sint64Defaulted = Int64(789) + pb.Reset() + checkInitialized(pb, t) +} + +// All required fields set, no defaults provided. +func TestEncodeDecode1(t *testing.T) { + pb := initGoTest(false) + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 0x20 + "714000000000000000"+ // field 14, encoding 1, value 0x40 + "78a019"+ // field 15, encoding 0, value 0xca0 = 3232 + "8001c032"+ // field 16, encoding 0, value 0x1940 = 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2, string "string" + "b304"+ // field 70, encoding 3, start group + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // field 70, encoding 4, end group + "aa0605"+"6279746573"+ // field 101, encoding 2, string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f") // field 103, encoding 0, 0x7f zigzag64 +} + +// All required fields set, defaults provided. +func TestEncodeDecode2(t *testing.T) { + pb := initGoTest(true) + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All default fields set to their default value by hand +func TestEncodeDecode3(t *testing.T) { + pb := initGoTest(false) + pb.F_BoolDefaulted = Bool(true) + pb.F_Int32Defaulted = Int32(32) + pb.F_Int64Defaulted = Int64(64) + pb.F_Fixed32Defaulted = Uint32(320) + pb.F_Fixed64Defaulted = Uint64(640) + pb.F_Uint32Defaulted = Uint32(3200) + pb.F_Uint64Defaulted = Uint64(6400) + pb.F_FloatDefaulted = Float32(314159) + pb.F_DoubleDefaulted = Float64(271828) + pb.F_StringDefaulted = String("hello, \"world!\"\n") + pb.F_BytesDefaulted = []byte("Bignose") + pb.F_Sint32Defaulted = Int32(-32) + pb.F_Sint64Defaulted = Int64(-64) + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All required fields set, defaults provided, all non-defaulted optional fields have values. +func TestEncodeDecode4(t *testing.T) { + pb := initGoTest(true) + pb.Table = String("hello") + pb.Param = Int32(7) + pb.OptionalField = initGoTestField() + pb.F_BoolOptional = Bool(true) + pb.F_Int32Optional = Int32(32) + pb.F_Int64Optional = Int64(64) + pb.F_Fixed32Optional = Uint32(3232) + pb.F_Fixed64Optional = Uint64(6464) + pb.F_Uint32Optional = Uint32(323232) + pb.F_Uint64Optional = Uint64(646464) + pb.F_FloatOptional = Float32(32.) + pb.F_DoubleOptional = Float64(64.) + pb.F_StringOptional = String("hello") + pb.F_BytesOptional = []byte("Bignose") + pb.F_Sint32Optional = Int32(-32) + pb.F_Sint64Optional = Int64(-64) + pb.Optionalgroup = initGoTest_OptionalGroup() + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "1205"+"68656c6c6f"+ // field 2, encoding 2, string "hello" + "1807"+ // field 3, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "320d"+"0a056c6162656c120474797065"+ // field 6, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "f00101"+ // field 30, encoding 0, value 1 + "f80120"+ // field 31, encoding 0, value 32 + "800240"+ // field 32, encoding 0, value 64 + "8d02a00c0000"+ // field 33, encoding 5, value 3232 + "91024019000000000000"+ // field 34, encoding 1, value 6464 + "9802a0dd13"+ // field 35, encoding 0, value 323232 + "a002c0ba27"+ // field 36, encoding 0, value 646464 + "ad0200000042"+ // field 37, encoding 5, value 32.0 + "b1020000000000005040"+ // field 38, encoding 1, value 64.0 + "ba0205"+"68656c6c6f"+ // field 39, encoding 2, string "hello" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "d305"+ // start group field 90 level 1 + "da0508"+"6f7074696f6e616c"+ // field 91, encoding 2, string "optional" + "d405"+ // end group field 90 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "ea1207"+"4269676e6f7365"+ // field 301, encoding 2, string "Bignose" + "f0123f"+ // field 302, encoding 0, value 63 + "f8127f"+ // field 303, encoding 0, value 127 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All required fields set, defaults provided, all repeated fields given two values. +func TestEncodeDecode5(t *testing.T) { + pb := initGoTest(true) + pb.RepeatedField = []*GoTestField{initGoTestField(), initGoTestField()} + pb.F_BoolRepeated = []bool{false, true} + pb.F_Int32Repeated = []int32{32, 33} + pb.F_Int64Repeated = []int64{64, 65} + pb.F_Fixed32Repeated = []uint32{3232, 3333} + pb.F_Fixed64Repeated = []uint64{6464, 6565} + pb.F_Uint32Repeated = []uint32{323232, 333333} + pb.F_Uint64Repeated = []uint64{646464, 656565} + pb.F_FloatRepeated = []float32{32., 33.} + pb.F_DoubleRepeated = []float64{64., 65.} + pb.F_StringRepeated = []string{"hello", "sailor"} + pb.F_BytesRepeated = [][]byte{[]byte("big"), []byte("nose")} + pb.F_Sint32Repeated = []int32{32, -32} + pb.F_Sint64Repeated = []int64{64, -64} + pb.Repeatedgroup = []*GoTest_RepeatedGroup{initGoTest_RepeatedGroup(), initGoTest_RepeatedGroup()} + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField) + "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "a00100"+ // field 20, encoding 0, value 0 + "a00101"+ // field 20, encoding 0, value 1 + "a80120"+ // field 21, encoding 0, value 32 + "a80121"+ // field 21, encoding 0, value 33 + "b00140"+ // field 22, encoding 0, value 64 + "b00141"+ // field 22, encoding 0, value 65 + "bd01a00c0000"+ // field 23, encoding 5, value 3232 + "bd01050d0000"+ // field 23, encoding 5, value 3333 + "c1014019000000000000"+ // field 24, encoding 1, value 6464 + "c101a519000000000000"+ // field 24, encoding 1, value 6565 + "c801a0dd13"+ // field 25, encoding 0, value 323232 + "c80195ac14"+ // field 25, encoding 0, value 333333 + "d001c0ba27"+ // field 26, encoding 0, value 646464 + "d001b58928"+ // field 26, encoding 0, value 656565 + "dd0100000042"+ // field 27, encoding 5, value 32.0 + "dd0100000442"+ // field 27, encoding 5, value 33.0 + "e1010000000000005040"+ // field 28, encoding 1, value 64.0 + "e1010000000000405040"+ // field 28, encoding 1, value 65.0 + "ea0105"+"68656c6c6f"+ // field 29, encoding 2, string "hello" + "ea0106"+"7361696c6f72"+ // field 29, encoding 2, string "sailor" + "c00201"+ // field 40, encoding 0, value 1 + "c80220"+ // field 41, encoding 0, value 32 + "d00240"+ // field 42, encoding 0, value 64 + "dd0240010000"+ // field 43, encoding 5, value 320 + "e1028002000000000000"+ // field 44, encoding 1, value 640 + "e8028019"+ // field 45, encoding 0, value 3200 + "f0028032"+ // field 46, encoding 0, value 6400 + "fd02e0659948"+ // field 47, encoding 5, value 314159.0 + "81030000000050971041"+ // field 48, encoding 1, value 271828.0 + "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "8305"+ // start group field 80 level 1 + "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated" + "8405"+ // end group field 80 level 1 + "8305"+ // start group field 80 level 1 + "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated" + "8405"+ // end group field 80 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "ca0c03"+"626967"+ // field 201, encoding 2, string "big" + "ca0c04"+"6e6f7365"+ // field 201, encoding 2, string "nose" + "d00c40"+ // field 202, encoding 0, value 32 + "d00c3f"+ // field 202, encoding 0, value -32 + "d80c8001"+ // field 203, encoding 0, value 64 + "d80c7f"+ // field 203, encoding 0, value -64 + "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" + "90193f"+ // field 402, encoding 0, value 63 + "98197f") // field 403, encoding 0, value 127 + +} + +// All required fields set, all packed repeated fields given two values. +func TestEncodeDecode6(t *testing.T) { + pb := initGoTest(false) + pb.F_BoolRepeatedPacked = []bool{false, true} + pb.F_Int32RepeatedPacked = []int32{32, 33} + pb.F_Int64RepeatedPacked = []int64{64, 65} + pb.F_Fixed32RepeatedPacked = []uint32{3232, 3333} + pb.F_Fixed64RepeatedPacked = []uint64{6464, 6565} + pb.F_Uint32RepeatedPacked = []uint32{323232, 333333} + pb.F_Uint64RepeatedPacked = []uint64{646464, 656565} + pb.F_FloatRepeatedPacked = []float32{32., 33.} + pb.F_DoubleRepeatedPacked = []float64{64., 65.} + pb.F_Sint32RepeatedPacked = []int32{32, -32} + pb.F_Sint64RepeatedPacked = []int64{64, -64} + + overify(t, pb, + "0807"+ // field 1, encoding 0, value 7 + "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) + "5001"+ // field 10, encoding 0, value 1 + "5803"+ // field 11, encoding 0, value 3 + "6006"+ // field 12, encoding 0, value 6 + "6d20000000"+ // field 13, encoding 5, value 32 + "714000000000000000"+ // field 14, encoding 1, value 64 + "78a019"+ // field 15, encoding 0, value 3232 + "8001c032"+ // field 16, encoding 0, value 6464 + "8d0100004a45"+ // field 17, encoding 5, value 3232.0 + "9101000000000040b940"+ // field 18, encoding 1, value 6464.0 + "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" + "9203020001"+ // field 50, encoding 2, 2 bytes, value 0, value 1 + "9a03022021"+ // field 51, encoding 2, 2 bytes, value 32, value 33 + "a203024041"+ // field 52, encoding 2, 2 bytes, value 64, value 65 + "aa0308"+ // field 53, encoding 2, 8 bytes + "a00c0000050d0000"+ // value 3232, value 3333 + "b20310"+ // field 54, encoding 2, 16 bytes + "4019000000000000a519000000000000"+ // value 6464, value 6565 + "ba0306"+ // field 55, encoding 2, 6 bytes + "a0dd1395ac14"+ // value 323232, value 333333 + "c20306"+ // field 56, encoding 2, 6 bytes + "c0ba27b58928"+ // value 646464, value 656565 + "ca0308"+ // field 57, encoding 2, 8 bytes + "0000004200000442"+ // value 32.0, value 33.0 + "d20310"+ // field 58, encoding 2, 16 bytes + "00000000000050400000000000405040"+ // value 64.0, value 65.0 + "b304"+ // start group field 70 level 1 + "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" + "b404"+ // end group field 70 level 1 + "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" + "b0063f"+ // field 102, encoding 0, 0x3f zigzag32 + "b8067f"+ // field 103, encoding 0, 0x7f zigzag64 + "b21f02"+ // field 502, encoding 2, 2 bytes + "403f"+ // value 32, value -32 + "ba1f03"+ // field 503, encoding 2, 3 bytes + "80017f") // value 64, value -64 +} + +// Test that we can encode empty bytes fields. +func TestEncodeDecodeBytes1(t *testing.T) { + pb := initGoTest(false) + + // Create our bytes + pb.F_BytesRequired = []byte{} + pb.F_BytesRepeated = [][]byte{{}} + pb.F_BytesOptional = []byte{} + + d, err := Marshal(pb) + if err != nil { + t.Error(err) + } + + pbd := new(GoTest) + if err := Unmarshal(d, pbd); err != nil { + t.Error(err) + } + + if pbd.F_BytesRequired == nil || len(pbd.F_BytesRequired) != 0 { + t.Error("required empty bytes field is incorrect") + } + if pbd.F_BytesRepeated == nil || len(pbd.F_BytesRepeated) == 1 && pbd.F_BytesRepeated[0] == nil { + t.Error("repeated empty bytes field is incorrect") + } + if pbd.F_BytesOptional == nil || len(pbd.F_BytesOptional) != 0 { + t.Error("optional empty bytes field is incorrect") + } +} + +// Test that we encode nil-valued fields of a repeated bytes field correctly. +// Since entries in a repeated field cannot be nil, nil must mean empty value. +func TestEncodeDecodeBytes2(t *testing.T) { + pb := initGoTest(false) + + // Create our bytes + pb.F_BytesRepeated = [][]byte{nil} + + d, err := Marshal(pb) + if err != nil { + t.Error(err) + } + + pbd := new(GoTest) + if err := Unmarshal(d, pbd); err != nil { + t.Error(err) + } + + if len(pbd.F_BytesRepeated) != 1 || pbd.F_BytesRepeated[0] == nil { + t.Error("Unexpected value for repeated bytes field") + } +} + +// All required fields set, defaults provided, all repeated fields given two values. +func TestSkippingUnrecognizedFields(t *testing.T) { + o := old() + pb := initGoTestField() + + // Marshal it normally. + o.Marshal(pb) + + // Now new a GoSkipTest record. + skip := &GoSkipTest{ + SkipInt32: Int32(32), + SkipFixed32: Uint32(3232), + SkipFixed64: Uint64(6464), + SkipString: String("skipper"), + Skipgroup: &GoSkipTest_SkipGroup{ + GroupInt32: Int32(75), + GroupString: String("wxyz"), + }, + } + + // Marshal it into same buffer. + o.Marshal(skip) + + pbd := new(GoTestField) + o.Unmarshal(pbd) + + // The __unrecognized field should be a marshaling of GoSkipTest + skipd := new(GoSkipTest) + + o.SetBuf(pbd.XXX_unrecognized) + o.Unmarshal(skipd) + + if *skipd.SkipInt32 != *skip.SkipInt32 { + t.Error("skip int32", skipd.SkipInt32) + } + if *skipd.SkipFixed32 != *skip.SkipFixed32 { + t.Error("skip fixed32", skipd.SkipFixed32) + } + if *skipd.SkipFixed64 != *skip.SkipFixed64 { + t.Error("skip fixed64", skipd.SkipFixed64) + } + if *skipd.SkipString != *skip.SkipString { + t.Error("skip string", *skipd.SkipString) + } + if *skipd.Skipgroup.GroupInt32 != *skip.Skipgroup.GroupInt32 { + t.Error("skip group int32", skipd.Skipgroup.GroupInt32) + } + if *skipd.Skipgroup.GroupString != *skip.Skipgroup.GroupString { + t.Error("skip group string", *skipd.Skipgroup.GroupString) + } +} + +// Check that unrecognized fields of a submessage are preserved. +func TestSubmessageUnrecognizedFields(t *testing.T) { + nm := &NewMessage{ + Nested: &NewMessage_Nested{ + Name: String("Nigel"), + FoodGroup: String("carbs"), + }, + } + b, err := Marshal(nm) + if err != nil { + t.Fatalf("Marshal of NewMessage: %v", err) + } + + // Unmarshal into an OldMessage. + om := new(OldMessage) + if err = Unmarshal(b, om); err != nil { + t.Fatalf("Unmarshal to OldMessage: %v", err) + } + exp := &OldMessage{ + Nested: &OldMessage_Nested{ + Name: String("Nigel"), + // normal protocol buffer users should not do this + XXX_unrecognized: []byte("\x12\x05carbs"), + }, + } + if !Equal(om, exp) { + t.Errorf("om = %v, want %v", om, exp) + } + + // Clone the OldMessage. + om = Clone(om).(*OldMessage) + if !Equal(om, exp) { + t.Errorf("Clone(om) = %v, want %v", om, exp) + } + + // Marshal the OldMessage, then unmarshal it into an empty NewMessage. + if b, err = Marshal(om); err != nil { + t.Fatalf("Marshal of OldMessage: %v", err) + } + t.Logf("Marshal(%v) -> %q", om, b) + nm2 := new(NewMessage) + if err := Unmarshal(b, nm2); err != nil { + t.Fatalf("Unmarshal to NewMessage: %v", err) + } + if !Equal(nm, nm2) { + t.Errorf("NewMessage round-trip: %v => %v", nm, nm2) + } +} + +// Check that an int32 field can be upgraded to an int64 field. +func TestNegativeInt32(t *testing.T) { + om := &OldMessage{ + Num: Int32(-1), + } + b, err := Marshal(om) + if err != nil { + t.Fatalf("Marshal of OldMessage: %v", err) + } + + // Check the size. It should be 11 bytes; + // 1 for the field/wire type, and 10 for the negative number. + if len(b) != 11 { + t.Errorf("%v marshaled as %q, wanted 11 bytes", om, b) + } + + // Unmarshal into a NewMessage. + nm := new(NewMessage) + if err := Unmarshal(b, nm); err != nil { + t.Fatalf("Unmarshal to NewMessage: %v", err) + } + want := &NewMessage{ + Num: Int64(-1), + } + if !Equal(nm, want) { + t.Errorf("nm = %v, want %v", nm, want) + } +} + +// Check that we can grow an array (repeated field) to have many elements. +// This test doesn't depend only on our encoding; for variety, it makes sure +// we create, encode, and decode the correct contents explicitly. It's therefore +// a bit messier. +// This test also uses (and hence tests) the Marshal/Unmarshal functions +// instead of the methods. +func TestBigRepeated(t *testing.T) { + pb := initGoTest(true) + + // Create the arrays + const N = 50 // Internally the library starts much smaller. + pb.Repeatedgroup = make([]*GoTest_RepeatedGroup, N) + pb.F_Sint64Repeated = make([]int64, N) + pb.F_Sint32Repeated = make([]int32, N) + pb.F_BytesRepeated = make([][]byte, N) + pb.F_StringRepeated = make([]string, N) + pb.F_DoubleRepeated = make([]float64, N) + pb.F_FloatRepeated = make([]float32, N) + pb.F_Uint64Repeated = make([]uint64, N) + pb.F_Uint32Repeated = make([]uint32, N) + pb.F_Fixed64Repeated = make([]uint64, N) + pb.F_Fixed32Repeated = make([]uint32, N) + pb.F_Int64Repeated = make([]int64, N) + pb.F_Int32Repeated = make([]int32, N) + pb.F_BoolRepeated = make([]bool, N) + pb.RepeatedField = make([]*GoTestField, N) + + // Fill in the arrays with checkable values. + igtf := initGoTestField() + igtrg := initGoTest_RepeatedGroup() + for i := 0; i < N; i++ { + pb.Repeatedgroup[i] = igtrg + pb.F_Sint64Repeated[i] = int64(i) + pb.F_Sint32Repeated[i] = int32(i) + s := fmt.Sprint(i) + pb.F_BytesRepeated[i] = []byte(s) + pb.F_StringRepeated[i] = s + pb.F_DoubleRepeated[i] = float64(i) + pb.F_FloatRepeated[i] = float32(i) + pb.F_Uint64Repeated[i] = uint64(i) + pb.F_Uint32Repeated[i] = uint32(i) + pb.F_Fixed64Repeated[i] = uint64(i) + pb.F_Fixed32Repeated[i] = uint32(i) + pb.F_Int64Repeated[i] = int64(i) + pb.F_Int32Repeated[i] = int32(i) + pb.F_BoolRepeated[i] = i%2 == 0 + pb.RepeatedField[i] = igtf + } + + // Marshal. + buf, _ := Marshal(pb) + + // Now test Unmarshal by recreating the original buffer. + pbd := new(GoTest) + Unmarshal(buf, pbd) + + // Check the checkable values + for i := uint64(0); i < N; i++ { + if pbd.Repeatedgroup[i] == nil { // TODO: more checking? + t.Error("pbd.Repeatedgroup bad") + } + var x uint64 + x = uint64(pbd.F_Sint64Repeated[i]) + if x != i { + t.Error("pbd.F_Sint64Repeated bad", x, i) + } + x = uint64(pbd.F_Sint32Repeated[i]) + if x != i { + t.Error("pbd.F_Sint32Repeated bad", x, i) + } + s := fmt.Sprint(i) + equalbytes(pbd.F_BytesRepeated[i], []byte(s), t) + if pbd.F_StringRepeated[i] != s { + t.Error("pbd.F_Sint32Repeated bad", pbd.F_StringRepeated[i], i) + } + x = uint64(pbd.F_DoubleRepeated[i]) + if x != i { + t.Error("pbd.F_DoubleRepeated bad", x, i) + } + x = uint64(pbd.F_FloatRepeated[i]) + if x != i { + t.Error("pbd.F_FloatRepeated bad", x, i) + } + x = pbd.F_Uint64Repeated[i] + if x != i { + t.Error("pbd.F_Uint64Repeated bad", x, i) + } + x = uint64(pbd.F_Uint32Repeated[i]) + if x != i { + t.Error("pbd.F_Uint32Repeated bad", x, i) + } + x = pbd.F_Fixed64Repeated[i] + if x != i { + t.Error("pbd.F_Fixed64Repeated bad", x, i) + } + x = uint64(pbd.F_Fixed32Repeated[i]) + if x != i { + t.Error("pbd.F_Fixed32Repeated bad", x, i) + } + x = uint64(pbd.F_Int64Repeated[i]) + if x != i { + t.Error("pbd.F_Int64Repeated bad", x, i) + } + x = uint64(pbd.F_Int32Repeated[i]) + if x != i { + t.Error("pbd.F_Int32Repeated bad", x, i) + } + if pbd.F_BoolRepeated[i] != (i%2 == 0) { + t.Error("pbd.F_BoolRepeated bad", x, i) + } + if pbd.RepeatedField[i] == nil { // TODO: more checking? + t.Error("pbd.RepeatedField bad") + } + } +} + +// Verify we give a useful message when decoding to the wrong structure type. +func TestTypeMismatch(t *testing.T) { + pb1 := initGoTest(true) + + // Marshal + o := old() + o.Marshal(pb1) + + // Now Unmarshal it to the wrong type. + pb2 := initGoTestField() + err := o.Unmarshal(pb2) + if err == nil { + t.Error("expected error, got no error") + } else if !strings.Contains(err.Error(), "bad wiretype") { + t.Error("expected bad wiretype error, got", err) + } +} + +func encodeDecode(t *testing.T, in, out Message, msg string) { + buf, err := Marshal(in) + if err != nil { + t.Fatalf("failed marshaling %v: %v", msg, err) + } + if err := Unmarshal(buf, out); err != nil { + t.Fatalf("failed unmarshaling %v: %v", msg, err) + } +} + +func TestPackedNonPackedDecoderSwitching(t *testing.T) { + np, p := new(NonPackedTest), new(PackedTest) + + // non-packed -> packed + np.A = []int32{0, 1, 1, 2, 3, 5} + encodeDecode(t, np, p, "non-packed -> packed") + if !reflect.DeepEqual(np.A, p.B) { + t.Errorf("failed non-packed -> packed; np.A=%+v, p.B=%+v", np.A, p.B) + } + + // packed -> non-packed + np.Reset() + p.B = []int32{3, 1, 4, 1, 5, 9} + encodeDecode(t, p, np, "packed -> non-packed") + if !reflect.DeepEqual(p.B, np.A) { + t.Errorf("failed packed -> non-packed; p.B=%+v, np.A=%+v", p.B, np.A) + } +} + +func TestProto1RepeatedGroup(t *testing.T) { + pb := &MessageList{ + Message: []*MessageList_Message{ + { + Name: String("blah"), + Count: Int32(7), + }, + // NOTE: pb.Message[1] is a nil + nil, + }, + } + + o := old() + err := o.Marshal(pb) + if err == nil || !strings.Contains(err.Error(), "repeated field Message has nil") { + t.Fatalf("unexpected or no error when marshaling: %v", err) + } +} + +// Test that enums work. Checks for a bug introduced by making enums +// named types instead of int32: newInt32FromUint64 would crash with +// a type mismatch in reflect.PointTo. +func TestEnum(t *testing.T) { + pb := new(GoEnum) + pb.Foo = FOO_FOO1.Enum() + o := old() + if err := o.Marshal(pb); err != nil { + t.Fatal("error encoding enum:", err) + } + pb1 := new(GoEnum) + if err := o.Unmarshal(pb1); err != nil { + t.Fatal("error decoding enum:", err) + } + if *pb1.Foo != FOO_FOO1 { + t.Error("expected 7 but got ", *pb1.Foo) + } +} + +// Enum types have String methods. Check that enum fields can be printed. +// We don't care what the value actually is, just as long as it doesn't crash. +func TestPrintingNilEnumFields(t *testing.T) { + pb := new(GoEnum) + _ = fmt.Sprintf("%+v", pb) +} + +// Verify that absent required fields cause Marshal/Unmarshal to return errors. +func TestRequiredFieldEnforcement(t *testing.T) { + pb := new(GoTestField) + _, err := Marshal(pb) + if err == nil { + t.Error("marshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Label") { + t.Errorf("marshal: bad error type: %v", err) + } + + // A slightly sneaky, yet valid, proto. It encodes the same required field twice, + // so simply counting the required fields is insufficient. + // field 1, encoding 2, value "hi" + buf := []byte("\x0A\x02hi\x0A\x02hi") + err = Unmarshal(buf, pb) + if err == nil { + t.Error("unmarshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "{Unknown}") { + t.Errorf("unmarshal: bad error type: %v", err) + } +} + +// Verify that absent required fields in groups cause Marshal/Unmarshal to return errors. +func TestRequiredFieldEnforcementGroups(t *testing.T) { + pb := &GoTestRequiredGroupField{Group: &GoTestRequiredGroupField_Group{}} + if _, err := Marshal(pb); err == nil { + t.Error("marshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Group.Field") { + t.Errorf("marshal: bad error type: %v", err) + } + + buf := []byte{11, 12} + if err := Unmarshal(buf, pb); err == nil { + t.Error("unmarshal: expected error, got nil") + } else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Group.{Unknown}") { + t.Errorf("unmarshal: bad error type: %v", err) + } +} + +func TestTypedNilMarshal(t *testing.T) { + // A typed nil should return ErrNil and not crash. + { + var m *GoEnum + if _, err := Marshal(m); err != ErrNil { + t.Errorf("Marshal(%#v): got %v, want ErrNil", m, err) + } + } + + { + m := &Communique{Union: &Communique_Msg{Msg: nil}} + if _, err := Marshal(m); err == nil || err == ErrNil { + t.Errorf("Marshal(%#v): got %v, want errOneofHasNil", m, err) + } + } +} + +// A type that implements the Marshaler interface, but is not nillable. +type nonNillableInt uint64 + +func (nni nonNillableInt) Marshal() ([]byte, error) { + return EncodeVarint(uint64(nni)), nil +} + +type NNIMessage struct { + nni nonNillableInt +} + +func (*NNIMessage) Reset() {} +func (*NNIMessage) String() string { return "" } +func (*NNIMessage) ProtoMessage() {} + +// A type that implements the Marshaler interface and is nillable. +type nillableMessage struct { + x uint64 +} + +func (nm *nillableMessage) Marshal() ([]byte, error) { + return EncodeVarint(nm.x), nil +} + +type NMMessage struct { + nm *nillableMessage +} + +func (*NMMessage) Reset() {} +func (*NMMessage) String() string { return "" } +func (*NMMessage) ProtoMessage() {} + +// Verify a type that uses the Marshaler interface, but has a nil pointer. +func TestNilMarshaler(t *testing.T) { + // Try a struct with a Marshaler field that is nil. + // It should be directly marshable. + nmm := new(NMMessage) + if _, err := Marshal(nmm); err != nil { + t.Error("unexpected error marshaling nmm: ", err) + } + + // Try a struct with a Marshaler field that is not nillable. + nnim := new(NNIMessage) + nnim.nni = 7 + var _ Marshaler = nnim.nni // verify it is truly a Marshaler + if _, err := Marshal(nnim); err != nil { + t.Error("unexpected error marshaling nnim: ", err) + } +} + +func TestAllSetDefaults(t *testing.T) { + // Exercise SetDefaults with all scalar field types. + m := &Defaults{ + // NaN != NaN, so override that here. + F_Nan: Float32(1.7), + } + expected := &Defaults{ + F_Bool: Bool(true), + F_Int32: Int32(32), + F_Int64: Int64(64), + F_Fixed32: Uint32(320), + F_Fixed64: Uint64(640), + F_Uint32: Uint32(3200), + F_Uint64: Uint64(6400), + F_Float: Float32(314159), + F_Double: Float64(271828), + F_String: String(`hello, "world!"` + "\n"), + F_Bytes: []byte("Bignose"), + F_Sint32: Int32(-32), + F_Sint64: Int64(-64), + F_Enum: Defaults_GREEN.Enum(), + F_Pinf: Float32(float32(math.Inf(1))), + F_Ninf: Float32(float32(math.Inf(-1))), + F_Nan: Float32(1.7), + StrZero: String(""), + } + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("SetDefaults failed\n got %v\nwant %v", m, expected) + } +} + +func TestSetDefaultsWithSetField(t *testing.T) { + // Check that a set value is not overridden. + m := &Defaults{ + F_Int32: Int32(12), + } + SetDefaults(m) + if v := m.GetF_Int32(); v != 12 { + t.Errorf("m.FInt32 = %v, want 12", v) + } +} + +func TestSetDefaultsWithSubMessage(t *testing.T) { + m := &OtherMessage{ + Key: Int64(123), + Inner: &InnerMessage{ + Host: String("gopher"), + }, + } + expected := &OtherMessage{ + Key: Int64(123), + Inner: &InnerMessage{ + Host: String("gopher"), + Port: Int32(4000), + }, + } + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("\n got %v\nwant %v", m, expected) + } +} + +func TestSetDefaultsWithRepeatedSubMessage(t *testing.T) { + m := &MyMessage{ + RepInner: []*InnerMessage{{}}, + } + expected := &MyMessage{ + RepInner: []*InnerMessage{{ + Port: Int32(4000), + }}, + } + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("\n got %v\nwant %v", m, expected) + } +} + +func TestSetDefaultWithRepeatedNonMessage(t *testing.T) { + m := &MyMessage{ + Pet: []string{"turtle", "wombat"}, + } + expected := Clone(m) + SetDefaults(m) + if !Equal(m, expected) { + t.Errorf("\n got %v\nwant %v", m, expected) + } +} + +func TestMaximumTagNumber(t *testing.T) { + m := &MaxTag{ + LastField: String("natural goat essence"), + } + buf, err := Marshal(m) + if err != nil { + t.Fatalf("proto.Marshal failed: %v", err) + } + m2 := new(MaxTag) + if err := Unmarshal(buf, m2); err != nil { + t.Fatalf("proto.Unmarshal failed: %v", err) + } + if got, want := m2.GetLastField(), *m.LastField; got != want { + t.Errorf("got %q, want %q", got, want) + } +} + +func TestJSON(t *testing.T) { + m := &MyMessage{ + Count: Int32(4), + Pet: []string{"bunny", "kitty"}, + Inner: &InnerMessage{ + Host: String("cauchy"), + }, + Bikeshed: MyMessage_GREEN.Enum(), + } + const expected = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":1}` + + b, err := json.Marshal(m) + if err != nil { + t.Fatalf("json.Marshal failed: %v", err) + } + s := string(b) + if s != expected { + t.Errorf("got %s\nwant %s", s, expected) + } + + received := new(MyMessage) + if err := json.Unmarshal(b, received); err != nil { + t.Fatalf("json.Unmarshal failed: %v", err) + } + if !Equal(received, m) { + t.Fatalf("got %s, want %s", received, m) + } + + // Test unmarshalling of JSON with symbolic enum name. + const old = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":"GREEN"}` + received.Reset() + if err := json.Unmarshal([]byte(old), received); err != nil { + t.Fatalf("json.Unmarshal failed: %v", err) + } + if !Equal(received, m) { + t.Fatalf("got %s, want %s", received, m) + } +} + +func TestBadWireType(t *testing.T) { + b := []byte{7<<3 | 6} // field 7, wire type 6 + pb := new(OtherMessage) + if err := Unmarshal(b, pb); err == nil { + t.Errorf("Unmarshal did not fail") + } else if !strings.Contains(err.Error(), "unknown wire type") { + t.Errorf("wrong error: %v", err) + } +} + +func TestBytesWithInvalidLength(t *testing.T) { + // If a byte sequence has an invalid (negative) length, Unmarshal should not panic. + b := []byte{2<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0} + Unmarshal(b, new(MyMessage)) +} + +func TestLengthOverflow(t *testing.T) { + // Overflowing a length should not panic. + b := []byte{2<<3 | WireBytes, 1, 1, 3<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x01} + Unmarshal(b, new(MyMessage)) +} + +func TestVarintOverflow(t *testing.T) { + // Overflowing a 64-bit length should not be allowed. + b := []byte{1<<3 | WireVarint, 0x01, 3<<3 | WireBytes, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01} + if err := Unmarshal(b, new(MyMessage)); err == nil { + t.Fatalf("Overflowed uint64 length without error") + } +} + +func TestUnmarshalFuzz(t *testing.T) { + const N = 1000 + seed := time.Now().UnixNano() + t.Logf("RNG seed is %d", seed) + rng := rand.New(rand.NewSource(seed)) + buf := make([]byte, 20) + for i := 0; i < N; i++ { + for j := range buf { + buf[j] = byte(rng.Intn(256)) + } + fuzzUnmarshal(t, buf) + } +} + +func TestMergeMessages(t *testing.T) { + pb := &MessageList{Message: []*MessageList_Message{{Name: String("x"), Count: Int32(1)}}} + data, err := Marshal(pb) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + pb1 := new(MessageList) + if err := Unmarshal(data, pb1); err != nil { + t.Fatalf("first Unmarshal: %v", err) + } + if err := Unmarshal(data, pb1); err != nil { + t.Fatalf("second Unmarshal: %v", err) + } + if len(pb1.Message) != 1 { + t.Errorf("two Unmarshals produced %d Messages, want 1", len(pb1.Message)) + } + + pb2 := new(MessageList) + if err := UnmarshalMerge(data, pb2); err != nil { + t.Fatalf("first UnmarshalMerge: %v", err) + } + if err := UnmarshalMerge(data, pb2); err != nil { + t.Fatalf("second UnmarshalMerge: %v", err) + } + if len(pb2.Message) != 2 { + t.Errorf("two UnmarshalMerges produced %d Messages, want 2", len(pb2.Message)) + } +} + +func TestExtensionMarshalOrder(t *testing.T) { + m := &MyMessage{Count: Int(123)} + if err := SetExtension(m, E_Ext_More, &Ext{Data: String("alpha")}); err != nil { + t.Fatalf("SetExtension: %v", err) + } + if err := SetExtension(m, E_Ext_Text, String("aleph")); err != nil { + t.Fatalf("SetExtension: %v", err) + } + if err := SetExtension(m, E_Ext_Number, Int32(1)); err != nil { + t.Fatalf("SetExtension: %v", err) + } + + // Serialize m several times, and check we get the same bytes each time. + var orig []byte + for i := 0; i < 100; i++ { + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if i == 0 { + orig = b + continue + } + if !bytes.Equal(b, orig) { + t.Errorf("Bytes differ on attempt #%d", i) + } + } +} + +// Many extensions, because small maps might not iterate differently on each iteration. +var exts = []*ExtensionDesc{ + E_X201, + E_X202, + E_X203, + E_X204, + E_X205, + E_X206, + E_X207, + E_X208, + E_X209, + E_X210, + E_X211, + E_X212, + E_X213, + E_X214, + E_X215, + E_X216, + E_X217, + E_X218, + E_X219, + E_X220, + E_X221, + E_X222, + E_X223, + E_X224, + E_X225, + E_X226, + E_X227, + E_X228, + E_X229, + E_X230, + E_X231, + E_X232, + E_X233, + E_X234, + E_X235, + E_X236, + E_X237, + E_X238, + E_X239, + E_X240, + E_X241, + E_X242, + E_X243, + E_X244, + E_X245, + E_X246, + E_X247, + E_X248, + E_X249, + E_X250, +} + +func TestMessageSetMarshalOrder(t *testing.T) { + m := &MyMessageSet{} + for _, x := range exts { + if err := SetExtension(m, x, &Empty{}); err != nil { + t.Fatalf("SetExtension: %v", err) + } + } + + buf, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + // Serialize m several times, and check we get the same bytes each time. + for i := 0; i < 10; i++ { + b1, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if !bytes.Equal(b1, buf) { + t.Errorf("Bytes differ on re-Marshal #%d", i) + } + + m2 := &MyMessageSet{} + if err = Unmarshal(buf, m2); err != nil { + t.Errorf("Unmarshal: %v", err) + } + b2, err := Marshal(m2) + if err != nil { + t.Errorf("re-Marshal: %v", err) + } + if !bytes.Equal(b2, buf) { + t.Errorf("Bytes differ on round-trip #%d", i) + } + } +} + +func TestUnmarshalMergesMessages(t *testing.T) { + // If a nested message occurs twice in the input, + // the fields should be merged when decoding. + a := &OtherMessage{ + Key: Int64(123), + Inner: &InnerMessage{ + Host: String("polhode"), + Port: Int32(1234), + }, + } + aData, err := Marshal(a) + if err != nil { + t.Fatalf("Marshal(a): %v", err) + } + b := &OtherMessage{ + Weight: Float32(1.2), + Inner: &InnerMessage{ + Host: String("herpolhode"), + Connected: Bool(true), + }, + } + bData, err := Marshal(b) + if err != nil { + t.Fatalf("Marshal(b): %v", err) + } + want := &OtherMessage{ + Key: Int64(123), + Weight: Float32(1.2), + Inner: &InnerMessage{ + Host: String("herpolhode"), + Port: Int32(1234), + Connected: Bool(true), + }, + } + got := new(OtherMessage) + if err := Unmarshal(append(aData, bData...), got); err != nil { + t.Fatalf("Unmarshal: %v", err) + } + if !Equal(got, want) { + t.Errorf("\n got %v\nwant %v", got, want) + } +} + +func TestEncodingSizes(t *testing.T) { + tests := []struct { + m Message + n int + }{ + {&Defaults{F_Int32: Int32(math.MaxInt32)}, 6}, + {&Defaults{F_Int32: Int32(math.MinInt32)}, 11}, + {&Defaults{F_Uint32: Uint32(uint32(math.MaxInt32) + 1)}, 6}, + {&Defaults{F_Uint32: Uint32(math.MaxUint32)}, 6}, + } + for _, test := range tests { + b, err := Marshal(test.m) + if err != nil { + t.Errorf("Marshal(%v): %v", test.m, err) + continue + } + if len(b) != test.n { + t.Errorf("Marshal(%v) yielded %d bytes, want %d bytes", test.m, len(b), test.n) + } + } +} + +func TestRequiredNotSetError(t *testing.T) { + pb := initGoTest(false) + pb.RequiredField.Label = nil + pb.F_Int32Required = nil + pb.F_Int64Required = nil + + expected := "0807" + // field 1, encoding 0, value 7 + "2206" + "120474797065" + // field 4, encoding 2 (GoTestField) + "5001" + // field 10, encoding 0, value 1 + "6d20000000" + // field 13, encoding 5, value 0x20 + "714000000000000000" + // field 14, encoding 1, value 0x40 + "78a019" + // field 15, encoding 0, value 0xca0 = 3232 + "8001c032" + // field 16, encoding 0, value 0x1940 = 6464 + "8d0100004a45" + // field 17, encoding 5, value 3232.0 + "9101000000000040b940" + // field 18, encoding 1, value 6464.0 + "9a0106" + "737472696e67" + // field 19, encoding 2, string "string" + "b304" + // field 70, encoding 3, start group + "ba0408" + "7265717569726564" + // field 71, encoding 2, string "required" + "b404" + // field 70, encoding 4, end group + "aa0605" + "6279746573" + // field 101, encoding 2, string "bytes" + "b0063f" + // field 102, encoding 0, 0x3f zigzag32 + "b8067f" // field 103, encoding 0, 0x7f zigzag64 + + o := old() + mbytes, err := Marshal(pb) + if _, ok := err.(*RequiredNotSetError); !ok { + fmt.Printf("marshal-1 err = %v, want *RequiredNotSetError", err) + o.DebugPrint("", mbytes) + t.Fatalf("expected = %s", expected) + } + if strings.Index(err.Error(), "RequiredField.Label") < 0 { + t.Errorf("marshal-1 wrong err msg: %v", err) + } + if !equal(mbytes, expected, t) { + o.DebugPrint("neq 1", mbytes) + t.Fatalf("expected = %s", expected) + } + + // Now test Unmarshal by recreating the original buffer. + pbd := new(GoTest) + err = Unmarshal(mbytes, pbd) + if _, ok := err.(*RequiredNotSetError); !ok { + t.Fatalf("unmarshal err = %v, want *RequiredNotSetError", err) + o.DebugPrint("", mbytes) + t.Fatalf("string = %s", expected) + } + if strings.Index(err.Error(), "RequiredField.{Unknown}") < 0 { + t.Errorf("unmarshal wrong err msg: %v", err) + } + mbytes, err = Marshal(pbd) + if _, ok := err.(*RequiredNotSetError); !ok { + t.Errorf("marshal-2 err = %v, want *RequiredNotSetError", err) + o.DebugPrint("", mbytes) + t.Fatalf("string = %s", expected) + } + if strings.Index(err.Error(), "RequiredField.Label") < 0 { + t.Errorf("marshal-2 wrong err msg: %v", err) + } + if !equal(mbytes, expected, t) { + o.DebugPrint("neq 2", mbytes) + t.Fatalf("string = %s", expected) + } +} + +func fuzzUnmarshal(t *testing.T, data []byte) { + defer func() { + if e := recover(); e != nil { + t.Errorf("These bytes caused a panic: %+v", data) + t.Logf("Stack:\n%s", debug.Stack()) + t.FailNow() + } + }() + + pb := new(MyMessage) + Unmarshal(data, pb) +} + +func TestMapFieldMarshal(t *testing.T) { + m := &MessageWithMap{ + NameMapping: map[int32]string{ + 1: "Rob", + 4: "Ian", + 8: "Dave", + }, + } + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + // b should be the concatenation of these three byte sequences in some order. + parts := []string{ + "\n\a\b\x01\x12\x03Rob", + "\n\a\b\x04\x12\x03Ian", + "\n\b\b\x08\x12\x04Dave", + } + ok := false + for i := range parts { + for j := range parts { + if j == i { + continue + } + for k := range parts { + if k == i || k == j { + continue + } + try := parts[i] + parts[j] + parts[k] + if bytes.Equal(b, []byte(try)) { + ok = true + break + } + } + } + } + if !ok { + t.Fatalf("Incorrect Marshal output.\n got %q\nwant %q (or a permutation of that)", b, parts[0]+parts[1]+parts[2]) + } + t.Logf("FYI b: %q", b) + + (new(Buffer)).DebugPrint("Dump of b", b) +} + +func TestMapFieldRoundTrips(t *testing.T) { + m := &MessageWithMap{ + NameMapping: map[int32]string{ + 1: "Rob", + 4: "Ian", + 8: "Dave", + }, + MsgMapping: map[int64]*FloatingPoint{ + 0x7001: {F: Float64(2.0)}, + }, + ByteMapping: map[bool][]byte{ + false: []byte("that's not right!"), + true: []byte("aye, 'tis true!"), + }, + } + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + t.Logf("FYI b: %q", b) + m2 := new(MessageWithMap) + if err := Unmarshal(b, m2); err != nil { + t.Fatalf("Unmarshal: %v", err) + } + for _, pair := range [][2]interface{}{ + {m.NameMapping, m2.NameMapping}, + {m.MsgMapping, m2.MsgMapping}, + {m.ByteMapping, m2.ByteMapping}, + } { + if !reflect.DeepEqual(pair[0], pair[1]) { + t.Errorf("Map did not survive a round trip.\ninitial: %v\n final: %v", pair[0], pair[1]) + } + } +} + +func TestMapFieldWithNil(t *testing.T) { + m1 := &MessageWithMap{ + MsgMapping: map[int64]*FloatingPoint{ + 1: nil, + }, + } + b, err := Marshal(m1) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + m2 := new(MessageWithMap) + if err := Unmarshal(b, m2); err != nil { + t.Fatalf("Unmarshal: %v, got these bytes: %v", err, b) + } + if v, ok := m2.MsgMapping[1]; !ok { + t.Error("msg_mapping[1] not present") + } else if v != nil { + t.Errorf("msg_mapping[1] not nil: %v", v) + } +} + +func TestMapFieldWithNilBytes(t *testing.T) { + m1 := &MessageWithMap{ + ByteMapping: map[bool][]byte{ + false: {}, + true: nil, + }, + } + n := Size(m1) + b, err := Marshal(m1) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if n != len(b) { + t.Errorf("Size(m1) = %d; want len(Marshal(m1)) = %d", n, len(b)) + } + m2 := new(MessageWithMap) + if err := Unmarshal(b, m2); err != nil { + t.Fatalf("Unmarshal: %v, got these bytes: %v", err, b) + } + if v, ok := m2.ByteMapping[false]; !ok { + t.Error("byte_mapping[false] not present") + } else if len(v) != 0 { + t.Errorf("byte_mapping[false] not empty: %#v", v) + } + if v, ok := m2.ByteMapping[true]; !ok { + t.Error("byte_mapping[true] not present") + } else if len(v) != 0 { + t.Errorf("byte_mapping[true] not empty: %#v", v) + } +} + +func TestDecodeMapFieldMissingKey(t *testing.T) { + b := []byte{ + 0x0A, 0x03, // message, tag 1 (name_mapping), of length 3 bytes + // no key + 0x12, 0x01, 0x6D, // string value of length 1 byte, value "m" + } + got := &MessageWithMap{} + err := Unmarshal(b, got) + if err != nil { + t.Fatalf("failed to marshal map with missing key: %v", err) + } + want := &MessageWithMap{NameMapping: map[int32]string{0: "m"}} + if !Equal(got, want) { + t.Errorf("Unmarshaled map with no key was not as expected. got: %v, want %v", got, want) + } +} + +func TestDecodeMapFieldMissingValue(t *testing.T) { + b := []byte{ + 0x0A, 0x02, // message, tag 1 (name_mapping), of length 2 bytes + 0x08, 0x01, // varint key, value 1 + // no value + } + got := &MessageWithMap{} + err := Unmarshal(b, got) + if err != nil { + t.Fatalf("failed to marshal map with missing value: %v", err) + } + want := &MessageWithMap{NameMapping: map[int32]string{1: ""}} + if !Equal(got, want) { + t.Errorf("Unmarshaled map with no value was not as expected. got: %v, want %v", got, want) + } +} + +func TestOneof(t *testing.T) { + m := &Communique{} + b, err := Marshal(m) + if err != nil { + t.Fatalf("Marshal of empty message with oneof: %v", err) + } + if len(b) != 0 { + t.Errorf("Marshal of empty message yielded too many bytes: %v", b) + } + + m = &Communique{ + Union: &Communique_Name{Name: "Barry"}, + } + + // Round-trip. + b, err = Marshal(m) + if err != nil { + t.Fatalf("Marshal of message with oneof: %v", err) + } + if len(b) != 7 { // name tag/wire (1) + name len (1) + name (5) + t.Errorf("Incorrect marshal of message with oneof: %v", b) + } + m.Reset() + if err = Unmarshal(b, m); err != nil { + t.Fatalf("Unmarshal of message with oneof: %v", err) + } + if x, ok := m.Union.(*Communique_Name); !ok || x.Name != "Barry" { + t.Errorf("After round trip, Union = %+v", m.Union) + } + if name := m.GetName(); name != "Barry" { + t.Errorf("After round trip, GetName = %q, want %q", name, "Barry") + } + + // Let's try with a message in the oneof. + m.Union = &Communique_Msg{Msg: &Strings{StringField: String("deep deep string")}} + b, err = Marshal(m) + if err != nil { + t.Fatalf("Marshal of message with oneof set to message: %v", err) + } + if len(b) != 20 { // msg tag/wire (1) + msg len (1) + msg (1 + 1 + 16) + t.Errorf("Incorrect marshal of message with oneof set to message: %v", b) + } + m.Reset() + if err := Unmarshal(b, m); err != nil { + t.Fatalf("Unmarshal of message with oneof set to message: %v", err) + } + ss, ok := m.Union.(*Communique_Msg) + if !ok || ss.Msg.GetStringField() != "deep deep string" { + t.Errorf("After round trip with oneof set to message, Union = %+v", m.Union) + } +} + +func TestInefficientPackedBool(t *testing.T) { + // https://github.com/golang/protobuf/issues/76 + inp := []byte{ + 0x12, 0x02, // 0x12 = 2<<3|2; 2 bytes + // Usually a bool should take a single byte, + // but it is permitted to be any varint. + 0xb9, 0x30, + } + if err := Unmarshal(inp, new(MoreRepeated)); err != nil { + t.Error(err) + } +} + +// Benchmarks + +func testMsg() *GoTest { + pb := initGoTest(true) + const N = 1000 // Internally the library starts much smaller. + pb.F_Int32Repeated = make([]int32, N) + pb.F_DoubleRepeated = make([]float64, N) + for i := 0; i < N; i++ { + pb.F_Int32Repeated[i] = int32(i) + pb.F_DoubleRepeated[i] = float64(i) + } + return pb +} + +func bytesMsg() *GoTest { + pb := initGoTest(true) + buf := make([]byte, 4000) + for i := range buf { + buf[i] = byte(i) + } + pb.F_BytesDefaulted = buf + return pb +} + +func benchmarkMarshal(b *testing.B, pb Message, marshal func(Message) ([]byte, error)) { + d, _ := marshal(pb) + b.SetBytes(int64(len(d))) + b.ResetTimer() + for i := 0; i < b.N; i++ { + marshal(pb) + } +} + +func benchmarkBufferMarshal(b *testing.B, pb Message) { + p := NewBuffer(nil) + benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) { + p.Reset() + err := p.Marshal(pb0) + return p.Bytes(), err + }) +} + +func benchmarkSize(b *testing.B, pb Message) { + benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) { + Size(pb) + return nil, nil + }) +} + +func newOf(pb Message) Message { + in := reflect.ValueOf(pb) + if in.IsNil() { + return pb + } + return reflect.New(in.Type().Elem()).Interface().(Message) +} + +func benchmarkUnmarshal(b *testing.B, pb Message, unmarshal func([]byte, Message) error) { + d, _ := Marshal(pb) + b.SetBytes(int64(len(d))) + pbd := newOf(pb) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + unmarshal(d, pbd) + } +} + +func benchmarkBufferUnmarshal(b *testing.B, pb Message) { + p := NewBuffer(nil) + benchmarkUnmarshal(b, pb, func(d []byte, pb0 Message) error { + p.SetBuf(d) + return p.Unmarshal(pb0) + }) +} + +// Benchmark{Marshal,BufferMarshal,Size,Unmarshal,BufferUnmarshal}{,Bytes} + +func BenchmarkMarshal(b *testing.B) { + benchmarkMarshal(b, testMsg(), Marshal) +} + +func BenchmarkBufferMarshal(b *testing.B) { + benchmarkBufferMarshal(b, testMsg()) +} + +func BenchmarkSize(b *testing.B) { + benchmarkSize(b, testMsg()) +} + +func BenchmarkUnmarshal(b *testing.B) { + benchmarkUnmarshal(b, testMsg(), Unmarshal) +} + +func BenchmarkBufferUnmarshal(b *testing.B) { + benchmarkBufferUnmarshal(b, testMsg()) +} + +func BenchmarkMarshalBytes(b *testing.B) { + benchmarkMarshal(b, bytesMsg(), Marshal) +} + +func BenchmarkBufferMarshalBytes(b *testing.B) { + benchmarkBufferMarshal(b, bytesMsg()) +} + +func BenchmarkSizeBytes(b *testing.B) { + benchmarkSize(b, bytesMsg()) +} + +func BenchmarkUnmarshalBytes(b *testing.B) { + benchmarkUnmarshal(b, bytesMsg(), Unmarshal) +} + +func BenchmarkBufferUnmarshalBytes(b *testing.B) { + benchmarkBufferUnmarshal(b, bytesMsg()) +} + +func BenchmarkUnmarshalUnrecognizedFields(b *testing.B) { + b.StopTimer() + pb := initGoTestField() + skip := &GoSkipTest{ + SkipInt32: Int32(32), + SkipFixed32: Uint32(3232), + SkipFixed64: Uint64(6464), + SkipString: String("skipper"), + Skipgroup: &GoSkipTest_SkipGroup{ + GroupInt32: Int32(75), + GroupString: String("wxyz"), + }, + } + + pbd := new(GoTestField) + p := NewBuffer(nil) + p.Marshal(pb) + p.Marshal(skip) + p2 := NewBuffer(nil) + + b.StartTimer() + for i := 0; i < b.N; i++ { + p2.SetBuf(p.Bytes()) + p2.Unmarshal(pbd) + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/any_test.go b/vendor/github.com/gogo/protobuf/proto/any_test.go new file mode 100644 index 000000000..f098d8287 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/any_test.go @@ -0,0 +1,300 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "strings" + "testing" + + "github.com/gogo/protobuf/proto" + + pb "github.com/gogo/protobuf/proto/proto3_proto" + testpb "github.com/gogo/protobuf/proto/testdata" + "github.com/gogo/protobuf/types" +) + +var ( + expandedMarshaler = proto.TextMarshaler{ExpandAny: true} + expandedCompactMarshaler = proto.TextMarshaler{Compact: true, ExpandAny: true} +) + +// anyEqual reports whether two messages which may be google.protobuf.Any or may +// contain google.protobuf.Any fields are equal. We can't use proto.Equal for +// comparison, because semantically equivalent messages may be marshaled to +// binary in different tag order. Instead, trust that TextMarshaler with +// ExpandAny option works and compare the text marshaling results. +func anyEqual(got, want proto.Message) bool { + // if messages are proto.Equal, no need to marshal. + if proto.Equal(got, want) { + return true + } + g := expandedMarshaler.Text(got) + w := expandedMarshaler.Text(want) + return g == w +} + +type golden struct { + m proto.Message + t, c string +} + +var goldenMessages = makeGolden() + +func makeGolden() []golden { + nested := &pb.Nested{Bunny: "Monty"} + nb, err := proto.Marshal(nested) + if err != nil { + panic(err) + } + m1 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(nested), Value: nb}, + } + m2 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: "http://[::1]/type.googleapis.com/" + proto.MessageName(nested), Value: nb}, + } + m3 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: `type.googleapis.com/"/` + proto.MessageName(nested), Value: nb}, + } + m4 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: "type.googleapis.com/a/path/" + proto.MessageName(nested), Value: nb}, + } + m5 := &types.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(nested), Value: nb} + + any1 := &testpb.MyMessage{Count: proto.Int32(47), Name: proto.String("David")} + proto.SetExtension(any1, testpb.E_Ext_More, &testpb.Ext{Data: proto.String("foo")}) + proto.SetExtension(any1, testpb.E_Ext_Text, proto.String("bar")) + any1b, err := proto.Marshal(any1) + if err != nil { + panic(err) + } + any2 := &testpb.MyMessage{Count: proto.Int32(42), Bikeshed: testpb.MyMessage_GREEN.Enum(), RepBytes: [][]byte{[]byte("roboto")}} + proto.SetExtension(any2, testpb.E_Ext_More, &testpb.Ext{Data: proto.String("baz")}) + any2b, err := proto.Marshal(any2) + if err != nil { + panic(err) + } + m6 := &pb.Message{ + Name: "David", + ResultCount: 47, + Anything: &types.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(any1), Value: any1b}, + ManyThings: []*types.Any{ + {TypeUrl: "type.googleapis.com/" + proto.MessageName(any2), Value: any2b}, + {TypeUrl: "type.googleapis.com/" + proto.MessageName(any1), Value: any1b}, + }, + } + + const ( + m1Golden = ` +name: "David" +result_count: 47 +anything: < + [type.googleapis.com/proto3_proto.Nested]: < + bunny: "Monty" + > +> +` + m2Golden = ` +name: "David" +result_count: 47 +anything: < + ["http://[::1]/type.googleapis.com/proto3_proto.Nested"]: < + bunny: "Monty" + > +> +` + m3Golden = ` +name: "David" +result_count: 47 +anything: < + ["type.googleapis.com/\"/proto3_proto.Nested"]: < + bunny: "Monty" + > +> +` + m4Golden = ` +name: "David" +result_count: 47 +anything: < + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Monty" + > +> +` + m5Golden = ` +[type.googleapis.com/proto3_proto.Nested]: < + bunny: "Monty" +> +` + m6Golden = ` +name: "David" +result_count: 47 +anything: < + [type.googleapis.com/testdata.MyMessage]: < + count: 47 + name: "David" + [testdata.Ext.more]: < + data: "foo" + > + [testdata.Ext.text]: "bar" + > +> +many_things: < + [type.googleapis.com/testdata.MyMessage]: < + count: 42 + bikeshed: GREEN + rep_bytes: "roboto" + [testdata.Ext.more]: < + data: "baz" + > + > +> +many_things: < + [type.googleapis.com/testdata.MyMessage]: < + count: 47 + name: "David" + [testdata.Ext.more]: < + data: "foo" + > + [testdata.Ext.text]: "bar" + > +> +` + ) + return []golden{ + {m1, strings.TrimSpace(m1Golden) + "\n", strings.TrimSpace(compact(m1Golden)) + " "}, + {m2, strings.TrimSpace(m2Golden) + "\n", strings.TrimSpace(compact(m2Golden)) + " "}, + {m3, strings.TrimSpace(m3Golden) + "\n", strings.TrimSpace(compact(m3Golden)) + " "}, + {m4, strings.TrimSpace(m4Golden) + "\n", strings.TrimSpace(compact(m4Golden)) + " "}, + {m5, strings.TrimSpace(m5Golden) + "\n", strings.TrimSpace(compact(m5Golden)) + " "}, + {m6, strings.TrimSpace(m6Golden) + "\n", strings.TrimSpace(compact(m6Golden)) + " "}, + } +} + +func TestMarshalGolden(t *testing.T) { + for _, tt := range goldenMessages { + if got, want := expandedMarshaler.Text(tt.m), tt.t; got != want { + t.Errorf("message %v: got:\n%s\nwant:\n%s", tt.m, got, want) + } + if got, want := expandedCompactMarshaler.Text(tt.m), tt.c; got != want { + t.Errorf("message %v: got:\n`%s`\nwant:\n`%s`", tt.m, got, want) + } + } +} + +func TestUnmarshalGolden(t *testing.T) { + for _, tt := range goldenMessages { + want := tt.m + got := proto.Clone(tt.m) + got.Reset() + if err := proto.UnmarshalText(tt.t, got); err != nil { + t.Errorf("failed to unmarshal\n%s\nerror: %v", tt.t, err) + } + if !anyEqual(got, want) { + t.Errorf("message:\n%s\ngot:\n%s\nwant:\n%s", tt.t, got, want) + } + got.Reset() + if err := proto.UnmarshalText(tt.c, got); err != nil { + t.Errorf("failed to unmarshal\n%s\nerror: %v", tt.c, err) + } + if !anyEqual(got, want) { + t.Errorf("message:\n%s\ngot:\n%s\nwant:\n%s", tt.c, got, want) + } + } +} + +func TestMarshalUnknownAny(t *testing.T) { + m := &pb.Message{ + Anything: &types.Any{ + TypeUrl: "foo", + Value: []byte("bar"), + }, + } + want := `anything: < + type_url: "foo" + value: "bar" +> +` + got := expandedMarshaler.Text(m) + if got != want { + t.Errorf("got\n`%s`\nwant\n`%s`", got, want) + } +} + +func TestAmbiguousAny(t *testing.T) { + pb := &types.Any{} + err := proto.UnmarshalText(` + type_url: "ttt/proto3_proto.Nested" + value: "\n\x05Monty" + `, pb) + t.Logf("result: %v (error: %v)", expandedMarshaler.Text(pb), err) + if err != nil { + t.Errorf("failed to parse ambiguous Any message: %v", err) + } +} + +func TestUnmarshalOverwriteAny(t *testing.T) { + pb := &types.Any{} + err := proto.UnmarshalText(` + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Monty" + > + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Rabbit of Caerbannog" + > + `, pb) + want := `line 7: Any message unpacked multiple times, or "type_url" already set` + if err.Error() != want { + t.Errorf("incorrect error.\nHave: %v\nWant: %v", err.Error(), want) + } +} + +func TestUnmarshalAnyMixAndMatch(t *testing.T) { + pb := &types.Any{} + err := proto.UnmarshalText(` + value: "\n\x05Monty" + [type.googleapis.com/a/path/proto3_proto.Nested]: < + bunny: "Rabbit of Caerbannog" + > + `, pb) + want := `line 5: Any message unpacked multiple times, or "value" already set` + if err.Error() != want { + t.Errorf("incorrect error.\nHave: %v\nWant: %v", err.Error(), want) + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/clone_test.go b/vendor/github.com/gogo/protobuf/proto/clone_test.go new file mode 100644 index 000000000..1a16eb554 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/clone_test.go @@ -0,0 +1,300 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2011 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "testing" + + "github.com/gogo/protobuf/proto" + + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + pb "github.com/gogo/protobuf/proto/testdata" +) + +var cloneTestMessage = &pb.MyMessage{ + Count: proto.Int32(42), + Name: proto.String("Dave"), + Pet: []string{"bunny", "kitty", "horsey"}, + Inner: &pb.InnerMessage{ + Host: proto.String("niles"), + Port: proto.Int32(9099), + Connected: proto.Bool(true), + }, + Others: []*pb.OtherMessage{ + { + Value: []byte("some bytes"), + }, + }, + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(6), + }, + RepBytes: [][]byte{[]byte("sham"), []byte("wow")}, +} + +func init() { + ext := &pb.Ext{ + Data: proto.String("extension"), + } + if err := proto.SetExtension(cloneTestMessage, pb.E_Ext_More, ext); err != nil { + panic("SetExtension: " + err.Error()) + } +} + +func TestClone(t *testing.T) { + m := proto.Clone(cloneTestMessage).(*pb.MyMessage) + if !proto.Equal(m, cloneTestMessage) { + t.Errorf("Clone(%v) = %v", cloneTestMessage, m) + } + + // Verify it was a deep copy. + *m.Inner.Port++ + if proto.Equal(m, cloneTestMessage) { + t.Error("Mutating clone changed the original") + } + // Byte fields and repeated fields should be copied. + if &m.Pet[0] == &cloneTestMessage.Pet[0] { + t.Error("Pet: repeated field not copied") + } + if &m.Others[0] == &cloneTestMessage.Others[0] { + t.Error("Others: repeated field not copied") + } + if &m.Others[0].Value[0] == &cloneTestMessage.Others[0].Value[0] { + t.Error("Others[0].Value: bytes field not copied") + } + if &m.RepBytes[0] == &cloneTestMessage.RepBytes[0] { + t.Error("RepBytes: repeated field not copied") + } + if &m.RepBytes[0][0] == &cloneTestMessage.RepBytes[0][0] { + t.Error("RepBytes[0]: bytes field not copied") + } +} + +func TestCloneNil(t *testing.T) { + var m *pb.MyMessage + if c := proto.Clone(m); !proto.Equal(m, c) { + t.Errorf("Clone(%v) = %v", m, c) + } +} + +var mergeTests = []struct { + src, dst, want proto.Message +}{ + { + src: &pb.MyMessage{ + Count: proto.Int32(42), + }, + dst: &pb.MyMessage{ + Name: proto.String("Dave"), + }, + want: &pb.MyMessage{ + Count: proto.Int32(42), + Name: proto.String("Dave"), + }, + }, + { + src: &pb.MyMessage{ + Inner: &pb.InnerMessage{ + Host: proto.String("hey"), + Connected: proto.Bool(true), + }, + Pet: []string{"horsey"}, + Others: []*pb.OtherMessage{ + { + Value: []byte("some bytes"), + }, + }, + }, + dst: &pb.MyMessage{ + Inner: &pb.InnerMessage{ + Host: proto.String("niles"), + Port: proto.Int32(9099), + }, + Pet: []string{"bunny", "kitty"}, + Others: []*pb.OtherMessage{ + { + Key: proto.Int64(31415926535), + }, + { + // Explicitly test a src=nil field + Inner: nil, + }, + }, + }, + want: &pb.MyMessage{ + Inner: &pb.InnerMessage{ + Host: proto.String("hey"), + Connected: proto.Bool(true), + Port: proto.Int32(9099), + }, + Pet: []string{"bunny", "kitty", "horsey"}, + Others: []*pb.OtherMessage{ + { + Key: proto.Int64(31415926535), + }, + {}, + { + Value: []byte("some bytes"), + }, + }, + }, + }, + { + src: &pb.MyMessage{ + RepBytes: [][]byte{[]byte("wow")}, + }, + dst: &pb.MyMessage{ + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(6), + }, + RepBytes: [][]byte{[]byte("sham")}, + }, + want: &pb.MyMessage{ + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(6), + }, + RepBytes: [][]byte{[]byte("sham"), []byte("wow")}, + }, + }, + // Check that a scalar bytes field replaces rather than appends. + { + src: &pb.OtherMessage{Value: []byte("foo")}, + dst: &pb.OtherMessage{Value: []byte("bar")}, + want: &pb.OtherMessage{Value: []byte("foo")}, + }, + { + src: &pb.MessageWithMap{ + NameMapping: map[int32]string{6: "Nigel"}, + MsgMapping: map[int64]*pb.FloatingPoint{ + 0x4001: {F: proto.Float64(2.0)}, + 0x4002: { + F: proto.Float64(2.0), + }, + }, + ByteMapping: map[bool][]byte{true: []byte("wowsa")}, + }, + dst: &pb.MessageWithMap{ + NameMapping: map[int32]string{ + 6: "Bruce", // should be overwritten + 7: "Andrew", + }, + MsgMapping: map[int64]*pb.FloatingPoint{ + 0x4002: { + F: proto.Float64(3.0), + Exact: proto.Bool(true), + }, // the entire message should be overwritten + }, + }, + want: &pb.MessageWithMap{ + NameMapping: map[int32]string{ + 6: "Nigel", + 7: "Andrew", + }, + MsgMapping: map[int64]*pb.FloatingPoint{ + 0x4001: {F: proto.Float64(2.0)}, + 0x4002: { + F: proto.Float64(2.0), + }, + }, + ByteMapping: map[bool][]byte{true: []byte("wowsa")}, + }, + }, + // proto3 shouldn't merge zero values, + // in the same way that proto2 shouldn't merge nils. + { + src: &proto3pb.Message{ + Name: "Aaron", + Data: []byte(""), // zero value, but not nil + }, + dst: &proto3pb.Message{ + HeightInCm: 176, + Data: []byte("texas!"), + }, + want: &proto3pb.Message{ + Name: "Aaron", + HeightInCm: 176, + Data: []byte("texas!"), + }, + }, + // Oneof fields should merge by assignment. + { + src: &pb.Communique{ + Union: &pb.Communique_Number{Number: 41}, + }, + dst: &pb.Communique{ + Union: &pb.Communique_Name{Name: "Bobby Tables"}, + }, + want: &pb.Communique{ + Union: &pb.Communique_Number{Number: 41}, + }, + }, + // Oneof nil is the same as not set. + { + src: &pb.Communique{}, + dst: &pb.Communique{ + Union: &pb.Communique_Name{Name: "Bobby Tables"}, + }, + want: &pb.Communique{ + Union: &pb.Communique_Name{Name: "Bobby Tables"}, + }, + }, + { + src: &proto3pb.Message{ + Terrain: map[string]*proto3pb.Nested{ + "kay_a": {Cute: true}, // replace + "kay_b": {Bunny: "rabbit"}, // insert + }, + }, + dst: &proto3pb.Message{ + Terrain: map[string]*proto3pb.Nested{ + "kay_a": {Bunny: "lost"}, // replaced + "kay_c": {Bunny: "bunny"}, // keep + }, + }, + want: &proto3pb.Message{ + Terrain: map[string]*proto3pb.Nested{ + "kay_a": {Cute: true}, + "kay_b": {Bunny: "rabbit"}, + "kay_c": {Bunny: "bunny"}, + }, + }, + }, +} + +func TestMerge(t *testing.T) { + for _, m := range mergeTests { + got := proto.Clone(m.dst) + proto.Merge(got, m.src) + if !proto.Equal(got, m.want) { + t.Errorf("Merge(%v, %v)\n got %v\nwant %v\n", m.dst, m.src, got, m.want) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/decode_test.go b/vendor/github.com/gogo/protobuf/proto/decode_test.go new file mode 100644 index 000000000..64d4decd9 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/decode_test.go @@ -0,0 +1,262 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// +build go1.7 + +package proto_test + +import ( + "testing" + + "github.com/gogo/protobuf/proto" + tpb "github.com/gogo/protobuf/proto/proto3_proto" +) + +var ( + bytesBlackhole []byte + msgBlackhole = new(tpb.Message) +) + +// Disabled this Benchmark because it is using features (b.Run) from go1.7 and gogoprotobuf still have compatibility with go1.5 +// BenchmarkVarint32ArraySmall shows the performance on an array of small int32 fields (1 and +// 2 bytes long). +// func BenchmarkVarint32ArraySmall(b *testing.B) { +// for i := uint(1); i <= 10; i++ { +// dist := genInt32Dist([7]int{0, 3, 1}, 1<unmarshal. +} + +func TestMarshalUnmarshalRepeatedExtension(t *testing.T) { + // Add a repeated extension to the result. + tests := []struct { + name string + ext []*pb.ComplexExtension + }{ + { + "two fields", + []*pb.ComplexExtension{ + {First: proto.Int32(7)}, + {Second: proto.Int32(11)}, + }, + }, + { + "repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {Third: []int32{2000}}, + }, + }, + { + "two fields and repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {First: proto.Int32(9)}, + {Second: proto.Int32(21)}, + {Third: []int32{2000}}, + }, + }, + } + for _, test := range tests { + // Marshal message with a repeated extension. + msg1 := new(pb.OtherMessage) + err := proto.SetExtension(msg1, pb.E_RComplex, test.ext) + if err != nil { + t.Fatalf("[%s] Error setting extension: %v", test.name, err) + } + b, err := proto.Marshal(msg1) + if err != nil { + t.Fatalf("[%s] Error marshaling message: %v", test.name, err) + } + + // Unmarshal and read the merged proto. + msg2 := new(pb.OtherMessage) + err = proto.Unmarshal(b, msg2) + if err != nil { + t.Fatalf("[%s] Error unmarshaling message: %v", test.name, err) + } + e, err := proto.GetExtension(msg2, pb.E_RComplex) + if err != nil { + t.Fatalf("[%s] Error getting extension: %v", test.name, err) + } + ext := e.([]*pb.ComplexExtension) + if ext == nil { + t.Fatalf("[%s] Invalid extension", test.name) + } + if !reflect.DeepEqual(ext, test.ext) { + t.Errorf("[%s] Wrong value for ComplexExtension: got: %v want: %v\n", test.name, ext, test.ext) + } + } +} + +func TestUnmarshalRepeatingNonRepeatedExtension(t *testing.T) { + // We may see multiple instances of the same extension in the wire + // format. For example, the proto compiler may encode custom options in + // this way. Here, we verify that we merge the extensions together. + tests := []struct { + name string + ext []*pb.ComplexExtension + }{ + { + "two fields", + []*pb.ComplexExtension{ + {First: proto.Int32(7)}, + {Second: proto.Int32(11)}, + }, + }, + { + "repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {Third: []int32{2000}}, + }, + }, + { + "two fields and repeated field", + []*pb.ComplexExtension{ + {Third: []int32{1000}}, + {First: proto.Int32(9)}, + {Second: proto.Int32(21)}, + {Third: []int32{2000}}, + }, + }, + } + for _, test := range tests { + var buf bytes.Buffer + var want pb.ComplexExtension + + // Generate a serialized representation of a repeated extension + // by catenating bytes together. + for i, e := range test.ext { + // Merge to create the wanted proto. + proto.Merge(&want, e) + + // serialize the message + msg := new(pb.OtherMessage) + err := proto.SetExtension(msg, pb.E_Complex, e) + if err != nil { + t.Fatalf("[%s] Error setting extension %d: %v", test.name, i, err) + } + b, err := proto.Marshal(msg) + if err != nil { + t.Fatalf("[%s] Error marshaling message %d: %v", test.name, i, err) + } + buf.Write(b) + } + + // Unmarshal and read the merged proto. + msg2 := new(pb.OtherMessage) + err := proto.Unmarshal(buf.Bytes(), msg2) + if err != nil { + t.Fatalf("[%s] Error unmarshaling message: %v", test.name, err) + } + e, err := proto.GetExtension(msg2, pb.E_Complex) + if err != nil { + t.Fatalf("[%s] Error getting extension: %v", test.name, err) + } + ext := e.(*pb.ComplexExtension) + if ext == nil { + t.Fatalf("[%s] Invalid extension", test.name) + } + if !reflect.DeepEqual(*ext, want) { + t.Errorf("[%s] Wrong value for ComplexExtension: got: %v want: %v\n", test.name, ext, want) + } + } +} + +func TestClearAllExtensions(t *testing.T) { + // unregistered extension + desc := &proto.ExtensionDesc{ + ExtendedType: (*pb.MyMessage)(nil), + ExtensionType: (*bool)(nil), + Field: 101010100, + Name: "emptyextension", + Tag: "varint,0,opt", + } + m := &pb.MyMessage{} + if proto.HasExtension(m, desc) { + t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m)) + } + if err := proto.SetExtension(m, desc, proto.Bool(true)); err != nil { + t.Errorf("proto.SetExtension(m, desc, true): got error %q, want nil", err) + } + if !proto.HasExtension(m, desc) { + t.Errorf("proto.HasExtension(%s): got false, want true", proto.MarshalTextString(m)) + } + proto.ClearAllExtensions(m) + if proto.HasExtension(m, desc) { + t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m)) + } +} + +func TestMarshalRace(t *testing.T) { + // unregistered extension + desc := &proto.ExtensionDesc{ + ExtendedType: (*pb.MyMessage)(nil), + ExtensionType: (*bool)(nil), + Field: 101010100, + Name: "emptyextension", + Tag: "varint,0,opt", + } + + m := &pb.MyMessage{Count: proto.Int32(4)} + if err := proto.SetExtension(m, desc, proto.Bool(true)); err != nil { + t.Errorf("proto.SetExtension(m, desc, true): got error %q, want nil", err) + } + + errChan := make(chan error, 3) + for n := 3; n > 0; n-- { + go func() { + _, err := proto.Marshal(m) + errChan <- err + }() + } + for i := 0; i < 3; i++ { + err := <-errChan + if err != nil { + t.Fatal(err) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/map_test.go b/vendor/github.com/gogo/protobuf/proto/map_test.go new file mode 100644 index 000000000..18b946d00 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/map_test.go @@ -0,0 +1,46 @@ +package proto_test + +import ( + "fmt" + "testing" + + "github.com/gogo/protobuf/proto" + ppb "github.com/gogo/protobuf/proto/proto3_proto" +) + +func marshalled() []byte { + m := &ppb.IntMaps{} + for i := 0; i < 1000; i++ { + m.Maps = append(m.Maps, &ppb.IntMap{ + Rtt: map[int32]int32{1: 2}, + }) + } + b, err := proto.Marshal(m) + if err != nil { + panic(fmt.Sprintf("Can't marshal %+v: %v", m, err)) + } + return b +} + +func BenchmarkConcurrentMapUnmarshal(b *testing.B) { + in := marshalled() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + var out ppb.IntMaps + if err := proto.Unmarshal(in, &out); err != nil { + b.Errorf("Can't unmarshal ppb.IntMaps: %v", err) + } + } + }) +} + +func BenchmarkSequentialMapUnmarshal(b *testing.B) { + in := marshalled() + b.ResetTimer() + for i := 0; i < b.N; i++ { + var out ppb.IntMaps + if err := proto.Unmarshal(in, &out); err != nil { + b.Errorf("Can't unmarshal ppb.IntMaps: %v", err) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/message_set_test.go b/vendor/github.com/gogo/protobuf/proto/message_set_test.go new file mode 100644 index 000000000..353a3ea76 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/message_set_test.go @@ -0,0 +1,66 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto + +import ( + "bytes" + "testing" +) + +func TestUnmarshalMessageSetWithDuplicate(t *testing.T) { + // Check that a repeated message set entry will be concatenated. + in := &messageSet{ + Item: []*_MessageSet_Item{ + {TypeId: Int32(12345), Message: []byte("hoo")}, + {TypeId: Int32(12345), Message: []byte("hah")}, + }, + } + b, err := Marshal(in) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + t.Logf("Marshaled bytes: %q", b) + + var extensions XXX_InternalExtensions + if err := UnmarshalMessageSet(b, &extensions); err != nil { + t.Fatalf("UnmarshalMessageSet: %v", err) + } + ext, ok := extensions.p.extensionMap[12345] + if !ok { + t.Fatalf("Didn't retrieve extension 12345; map is %v", extensions.p.extensionMap) + } + // Skip wire type/field number and length varints. + got := skipVarint(skipVarint(ext.enc)) + if want := []byte("hoohah"); !bytes.Equal(got, want) { + t.Errorf("Combined extension is %q, want %q", got, want) + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/proto3_proto/proto3.proto b/vendor/github.com/gogo/protobuf/proto/proto3_proto/proto3.proto new file mode 100644 index 000000000..85a36818f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/proto3_proto/proto3.proto @@ -0,0 +1,87 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +import "google/protobuf/any.proto"; +import "testdata/test.proto"; + +package proto3_proto; + +message Message { + enum Humour { + UNKNOWN = 0; + PUNS = 1; + SLAPSTICK = 2; + BILL_BAILEY = 3; + } + + string name = 1; + Humour hilarity = 2; + uint32 height_in_cm = 3; + bytes data = 4; + int64 result_count = 7; + bool true_scotsman = 8; + float score = 9; + + repeated uint64 key = 5; + repeated int32 short_key = 19; + Nested nested = 6; + repeated Humour r_funny = 16; + + map terrain = 10; + testdata.SubDefaults proto2_field = 11; + map proto2_value = 13; + + google.protobuf.Any anything = 14; + repeated google.protobuf.Any many_things = 15; + + Message submessage = 17; + repeated Message children = 18; +} + +message Nested { + string bunny = 1; + bool cute = 2; +} + +message MessageWithMap { + map byte_mapping = 1; +} + + +message IntMap { + map rtt = 1; +} + +message IntMaps { + repeated IntMap maps = 1; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/proto/proto3_test.go b/vendor/github.com/gogo/protobuf/proto/proto3_test.go new file mode 100644 index 000000000..75b66c179 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/proto3_test.go @@ -0,0 +1,135 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "testing" + + "github.com/gogo/protobuf/proto" + pb "github.com/gogo/protobuf/proto/proto3_proto" + tpb "github.com/gogo/protobuf/proto/testdata" +) + +func TestProto3ZeroValues(t *testing.T) { + tests := []struct { + desc string + m proto.Message + }{ + {"zero message", &pb.Message{}}, + {"empty bytes field", &pb.Message{Data: []byte{}}}, + } + for _, test := range tests { + b, err := proto.Marshal(test.m) + if err != nil { + t.Errorf("%s: proto.Marshal: %v", test.desc, err) + continue + } + if len(b) > 0 { + t.Errorf("%s: Encoding is non-empty: %q", test.desc, b) + } + } +} + +func TestRoundTripProto3(t *testing.T) { + m := &pb.Message{ + Name: "David", // (2 | 1<<3): 0x0a 0x05 "David" + Hilarity: pb.Message_PUNS, // (0 | 2<<3): 0x10 0x01 + HeightInCm: 178, // (0 | 3<<3): 0x18 0xb2 0x01 + Data: []byte("roboto"), // (2 | 4<<3): 0x20 0x06 "roboto" + ResultCount: 47, // (0 | 7<<3): 0x38 0x2f + TrueScotsman: true, // (0 | 8<<3): 0x40 0x01 + Score: 8.1, // (5 | 9<<3): 0x4d <8.1> + + Key: []uint64{1, 0xdeadbeef}, + Nested: &pb.Nested{ + Bunny: "Monty", + }, + } + t.Logf(" m: %v", m) + + b, err := proto.Marshal(m) + if err != nil { + t.Fatalf("proto.Marshal: %v", err) + } + t.Logf(" b: %q", b) + + m2 := new(pb.Message) + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatalf("proto.Unmarshal: %v", err) + } + t.Logf("m2: %v", m2) + + if !proto.Equal(m, m2) { + t.Errorf("proto.Equal returned false:\n m: %v\nm2: %v", m, m2) + } +} + +func TestGettersForBasicTypesExist(t *testing.T) { + var m pb.Message + if got := m.GetNested().GetBunny(); got != "" { + t.Errorf("m.GetNested().GetBunny() = %q, want empty string", got) + } + if got := m.GetNested().GetCute(); got { + t.Errorf("m.GetNested().GetCute() = %t, want false", got) + } +} + +func TestProto3SetDefaults(t *testing.T) { + in := &pb.Message{ + Terrain: map[string]*pb.Nested{ + "meadow": new(pb.Nested), + }, + Proto2Field: new(tpb.SubDefaults), + Proto2Value: map[string]*tpb.SubDefaults{ + "badlands": new(tpb.SubDefaults), + }, + } + + got := proto.Clone(in).(*pb.Message) + proto.SetDefaults(got) + + // There are no defaults in proto3. Everything should be the zero value, but + // we need to remember to set defaults for nested proto2 messages. + want := &pb.Message{ + Terrain: map[string]*pb.Nested{ + "meadow": new(pb.Nested), + }, + Proto2Field: &tpb.SubDefaults{N: proto.Int64(7)}, + Proto2Value: map[string]*tpb.SubDefaults{ + "badlands": {N: proto.Int64(7)}, + }, + } + + if !proto.Equal(got, want) { + t.Errorf("with in = %v\nproto.SetDefaults(in) =>\ngot %v\nwant %v", in, got, want) + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/size2_test.go b/vendor/github.com/gogo/protobuf/proto/size2_test.go new file mode 100644 index 000000000..a2729c39a --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/size2_test.go @@ -0,0 +1,63 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto + +import ( + "testing" +) + +// This is a separate file and package from size_test.go because that one uses +// generated messages and thus may not be in package proto without having a circular +// dependency, whereas this file tests unexported details of size.go. + +func TestVarintSize(t *testing.T) { + // Check the edge cases carefully. + testCases := []struct { + n uint64 + size int + }{ + {0, 1}, + {1, 1}, + {127, 1}, + {128, 2}, + {16383, 2}, + {16384, 3}, + {1<<63 - 1, 9}, + {1 << 63, 10}, + } + for _, tc := range testCases { + size := sizeVarint(tc.n) + if size != tc.size { + t.Errorf("sizeVarint(%d) = %d, want %d", tc.n, size, tc.size) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/size_test.go b/vendor/github.com/gogo/protobuf/proto/size_test.go new file mode 100644 index 000000000..0a6c1772b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/size_test.go @@ -0,0 +1,164 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "log" + "strings" + "testing" + + . "github.com/gogo/protobuf/proto" + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + pb "github.com/gogo/protobuf/proto/testdata" +) + +var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)} + +// messageWithExtension2 is in equal_test.go. +var messageWithExtension3 = &pb.MyMessage{Count: Int32(8)} + +func init() { + if err := SetExtension(messageWithExtension1, pb.E_Ext_More, &pb.Ext{Data: String("Abbott")}); err != nil { + log.Panicf("SetExtension: %v", err) + } + if err := SetExtension(messageWithExtension3, pb.E_Ext_More, &pb.Ext{Data: String("Costello")}); err != nil { + log.Panicf("SetExtension: %v", err) + } + + // Force messageWithExtension3 to have the extension encoded. + Marshal(messageWithExtension3) + +} + +var SizeTests = []struct { + desc string + pb Message +}{ + {"empty", &pb.OtherMessage{}}, + // Basic types. + {"bool", &pb.Defaults{F_Bool: Bool(true)}}, + {"int32", &pb.Defaults{F_Int32: Int32(12)}}, + {"negative int32", &pb.Defaults{F_Int32: Int32(-1)}}, + {"small int64", &pb.Defaults{F_Int64: Int64(1)}}, + {"big int64", &pb.Defaults{F_Int64: Int64(1 << 20)}}, + {"negative int64", &pb.Defaults{F_Int64: Int64(-1)}}, + {"fixed32", &pb.Defaults{F_Fixed32: Uint32(71)}}, + {"fixed64", &pb.Defaults{F_Fixed64: Uint64(72)}}, + {"uint32", &pb.Defaults{F_Uint32: Uint32(123)}}, + {"uint64", &pb.Defaults{F_Uint64: Uint64(124)}}, + {"float", &pb.Defaults{F_Float: Float32(12.6)}}, + {"double", &pb.Defaults{F_Double: Float64(13.9)}}, + {"string", &pb.Defaults{F_String: String("niles")}}, + {"bytes", &pb.Defaults{F_Bytes: []byte("wowsa")}}, + {"bytes, empty", &pb.Defaults{F_Bytes: []byte{}}}, + {"sint32", &pb.Defaults{F_Sint32: Int32(65)}}, + {"sint64", &pb.Defaults{F_Sint64: Int64(67)}}, + {"enum", &pb.Defaults{F_Enum: pb.Defaults_BLUE.Enum()}}, + // Repeated. + {"empty repeated bool", &pb.MoreRepeated{Bools: []bool{}}}, + {"repeated bool", &pb.MoreRepeated{Bools: []bool{false, true, true, false}}}, + {"packed repeated bool", &pb.MoreRepeated{BoolsPacked: []bool{false, true, true, false, true, true, true}}}, + {"repeated int32", &pb.MoreRepeated{Ints: []int32{1, 12203, 1729, -1}}}, + {"repeated int32 packed", &pb.MoreRepeated{IntsPacked: []int32{1, 12203, 1729}}}, + {"repeated int64 packed", &pb.MoreRepeated{Int64SPacked: []int64{ + // Need enough large numbers to verify that the header is counting the number of bytes + // for the field, not the number of elements. + 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, + 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, + }}}, + {"repeated string", &pb.MoreRepeated{Strings: []string{"r", "ken", "gri"}}}, + {"repeated fixed", &pb.MoreRepeated{Fixeds: []uint32{1, 2, 3, 4}}}, + // Nested. + {"nested", &pb.OldMessage{Nested: &pb.OldMessage_Nested{Name: String("whatever")}}}, + {"group", &pb.GroupOld{G: &pb.GroupOld_G{X: Int32(12345)}}}, + // Other things. + {"unrecognized", &pb.MoreRepeated{XXX_unrecognized: []byte{13<<3 | 0, 4}}}, + {"extension (unencoded)", messageWithExtension1}, + {"extension (encoded)", messageWithExtension3}, + // proto3 message + {"proto3 empty", &proto3pb.Message{}}, + {"proto3 bool", &proto3pb.Message{TrueScotsman: true}}, + {"proto3 int64", &proto3pb.Message{ResultCount: 1}}, + {"proto3 uint32", &proto3pb.Message{HeightInCm: 123}}, + {"proto3 float", &proto3pb.Message{Score: 12.6}}, + {"proto3 string", &proto3pb.Message{Name: "Snezana"}}, + {"proto3 bytes", &proto3pb.Message{Data: []byte("wowsa")}}, + {"proto3 bytes, empty", &proto3pb.Message{Data: []byte{}}}, + {"proto3 enum", &proto3pb.Message{Hilarity: proto3pb.Message_PUNS}}, + {"proto3 map field with empty bytes", &proto3pb.MessageWithMap{ByteMapping: map[bool][]byte{false: {}}}}, + + {"map field", &pb.MessageWithMap{NameMapping: map[int32]string{1: "Rob", 7: "Andrew"}}}, + {"map field with message", &pb.MessageWithMap{MsgMapping: map[int64]*pb.FloatingPoint{0x7001: {F: Float64(2.0)}}}}, + {"map field with bytes", &pb.MessageWithMap{ByteMapping: map[bool][]byte{true: []byte("this time for sure")}}}, + {"map field with empty bytes", &pb.MessageWithMap{ByteMapping: map[bool][]byte{true: {}}}}, + + {"map field with big entry", &pb.MessageWithMap{NameMapping: map[int32]string{8: strings.Repeat("x", 125)}}}, + {"map field with big key and val", &pb.MessageWithMap{StrToStr: map[string]string{strings.Repeat("x", 70): strings.Repeat("y", 70)}}}, + {"map field with big numeric key", &pb.MessageWithMap{NameMapping: map[int32]string{0xf00d: "om nom nom"}}}, + + {"oneof not set", &pb.Oneof{}}, + {"oneof bool", &pb.Oneof{Union: &pb.Oneof_F_Bool{F_Bool: true}}}, + {"oneof zero int32", &pb.Oneof{Union: &pb.Oneof_F_Int32{F_Int32: 0}}}, + {"oneof big int32", &pb.Oneof{Union: &pb.Oneof_F_Int32{F_Int32: 1 << 20}}}, + {"oneof int64", &pb.Oneof{Union: &pb.Oneof_F_Int64{F_Int64: 42}}}, + {"oneof fixed32", &pb.Oneof{Union: &pb.Oneof_F_Fixed32{F_Fixed32: 43}}}, + {"oneof fixed64", &pb.Oneof{Union: &pb.Oneof_F_Fixed64{F_Fixed64: 44}}}, + {"oneof uint32", &pb.Oneof{Union: &pb.Oneof_F_Uint32{F_Uint32: 45}}}, + {"oneof uint64", &pb.Oneof{Union: &pb.Oneof_F_Uint64{F_Uint64: 46}}}, + {"oneof float", &pb.Oneof{Union: &pb.Oneof_F_Float{F_Float: 47.1}}}, + {"oneof double", &pb.Oneof{Union: &pb.Oneof_F_Double{F_Double: 48.9}}}, + {"oneof string", &pb.Oneof{Union: &pb.Oneof_F_String{F_String: "Rhythmic Fman"}}}, + {"oneof bytes", &pb.Oneof{Union: &pb.Oneof_F_Bytes{F_Bytes: []byte("let go")}}}, + {"oneof sint32", &pb.Oneof{Union: &pb.Oneof_F_Sint32{F_Sint32: 50}}}, + {"oneof sint64", &pb.Oneof{Union: &pb.Oneof_F_Sint64{F_Sint64: 51}}}, + {"oneof enum", &pb.Oneof{Union: &pb.Oneof_F_Enum{F_Enum: pb.MyMessage_BLUE}}}, + {"message for oneof", &pb.GoTestField{Label: String("k"), Type: String("v")}}, + {"oneof message", &pb.Oneof{Union: &pb.Oneof_F_Message{F_Message: &pb.GoTestField{Label: String("k"), Type: String("v")}}}}, + {"oneof group", &pb.Oneof{Union: &pb.Oneof_FGroup{FGroup: &pb.Oneof_F_Group{X: Int32(52)}}}}, + {"oneof largest tag", &pb.Oneof{Union: &pb.Oneof_F_Largest_Tag{F_Largest_Tag: 1}}}, + {"multiple oneofs", &pb.Oneof{Union: &pb.Oneof_F_Int32{F_Int32: 1}, Tormato: &pb.Oneof_Value{Value: 2}}}, +} + +func TestSize(t *testing.T) { + for _, tc := range SizeTests { + size := Size(tc.pb) + b, err := Marshal(tc.pb) + if err != nil { + t.Errorf("%v: Marshal failed: %v", tc.desc, err) + continue + } + if size != len(b) { + t.Errorf("%v: Size(%v) = %d, want %d", tc.desc, tc.pb, size, len(b)) + t.Logf("%v: bytes: %#v", tc.desc, b) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/testdata/Makefile b/vendor/github.com/gogo/protobuf/proto/testdata/Makefile new file mode 100644 index 000000000..31d83277c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/testdata/Makefile @@ -0,0 +1,37 @@ +# Go support for Protocol Buffers - Google's data interchange format +# +# Copyright 2010 The Go Authors. All rights reserved. +# https://github.com/golang/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: regenerate + +regenerate: + go install github.com/gogo/protobuf/protoc-min-version + protoc-min-version --version="3.0.0" --gogo_out=. test.proto + diff --git a/vendor/github.com/gogo/protobuf/proto/testdata/golden_test.go b/vendor/github.com/gogo/protobuf/proto/testdata/golden_test.go new file mode 100644 index 000000000..8e8451537 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/testdata/golden_test.go @@ -0,0 +1,86 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Verify that the compiler output for test.proto is unchanged. + +package testdata + +import ( + "crypto/sha1" + "fmt" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "testing" +) + +// sum returns in string form (for easy comparison) the SHA-1 hash of the named file. +func sum(t *testing.T, name string) string { + data, err := ioutil.ReadFile(name) + if err != nil { + t.Fatal(err) + } + t.Logf("sum(%q): length is %d", name, len(data)) + hash := sha1.New() + _, err = hash.Write(data) + if err != nil { + t.Fatal(err) + } + return fmt.Sprintf("% x", hash.Sum(nil)) +} + +func run(t *testing.T, name string, args ...string) { + cmd := exec.Command(name, args...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + t.Fatal(err) + } +} + +func TestGolden(t *testing.T) { + // Compute the original checksum. + goldenSum := sum(t, "test.pb.go") + // Run the proto compiler. + run(t, "protoc", "--gogo_out="+os.TempDir(), "test.proto") + newFile := filepath.Join(os.TempDir(), "test.pb.go") + defer os.Remove(newFile) + // Compute the new checksum. + newSum := sum(t, newFile) + // Verify + if newSum != goldenSum { + run(t, "diff", "-u", "test.pb.go", newFile) + t.Fatal("Code generated by protoc-gen-go has changed; update test.pb.go") + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/testdata/test.pb.go b/vendor/github.com/gogo/protobuf/proto/testdata/test.pb.go new file mode 100644 index 000000000..1a9a99376 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/testdata/test.pb.go @@ -0,0 +1,4147 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: test.proto + +/* +Package testdata is a generated protocol buffer package. + +It is generated from these files: + test.proto + +It has these top-level messages: + GoEnum + GoTestField + GoTest + GoTestRequiredGroupField + GoSkipTest + NonPackedTest + PackedTest + MaxTag + OldMessage + NewMessage + InnerMessage + OtherMessage + RequiredInnerMessage + MyMessage + Ext + ComplexExtension + DefaultsMessage + MyMessageSet + Empty + MessageList + Strings + Defaults + SubDefaults + RepeatedEnum + MoreRepeated + GroupOld + GroupNew + FloatingPoint + MessageWithMap + Oneof + Communique +*/ +package testdata + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type FOO int32 + +const ( + FOO_FOO1 FOO = 1 +) + +var FOO_name = map[int32]string{ + 1: "FOO1", +} +var FOO_value = map[string]int32{ + "FOO1": 1, +} + +func (x FOO) Enum() *FOO { + p := new(FOO) + *p = x + return p +} +func (x FOO) String() string { + return proto.EnumName(FOO_name, int32(x)) +} +func (x *FOO) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(FOO_value, data, "FOO") + if err != nil { + return err + } + *x = FOO(value) + return nil +} +func (FOO) EnumDescriptor() ([]byte, []int) { return fileDescriptorTest, []int{0} } + +// An enum, for completeness. +type GoTest_KIND int32 + +const ( + GoTest_VOID GoTest_KIND = 0 + // Basic types + GoTest_BOOL GoTest_KIND = 1 + GoTest_BYTES GoTest_KIND = 2 + GoTest_FINGERPRINT GoTest_KIND = 3 + GoTest_FLOAT GoTest_KIND = 4 + GoTest_INT GoTest_KIND = 5 + GoTest_STRING GoTest_KIND = 6 + GoTest_TIME GoTest_KIND = 7 + // Groupings + GoTest_TUPLE GoTest_KIND = 8 + GoTest_ARRAY GoTest_KIND = 9 + GoTest_MAP GoTest_KIND = 10 + // Table types + GoTest_TABLE GoTest_KIND = 11 + // Functions + GoTest_FUNCTION GoTest_KIND = 12 +) + +var GoTest_KIND_name = map[int32]string{ + 0: "VOID", + 1: "BOOL", + 2: "BYTES", + 3: "FINGERPRINT", + 4: "FLOAT", + 5: "INT", + 6: "STRING", + 7: "TIME", + 8: "TUPLE", + 9: "ARRAY", + 10: "MAP", + 11: "TABLE", + 12: "FUNCTION", +} +var GoTest_KIND_value = map[string]int32{ + "VOID": 0, + "BOOL": 1, + "BYTES": 2, + "FINGERPRINT": 3, + "FLOAT": 4, + "INT": 5, + "STRING": 6, + "TIME": 7, + "TUPLE": 8, + "ARRAY": 9, + "MAP": 10, + "TABLE": 11, + "FUNCTION": 12, +} + +func (x GoTest_KIND) Enum() *GoTest_KIND { + p := new(GoTest_KIND) + *p = x + return p +} +func (x GoTest_KIND) String() string { + return proto.EnumName(GoTest_KIND_name, int32(x)) +} +func (x *GoTest_KIND) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(GoTest_KIND_value, data, "GoTest_KIND") + if err != nil { + return err + } + *x = GoTest_KIND(value) + return nil +} +func (GoTest_KIND) EnumDescriptor() ([]byte, []int) { return fileDescriptorTest, []int{2, 0} } + +type MyMessage_Color int32 + +const ( + MyMessage_RED MyMessage_Color = 0 + MyMessage_GREEN MyMessage_Color = 1 + MyMessage_BLUE MyMessage_Color = 2 +) + +var MyMessage_Color_name = map[int32]string{ + 0: "RED", + 1: "GREEN", + 2: "BLUE", +} +var MyMessage_Color_value = map[string]int32{ + "RED": 0, + "GREEN": 1, + "BLUE": 2, +} + +func (x MyMessage_Color) Enum() *MyMessage_Color { + p := new(MyMessage_Color) + *p = x + return p +} +func (x MyMessage_Color) String() string { + return proto.EnumName(MyMessage_Color_name, int32(x)) +} +func (x *MyMessage_Color) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(MyMessage_Color_value, data, "MyMessage_Color") + if err != nil { + return err + } + *x = MyMessage_Color(value) + return nil +} +func (MyMessage_Color) EnumDescriptor() ([]byte, []int) { return fileDescriptorTest, []int{13, 0} } + +type DefaultsMessage_DefaultsEnum int32 + +const ( + DefaultsMessage_ZERO DefaultsMessage_DefaultsEnum = 0 + DefaultsMessage_ONE DefaultsMessage_DefaultsEnum = 1 + DefaultsMessage_TWO DefaultsMessage_DefaultsEnum = 2 +) + +var DefaultsMessage_DefaultsEnum_name = map[int32]string{ + 0: "ZERO", + 1: "ONE", + 2: "TWO", +} +var DefaultsMessage_DefaultsEnum_value = map[string]int32{ + "ZERO": 0, + "ONE": 1, + "TWO": 2, +} + +func (x DefaultsMessage_DefaultsEnum) Enum() *DefaultsMessage_DefaultsEnum { + p := new(DefaultsMessage_DefaultsEnum) + *p = x + return p +} +func (x DefaultsMessage_DefaultsEnum) String() string { + return proto.EnumName(DefaultsMessage_DefaultsEnum_name, int32(x)) +} +func (x *DefaultsMessage_DefaultsEnum) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(DefaultsMessage_DefaultsEnum_value, data, "DefaultsMessage_DefaultsEnum") + if err != nil { + return err + } + *x = DefaultsMessage_DefaultsEnum(value) + return nil +} +func (DefaultsMessage_DefaultsEnum) EnumDescriptor() ([]byte, []int) { + return fileDescriptorTest, []int{16, 0} +} + +type Defaults_Color int32 + +const ( + Defaults_RED Defaults_Color = 0 + Defaults_GREEN Defaults_Color = 1 + Defaults_BLUE Defaults_Color = 2 +) + +var Defaults_Color_name = map[int32]string{ + 0: "RED", + 1: "GREEN", + 2: "BLUE", +} +var Defaults_Color_value = map[string]int32{ + "RED": 0, + "GREEN": 1, + "BLUE": 2, +} + +func (x Defaults_Color) Enum() *Defaults_Color { + p := new(Defaults_Color) + *p = x + return p +} +func (x Defaults_Color) String() string { + return proto.EnumName(Defaults_Color_name, int32(x)) +} +func (x *Defaults_Color) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(Defaults_Color_value, data, "Defaults_Color") + if err != nil { + return err + } + *x = Defaults_Color(value) + return nil +} +func (Defaults_Color) EnumDescriptor() ([]byte, []int) { return fileDescriptorTest, []int{21, 0} } + +type RepeatedEnum_Color int32 + +const ( + RepeatedEnum_RED RepeatedEnum_Color = 1 +) + +var RepeatedEnum_Color_name = map[int32]string{ + 1: "RED", +} +var RepeatedEnum_Color_value = map[string]int32{ + "RED": 1, +} + +func (x RepeatedEnum_Color) Enum() *RepeatedEnum_Color { + p := new(RepeatedEnum_Color) + *p = x + return p +} +func (x RepeatedEnum_Color) String() string { + return proto.EnumName(RepeatedEnum_Color_name, int32(x)) +} +func (x *RepeatedEnum_Color) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(RepeatedEnum_Color_value, data, "RepeatedEnum_Color") + if err != nil { + return err + } + *x = RepeatedEnum_Color(value) + return nil +} +func (RepeatedEnum_Color) EnumDescriptor() ([]byte, []int) { return fileDescriptorTest, []int{23, 0} } + +type GoEnum struct { + Foo *FOO `protobuf:"varint,1,req,name=foo,enum=testdata.FOO" json:"foo,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoEnum) Reset() { *m = GoEnum{} } +func (m *GoEnum) String() string { return proto.CompactTextString(m) } +func (*GoEnum) ProtoMessage() {} +func (*GoEnum) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{0} } + +func (m *GoEnum) GetFoo() FOO { + if m != nil && m.Foo != nil { + return *m.Foo + } + return FOO_FOO1 +} + +type GoTestField struct { + Label *string `protobuf:"bytes,1,req,name=Label" json:"Label,omitempty"` + Type *string `protobuf:"bytes,2,req,name=Type" json:"Type,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTestField) Reset() { *m = GoTestField{} } +func (m *GoTestField) String() string { return proto.CompactTextString(m) } +func (*GoTestField) ProtoMessage() {} +func (*GoTestField) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{1} } + +func (m *GoTestField) GetLabel() string { + if m != nil && m.Label != nil { + return *m.Label + } + return "" +} + +func (m *GoTestField) GetType() string { + if m != nil && m.Type != nil { + return *m.Type + } + return "" +} + +type GoTest struct { + // Some typical parameters + Kind *GoTest_KIND `protobuf:"varint,1,req,name=Kind,enum=testdata.GoTest_KIND" json:"Kind,omitempty"` + Table *string `protobuf:"bytes,2,opt,name=Table" json:"Table,omitempty"` + Param *int32 `protobuf:"varint,3,opt,name=Param" json:"Param,omitempty"` + // Required, repeated and optional foreign fields. + RequiredField *GoTestField `protobuf:"bytes,4,req,name=RequiredField" json:"RequiredField,omitempty"` + RepeatedField []*GoTestField `protobuf:"bytes,5,rep,name=RepeatedField" json:"RepeatedField,omitempty"` + OptionalField *GoTestField `protobuf:"bytes,6,opt,name=OptionalField" json:"OptionalField,omitempty"` + // Required fields of all basic types + F_BoolRequired *bool `protobuf:"varint,10,req,name=F_Bool_required,json=FBoolRequired" json:"F_Bool_required,omitempty"` + F_Int32Required *int32 `protobuf:"varint,11,req,name=F_Int32_required,json=FInt32Required" json:"F_Int32_required,omitempty"` + F_Int64Required *int64 `protobuf:"varint,12,req,name=F_Int64_required,json=FInt64Required" json:"F_Int64_required,omitempty"` + F_Fixed32Required *uint32 `protobuf:"fixed32,13,req,name=F_Fixed32_required,json=FFixed32Required" json:"F_Fixed32_required,omitempty"` + F_Fixed64Required *uint64 `protobuf:"fixed64,14,req,name=F_Fixed64_required,json=FFixed64Required" json:"F_Fixed64_required,omitempty"` + F_Uint32Required *uint32 `protobuf:"varint,15,req,name=F_Uint32_required,json=FUint32Required" json:"F_Uint32_required,omitempty"` + F_Uint64Required *uint64 `protobuf:"varint,16,req,name=F_Uint64_required,json=FUint64Required" json:"F_Uint64_required,omitempty"` + F_FloatRequired *float32 `protobuf:"fixed32,17,req,name=F_Float_required,json=FFloatRequired" json:"F_Float_required,omitempty"` + F_DoubleRequired *float64 `protobuf:"fixed64,18,req,name=F_Double_required,json=FDoubleRequired" json:"F_Double_required,omitempty"` + F_StringRequired *string `protobuf:"bytes,19,req,name=F_String_required,json=FStringRequired" json:"F_String_required,omitempty"` + F_BytesRequired []byte `protobuf:"bytes,101,req,name=F_Bytes_required,json=FBytesRequired" json:"F_Bytes_required,omitempty"` + F_Sint32Required *int32 `protobuf:"zigzag32,102,req,name=F_Sint32_required,json=FSint32Required" json:"F_Sint32_required,omitempty"` + F_Sint64Required *int64 `protobuf:"zigzag64,103,req,name=F_Sint64_required,json=FSint64Required" json:"F_Sint64_required,omitempty"` + // Repeated fields of all basic types + F_BoolRepeated []bool `protobuf:"varint,20,rep,name=F_Bool_repeated,json=FBoolRepeated" json:"F_Bool_repeated,omitempty"` + F_Int32Repeated []int32 `protobuf:"varint,21,rep,name=F_Int32_repeated,json=FInt32Repeated" json:"F_Int32_repeated,omitempty"` + F_Int64Repeated []int64 `protobuf:"varint,22,rep,name=F_Int64_repeated,json=FInt64Repeated" json:"F_Int64_repeated,omitempty"` + F_Fixed32Repeated []uint32 `protobuf:"fixed32,23,rep,name=F_Fixed32_repeated,json=FFixed32Repeated" json:"F_Fixed32_repeated,omitempty"` + F_Fixed64Repeated []uint64 `protobuf:"fixed64,24,rep,name=F_Fixed64_repeated,json=FFixed64Repeated" json:"F_Fixed64_repeated,omitempty"` + F_Uint32Repeated []uint32 `protobuf:"varint,25,rep,name=F_Uint32_repeated,json=FUint32Repeated" json:"F_Uint32_repeated,omitempty"` + F_Uint64Repeated []uint64 `protobuf:"varint,26,rep,name=F_Uint64_repeated,json=FUint64Repeated" json:"F_Uint64_repeated,omitempty"` + F_FloatRepeated []float32 `protobuf:"fixed32,27,rep,name=F_Float_repeated,json=FFloatRepeated" json:"F_Float_repeated,omitempty"` + F_DoubleRepeated []float64 `protobuf:"fixed64,28,rep,name=F_Double_repeated,json=FDoubleRepeated" json:"F_Double_repeated,omitempty"` + F_StringRepeated []string `protobuf:"bytes,29,rep,name=F_String_repeated,json=FStringRepeated" json:"F_String_repeated,omitempty"` + F_BytesRepeated [][]byte `protobuf:"bytes,201,rep,name=F_Bytes_repeated,json=FBytesRepeated" json:"F_Bytes_repeated,omitempty"` + F_Sint32Repeated []int32 `protobuf:"zigzag32,202,rep,name=F_Sint32_repeated,json=FSint32Repeated" json:"F_Sint32_repeated,omitempty"` + F_Sint64Repeated []int64 `protobuf:"zigzag64,203,rep,name=F_Sint64_repeated,json=FSint64Repeated" json:"F_Sint64_repeated,omitempty"` + // Optional fields of all basic types + F_BoolOptional *bool `protobuf:"varint,30,opt,name=F_Bool_optional,json=FBoolOptional" json:"F_Bool_optional,omitempty"` + F_Int32Optional *int32 `protobuf:"varint,31,opt,name=F_Int32_optional,json=FInt32Optional" json:"F_Int32_optional,omitempty"` + F_Int64Optional *int64 `protobuf:"varint,32,opt,name=F_Int64_optional,json=FInt64Optional" json:"F_Int64_optional,omitempty"` + F_Fixed32Optional *uint32 `protobuf:"fixed32,33,opt,name=F_Fixed32_optional,json=FFixed32Optional" json:"F_Fixed32_optional,omitempty"` + F_Fixed64Optional *uint64 `protobuf:"fixed64,34,opt,name=F_Fixed64_optional,json=FFixed64Optional" json:"F_Fixed64_optional,omitempty"` + F_Uint32Optional *uint32 `protobuf:"varint,35,opt,name=F_Uint32_optional,json=FUint32Optional" json:"F_Uint32_optional,omitempty"` + F_Uint64Optional *uint64 `protobuf:"varint,36,opt,name=F_Uint64_optional,json=FUint64Optional" json:"F_Uint64_optional,omitempty"` + F_FloatOptional *float32 `protobuf:"fixed32,37,opt,name=F_Float_optional,json=FFloatOptional" json:"F_Float_optional,omitempty"` + F_DoubleOptional *float64 `protobuf:"fixed64,38,opt,name=F_Double_optional,json=FDoubleOptional" json:"F_Double_optional,omitempty"` + F_StringOptional *string `protobuf:"bytes,39,opt,name=F_String_optional,json=FStringOptional" json:"F_String_optional,omitempty"` + F_BytesOptional []byte `protobuf:"bytes,301,opt,name=F_Bytes_optional,json=FBytesOptional" json:"F_Bytes_optional,omitempty"` + F_Sint32Optional *int32 `protobuf:"zigzag32,302,opt,name=F_Sint32_optional,json=FSint32Optional" json:"F_Sint32_optional,omitempty"` + F_Sint64Optional *int64 `protobuf:"zigzag64,303,opt,name=F_Sint64_optional,json=FSint64Optional" json:"F_Sint64_optional,omitempty"` + // Default-valued fields of all basic types + F_BoolDefaulted *bool `protobuf:"varint,40,opt,name=F_Bool_defaulted,json=FBoolDefaulted,def=1" json:"F_Bool_defaulted,omitempty"` + F_Int32Defaulted *int32 `protobuf:"varint,41,opt,name=F_Int32_defaulted,json=FInt32Defaulted,def=32" json:"F_Int32_defaulted,omitempty"` + F_Int64Defaulted *int64 `protobuf:"varint,42,opt,name=F_Int64_defaulted,json=FInt64Defaulted,def=64" json:"F_Int64_defaulted,omitempty"` + F_Fixed32Defaulted *uint32 `protobuf:"fixed32,43,opt,name=F_Fixed32_defaulted,json=FFixed32Defaulted,def=320" json:"F_Fixed32_defaulted,omitempty"` + F_Fixed64Defaulted *uint64 `protobuf:"fixed64,44,opt,name=F_Fixed64_defaulted,json=FFixed64Defaulted,def=640" json:"F_Fixed64_defaulted,omitempty"` + F_Uint32Defaulted *uint32 `protobuf:"varint,45,opt,name=F_Uint32_defaulted,json=FUint32Defaulted,def=3200" json:"F_Uint32_defaulted,omitempty"` + F_Uint64Defaulted *uint64 `protobuf:"varint,46,opt,name=F_Uint64_defaulted,json=FUint64Defaulted,def=6400" json:"F_Uint64_defaulted,omitempty"` + F_FloatDefaulted *float32 `protobuf:"fixed32,47,opt,name=F_Float_defaulted,json=FFloatDefaulted,def=314159" json:"F_Float_defaulted,omitempty"` + F_DoubleDefaulted *float64 `protobuf:"fixed64,48,opt,name=F_Double_defaulted,json=FDoubleDefaulted,def=271828" json:"F_Double_defaulted,omitempty"` + F_StringDefaulted *string `protobuf:"bytes,49,opt,name=F_String_defaulted,json=FStringDefaulted,def=hello, \"world!\"\n" json:"F_String_defaulted,omitempty"` + F_BytesDefaulted []byte `protobuf:"bytes,401,opt,name=F_Bytes_defaulted,json=FBytesDefaulted,def=Bignose" json:"F_Bytes_defaulted,omitempty"` + F_Sint32Defaulted *int32 `protobuf:"zigzag32,402,opt,name=F_Sint32_defaulted,json=FSint32Defaulted,def=-32" json:"F_Sint32_defaulted,omitempty"` + F_Sint64Defaulted *int64 `protobuf:"zigzag64,403,opt,name=F_Sint64_defaulted,json=FSint64Defaulted,def=-64" json:"F_Sint64_defaulted,omitempty"` + // Packed repeated fields (no string or bytes). + F_BoolRepeatedPacked []bool `protobuf:"varint,50,rep,packed,name=F_Bool_repeated_packed,json=FBoolRepeatedPacked" json:"F_Bool_repeated_packed,omitempty"` + F_Int32RepeatedPacked []int32 `protobuf:"varint,51,rep,packed,name=F_Int32_repeated_packed,json=FInt32RepeatedPacked" json:"F_Int32_repeated_packed,omitempty"` + F_Int64RepeatedPacked []int64 `protobuf:"varint,52,rep,packed,name=F_Int64_repeated_packed,json=FInt64RepeatedPacked" json:"F_Int64_repeated_packed,omitempty"` + F_Fixed32RepeatedPacked []uint32 `protobuf:"fixed32,53,rep,packed,name=F_Fixed32_repeated_packed,json=FFixed32RepeatedPacked" json:"F_Fixed32_repeated_packed,omitempty"` + F_Fixed64RepeatedPacked []uint64 `protobuf:"fixed64,54,rep,packed,name=F_Fixed64_repeated_packed,json=FFixed64RepeatedPacked" json:"F_Fixed64_repeated_packed,omitempty"` + F_Uint32RepeatedPacked []uint32 `protobuf:"varint,55,rep,packed,name=F_Uint32_repeated_packed,json=FUint32RepeatedPacked" json:"F_Uint32_repeated_packed,omitempty"` + F_Uint64RepeatedPacked []uint64 `protobuf:"varint,56,rep,packed,name=F_Uint64_repeated_packed,json=FUint64RepeatedPacked" json:"F_Uint64_repeated_packed,omitempty"` + F_FloatRepeatedPacked []float32 `protobuf:"fixed32,57,rep,packed,name=F_Float_repeated_packed,json=FFloatRepeatedPacked" json:"F_Float_repeated_packed,omitempty"` + F_DoubleRepeatedPacked []float64 `protobuf:"fixed64,58,rep,packed,name=F_Double_repeated_packed,json=FDoubleRepeatedPacked" json:"F_Double_repeated_packed,omitempty"` + F_Sint32RepeatedPacked []int32 `protobuf:"zigzag32,502,rep,packed,name=F_Sint32_repeated_packed,json=FSint32RepeatedPacked" json:"F_Sint32_repeated_packed,omitempty"` + F_Sint64RepeatedPacked []int64 `protobuf:"zigzag64,503,rep,packed,name=F_Sint64_repeated_packed,json=FSint64RepeatedPacked" json:"F_Sint64_repeated_packed,omitempty"` + Requiredgroup *GoTest_RequiredGroup `protobuf:"group,70,req,name=RequiredGroup,json=requiredgroup" json:"requiredgroup,omitempty"` + Repeatedgroup []*GoTest_RepeatedGroup `protobuf:"group,80,rep,name=RepeatedGroup,json=repeatedgroup" json:"repeatedgroup,omitempty"` + Optionalgroup *GoTest_OptionalGroup `protobuf:"group,90,opt,name=OptionalGroup,json=optionalgroup" json:"optionalgroup,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTest) Reset() { *m = GoTest{} } +func (m *GoTest) String() string { return proto.CompactTextString(m) } +func (*GoTest) ProtoMessage() {} +func (*GoTest) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{2} } + +const Default_GoTest_F_BoolDefaulted bool = true +const Default_GoTest_F_Int32Defaulted int32 = 32 +const Default_GoTest_F_Int64Defaulted int64 = 64 +const Default_GoTest_F_Fixed32Defaulted uint32 = 320 +const Default_GoTest_F_Fixed64Defaulted uint64 = 640 +const Default_GoTest_F_Uint32Defaulted uint32 = 3200 +const Default_GoTest_F_Uint64Defaulted uint64 = 6400 +const Default_GoTest_F_FloatDefaulted float32 = 314159 +const Default_GoTest_F_DoubleDefaulted float64 = 271828 +const Default_GoTest_F_StringDefaulted string = "hello, \"world!\"\n" + +var Default_GoTest_F_BytesDefaulted []byte = []byte("Bignose") + +const Default_GoTest_F_Sint32Defaulted int32 = -32 +const Default_GoTest_F_Sint64Defaulted int64 = -64 + +func (m *GoTest) GetKind() GoTest_KIND { + if m != nil && m.Kind != nil { + return *m.Kind + } + return GoTest_VOID +} + +func (m *GoTest) GetTable() string { + if m != nil && m.Table != nil { + return *m.Table + } + return "" +} + +func (m *GoTest) GetParam() int32 { + if m != nil && m.Param != nil { + return *m.Param + } + return 0 +} + +func (m *GoTest) GetRequiredField() *GoTestField { + if m != nil { + return m.RequiredField + } + return nil +} + +func (m *GoTest) GetRepeatedField() []*GoTestField { + if m != nil { + return m.RepeatedField + } + return nil +} + +func (m *GoTest) GetOptionalField() *GoTestField { + if m != nil { + return m.OptionalField + } + return nil +} + +func (m *GoTest) GetF_BoolRequired() bool { + if m != nil && m.F_BoolRequired != nil { + return *m.F_BoolRequired + } + return false +} + +func (m *GoTest) GetF_Int32Required() int32 { + if m != nil && m.F_Int32Required != nil { + return *m.F_Int32Required + } + return 0 +} + +func (m *GoTest) GetF_Int64Required() int64 { + if m != nil && m.F_Int64Required != nil { + return *m.F_Int64Required + } + return 0 +} + +func (m *GoTest) GetF_Fixed32Required() uint32 { + if m != nil && m.F_Fixed32Required != nil { + return *m.F_Fixed32Required + } + return 0 +} + +func (m *GoTest) GetF_Fixed64Required() uint64 { + if m != nil && m.F_Fixed64Required != nil { + return *m.F_Fixed64Required + } + return 0 +} + +func (m *GoTest) GetF_Uint32Required() uint32 { + if m != nil && m.F_Uint32Required != nil { + return *m.F_Uint32Required + } + return 0 +} + +func (m *GoTest) GetF_Uint64Required() uint64 { + if m != nil && m.F_Uint64Required != nil { + return *m.F_Uint64Required + } + return 0 +} + +func (m *GoTest) GetF_FloatRequired() float32 { + if m != nil && m.F_FloatRequired != nil { + return *m.F_FloatRequired + } + return 0 +} + +func (m *GoTest) GetF_DoubleRequired() float64 { + if m != nil && m.F_DoubleRequired != nil { + return *m.F_DoubleRequired + } + return 0 +} + +func (m *GoTest) GetF_StringRequired() string { + if m != nil && m.F_StringRequired != nil { + return *m.F_StringRequired + } + return "" +} + +func (m *GoTest) GetF_BytesRequired() []byte { + if m != nil { + return m.F_BytesRequired + } + return nil +} + +func (m *GoTest) GetF_Sint32Required() int32 { + if m != nil && m.F_Sint32Required != nil { + return *m.F_Sint32Required + } + return 0 +} + +func (m *GoTest) GetF_Sint64Required() int64 { + if m != nil && m.F_Sint64Required != nil { + return *m.F_Sint64Required + } + return 0 +} + +func (m *GoTest) GetF_BoolRepeated() []bool { + if m != nil { + return m.F_BoolRepeated + } + return nil +} + +func (m *GoTest) GetF_Int32Repeated() []int32 { + if m != nil { + return m.F_Int32Repeated + } + return nil +} + +func (m *GoTest) GetF_Int64Repeated() []int64 { + if m != nil { + return m.F_Int64Repeated + } + return nil +} + +func (m *GoTest) GetF_Fixed32Repeated() []uint32 { + if m != nil { + return m.F_Fixed32Repeated + } + return nil +} + +func (m *GoTest) GetF_Fixed64Repeated() []uint64 { + if m != nil { + return m.F_Fixed64Repeated + } + return nil +} + +func (m *GoTest) GetF_Uint32Repeated() []uint32 { + if m != nil { + return m.F_Uint32Repeated + } + return nil +} + +func (m *GoTest) GetF_Uint64Repeated() []uint64 { + if m != nil { + return m.F_Uint64Repeated + } + return nil +} + +func (m *GoTest) GetF_FloatRepeated() []float32 { + if m != nil { + return m.F_FloatRepeated + } + return nil +} + +func (m *GoTest) GetF_DoubleRepeated() []float64 { + if m != nil { + return m.F_DoubleRepeated + } + return nil +} + +func (m *GoTest) GetF_StringRepeated() []string { + if m != nil { + return m.F_StringRepeated + } + return nil +} + +func (m *GoTest) GetF_BytesRepeated() [][]byte { + if m != nil { + return m.F_BytesRepeated + } + return nil +} + +func (m *GoTest) GetF_Sint32Repeated() []int32 { + if m != nil { + return m.F_Sint32Repeated + } + return nil +} + +func (m *GoTest) GetF_Sint64Repeated() []int64 { + if m != nil { + return m.F_Sint64Repeated + } + return nil +} + +func (m *GoTest) GetF_BoolOptional() bool { + if m != nil && m.F_BoolOptional != nil { + return *m.F_BoolOptional + } + return false +} + +func (m *GoTest) GetF_Int32Optional() int32 { + if m != nil && m.F_Int32Optional != nil { + return *m.F_Int32Optional + } + return 0 +} + +func (m *GoTest) GetF_Int64Optional() int64 { + if m != nil && m.F_Int64Optional != nil { + return *m.F_Int64Optional + } + return 0 +} + +func (m *GoTest) GetF_Fixed32Optional() uint32 { + if m != nil && m.F_Fixed32Optional != nil { + return *m.F_Fixed32Optional + } + return 0 +} + +func (m *GoTest) GetF_Fixed64Optional() uint64 { + if m != nil && m.F_Fixed64Optional != nil { + return *m.F_Fixed64Optional + } + return 0 +} + +func (m *GoTest) GetF_Uint32Optional() uint32 { + if m != nil && m.F_Uint32Optional != nil { + return *m.F_Uint32Optional + } + return 0 +} + +func (m *GoTest) GetF_Uint64Optional() uint64 { + if m != nil && m.F_Uint64Optional != nil { + return *m.F_Uint64Optional + } + return 0 +} + +func (m *GoTest) GetF_FloatOptional() float32 { + if m != nil && m.F_FloatOptional != nil { + return *m.F_FloatOptional + } + return 0 +} + +func (m *GoTest) GetF_DoubleOptional() float64 { + if m != nil && m.F_DoubleOptional != nil { + return *m.F_DoubleOptional + } + return 0 +} + +func (m *GoTest) GetF_StringOptional() string { + if m != nil && m.F_StringOptional != nil { + return *m.F_StringOptional + } + return "" +} + +func (m *GoTest) GetF_BytesOptional() []byte { + if m != nil { + return m.F_BytesOptional + } + return nil +} + +func (m *GoTest) GetF_Sint32Optional() int32 { + if m != nil && m.F_Sint32Optional != nil { + return *m.F_Sint32Optional + } + return 0 +} + +func (m *GoTest) GetF_Sint64Optional() int64 { + if m != nil && m.F_Sint64Optional != nil { + return *m.F_Sint64Optional + } + return 0 +} + +func (m *GoTest) GetF_BoolDefaulted() bool { + if m != nil && m.F_BoolDefaulted != nil { + return *m.F_BoolDefaulted + } + return Default_GoTest_F_BoolDefaulted +} + +func (m *GoTest) GetF_Int32Defaulted() int32 { + if m != nil && m.F_Int32Defaulted != nil { + return *m.F_Int32Defaulted + } + return Default_GoTest_F_Int32Defaulted +} + +func (m *GoTest) GetF_Int64Defaulted() int64 { + if m != nil && m.F_Int64Defaulted != nil { + return *m.F_Int64Defaulted + } + return Default_GoTest_F_Int64Defaulted +} + +func (m *GoTest) GetF_Fixed32Defaulted() uint32 { + if m != nil && m.F_Fixed32Defaulted != nil { + return *m.F_Fixed32Defaulted + } + return Default_GoTest_F_Fixed32Defaulted +} + +func (m *GoTest) GetF_Fixed64Defaulted() uint64 { + if m != nil && m.F_Fixed64Defaulted != nil { + return *m.F_Fixed64Defaulted + } + return Default_GoTest_F_Fixed64Defaulted +} + +func (m *GoTest) GetF_Uint32Defaulted() uint32 { + if m != nil && m.F_Uint32Defaulted != nil { + return *m.F_Uint32Defaulted + } + return Default_GoTest_F_Uint32Defaulted +} + +func (m *GoTest) GetF_Uint64Defaulted() uint64 { + if m != nil && m.F_Uint64Defaulted != nil { + return *m.F_Uint64Defaulted + } + return Default_GoTest_F_Uint64Defaulted +} + +func (m *GoTest) GetF_FloatDefaulted() float32 { + if m != nil && m.F_FloatDefaulted != nil { + return *m.F_FloatDefaulted + } + return Default_GoTest_F_FloatDefaulted +} + +func (m *GoTest) GetF_DoubleDefaulted() float64 { + if m != nil && m.F_DoubleDefaulted != nil { + return *m.F_DoubleDefaulted + } + return Default_GoTest_F_DoubleDefaulted +} + +func (m *GoTest) GetF_StringDefaulted() string { + if m != nil && m.F_StringDefaulted != nil { + return *m.F_StringDefaulted + } + return Default_GoTest_F_StringDefaulted +} + +func (m *GoTest) GetF_BytesDefaulted() []byte { + if m != nil && m.F_BytesDefaulted != nil { + return m.F_BytesDefaulted + } + return append([]byte(nil), Default_GoTest_F_BytesDefaulted...) +} + +func (m *GoTest) GetF_Sint32Defaulted() int32 { + if m != nil && m.F_Sint32Defaulted != nil { + return *m.F_Sint32Defaulted + } + return Default_GoTest_F_Sint32Defaulted +} + +func (m *GoTest) GetF_Sint64Defaulted() int64 { + if m != nil && m.F_Sint64Defaulted != nil { + return *m.F_Sint64Defaulted + } + return Default_GoTest_F_Sint64Defaulted +} + +func (m *GoTest) GetF_BoolRepeatedPacked() []bool { + if m != nil { + return m.F_BoolRepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Int32RepeatedPacked() []int32 { + if m != nil { + return m.F_Int32RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Int64RepeatedPacked() []int64 { + if m != nil { + return m.F_Int64RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Fixed32RepeatedPacked() []uint32 { + if m != nil { + return m.F_Fixed32RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Fixed64RepeatedPacked() []uint64 { + if m != nil { + return m.F_Fixed64RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Uint32RepeatedPacked() []uint32 { + if m != nil { + return m.F_Uint32RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Uint64RepeatedPacked() []uint64 { + if m != nil { + return m.F_Uint64RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_FloatRepeatedPacked() []float32 { + if m != nil { + return m.F_FloatRepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_DoubleRepeatedPacked() []float64 { + if m != nil { + return m.F_DoubleRepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Sint32RepeatedPacked() []int32 { + if m != nil { + return m.F_Sint32RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Sint64RepeatedPacked() []int64 { + if m != nil { + return m.F_Sint64RepeatedPacked + } + return nil +} + +func (m *GoTest) GetRequiredgroup() *GoTest_RequiredGroup { + if m != nil { + return m.Requiredgroup + } + return nil +} + +func (m *GoTest) GetRepeatedgroup() []*GoTest_RepeatedGroup { + if m != nil { + return m.Repeatedgroup + } + return nil +} + +func (m *GoTest) GetOptionalgroup() *GoTest_OptionalGroup { + if m != nil { + return m.Optionalgroup + } + return nil +} + +// Required, repeated, and optional groups. +type GoTest_RequiredGroup struct { + RequiredField *string `protobuf:"bytes,71,req,name=RequiredField" json:"RequiredField,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTest_RequiredGroup) Reset() { *m = GoTest_RequiredGroup{} } +func (m *GoTest_RequiredGroup) String() string { return proto.CompactTextString(m) } +func (*GoTest_RequiredGroup) ProtoMessage() {} +func (*GoTest_RequiredGroup) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{2, 0} } + +func (m *GoTest_RequiredGroup) GetRequiredField() string { + if m != nil && m.RequiredField != nil { + return *m.RequiredField + } + return "" +} + +type GoTest_RepeatedGroup struct { + RequiredField *string `protobuf:"bytes,81,req,name=RequiredField" json:"RequiredField,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTest_RepeatedGroup) Reset() { *m = GoTest_RepeatedGroup{} } +func (m *GoTest_RepeatedGroup) String() string { return proto.CompactTextString(m) } +func (*GoTest_RepeatedGroup) ProtoMessage() {} +func (*GoTest_RepeatedGroup) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{2, 1} } + +func (m *GoTest_RepeatedGroup) GetRequiredField() string { + if m != nil && m.RequiredField != nil { + return *m.RequiredField + } + return "" +} + +type GoTest_OptionalGroup struct { + RequiredField *string `protobuf:"bytes,91,req,name=RequiredField" json:"RequiredField,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTest_OptionalGroup) Reset() { *m = GoTest_OptionalGroup{} } +func (m *GoTest_OptionalGroup) String() string { return proto.CompactTextString(m) } +func (*GoTest_OptionalGroup) ProtoMessage() {} +func (*GoTest_OptionalGroup) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{2, 2} } + +func (m *GoTest_OptionalGroup) GetRequiredField() string { + if m != nil && m.RequiredField != nil { + return *m.RequiredField + } + return "" +} + +// For testing a group containing a required field. +type GoTestRequiredGroupField struct { + Group *GoTestRequiredGroupField_Group `protobuf:"group,1,req,name=Group,json=group" json:"group,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTestRequiredGroupField) Reset() { *m = GoTestRequiredGroupField{} } +func (m *GoTestRequiredGroupField) String() string { return proto.CompactTextString(m) } +func (*GoTestRequiredGroupField) ProtoMessage() {} +func (*GoTestRequiredGroupField) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{3} } + +func (m *GoTestRequiredGroupField) GetGroup() *GoTestRequiredGroupField_Group { + if m != nil { + return m.Group + } + return nil +} + +type GoTestRequiredGroupField_Group struct { + Field *int32 `protobuf:"varint,2,req,name=Field" json:"Field,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTestRequiredGroupField_Group) Reset() { *m = GoTestRequiredGroupField_Group{} } +func (m *GoTestRequiredGroupField_Group) String() string { return proto.CompactTextString(m) } +func (*GoTestRequiredGroupField_Group) ProtoMessage() {} +func (*GoTestRequiredGroupField_Group) Descriptor() ([]byte, []int) { + return fileDescriptorTest, []int{3, 0} +} + +func (m *GoTestRequiredGroupField_Group) GetField() int32 { + if m != nil && m.Field != nil { + return *m.Field + } + return 0 +} + +// For testing skipping of unrecognized fields. +// Numbers are all big, larger than tag numbers in GoTestField, +// the message used in the corresponding test. +type GoSkipTest struct { + SkipInt32 *int32 `protobuf:"varint,11,req,name=skip_int32,json=skipInt32" json:"skip_int32,omitempty"` + SkipFixed32 *uint32 `protobuf:"fixed32,12,req,name=skip_fixed32,json=skipFixed32" json:"skip_fixed32,omitempty"` + SkipFixed64 *uint64 `protobuf:"fixed64,13,req,name=skip_fixed64,json=skipFixed64" json:"skip_fixed64,omitempty"` + SkipString *string `protobuf:"bytes,14,req,name=skip_string,json=skipString" json:"skip_string,omitempty"` + Skipgroup *GoSkipTest_SkipGroup `protobuf:"group,15,req,name=SkipGroup,json=skipgroup" json:"skipgroup,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoSkipTest) Reset() { *m = GoSkipTest{} } +func (m *GoSkipTest) String() string { return proto.CompactTextString(m) } +func (*GoSkipTest) ProtoMessage() {} +func (*GoSkipTest) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{4} } + +func (m *GoSkipTest) GetSkipInt32() int32 { + if m != nil && m.SkipInt32 != nil { + return *m.SkipInt32 + } + return 0 +} + +func (m *GoSkipTest) GetSkipFixed32() uint32 { + if m != nil && m.SkipFixed32 != nil { + return *m.SkipFixed32 + } + return 0 +} + +func (m *GoSkipTest) GetSkipFixed64() uint64 { + if m != nil && m.SkipFixed64 != nil { + return *m.SkipFixed64 + } + return 0 +} + +func (m *GoSkipTest) GetSkipString() string { + if m != nil && m.SkipString != nil { + return *m.SkipString + } + return "" +} + +func (m *GoSkipTest) GetSkipgroup() *GoSkipTest_SkipGroup { + if m != nil { + return m.Skipgroup + } + return nil +} + +type GoSkipTest_SkipGroup struct { + GroupInt32 *int32 `protobuf:"varint,16,req,name=group_int32,json=groupInt32" json:"group_int32,omitempty"` + GroupString *string `protobuf:"bytes,17,req,name=group_string,json=groupString" json:"group_string,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoSkipTest_SkipGroup) Reset() { *m = GoSkipTest_SkipGroup{} } +func (m *GoSkipTest_SkipGroup) String() string { return proto.CompactTextString(m) } +func (*GoSkipTest_SkipGroup) ProtoMessage() {} +func (*GoSkipTest_SkipGroup) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{4, 0} } + +func (m *GoSkipTest_SkipGroup) GetGroupInt32() int32 { + if m != nil && m.GroupInt32 != nil { + return *m.GroupInt32 + } + return 0 +} + +func (m *GoSkipTest_SkipGroup) GetGroupString() string { + if m != nil && m.GroupString != nil { + return *m.GroupString + } + return "" +} + +// For testing packed/non-packed decoder switching. +// A serialized instance of one should be deserializable as the other. +type NonPackedTest struct { + A []int32 `protobuf:"varint,1,rep,name=a" json:"a,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *NonPackedTest) Reset() { *m = NonPackedTest{} } +func (m *NonPackedTest) String() string { return proto.CompactTextString(m) } +func (*NonPackedTest) ProtoMessage() {} +func (*NonPackedTest) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{5} } + +func (m *NonPackedTest) GetA() []int32 { + if m != nil { + return m.A + } + return nil +} + +type PackedTest struct { + B []int32 `protobuf:"varint,1,rep,packed,name=b" json:"b,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *PackedTest) Reset() { *m = PackedTest{} } +func (m *PackedTest) String() string { return proto.CompactTextString(m) } +func (*PackedTest) ProtoMessage() {} +func (*PackedTest) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{6} } + +func (m *PackedTest) GetB() []int32 { + if m != nil { + return m.B + } + return nil +} + +type MaxTag struct { + // Maximum possible tag number. + LastField *string `protobuf:"bytes,536870911,opt,name=last_field,json=lastField" json:"last_field,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MaxTag) Reset() { *m = MaxTag{} } +func (m *MaxTag) String() string { return proto.CompactTextString(m) } +func (*MaxTag) ProtoMessage() {} +func (*MaxTag) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{7} } + +func (m *MaxTag) GetLastField() string { + if m != nil && m.LastField != nil { + return *m.LastField + } + return "" +} + +type OldMessage struct { + Nested *OldMessage_Nested `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"` + Num *int32 `protobuf:"varint,2,opt,name=num" json:"num,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OldMessage) Reset() { *m = OldMessage{} } +func (m *OldMessage) String() string { return proto.CompactTextString(m) } +func (*OldMessage) ProtoMessage() {} +func (*OldMessage) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{8} } + +func (m *OldMessage) GetNested() *OldMessage_Nested { + if m != nil { + return m.Nested + } + return nil +} + +func (m *OldMessage) GetNum() int32 { + if m != nil && m.Num != nil { + return *m.Num + } + return 0 +} + +type OldMessage_Nested struct { + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OldMessage_Nested) Reset() { *m = OldMessage_Nested{} } +func (m *OldMessage_Nested) String() string { return proto.CompactTextString(m) } +func (*OldMessage_Nested) ProtoMessage() {} +func (*OldMessage_Nested) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{8, 0} } + +func (m *OldMessage_Nested) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +// NewMessage is wire compatible with OldMessage; +// imagine it as a future version. +type NewMessage struct { + Nested *NewMessage_Nested `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"` + // This is an int32 in OldMessage. + Num *int64 `protobuf:"varint,2,opt,name=num" json:"num,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *NewMessage) Reset() { *m = NewMessage{} } +func (m *NewMessage) String() string { return proto.CompactTextString(m) } +func (*NewMessage) ProtoMessage() {} +func (*NewMessage) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{9} } + +func (m *NewMessage) GetNested() *NewMessage_Nested { + if m != nil { + return m.Nested + } + return nil +} + +func (m *NewMessage) GetNum() int64 { + if m != nil && m.Num != nil { + return *m.Num + } + return 0 +} + +type NewMessage_Nested struct { + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + FoodGroup *string `protobuf:"bytes,2,opt,name=food_group,json=foodGroup" json:"food_group,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *NewMessage_Nested) Reset() { *m = NewMessage_Nested{} } +func (m *NewMessage_Nested) String() string { return proto.CompactTextString(m) } +func (*NewMessage_Nested) ProtoMessage() {} +func (*NewMessage_Nested) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{9, 0} } + +func (m *NewMessage_Nested) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +func (m *NewMessage_Nested) GetFoodGroup() string { + if m != nil && m.FoodGroup != nil { + return *m.FoodGroup + } + return "" +} + +type InnerMessage struct { + Host *string `protobuf:"bytes,1,req,name=host" json:"host,omitempty"` + Port *int32 `protobuf:"varint,2,opt,name=port,def=4000" json:"port,omitempty"` + Connected *bool `protobuf:"varint,3,opt,name=connected" json:"connected,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *InnerMessage) Reset() { *m = InnerMessage{} } +func (m *InnerMessage) String() string { return proto.CompactTextString(m) } +func (*InnerMessage) ProtoMessage() {} +func (*InnerMessage) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{10} } + +const Default_InnerMessage_Port int32 = 4000 + +func (m *InnerMessage) GetHost() string { + if m != nil && m.Host != nil { + return *m.Host + } + return "" +} + +func (m *InnerMessage) GetPort() int32 { + if m != nil && m.Port != nil { + return *m.Port + } + return Default_InnerMessage_Port +} + +func (m *InnerMessage) GetConnected() bool { + if m != nil && m.Connected != nil { + return *m.Connected + } + return false +} + +type OtherMessage struct { + Key *int64 `protobuf:"varint,1,opt,name=key" json:"key,omitempty"` + Value []byte `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"` + Weight *float32 `protobuf:"fixed32,3,opt,name=weight" json:"weight,omitempty"` + Inner *InnerMessage `protobuf:"bytes,4,opt,name=inner" json:"inner,omitempty"` + proto.XXX_InternalExtensions `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OtherMessage) Reset() { *m = OtherMessage{} } +func (m *OtherMessage) String() string { return proto.CompactTextString(m) } +func (*OtherMessage) ProtoMessage() {} +func (*OtherMessage) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{11} } + +var extRange_OtherMessage = []proto.ExtensionRange{ + {Start: 100, End: 536870911}, +} + +func (*OtherMessage) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_OtherMessage +} + +func (m *OtherMessage) GetKey() int64 { + if m != nil && m.Key != nil { + return *m.Key + } + return 0 +} + +func (m *OtherMessage) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +func (m *OtherMessage) GetWeight() float32 { + if m != nil && m.Weight != nil { + return *m.Weight + } + return 0 +} + +func (m *OtherMessage) GetInner() *InnerMessage { + if m != nil { + return m.Inner + } + return nil +} + +type RequiredInnerMessage struct { + LeoFinallyWonAnOscar *InnerMessage `protobuf:"bytes,1,req,name=leo_finally_won_an_oscar,json=leoFinallyWonAnOscar" json:"leo_finally_won_an_oscar,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *RequiredInnerMessage) Reset() { *m = RequiredInnerMessage{} } +func (m *RequiredInnerMessage) String() string { return proto.CompactTextString(m) } +func (*RequiredInnerMessage) ProtoMessage() {} +func (*RequiredInnerMessage) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{12} } + +func (m *RequiredInnerMessage) GetLeoFinallyWonAnOscar() *InnerMessage { + if m != nil { + return m.LeoFinallyWonAnOscar + } + return nil +} + +type MyMessage struct { + Count *int32 `protobuf:"varint,1,req,name=count" json:"count,omitempty"` + Name *string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"` + Quote *string `protobuf:"bytes,3,opt,name=quote" json:"quote,omitempty"` + Pet []string `protobuf:"bytes,4,rep,name=pet" json:"pet,omitempty"` + Inner *InnerMessage `protobuf:"bytes,5,opt,name=inner" json:"inner,omitempty"` + Others []*OtherMessage `protobuf:"bytes,6,rep,name=others" json:"others,omitempty"` + WeMustGoDeeper *RequiredInnerMessage `protobuf:"bytes,13,opt,name=we_must_go_deeper,json=weMustGoDeeper" json:"we_must_go_deeper,omitempty"` + RepInner []*InnerMessage `protobuf:"bytes,12,rep,name=rep_inner,json=repInner" json:"rep_inner,omitempty"` + Bikeshed *MyMessage_Color `protobuf:"varint,7,opt,name=bikeshed,enum=testdata.MyMessage_Color" json:"bikeshed,omitempty"` + Somegroup *MyMessage_SomeGroup `protobuf:"group,8,opt,name=SomeGroup,json=somegroup" json:"somegroup,omitempty"` + // This field becomes [][]byte in the generated code. + RepBytes [][]byte `protobuf:"bytes,10,rep,name=rep_bytes,json=repBytes" json:"rep_bytes,omitempty"` + Bigfloat *float64 `protobuf:"fixed64,11,opt,name=bigfloat" json:"bigfloat,omitempty"` + proto.XXX_InternalExtensions `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MyMessage) Reset() { *m = MyMessage{} } +func (m *MyMessage) String() string { return proto.CompactTextString(m) } +func (*MyMessage) ProtoMessage() {} +func (*MyMessage) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{13} } + +var extRange_MyMessage = []proto.ExtensionRange{ + {Start: 100, End: 536870911}, +} + +func (*MyMessage) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_MyMessage +} + +func (m *MyMessage) GetCount() int32 { + if m != nil && m.Count != nil { + return *m.Count + } + return 0 +} + +func (m *MyMessage) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +func (m *MyMessage) GetQuote() string { + if m != nil && m.Quote != nil { + return *m.Quote + } + return "" +} + +func (m *MyMessage) GetPet() []string { + if m != nil { + return m.Pet + } + return nil +} + +func (m *MyMessage) GetInner() *InnerMessage { + if m != nil { + return m.Inner + } + return nil +} + +func (m *MyMessage) GetOthers() []*OtherMessage { + if m != nil { + return m.Others + } + return nil +} + +func (m *MyMessage) GetWeMustGoDeeper() *RequiredInnerMessage { + if m != nil { + return m.WeMustGoDeeper + } + return nil +} + +func (m *MyMessage) GetRepInner() []*InnerMessage { + if m != nil { + return m.RepInner + } + return nil +} + +func (m *MyMessage) GetBikeshed() MyMessage_Color { + if m != nil && m.Bikeshed != nil { + return *m.Bikeshed + } + return MyMessage_RED +} + +func (m *MyMessage) GetSomegroup() *MyMessage_SomeGroup { + if m != nil { + return m.Somegroup + } + return nil +} + +func (m *MyMessage) GetRepBytes() [][]byte { + if m != nil { + return m.RepBytes + } + return nil +} + +func (m *MyMessage) GetBigfloat() float64 { + if m != nil && m.Bigfloat != nil { + return *m.Bigfloat + } + return 0 +} + +type MyMessage_SomeGroup struct { + GroupField *int32 `protobuf:"varint,9,opt,name=group_field,json=groupField" json:"group_field,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MyMessage_SomeGroup) Reset() { *m = MyMessage_SomeGroup{} } +func (m *MyMessage_SomeGroup) String() string { return proto.CompactTextString(m) } +func (*MyMessage_SomeGroup) ProtoMessage() {} +func (*MyMessage_SomeGroup) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{13, 0} } + +func (m *MyMessage_SomeGroup) GetGroupField() int32 { + if m != nil && m.GroupField != nil { + return *m.GroupField + } + return 0 +} + +type Ext struct { + Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Ext) Reset() { *m = Ext{} } +func (m *Ext) String() string { return proto.CompactTextString(m) } +func (*Ext) ProtoMessage() {} +func (*Ext) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{14} } + +func (m *Ext) GetData() string { + if m != nil && m.Data != nil { + return *m.Data + } + return "" +} + +var E_Ext_More = &proto.ExtensionDesc{ + ExtendedType: (*MyMessage)(nil), + ExtensionType: (*Ext)(nil), + Field: 103, + Name: "testdata.Ext.more", + Tag: "bytes,103,opt,name=more", + Filename: "test.proto", +} + +var E_Ext_Text = &proto.ExtensionDesc{ + ExtendedType: (*MyMessage)(nil), + ExtensionType: (*string)(nil), + Field: 104, + Name: "testdata.Ext.text", + Tag: "bytes,104,opt,name=text", + Filename: "test.proto", +} + +var E_Ext_Number = &proto.ExtensionDesc{ + ExtendedType: (*MyMessage)(nil), + ExtensionType: (*int32)(nil), + Field: 105, + Name: "testdata.Ext.number", + Tag: "varint,105,opt,name=number", + Filename: "test.proto", +} + +type ComplexExtension struct { + First *int32 `protobuf:"varint,1,opt,name=first" json:"first,omitempty"` + Second *int32 `protobuf:"varint,2,opt,name=second" json:"second,omitempty"` + Third []int32 `protobuf:"varint,3,rep,name=third" json:"third,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *ComplexExtension) Reset() { *m = ComplexExtension{} } +func (m *ComplexExtension) String() string { return proto.CompactTextString(m) } +func (*ComplexExtension) ProtoMessage() {} +func (*ComplexExtension) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{15} } + +func (m *ComplexExtension) GetFirst() int32 { + if m != nil && m.First != nil { + return *m.First + } + return 0 +} + +func (m *ComplexExtension) GetSecond() int32 { + if m != nil && m.Second != nil { + return *m.Second + } + return 0 +} + +func (m *ComplexExtension) GetThird() []int32 { + if m != nil { + return m.Third + } + return nil +} + +type DefaultsMessage struct { + proto.XXX_InternalExtensions `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *DefaultsMessage) Reset() { *m = DefaultsMessage{} } +func (m *DefaultsMessage) String() string { return proto.CompactTextString(m) } +func (*DefaultsMessage) ProtoMessage() {} +func (*DefaultsMessage) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{16} } + +var extRange_DefaultsMessage = []proto.ExtensionRange{ + {Start: 100, End: 536870911}, +} + +func (*DefaultsMessage) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_DefaultsMessage +} + +type MyMessageSet struct { + proto.XXX_InternalExtensions `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MyMessageSet) Reset() { *m = MyMessageSet{} } +func (m *MyMessageSet) String() string { return proto.CompactTextString(m) } +func (*MyMessageSet) ProtoMessage() {} +func (*MyMessageSet) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{17} } + +func (m *MyMessageSet) Marshal() ([]byte, error) { + return proto.MarshalMessageSet(&m.XXX_InternalExtensions) +} +func (m *MyMessageSet) Unmarshal(buf []byte) error { + return proto.UnmarshalMessageSet(buf, &m.XXX_InternalExtensions) +} +func (m *MyMessageSet) MarshalJSON() ([]byte, error) { + return proto.MarshalMessageSetJSON(&m.XXX_InternalExtensions) +} +func (m *MyMessageSet) UnmarshalJSON(buf []byte) error { + return proto.UnmarshalMessageSetJSON(buf, &m.XXX_InternalExtensions) +} + +// ensure MyMessageSet satisfies proto.Marshaler and proto.Unmarshaler +var _ proto.Marshaler = (*MyMessageSet)(nil) +var _ proto.Unmarshaler = (*MyMessageSet)(nil) + +var extRange_MyMessageSet = []proto.ExtensionRange{ + {Start: 100, End: 2147483646}, +} + +func (*MyMessageSet) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_MyMessageSet +} + +type Empty struct { + XXX_unrecognized []byte `json:"-"` +} + +func (m *Empty) Reset() { *m = Empty{} } +func (m *Empty) String() string { return proto.CompactTextString(m) } +func (*Empty) ProtoMessage() {} +func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{18} } + +type MessageList struct { + Message []*MessageList_Message `protobuf:"group,1,rep,name=Message,json=message" json:"message,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MessageList) Reset() { *m = MessageList{} } +func (m *MessageList) String() string { return proto.CompactTextString(m) } +func (*MessageList) ProtoMessage() {} +func (*MessageList) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{19} } + +func (m *MessageList) GetMessage() []*MessageList_Message { + if m != nil { + return m.Message + } + return nil +} + +type MessageList_Message struct { + Name *string `protobuf:"bytes,2,req,name=name" json:"name,omitempty"` + Count *int32 `protobuf:"varint,3,req,name=count" json:"count,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MessageList_Message) Reset() { *m = MessageList_Message{} } +func (m *MessageList_Message) String() string { return proto.CompactTextString(m) } +func (*MessageList_Message) ProtoMessage() {} +func (*MessageList_Message) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{19, 0} } + +func (m *MessageList_Message) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +func (m *MessageList_Message) GetCount() int32 { + if m != nil && m.Count != nil { + return *m.Count + } + return 0 +} + +type Strings struct { + StringField *string `protobuf:"bytes,1,opt,name=string_field,json=stringField" json:"string_field,omitempty"` + BytesField []byte `protobuf:"bytes,2,opt,name=bytes_field,json=bytesField" json:"bytes_field,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Strings) Reset() { *m = Strings{} } +func (m *Strings) String() string { return proto.CompactTextString(m) } +func (*Strings) ProtoMessage() {} +func (*Strings) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{20} } + +func (m *Strings) GetStringField() string { + if m != nil && m.StringField != nil { + return *m.StringField + } + return "" +} + +func (m *Strings) GetBytesField() []byte { + if m != nil { + return m.BytesField + } + return nil +} + +type Defaults struct { + // Default-valued fields of all basic types. + // Same as GoTest, but copied here to make testing easier. + F_Bool *bool `protobuf:"varint,1,opt,name=F_Bool,json=FBool,def=1" json:"F_Bool,omitempty"` + F_Int32 *int32 `protobuf:"varint,2,opt,name=F_Int32,json=FInt32,def=32" json:"F_Int32,omitempty"` + F_Int64 *int64 `protobuf:"varint,3,opt,name=F_Int64,json=FInt64,def=64" json:"F_Int64,omitempty"` + F_Fixed32 *uint32 `protobuf:"fixed32,4,opt,name=F_Fixed32,json=FFixed32,def=320" json:"F_Fixed32,omitempty"` + F_Fixed64 *uint64 `protobuf:"fixed64,5,opt,name=F_Fixed64,json=FFixed64,def=640" json:"F_Fixed64,omitempty"` + F_Uint32 *uint32 `protobuf:"varint,6,opt,name=F_Uint32,json=FUint32,def=3200" json:"F_Uint32,omitempty"` + F_Uint64 *uint64 `protobuf:"varint,7,opt,name=F_Uint64,json=FUint64,def=6400" json:"F_Uint64,omitempty"` + F_Float *float32 `protobuf:"fixed32,8,opt,name=F_Float,json=FFloat,def=314159" json:"F_Float,omitempty"` + F_Double *float64 `protobuf:"fixed64,9,opt,name=F_Double,json=FDouble,def=271828" json:"F_Double,omitempty"` + F_String *string `protobuf:"bytes,10,opt,name=F_String,json=FString,def=hello, \"world!\"\n" json:"F_String,omitempty"` + F_Bytes []byte `protobuf:"bytes,11,opt,name=F_Bytes,json=FBytes,def=Bignose" json:"F_Bytes,omitempty"` + F_Sint32 *int32 `protobuf:"zigzag32,12,opt,name=F_Sint32,json=FSint32,def=-32" json:"F_Sint32,omitempty"` + F_Sint64 *int64 `protobuf:"zigzag64,13,opt,name=F_Sint64,json=FSint64,def=-64" json:"F_Sint64,omitempty"` + F_Enum *Defaults_Color `protobuf:"varint,14,opt,name=F_Enum,json=FEnum,enum=testdata.Defaults_Color,def=1" json:"F_Enum,omitempty"` + // More fields with crazy defaults. + F_Pinf *float32 `protobuf:"fixed32,15,opt,name=F_Pinf,json=FPinf,def=inf" json:"F_Pinf,omitempty"` + F_Ninf *float32 `protobuf:"fixed32,16,opt,name=F_Ninf,json=FNinf,def=-inf" json:"F_Ninf,omitempty"` + F_Nan *float32 `protobuf:"fixed32,17,opt,name=F_Nan,json=FNan,def=nan" json:"F_Nan,omitempty"` + // Sub-message. + Sub *SubDefaults `protobuf:"bytes,18,opt,name=sub" json:"sub,omitempty"` + // Redundant but explicit defaults. + StrZero *string `protobuf:"bytes,19,opt,name=str_zero,json=strZero,def=" json:"str_zero,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Defaults) Reset() { *m = Defaults{} } +func (m *Defaults) String() string { return proto.CompactTextString(m) } +func (*Defaults) ProtoMessage() {} +func (*Defaults) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{21} } + +const Default_Defaults_F_Bool bool = true +const Default_Defaults_F_Int32 int32 = 32 +const Default_Defaults_F_Int64 int64 = 64 +const Default_Defaults_F_Fixed32 uint32 = 320 +const Default_Defaults_F_Fixed64 uint64 = 640 +const Default_Defaults_F_Uint32 uint32 = 3200 +const Default_Defaults_F_Uint64 uint64 = 6400 +const Default_Defaults_F_Float float32 = 314159 +const Default_Defaults_F_Double float64 = 271828 +const Default_Defaults_F_String string = "hello, \"world!\"\n" + +var Default_Defaults_F_Bytes []byte = []byte("Bignose") + +const Default_Defaults_F_Sint32 int32 = -32 +const Default_Defaults_F_Sint64 int64 = -64 +const Default_Defaults_F_Enum Defaults_Color = Defaults_GREEN + +var Default_Defaults_F_Pinf float32 = float32(math.Inf(1)) +var Default_Defaults_F_Ninf float32 = float32(math.Inf(-1)) +var Default_Defaults_F_Nan float32 = float32(math.NaN()) + +func (m *Defaults) GetF_Bool() bool { + if m != nil && m.F_Bool != nil { + return *m.F_Bool + } + return Default_Defaults_F_Bool +} + +func (m *Defaults) GetF_Int32() int32 { + if m != nil && m.F_Int32 != nil { + return *m.F_Int32 + } + return Default_Defaults_F_Int32 +} + +func (m *Defaults) GetF_Int64() int64 { + if m != nil && m.F_Int64 != nil { + return *m.F_Int64 + } + return Default_Defaults_F_Int64 +} + +func (m *Defaults) GetF_Fixed32() uint32 { + if m != nil && m.F_Fixed32 != nil { + return *m.F_Fixed32 + } + return Default_Defaults_F_Fixed32 +} + +func (m *Defaults) GetF_Fixed64() uint64 { + if m != nil && m.F_Fixed64 != nil { + return *m.F_Fixed64 + } + return Default_Defaults_F_Fixed64 +} + +func (m *Defaults) GetF_Uint32() uint32 { + if m != nil && m.F_Uint32 != nil { + return *m.F_Uint32 + } + return Default_Defaults_F_Uint32 +} + +func (m *Defaults) GetF_Uint64() uint64 { + if m != nil && m.F_Uint64 != nil { + return *m.F_Uint64 + } + return Default_Defaults_F_Uint64 +} + +func (m *Defaults) GetF_Float() float32 { + if m != nil && m.F_Float != nil { + return *m.F_Float + } + return Default_Defaults_F_Float +} + +func (m *Defaults) GetF_Double() float64 { + if m != nil && m.F_Double != nil { + return *m.F_Double + } + return Default_Defaults_F_Double +} + +func (m *Defaults) GetF_String() string { + if m != nil && m.F_String != nil { + return *m.F_String + } + return Default_Defaults_F_String +} + +func (m *Defaults) GetF_Bytes() []byte { + if m != nil && m.F_Bytes != nil { + return m.F_Bytes + } + return append([]byte(nil), Default_Defaults_F_Bytes...) +} + +func (m *Defaults) GetF_Sint32() int32 { + if m != nil && m.F_Sint32 != nil { + return *m.F_Sint32 + } + return Default_Defaults_F_Sint32 +} + +func (m *Defaults) GetF_Sint64() int64 { + if m != nil && m.F_Sint64 != nil { + return *m.F_Sint64 + } + return Default_Defaults_F_Sint64 +} + +func (m *Defaults) GetF_Enum() Defaults_Color { + if m != nil && m.F_Enum != nil { + return *m.F_Enum + } + return Default_Defaults_F_Enum +} + +func (m *Defaults) GetF_Pinf() float32 { + if m != nil && m.F_Pinf != nil { + return *m.F_Pinf + } + return Default_Defaults_F_Pinf +} + +func (m *Defaults) GetF_Ninf() float32 { + if m != nil && m.F_Ninf != nil { + return *m.F_Ninf + } + return Default_Defaults_F_Ninf +} + +func (m *Defaults) GetF_Nan() float32 { + if m != nil && m.F_Nan != nil { + return *m.F_Nan + } + return Default_Defaults_F_Nan +} + +func (m *Defaults) GetSub() *SubDefaults { + if m != nil { + return m.Sub + } + return nil +} + +func (m *Defaults) GetStrZero() string { + if m != nil && m.StrZero != nil { + return *m.StrZero + } + return "" +} + +type SubDefaults struct { + N *int64 `protobuf:"varint,1,opt,name=n,def=7" json:"n,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *SubDefaults) Reset() { *m = SubDefaults{} } +func (m *SubDefaults) String() string { return proto.CompactTextString(m) } +func (*SubDefaults) ProtoMessage() {} +func (*SubDefaults) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{22} } + +const Default_SubDefaults_N int64 = 7 + +func (m *SubDefaults) GetN() int64 { + if m != nil && m.N != nil { + return *m.N + } + return Default_SubDefaults_N +} + +type RepeatedEnum struct { + Color []RepeatedEnum_Color `protobuf:"varint,1,rep,name=color,enum=testdata.RepeatedEnum_Color" json:"color,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *RepeatedEnum) Reset() { *m = RepeatedEnum{} } +func (m *RepeatedEnum) String() string { return proto.CompactTextString(m) } +func (*RepeatedEnum) ProtoMessage() {} +func (*RepeatedEnum) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{23} } + +func (m *RepeatedEnum) GetColor() []RepeatedEnum_Color { + if m != nil { + return m.Color + } + return nil +} + +type MoreRepeated struct { + Bools []bool `protobuf:"varint,1,rep,name=bools" json:"bools,omitempty"` + BoolsPacked []bool `protobuf:"varint,2,rep,packed,name=bools_packed,json=boolsPacked" json:"bools_packed,omitempty"` + Ints []int32 `protobuf:"varint,3,rep,name=ints" json:"ints,omitempty"` + IntsPacked []int32 `protobuf:"varint,4,rep,packed,name=ints_packed,json=intsPacked" json:"ints_packed,omitempty"` + Int64SPacked []int64 `protobuf:"varint,7,rep,packed,name=int64s_packed,json=int64sPacked" json:"int64s_packed,omitempty"` + Strings []string `protobuf:"bytes,5,rep,name=strings" json:"strings,omitempty"` + Fixeds []uint32 `protobuf:"fixed32,6,rep,name=fixeds" json:"fixeds,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MoreRepeated) Reset() { *m = MoreRepeated{} } +func (m *MoreRepeated) String() string { return proto.CompactTextString(m) } +func (*MoreRepeated) ProtoMessage() {} +func (*MoreRepeated) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{24} } + +func (m *MoreRepeated) GetBools() []bool { + if m != nil { + return m.Bools + } + return nil +} + +func (m *MoreRepeated) GetBoolsPacked() []bool { + if m != nil { + return m.BoolsPacked + } + return nil +} + +func (m *MoreRepeated) GetInts() []int32 { + if m != nil { + return m.Ints + } + return nil +} + +func (m *MoreRepeated) GetIntsPacked() []int32 { + if m != nil { + return m.IntsPacked + } + return nil +} + +func (m *MoreRepeated) GetInt64SPacked() []int64 { + if m != nil { + return m.Int64SPacked + } + return nil +} + +func (m *MoreRepeated) GetStrings() []string { + if m != nil { + return m.Strings + } + return nil +} + +func (m *MoreRepeated) GetFixeds() []uint32 { + if m != nil { + return m.Fixeds + } + return nil +} + +type GroupOld struct { + G *GroupOld_G `protobuf:"group,101,opt,name=G,json=g" json:"g,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GroupOld) Reset() { *m = GroupOld{} } +func (m *GroupOld) String() string { return proto.CompactTextString(m) } +func (*GroupOld) ProtoMessage() {} +func (*GroupOld) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{25} } + +func (m *GroupOld) GetG() *GroupOld_G { + if m != nil { + return m.G + } + return nil +} + +type GroupOld_G struct { + X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GroupOld_G) Reset() { *m = GroupOld_G{} } +func (m *GroupOld_G) String() string { return proto.CompactTextString(m) } +func (*GroupOld_G) ProtoMessage() {} +func (*GroupOld_G) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{25, 0} } + +func (m *GroupOld_G) GetX() int32 { + if m != nil && m.X != nil { + return *m.X + } + return 0 +} + +type GroupNew struct { + G *GroupNew_G `protobuf:"group,101,opt,name=G,json=g" json:"g,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GroupNew) Reset() { *m = GroupNew{} } +func (m *GroupNew) String() string { return proto.CompactTextString(m) } +func (*GroupNew) ProtoMessage() {} +func (*GroupNew) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{26} } + +func (m *GroupNew) GetG() *GroupNew_G { + if m != nil { + return m.G + } + return nil +} + +type GroupNew_G struct { + X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"` + Y *int32 `protobuf:"varint,3,opt,name=y" json:"y,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GroupNew_G) Reset() { *m = GroupNew_G{} } +func (m *GroupNew_G) String() string { return proto.CompactTextString(m) } +func (*GroupNew_G) ProtoMessage() {} +func (*GroupNew_G) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{26, 0} } + +func (m *GroupNew_G) GetX() int32 { + if m != nil && m.X != nil { + return *m.X + } + return 0 +} + +func (m *GroupNew_G) GetY() int32 { + if m != nil && m.Y != nil { + return *m.Y + } + return 0 +} + +type FloatingPoint struct { + F *float64 `protobuf:"fixed64,1,req,name=f" json:"f,omitempty"` + Exact *bool `protobuf:"varint,2,opt,name=exact" json:"exact,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *FloatingPoint) Reset() { *m = FloatingPoint{} } +func (m *FloatingPoint) String() string { return proto.CompactTextString(m) } +func (*FloatingPoint) ProtoMessage() {} +func (*FloatingPoint) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{27} } + +func (m *FloatingPoint) GetF() float64 { + if m != nil && m.F != nil { + return *m.F + } + return 0 +} + +func (m *FloatingPoint) GetExact() bool { + if m != nil && m.Exact != nil { + return *m.Exact + } + return false +} + +type MessageWithMap struct { + NameMapping map[int32]string `protobuf:"bytes,1,rep,name=name_mapping,json=nameMapping" json:"name_mapping,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + MsgMapping map[int64]*FloatingPoint `protobuf:"bytes,2,rep,name=msg_mapping,json=msgMapping" json:"msg_mapping,omitempty" protobuf_key:"zigzag64,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + ByteMapping map[bool][]byte `protobuf:"bytes,3,rep,name=byte_mapping,json=byteMapping" json:"byte_mapping,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + StrToStr map[string]string `protobuf:"bytes,4,rep,name=str_to_str,json=strToStr" json:"str_to_str,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MessageWithMap) Reset() { *m = MessageWithMap{} } +func (m *MessageWithMap) String() string { return proto.CompactTextString(m) } +func (*MessageWithMap) ProtoMessage() {} +func (*MessageWithMap) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{28} } + +func (m *MessageWithMap) GetNameMapping() map[int32]string { + if m != nil { + return m.NameMapping + } + return nil +} + +func (m *MessageWithMap) GetMsgMapping() map[int64]*FloatingPoint { + if m != nil { + return m.MsgMapping + } + return nil +} + +func (m *MessageWithMap) GetByteMapping() map[bool][]byte { + if m != nil { + return m.ByteMapping + } + return nil +} + +func (m *MessageWithMap) GetStrToStr() map[string]string { + if m != nil { + return m.StrToStr + } + return nil +} + +type Oneof struct { + // Types that are valid to be assigned to Union: + // *Oneof_F_Bool + // *Oneof_F_Int32 + // *Oneof_F_Int64 + // *Oneof_F_Fixed32 + // *Oneof_F_Fixed64 + // *Oneof_F_Uint32 + // *Oneof_F_Uint64 + // *Oneof_F_Float + // *Oneof_F_Double + // *Oneof_F_String + // *Oneof_F_Bytes + // *Oneof_F_Sint32 + // *Oneof_F_Sint64 + // *Oneof_F_Enum + // *Oneof_F_Message + // *Oneof_FGroup + // *Oneof_F_Largest_Tag + Union isOneof_Union `protobuf_oneof:"union"` + // Types that are valid to be assigned to Tormato: + // *Oneof_Value + Tormato isOneof_Tormato `protobuf_oneof:"tormato"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Oneof) Reset() { *m = Oneof{} } +func (m *Oneof) String() string { return proto.CompactTextString(m) } +func (*Oneof) ProtoMessage() {} +func (*Oneof) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{29} } + +type isOneof_Union interface { + isOneof_Union() +} +type isOneof_Tormato interface { + isOneof_Tormato() +} + +type Oneof_F_Bool struct { + F_Bool bool `protobuf:"varint,1,opt,name=F_Bool,json=FBool,oneof"` +} +type Oneof_F_Int32 struct { + F_Int32 int32 `protobuf:"varint,2,opt,name=F_Int32,json=FInt32,oneof"` +} +type Oneof_F_Int64 struct { + F_Int64 int64 `protobuf:"varint,3,opt,name=F_Int64,json=FInt64,oneof"` +} +type Oneof_F_Fixed32 struct { + F_Fixed32 uint32 `protobuf:"fixed32,4,opt,name=F_Fixed32,json=FFixed32,oneof"` +} +type Oneof_F_Fixed64 struct { + F_Fixed64 uint64 `protobuf:"fixed64,5,opt,name=F_Fixed64,json=FFixed64,oneof"` +} +type Oneof_F_Uint32 struct { + F_Uint32 uint32 `protobuf:"varint,6,opt,name=F_Uint32,json=FUint32,oneof"` +} +type Oneof_F_Uint64 struct { + F_Uint64 uint64 `protobuf:"varint,7,opt,name=F_Uint64,json=FUint64,oneof"` +} +type Oneof_F_Float struct { + F_Float float32 `protobuf:"fixed32,8,opt,name=F_Float,json=FFloat,oneof"` +} +type Oneof_F_Double struct { + F_Double float64 `protobuf:"fixed64,9,opt,name=F_Double,json=FDouble,oneof"` +} +type Oneof_F_String struct { + F_String string `protobuf:"bytes,10,opt,name=F_String,json=FString,oneof"` +} +type Oneof_F_Bytes struct { + F_Bytes []byte `protobuf:"bytes,11,opt,name=F_Bytes,json=FBytes,oneof"` +} +type Oneof_F_Sint32 struct { + F_Sint32 int32 `protobuf:"zigzag32,12,opt,name=F_Sint32,json=FSint32,oneof"` +} +type Oneof_F_Sint64 struct { + F_Sint64 int64 `protobuf:"zigzag64,13,opt,name=F_Sint64,json=FSint64,oneof"` +} +type Oneof_F_Enum struct { + F_Enum MyMessage_Color `protobuf:"varint,14,opt,name=F_Enum,json=FEnum,enum=testdata.MyMessage_Color,oneof"` +} +type Oneof_F_Message struct { + F_Message *GoTestField `protobuf:"bytes,15,opt,name=F_Message,json=FMessage,oneof"` +} +type Oneof_FGroup struct { + FGroup *Oneof_F_Group `protobuf:"group,16,opt,name=F_Group,json=fGroup,oneof"` +} +type Oneof_F_Largest_Tag struct { + F_Largest_Tag int32 `protobuf:"varint,536870911,opt,name=F_Largest_Tag,json=FLargestTag,oneof"` +} +type Oneof_Value struct { + Value int32 `protobuf:"varint,100,opt,name=value,oneof"` +} + +func (*Oneof_F_Bool) isOneof_Union() {} +func (*Oneof_F_Int32) isOneof_Union() {} +func (*Oneof_F_Int64) isOneof_Union() {} +func (*Oneof_F_Fixed32) isOneof_Union() {} +func (*Oneof_F_Fixed64) isOneof_Union() {} +func (*Oneof_F_Uint32) isOneof_Union() {} +func (*Oneof_F_Uint64) isOneof_Union() {} +func (*Oneof_F_Float) isOneof_Union() {} +func (*Oneof_F_Double) isOneof_Union() {} +func (*Oneof_F_String) isOneof_Union() {} +func (*Oneof_F_Bytes) isOneof_Union() {} +func (*Oneof_F_Sint32) isOneof_Union() {} +func (*Oneof_F_Sint64) isOneof_Union() {} +func (*Oneof_F_Enum) isOneof_Union() {} +func (*Oneof_F_Message) isOneof_Union() {} +func (*Oneof_FGroup) isOneof_Union() {} +func (*Oneof_F_Largest_Tag) isOneof_Union() {} +func (*Oneof_Value) isOneof_Tormato() {} + +func (m *Oneof) GetUnion() isOneof_Union { + if m != nil { + return m.Union + } + return nil +} +func (m *Oneof) GetTormato() isOneof_Tormato { + if m != nil { + return m.Tormato + } + return nil +} + +func (m *Oneof) GetF_Bool() bool { + if x, ok := m.GetUnion().(*Oneof_F_Bool); ok { + return x.F_Bool + } + return false +} + +func (m *Oneof) GetF_Int32() int32 { + if x, ok := m.GetUnion().(*Oneof_F_Int32); ok { + return x.F_Int32 + } + return 0 +} + +func (m *Oneof) GetF_Int64() int64 { + if x, ok := m.GetUnion().(*Oneof_F_Int64); ok { + return x.F_Int64 + } + return 0 +} + +func (m *Oneof) GetF_Fixed32() uint32 { + if x, ok := m.GetUnion().(*Oneof_F_Fixed32); ok { + return x.F_Fixed32 + } + return 0 +} + +func (m *Oneof) GetF_Fixed64() uint64 { + if x, ok := m.GetUnion().(*Oneof_F_Fixed64); ok { + return x.F_Fixed64 + } + return 0 +} + +func (m *Oneof) GetF_Uint32() uint32 { + if x, ok := m.GetUnion().(*Oneof_F_Uint32); ok { + return x.F_Uint32 + } + return 0 +} + +func (m *Oneof) GetF_Uint64() uint64 { + if x, ok := m.GetUnion().(*Oneof_F_Uint64); ok { + return x.F_Uint64 + } + return 0 +} + +func (m *Oneof) GetF_Float() float32 { + if x, ok := m.GetUnion().(*Oneof_F_Float); ok { + return x.F_Float + } + return 0 +} + +func (m *Oneof) GetF_Double() float64 { + if x, ok := m.GetUnion().(*Oneof_F_Double); ok { + return x.F_Double + } + return 0 +} + +func (m *Oneof) GetF_String() string { + if x, ok := m.GetUnion().(*Oneof_F_String); ok { + return x.F_String + } + return "" +} + +func (m *Oneof) GetF_Bytes() []byte { + if x, ok := m.GetUnion().(*Oneof_F_Bytes); ok { + return x.F_Bytes + } + return nil +} + +func (m *Oneof) GetF_Sint32() int32 { + if x, ok := m.GetUnion().(*Oneof_F_Sint32); ok { + return x.F_Sint32 + } + return 0 +} + +func (m *Oneof) GetF_Sint64() int64 { + if x, ok := m.GetUnion().(*Oneof_F_Sint64); ok { + return x.F_Sint64 + } + return 0 +} + +func (m *Oneof) GetF_Enum() MyMessage_Color { + if x, ok := m.GetUnion().(*Oneof_F_Enum); ok { + return x.F_Enum + } + return MyMessage_RED +} + +func (m *Oneof) GetF_Message() *GoTestField { + if x, ok := m.GetUnion().(*Oneof_F_Message); ok { + return x.F_Message + } + return nil +} + +func (m *Oneof) GetFGroup() *Oneof_F_Group { + if x, ok := m.GetUnion().(*Oneof_FGroup); ok { + return x.FGroup + } + return nil +} + +func (m *Oneof) GetF_Largest_Tag() int32 { + if x, ok := m.GetUnion().(*Oneof_F_Largest_Tag); ok { + return x.F_Largest_Tag + } + return 0 +} + +func (m *Oneof) GetValue() int32 { + if x, ok := m.GetTormato().(*Oneof_Value); ok { + return x.Value + } + return 0 +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*Oneof) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _Oneof_OneofMarshaler, _Oneof_OneofUnmarshaler, _Oneof_OneofSizer, []interface{}{ + (*Oneof_F_Bool)(nil), + (*Oneof_F_Int32)(nil), + (*Oneof_F_Int64)(nil), + (*Oneof_F_Fixed32)(nil), + (*Oneof_F_Fixed64)(nil), + (*Oneof_F_Uint32)(nil), + (*Oneof_F_Uint64)(nil), + (*Oneof_F_Float)(nil), + (*Oneof_F_Double)(nil), + (*Oneof_F_String)(nil), + (*Oneof_F_Bytes)(nil), + (*Oneof_F_Sint32)(nil), + (*Oneof_F_Sint64)(nil), + (*Oneof_F_Enum)(nil), + (*Oneof_F_Message)(nil), + (*Oneof_FGroup)(nil), + (*Oneof_F_Largest_Tag)(nil), + (*Oneof_Value)(nil), + } +} + +func _Oneof_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*Oneof) + // union + switch x := m.Union.(type) { + case *Oneof_F_Bool: + t := uint64(0) + if x.F_Bool { + t = 1 + } + _ = b.EncodeVarint(1<<3 | proto.WireVarint) + _ = b.EncodeVarint(t) + case *Oneof_F_Int32: + _ = b.EncodeVarint(2<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.F_Int32)) + case *Oneof_F_Int64: + _ = b.EncodeVarint(3<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.F_Int64)) + case *Oneof_F_Fixed32: + _ = b.EncodeVarint(4<<3 | proto.WireFixed32) + _ = b.EncodeFixed32(uint64(x.F_Fixed32)) + case *Oneof_F_Fixed64: + _ = b.EncodeVarint(5<<3 | proto.WireFixed64) + _ = b.EncodeFixed64(uint64(x.F_Fixed64)) + case *Oneof_F_Uint32: + _ = b.EncodeVarint(6<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.F_Uint32)) + case *Oneof_F_Uint64: + _ = b.EncodeVarint(7<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.F_Uint64)) + case *Oneof_F_Float: + _ = b.EncodeVarint(8<<3 | proto.WireFixed32) + _ = b.EncodeFixed32(uint64(math.Float32bits(x.F_Float))) + case *Oneof_F_Double: + _ = b.EncodeVarint(9<<3 | proto.WireFixed64) + _ = b.EncodeFixed64(math.Float64bits(x.F_Double)) + case *Oneof_F_String: + _ = b.EncodeVarint(10<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.F_String) + case *Oneof_F_Bytes: + _ = b.EncodeVarint(11<<3 | proto.WireBytes) + _ = b.EncodeRawBytes(x.F_Bytes) + case *Oneof_F_Sint32: + _ = b.EncodeVarint(12<<3 | proto.WireVarint) + _ = b.EncodeZigzag32(uint64(x.F_Sint32)) + case *Oneof_F_Sint64: + _ = b.EncodeVarint(13<<3 | proto.WireVarint) + _ = b.EncodeZigzag64(uint64(x.F_Sint64)) + case *Oneof_F_Enum: + _ = b.EncodeVarint(14<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.F_Enum)) + case *Oneof_F_Message: + _ = b.EncodeVarint(15<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.F_Message); err != nil { + return err + } + case *Oneof_FGroup: + _ = b.EncodeVarint(16<<3 | proto.WireStartGroup) + if err := b.Marshal(x.FGroup); err != nil { + return err + } + _ = b.EncodeVarint(16<<3 | proto.WireEndGroup) + case *Oneof_F_Largest_Tag: + _ = b.EncodeVarint(536870911<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.F_Largest_Tag)) + case nil: + default: + return fmt.Errorf("Oneof.Union has unexpected type %T", x) + } + // tormato + switch x := m.Tormato.(type) { + case *Oneof_Value: + _ = b.EncodeVarint(100<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.Value)) + case nil: + default: + return fmt.Errorf("Oneof.Tormato has unexpected type %T", x) + } + return nil +} + +func _Oneof_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*Oneof) + switch tag { + case 1: // union.F_Bool + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Oneof_F_Bool{x != 0} + return true, err + case 2: // union.F_Int32 + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Oneof_F_Int32{int32(x)} + return true, err + case 3: // union.F_Int64 + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Oneof_F_Int64{int64(x)} + return true, err + case 4: // union.F_Fixed32 + if wire != proto.WireFixed32 { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeFixed32() + m.Union = &Oneof_F_Fixed32{uint32(x)} + return true, err + case 5: // union.F_Fixed64 + if wire != proto.WireFixed64 { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeFixed64() + m.Union = &Oneof_F_Fixed64{x} + return true, err + case 6: // union.F_Uint32 + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Oneof_F_Uint32{uint32(x)} + return true, err + case 7: // union.F_Uint64 + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Oneof_F_Uint64{x} + return true, err + case 8: // union.F_Float + if wire != proto.WireFixed32 { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeFixed32() + m.Union = &Oneof_F_Float{math.Float32frombits(uint32(x))} + return true, err + case 9: // union.F_Double + if wire != proto.WireFixed64 { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeFixed64() + m.Union = &Oneof_F_Double{math.Float64frombits(x)} + return true, err + case 10: // union.F_String + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Union = &Oneof_F_String{x} + return true, err + case 11: // union.F_Bytes + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeRawBytes(true) + m.Union = &Oneof_F_Bytes{x} + return true, err + case 12: // union.F_Sint32 + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeZigzag32() + m.Union = &Oneof_F_Sint32{int32(x)} + return true, err + case 13: // union.F_Sint64 + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeZigzag64() + m.Union = &Oneof_F_Sint64{int64(x)} + return true, err + case 14: // union.F_Enum + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Oneof_F_Enum{MyMessage_Color(x)} + return true, err + case 15: // union.F_Message + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(GoTestField) + err := b.DecodeMessage(msg) + m.Union = &Oneof_F_Message{msg} + return true, err + case 16: // union.f_group + if wire != proto.WireStartGroup { + return true, proto.ErrInternalBadWireType + } + msg := new(Oneof_F_Group) + err := b.DecodeGroup(msg) + m.Union = &Oneof_FGroup{msg} + return true, err + case 536870911: // union.F_Largest_Tag + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Oneof_F_Largest_Tag{int32(x)} + return true, err + case 100: // tormato.value + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Tormato = &Oneof_Value{int32(x)} + return true, err + default: + return false, nil + } +} + +func _Oneof_OneofSizer(msg proto.Message) (n int) { + m := msg.(*Oneof) + // union + switch x := m.Union.(type) { + case *Oneof_F_Bool: + n += proto.SizeVarint(1<<3 | proto.WireVarint) + n += 1 + case *Oneof_F_Int32: + n += proto.SizeVarint(2<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.F_Int32)) + case *Oneof_F_Int64: + n += proto.SizeVarint(3<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.F_Int64)) + case *Oneof_F_Fixed32: + n += proto.SizeVarint(4<<3 | proto.WireFixed32) + n += 4 + case *Oneof_F_Fixed64: + n += proto.SizeVarint(5<<3 | proto.WireFixed64) + n += 8 + case *Oneof_F_Uint32: + n += proto.SizeVarint(6<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.F_Uint32)) + case *Oneof_F_Uint64: + n += proto.SizeVarint(7<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.F_Uint64)) + case *Oneof_F_Float: + n += proto.SizeVarint(8<<3 | proto.WireFixed32) + n += 4 + case *Oneof_F_Double: + n += proto.SizeVarint(9<<3 | proto.WireFixed64) + n += 8 + case *Oneof_F_String: + n += proto.SizeVarint(10<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.F_String))) + n += len(x.F_String) + case *Oneof_F_Bytes: + n += proto.SizeVarint(11<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.F_Bytes))) + n += len(x.F_Bytes) + case *Oneof_F_Sint32: + n += proto.SizeVarint(12<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64((uint32(x.F_Sint32) << 1) ^ uint32((int32(x.F_Sint32) >> 31)))) + case *Oneof_F_Sint64: + n += proto.SizeVarint(13<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(uint64(x.F_Sint64<<1) ^ uint64((int64(x.F_Sint64) >> 63)))) + case *Oneof_F_Enum: + n += proto.SizeVarint(14<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.F_Enum)) + case *Oneof_F_Message: + s := proto.Size(x.F_Message) + n += proto.SizeVarint(15<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(s)) + n += s + case *Oneof_FGroup: + n += proto.SizeVarint(16<<3 | proto.WireStartGroup) + n += proto.Size(x.FGroup) + n += proto.SizeVarint(16<<3 | proto.WireEndGroup) + case *Oneof_F_Largest_Tag: + n += proto.SizeVarint(536870911<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.F_Largest_Tag)) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + // tormato + switch x := m.Tormato.(type) { + case *Oneof_Value: + n += proto.SizeVarint(100<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.Value)) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type Oneof_F_Group struct { + X *int32 `protobuf:"varint,17,opt,name=x" json:"x,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Oneof_F_Group) Reset() { *m = Oneof_F_Group{} } +func (m *Oneof_F_Group) String() string { return proto.CompactTextString(m) } +func (*Oneof_F_Group) ProtoMessage() {} +func (*Oneof_F_Group) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{29, 0} } + +func (m *Oneof_F_Group) GetX() int32 { + if m != nil && m.X != nil { + return *m.X + } + return 0 +} + +type Communique struct { + MakeMeCry *bool `protobuf:"varint,1,opt,name=make_me_cry,json=makeMeCry" json:"make_me_cry,omitempty"` + // This is a oneof, called "union". + // + // Types that are valid to be assigned to Union: + // *Communique_Number + // *Communique_Name + // *Communique_Data + // *Communique_TempC + // *Communique_Col + // *Communique_Msg + Union isCommunique_Union `protobuf_oneof:"union"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Communique) Reset() { *m = Communique{} } +func (m *Communique) String() string { return proto.CompactTextString(m) } +func (*Communique) ProtoMessage() {} +func (*Communique) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{30} } + +type isCommunique_Union interface { + isCommunique_Union() +} + +type Communique_Number struct { + Number int32 `protobuf:"varint,5,opt,name=number,oneof"` +} +type Communique_Name struct { + Name string `protobuf:"bytes,6,opt,name=name,oneof"` +} +type Communique_Data struct { + Data []byte `protobuf:"bytes,7,opt,name=data,oneof"` +} +type Communique_TempC struct { + TempC float64 `protobuf:"fixed64,8,opt,name=temp_c,json=tempC,oneof"` +} +type Communique_Col struct { + Col MyMessage_Color `protobuf:"varint,9,opt,name=col,enum=testdata.MyMessage_Color,oneof"` +} +type Communique_Msg struct { + Msg *Strings `protobuf:"bytes,10,opt,name=msg,oneof"` +} + +func (*Communique_Number) isCommunique_Union() {} +func (*Communique_Name) isCommunique_Union() {} +func (*Communique_Data) isCommunique_Union() {} +func (*Communique_TempC) isCommunique_Union() {} +func (*Communique_Col) isCommunique_Union() {} +func (*Communique_Msg) isCommunique_Union() {} + +func (m *Communique) GetUnion() isCommunique_Union { + if m != nil { + return m.Union + } + return nil +} + +func (m *Communique) GetMakeMeCry() bool { + if m != nil && m.MakeMeCry != nil { + return *m.MakeMeCry + } + return false +} + +func (m *Communique) GetNumber() int32 { + if x, ok := m.GetUnion().(*Communique_Number); ok { + return x.Number + } + return 0 +} + +func (m *Communique) GetName() string { + if x, ok := m.GetUnion().(*Communique_Name); ok { + return x.Name + } + return "" +} + +func (m *Communique) GetData() []byte { + if x, ok := m.GetUnion().(*Communique_Data); ok { + return x.Data + } + return nil +} + +func (m *Communique) GetTempC() float64 { + if x, ok := m.GetUnion().(*Communique_TempC); ok { + return x.TempC + } + return 0 +} + +func (m *Communique) GetCol() MyMessage_Color { + if x, ok := m.GetUnion().(*Communique_Col); ok { + return x.Col + } + return MyMessage_RED +} + +func (m *Communique) GetMsg() *Strings { + if x, ok := m.GetUnion().(*Communique_Msg); ok { + return x.Msg + } + return nil +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*Communique) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _Communique_OneofMarshaler, _Communique_OneofUnmarshaler, _Communique_OneofSizer, []interface{}{ + (*Communique_Number)(nil), + (*Communique_Name)(nil), + (*Communique_Data)(nil), + (*Communique_TempC)(nil), + (*Communique_Col)(nil), + (*Communique_Msg)(nil), + } +} + +func _Communique_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*Communique) + // union + switch x := m.Union.(type) { + case *Communique_Number: + _ = b.EncodeVarint(5<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.Number)) + case *Communique_Name: + _ = b.EncodeVarint(6<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.Name) + case *Communique_Data: + _ = b.EncodeVarint(7<<3 | proto.WireBytes) + _ = b.EncodeRawBytes(x.Data) + case *Communique_TempC: + _ = b.EncodeVarint(8<<3 | proto.WireFixed64) + _ = b.EncodeFixed64(math.Float64bits(x.TempC)) + case *Communique_Col: + _ = b.EncodeVarint(9<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.Col)) + case *Communique_Msg: + _ = b.EncodeVarint(10<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Msg); err != nil { + return err + } + case nil: + default: + return fmt.Errorf("Communique.Union has unexpected type %T", x) + } + return nil +} + +func _Communique_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*Communique) + switch tag { + case 5: // union.number + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Communique_Number{int32(x)} + return true, err + case 6: // union.name + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Union = &Communique_Name{x} + return true, err + case 7: // union.data + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeRawBytes(true) + m.Union = &Communique_Data{x} + return true, err + case 8: // union.temp_c + if wire != proto.WireFixed64 { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeFixed64() + m.Union = &Communique_TempC{math.Float64frombits(x)} + return true, err + case 9: // union.col + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Communique_Col{MyMessage_Color(x)} + return true, err + case 10: // union.msg + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(Strings) + err := b.DecodeMessage(msg) + m.Union = &Communique_Msg{msg} + return true, err + default: + return false, nil + } +} + +func _Communique_OneofSizer(msg proto.Message) (n int) { + m := msg.(*Communique) + // union + switch x := m.Union.(type) { + case *Communique_Number: + n += proto.SizeVarint(5<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.Number)) + case *Communique_Name: + n += proto.SizeVarint(6<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.Name))) + n += len(x.Name) + case *Communique_Data: + n += proto.SizeVarint(7<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.Data))) + n += len(x.Data) + case *Communique_TempC: + n += proto.SizeVarint(8<<3 | proto.WireFixed64) + n += 8 + case *Communique_Col: + n += proto.SizeVarint(9<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.Col)) + case *Communique_Msg: + s := proto.Size(x.Msg) + n += proto.SizeVarint(10<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(s)) + n += s + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +var E_Greeting = &proto.ExtensionDesc{ + ExtendedType: (*MyMessage)(nil), + ExtensionType: ([]string)(nil), + Field: 106, + Name: "testdata.greeting", + Tag: "bytes,106,rep,name=greeting", + Filename: "test.proto", +} + +var E_Complex = &proto.ExtensionDesc{ + ExtendedType: (*OtherMessage)(nil), + ExtensionType: (*ComplexExtension)(nil), + Field: 200, + Name: "testdata.complex", + Tag: "bytes,200,opt,name=complex", + Filename: "test.proto", +} + +var E_RComplex = &proto.ExtensionDesc{ + ExtendedType: (*OtherMessage)(nil), + ExtensionType: ([]*ComplexExtension)(nil), + Field: 201, + Name: "testdata.r_complex", + Tag: "bytes,201,rep,name=r_complex,json=rComplex", + Filename: "test.proto", +} + +var E_NoDefaultDouble = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*float64)(nil), + Field: 101, + Name: "testdata.no_default_double", + Tag: "fixed64,101,opt,name=no_default_double,json=noDefaultDouble", + Filename: "test.proto", +} + +var E_NoDefaultFloat = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*float32)(nil), + Field: 102, + Name: "testdata.no_default_float", + Tag: "fixed32,102,opt,name=no_default_float,json=noDefaultFloat", + Filename: "test.proto", +} + +var E_NoDefaultInt32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int32)(nil), + Field: 103, + Name: "testdata.no_default_int32", + Tag: "varint,103,opt,name=no_default_int32,json=noDefaultInt32", + Filename: "test.proto", +} + +var E_NoDefaultInt64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int64)(nil), + Field: 104, + Name: "testdata.no_default_int64", + Tag: "varint,104,opt,name=no_default_int64,json=noDefaultInt64", + Filename: "test.proto", +} + +var E_NoDefaultUint32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*uint32)(nil), + Field: 105, + Name: "testdata.no_default_uint32", + Tag: "varint,105,opt,name=no_default_uint32,json=noDefaultUint32", + Filename: "test.proto", +} + +var E_NoDefaultUint64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*uint64)(nil), + Field: 106, + Name: "testdata.no_default_uint64", + Tag: "varint,106,opt,name=no_default_uint64,json=noDefaultUint64", + Filename: "test.proto", +} + +var E_NoDefaultSint32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int32)(nil), + Field: 107, + Name: "testdata.no_default_sint32", + Tag: "zigzag32,107,opt,name=no_default_sint32,json=noDefaultSint32", + Filename: "test.proto", +} + +var E_NoDefaultSint64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int64)(nil), + Field: 108, + Name: "testdata.no_default_sint64", + Tag: "zigzag64,108,opt,name=no_default_sint64,json=noDefaultSint64", + Filename: "test.proto", +} + +var E_NoDefaultFixed32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*uint32)(nil), + Field: 109, + Name: "testdata.no_default_fixed32", + Tag: "fixed32,109,opt,name=no_default_fixed32,json=noDefaultFixed32", + Filename: "test.proto", +} + +var E_NoDefaultFixed64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*uint64)(nil), + Field: 110, + Name: "testdata.no_default_fixed64", + Tag: "fixed64,110,opt,name=no_default_fixed64,json=noDefaultFixed64", + Filename: "test.proto", +} + +var E_NoDefaultSfixed32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int32)(nil), + Field: 111, + Name: "testdata.no_default_sfixed32", + Tag: "fixed32,111,opt,name=no_default_sfixed32,json=noDefaultSfixed32", + Filename: "test.proto", +} + +var E_NoDefaultSfixed64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int64)(nil), + Field: 112, + Name: "testdata.no_default_sfixed64", + Tag: "fixed64,112,opt,name=no_default_sfixed64,json=noDefaultSfixed64", + Filename: "test.proto", +} + +var E_NoDefaultBool = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*bool)(nil), + Field: 113, + Name: "testdata.no_default_bool", + Tag: "varint,113,opt,name=no_default_bool,json=noDefaultBool", + Filename: "test.proto", +} + +var E_NoDefaultString = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*string)(nil), + Field: 114, + Name: "testdata.no_default_string", + Tag: "bytes,114,opt,name=no_default_string,json=noDefaultString", + Filename: "test.proto", +} + +var E_NoDefaultBytes = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: ([]byte)(nil), + Field: 115, + Name: "testdata.no_default_bytes", + Tag: "bytes,115,opt,name=no_default_bytes,json=noDefaultBytes", + Filename: "test.proto", +} + +var E_NoDefaultEnum = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*DefaultsMessage_DefaultsEnum)(nil), + Field: 116, + Name: "testdata.no_default_enum", + Tag: "varint,116,opt,name=no_default_enum,json=noDefaultEnum,enum=testdata.DefaultsMessage_DefaultsEnum", + Filename: "test.proto", +} + +var E_DefaultDouble = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*float64)(nil), + Field: 201, + Name: "testdata.default_double", + Tag: "fixed64,201,opt,name=default_double,json=defaultDouble,def=3.1415", + Filename: "test.proto", +} + +var E_DefaultFloat = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*float32)(nil), + Field: 202, + Name: "testdata.default_float", + Tag: "fixed32,202,opt,name=default_float,json=defaultFloat,def=3.14", + Filename: "test.proto", +} + +var E_DefaultInt32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int32)(nil), + Field: 203, + Name: "testdata.default_int32", + Tag: "varint,203,opt,name=default_int32,json=defaultInt32,def=42", + Filename: "test.proto", +} + +var E_DefaultInt64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int64)(nil), + Field: 204, + Name: "testdata.default_int64", + Tag: "varint,204,opt,name=default_int64,json=defaultInt64,def=43", + Filename: "test.proto", +} + +var E_DefaultUint32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*uint32)(nil), + Field: 205, + Name: "testdata.default_uint32", + Tag: "varint,205,opt,name=default_uint32,json=defaultUint32,def=44", + Filename: "test.proto", +} + +var E_DefaultUint64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*uint64)(nil), + Field: 206, + Name: "testdata.default_uint64", + Tag: "varint,206,opt,name=default_uint64,json=defaultUint64,def=45", + Filename: "test.proto", +} + +var E_DefaultSint32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int32)(nil), + Field: 207, + Name: "testdata.default_sint32", + Tag: "zigzag32,207,opt,name=default_sint32,json=defaultSint32,def=46", + Filename: "test.proto", +} + +var E_DefaultSint64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int64)(nil), + Field: 208, + Name: "testdata.default_sint64", + Tag: "zigzag64,208,opt,name=default_sint64,json=defaultSint64,def=47", + Filename: "test.proto", +} + +var E_DefaultFixed32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*uint32)(nil), + Field: 209, + Name: "testdata.default_fixed32", + Tag: "fixed32,209,opt,name=default_fixed32,json=defaultFixed32,def=48", + Filename: "test.proto", +} + +var E_DefaultFixed64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*uint64)(nil), + Field: 210, + Name: "testdata.default_fixed64", + Tag: "fixed64,210,opt,name=default_fixed64,json=defaultFixed64,def=49", + Filename: "test.proto", +} + +var E_DefaultSfixed32 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int32)(nil), + Field: 211, + Name: "testdata.default_sfixed32", + Tag: "fixed32,211,opt,name=default_sfixed32,json=defaultSfixed32,def=50", + Filename: "test.proto", +} + +var E_DefaultSfixed64 = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*int64)(nil), + Field: 212, + Name: "testdata.default_sfixed64", + Tag: "fixed64,212,opt,name=default_sfixed64,json=defaultSfixed64,def=51", + Filename: "test.proto", +} + +var E_DefaultBool = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*bool)(nil), + Field: 213, + Name: "testdata.default_bool", + Tag: "varint,213,opt,name=default_bool,json=defaultBool,def=1", + Filename: "test.proto", +} + +var E_DefaultString = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*string)(nil), + Field: 214, + Name: "testdata.default_string", + Tag: "bytes,214,opt,name=default_string,json=defaultString,def=Hello, string", + Filename: "test.proto", +} + +var E_DefaultBytes = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: ([]byte)(nil), + Field: 215, + Name: "testdata.default_bytes", + Tag: "bytes,215,opt,name=default_bytes,json=defaultBytes,def=Hello, bytes", + Filename: "test.proto", +} + +var E_DefaultEnum = &proto.ExtensionDesc{ + ExtendedType: (*DefaultsMessage)(nil), + ExtensionType: (*DefaultsMessage_DefaultsEnum)(nil), + Field: 216, + Name: "testdata.default_enum", + Tag: "varint,216,opt,name=default_enum,json=defaultEnum,enum=testdata.DefaultsMessage_DefaultsEnum,def=1", + Filename: "test.proto", +} + +var E_X201 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 201, + Name: "testdata.x201", + Tag: "bytes,201,opt,name=x201", + Filename: "test.proto", +} + +var E_X202 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 202, + Name: "testdata.x202", + Tag: "bytes,202,opt,name=x202", + Filename: "test.proto", +} + +var E_X203 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 203, + Name: "testdata.x203", + Tag: "bytes,203,opt,name=x203", + Filename: "test.proto", +} + +var E_X204 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 204, + Name: "testdata.x204", + Tag: "bytes,204,opt,name=x204", + Filename: "test.proto", +} + +var E_X205 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 205, + Name: "testdata.x205", + Tag: "bytes,205,opt,name=x205", + Filename: "test.proto", +} + +var E_X206 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 206, + Name: "testdata.x206", + Tag: "bytes,206,opt,name=x206", + Filename: "test.proto", +} + +var E_X207 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 207, + Name: "testdata.x207", + Tag: "bytes,207,opt,name=x207", + Filename: "test.proto", +} + +var E_X208 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 208, + Name: "testdata.x208", + Tag: "bytes,208,opt,name=x208", + Filename: "test.proto", +} + +var E_X209 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 209, + Name: "testdata.x209", + Tag: "bytes,209,opt,name=x209", + Filename: "test.proto", +} + +var E_X210 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 210, + Name: "testdata.x210", + Tag: "bytes,210,opt,name=x210", + Filename: "test.proto", +} + +var E_X211 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 211, + Name: "testdata.x211", + Tag: "bytes,211,opt,name=x211", + Filename: "test.proto", +} + +var E_X212 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 212, + Name: "testdata.x212", + Tag: "bytes,212,opt,name=x212", + Filename: "test.proto", +} + +var E_X213 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 213, + Name: "testdata.x213", + Tag: "bytes,213,opt,name=x213", + Filename: "test.proto", +} + +var E_X214 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 214, + Name: "testdata.x214", + Tag: "bytes,214,opt,name=x214", + Filename: "test.proto", +} + +var E_X215 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 215, + Name: "testdata.x215", + Tag: "bytes,215,opt,name=x215", + Filename: "test.proto", +} + +var E_X216 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 216, + Name: "testdata.x216", + Tag: "bytes,216,opt,name=x216", + Filename: "test.proto", +} + +var E_X217 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 217, + Name: "testdata.x217", + Tag: "bytes,217,opt,name=x217", + Filename: "test.proto", +} + +var E_X218 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 218, + Name: "testdata.x218", + Tag: "bytes,218,opt,name=x218", + Filename: "test.proto", +} + +var E_X219 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 219, + Name: "testdata.x219", + Tag: "bytes,219,opt,name=x219", + Filename: "test.proto", +} + +var E_X220 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 220, + Name: "testdata.x220", + Tag: "bytes,220,opt,name=x220", + Filename: "test.proto", +} + +var E_X221 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 221, + Name: "testdata.x221", + Tag: "bytes,221,opt,name=x221", + Filename: "test.proto", +} + +var E_X222 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 222, + Name: "testdata.x222", + Tag: "bytes,222,opt,name=x222", + Filename: "test.proto", +} + +var E_X223 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 223, + Name: "testdata.x223", + Tag: "bytes,223,opt,name=x223", + Filename: "test.proto", +} + +var E_X224 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 224, + Name: "testdata.x224", + Tag: "bytes,224,opt,name=x224", + Filename: "test.proto", +} + +var E_X225 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 225, + Name: "testdata.x225", + Tag: "bytes,225,opt,name=x225", + Filename: "test.proto", +} + +var E_X226 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 226, + Name: "testdata.x226", + Tag: "bytes,226,opt,name=x226", + Filename: "test.proto", +} + +var E_X227 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 227, + Name: "testdata.x227", + Tag: "bytes,227,opt,name=x227", + Filename: "test.proto", +} + +var E_X228 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 228, + Name: "testdata.x228", + Tag: "bytes,228,opt,name=x228", + Filename: "test.proto", +} + +var E_X229 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 229, + Name: "testdata.x229", + Tag: "bytes,229,opt,name=x229", + Filename: "test.proto", +} + +var E_X230 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 230, + Name: "testdata.x230", + Tag: "bytes,230,opt,name=x230", + Filename: "test.proto", +} + +var E_X231 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 231, + Name: "testdata.x231", + Tag: "bytes,231,opt,name=x231", + Filename: "test.proto", +} + +var E_X232 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 232, + Name: "testdata.x232", + Tag: "bytes,232,opt,name=x232", + Filename: "test.proto", +} + +var E_X233 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 233, + Name: "testdata.x233", + Tag: "bytes,233,opt,name=x233", + Filename: "test.proto", +} + +var E_X234 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 234, + Name: "testdata.x234", + Tag: "bytes,234,opt,name=x234", + Filename: "test.proto", +} + +var E_X235 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 235, + Name: "testdata.x235", + Tag: "bytes,235,opt,name=x235", + Filename: "test.proto", +} + +var E_X236 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 236, + Name: "testdata.x236", + Tag: "bytes,236,opt,name=x236", + Filename: "test.proto", +} + +var E_X237 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 237, + Name: "testdata.x237", + Tag: "bytes,237,opt,name=x237", + Filename: "test.proto", +} + +var E_X238 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 238, + Name: "testdata.x238", + Tag: "bytes,238,opt,name=x238", + Filename: "test.proto", +} + +var E_X239 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 239, + Name: "testdata.x239", + Tag: "bytes,239,opt,name=x239", + Filename: "test.proto", +} + +var E_X240 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 240, + Name: "testdata.x240", + Tag: "bytes,240,opt,name=x240", + Filename: "test.proto", +} + +var E_X241 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 241, + Name: "testdata.x241", + Tag: "bytes,241,opt,name=x241", + Filename: "test.proto", +} + +var E_X242 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 242, + Name: "testdata.x242", + Tag: "bytes,242,opt,name=x242", + Filename: "test.proto", +} + +var E_X243 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 243, + Name: "testdata.x243", + Tag: "bytes,243,opt,name=x243", + Filename: "test.proto", +} + +var E_X244 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 244, + Name: "testdata.x244", + Tag: "bytes,244,opt,name=x244", + Filename: "test.proto", +} + +var E_X245 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 245, + Name: "testdata.x245", + Tag: "bytes,245,opt,name=x245", + Filename: "test.proto", +} + +var E_X246 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 246, + Name: "testdata.x246", + Tag: "bytes,246,opt,name=x246", + Filename: "test.proto", +} + +var E_X247 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 247, + Name: "testdata.x247", + Tag: "bytes,247,opt,name=x247", + Filename: "test.proto", +} + +var E_X248 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 248, + Name: "testdata.x248", + Tag: "bytes,248,opt,name=x248", + Filename: "test.proto", +} + +var E_X249 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 249, + Name: "testdata.x249", + Tag: "bytes,249,opt,name=x249", + Filename: "test.proto", +} + +var E_X250 = &proto.ExtensionDesc{ + ExtendedType: (*MyMessageSet)(nil), + ExtensionType: (*Empty)(nil), + Field: 250, + Name: "testdata.x250", + Tag: "bytes,250,opt,name=x250", + Filename: "test.proto", +} + +func init() { + proto.RegisterType((*GoEnum)(nil), "testdata.GoEnum") + proto.RegisterType((*GoTestField)(nil), "testdata.GoTestField") + proto.RegisterType((*GoTest)(nil), "testdata.GoTest") + proto.RegisterType((*GoTest_RequiredGroup)(nil), "testdata.GoTest.RequiredGroup") + proto.RegisterType((*GoTest_RepeatedGroup)(nil), "testdata.GoTest.RepeatedGroup") + proto.RegisterType((*GoTest_OptionalGroup)(nil), "testdata.GoTest.OptionalGroup") + proto.RegisterType((*GoTestRequiredGroupField)(nil), "testdata.GoTestRequiredGroupField") + proto.RegisterType((*GoTestRequiredGroupField_Group)(nil), "testdata.GoTestRequiredGroupField.Group") + proto.RegisterType((*GoSkipTest)(nil), "testdata.GoSkipTest") + proto.RegisterType((*GoSkipTest_SkipGroup)(nil), "testdata.GoSkipTest.SkipGroup") + proto.RegisterType((*NonPackedTest)(nil), "testdata.NonPackedTest") + proto.RegisterType((*PackedTest)(nil), "testdata.PackedTest") + proto.RegisterType((*MaxTag)(nil), "testdata.MaxTag") + proto.RegisterType((*OldMessage)(nil), "testdata.OldMessage") + proto.RegisterType((*OldMessage_Nested)(nil), "testdata.OldMessage.Nested") + proto.RegisterType((*NewMessage)(nil), "testdata.NewMessage") + proto.RegisterType((*NewMessage_Nested)(nil), "testdata.NewMessage.Nested") + proto.RegisterType((*InnerMessage)(nil), "testdata.InnerMessage") + proto.RegisterType((*OtherMessage)(nil), "testdata.OtherMessage") + proto.RegisterType((*RequiredInnerMessage)(nil), "testdata.RequiredInnerMessage") + proto.RegisterType((*MyMessage)(nil), "testdata.MyMessage") + proto.RegisterType((*MyMessage_SomeGroup)(nil), "testdata.MyMessage.SomeGroup") + proto.RegisterType((*Ext)(nil), "testdata.Ext") + proto.RegisterType((*ComplexExtension)(nil), "testdata.ComplexExtension") + proto.RegisterType((*DefaultsMessage)(nil), "testdata.DefaultsMessage") + proto.RegisterType((*MyMessageSet)(nil), "testdata.MyMessageSet") + proto.RegisterType((*Empty)(nil), "testdata.Empty") + proto.RegisterType((*MessageList)(nil), "testdata.MessageList") + proto.RegisterType((*MessageList_Message)(nil), "testdata.MessageList.Message") + proto.RegisterType((*Strings)(nil), "testdata.Strings") + proto.RegisterType((*Defaults)(nil), "testdata.Defaults") + proto.RegisterType((*SubDefaults)(nil), "testdata.SubDefaults") + proto.RegisterType((*RepeatedEnum)(nil), "testdata.RepeatedEnum") + proto.RegisterType((*MoreRepeated)(nil), "testdata.MoreRepeated") + proto.RegisterType((*GroupOld)(nil), "testdata.GroupOld") + proto.RegisterType((*GroupOld_G)(nil), "testdata.GroupOld.G") + proto.RegisterType((*GroupNew)(nil), "testdata.GroupNew") + proto.RegisterType((*GroupNew_G)(nil), "testdata.GroupNew.G") + proto.RegisterType((*FloatingPoint)(nil), "testdata.FloatingPoint") + proto.RegisterType((*MessageWithMap)(nil), "testdata.MessageWithMap") + proto.RegisterType((*Oneof)(nil), "testdata.Oneof") + proto.RegisterType((*Oneof_F_Group)(nil), "testdata.Oneof.F_Group") + proto.RegisterType((*Communique)(nil), "testdata.Communique") + proto.RegisterEnum("testdata.FOO", FOO_name, FOO_value) + proto.RegisterEnum("testdata.GoTest_KIND", GoTest_KIND_name, GoTest_KIND_value) + proto.RegisterEnum("testdata.MyMessage_Color", MyMessage_Color_name, MyMessage_Color_value) + proto.RegisterEnum("testdata.DefaultsMessage_DefaultsEnum", DefaultsMessage_DefaultsEnum_name, DefaultsMessage_DefaultsEnum_value) + proto.RegisterEnum("testdata.Defaults_Color", Defaults_Color_name, Defaults_Color_value) + proto.RegisterEnum("testdata.RepeatedEnum_Color", RepeatedEnum_Color_name, RepeatedEnum_Color_value) + proto.RegisterExtension(E_Ext_More) + proto.RegisterExtension(E_Ext_Text) + proto.RegisterExtension(E_Ext_Number) + proto.RegisterExtension(E_Greeting) + proto.RegisterExtension(E_Complex) + proto.RegisterExtension(E_RComplex) + proto.RegisterExtension(E_NoDefaultDouble) + proto.RegisterExtension(E_NoDefaultFloat) + proto.RegisterExtension(E_NoDefaultInt32) + proto.RegisterExtension(E_NoDefaultInt64) + proto.RegisterExtension(E_NoDefaultUint32) + proto.RegisterExtension(E_NoDefaultUint64) + proto.RegisterExtension(E_NoDefaultSint32) + proto.RegisterExtension(E_NoDefaultSint64) + proto.RegisterExtension(E_NoDefaultFixed32) + proto.RegisterExtension(E_NoDefaultFixed64) + proto.RegisterExtension(E_NoDefaultSfixed32) + proto.RegisterExtension(E_NoDefaultSfixed64) + proto.RegisterExtension(E_NoDefaultBool) + proto.RegisterExtension(E_NoDefaultString) + proto.RegisterExtension(E_NoDefaultBytes) + proto.RegisterExtension(E_NoDefaultEnum) + proto.RegisterExtension(E_DefaultDouble) + proto.RegisterExtension(E_DefaultFloat) + proto.RegisterExtension(E_DefaultInt32) + proto.RegisterExtension(E_DefaultInt64) + proto.RegisterExtension(E_DefaultUint32) + proto.RegisterExtension(E_DefaultUint64) + proto.RegisterExtension(E_DefaultSint32) + proto.RegisterExtension(E_DefaultSint64) + proto.RegisterExtension(E_DefaultFixed32) + proto.RegisterExtension(E_DefaultFixed64) + proto.RegisterExtension(E_DefaultSfixed32) + proto.RegisterExtension(E_DefaultSfixed64) + proto.RegisterExtension(E_DefaultBool) + proto.RegisterExtension(E_DefaultString) + proto.RegisterExtension(E_DefaultBytes) + proto.RegisterExtension(E_DefaultEnum) + proto.RegisterExtension(E_X201) + proto.RegisterExtension(E_X202) + proto.RegisterExtension(E_X203) + proto.RegisterExtension(E_X204) + proto.RegisterExtension(E_X205) + proto.RegisterExtension(E_X206) + proto.RegisterExtension(E_X207) + proto.RegisterExtension(E_X208) + proto.RegisterExtension(E_X209) + proto.RegisterExtension(E_X210) + proto.RegisterExtension(E_X211) + proto.RegisterExtension(E_X212) + proto.RegisterExtension(E_X213) + proto.RegisterExtension(E_X214) + proto.RegisterExtension(E_X215) + proto.RegisterExtension(E_X216) + proto.RegisterExtension(E_X217) + proto.RegisterExtension(E_X218) + proto.RegisterExtension(E_X219) + proto.RegisterExtension(E_X220) + proto.RegisterExtension(E_X221) + proto.RegisterExtension(E_X222) + proto.RegisterExtension(E_X223) + proto.RegisterExtension(E_X224) + proto.RegisterExtension(E_X225) + proto.RegisterExtension(E_X226) + proto.RegisterExtension(E_X227) + proto.RegisterExtension(E_X228) + proto.RegisterExtension(E_X229) + proto.RegisterExtension(E_X230) + proto.RegisterExtension(E_X231) + proto.RegisterExtension(E_X232) + proto.RegisterExtension(E_X233) + proto.RegisterExtension(E_X234) + proto.RegisterExtension(E_X235) + proto.RegisterExtension(E_X236) + proto.RegisterExtension(E_X237) + proto.RegisterExtension(E_X238) + proto.RegisterExtension(E_X239) + proto.RegisterExtension(E_X240) + proto.RegisterExtension(E_X241) + proto.RegisterExtension(E_X242) + proto.RegisterExtension(E_X243) + proto.RegisterExtension(E_X244) + proto.RegisterExtension(E_X245) + proto.RegisterExtension(E_X246) + proto.RegisterExtension(E_X247) + proto.RegisterExtension(E_X248) + proto.RegisterExtension(E_X249) + proto.RegisterExtension(E_X250) +} + +func init() { proto.RegisterFile("test.proto", fileDescriptorTest) } + +var fileDescriptorTest = []byte{ + // 4453 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x5a, 0xc9, 0x77, 0xdb, 0x48, + 0x7a, 0x37, 0xc0, 0xfd, 0x23, 0x25, 0x42, 0x65, 0xb5, 0x9b, 0x96, 0xbc, 0xc0, 0x9c, 0xe9, 0x6e, + 0x7a, 0xd3, 0x48, 0x20, 0x44, 0xdb, 0x74, 0xa7, 0xdf, 0xf3, 0x42, 0xca, 0x7a, 0x63, 0x89, 0x0a, + 0xa4, 0xee, 0x7e, 0xd3, 0x39, 0xf0, 0x51, 0x22, 0x44, 0xb3, 0x4d, 0x02, 0x34, 0x09, 0xc5, 0x52, + 0x72, 0xe9, 0x4b, 0x72, 0xcd, 0x76, 0xc9, 0x35, 0xa7, 0x9c, 0x92, 0xbc, 0x97, 0x7f, 0x22, 0xe9, + 0xee, 0x59, 0x7b, 0xd6, 0xac, 0x93, 0x7d, 0x99, 0xec, 0xdb, 0x4c, 0x92, 0x4b, 0xcf, 0xab, 0xaf, + 0x0a, 0x40, 0x01, 0x24, 0x20, 0xf9, 0x24, 0x56, 0xd5, 0xef, 0xf7, 0xd5, 0xf6, 0xab, 0xef, 0xab, + 0xaf, 0x20, 0x00, 0xc7, 0x9c, 0x38, 0x2b, 0xa3, 0xb1, 0xed, 0xd8, 0x24, 0x4b, 0x7f, 0x77, 0x3b, + 0x4e, 0xa7, 0x7c, 0x1d, 0xd2, 0x1b, 0x76, 0xc3, 0x3a, 0x1a, 0x92, 0xab, 0x90, 0x38, 0xb4, 0xed, + 0x92, 0xa4, 0xca, 0x95, 0x79, 0x6d, 0x6e, 0xc5, 0x45, 0xac, 0x34, 0x5b, 0x2d, 0x83, 0xb6, 0x94, + 0xef, 0x40, 0x7e, 0xc3, 0xde, 0x33, 0x27, 0x4e, 0xb3, 0x6f, 0x0e, 0xba, 0x64, 0x11, 0x52, 0x4f, + 0x3b, 0xfb, 0xe6, 0x00, 0x19, 0x39, 0x83, 0x15, 0x08, 0x81, 0xe4, 0xde, 0xc9, 0xc8, 0x2c, 0xc9, + 0x58, 0x89, 0xbf, 0xcb, 0xbf, 0x72, 0x85, 0x76, 0x42, 0x99, 0xe4, 0x3a, 0x24, 0xbf, 0xdc, 0xb7, + 0xba, 0xbc, 0x97, 0xd7, 0xfc, 0x5e, 0x58, 0xfb, 0xca, 0x97, 0x37, 0xb7, 0x1f, 0x1b, 0x08, 0xa1, + 0xf6, 0xf7, 0x3a, 0xfb, 0x03, 0x6a, 0x4a, 0xa2, 0xf6, 0xb1, 0x40, 0x6b, 0x77, 0x3a, 0xe3, 0xce, + 0xb0, 0x94, 0x50, 0xa5, 0x4a, 0xca, 0x60, 0x05, 0x72, 0x1f, 0xe6, 0x0c, 0xf3, 0xc5, 0x51, 0x7f, + 0x6c, 0x76, 0x71, 0x70, 0xa5, 0xa4, 0x2a, 0x57, 0xf2, 0xd3, 0xf6, 0xb1, 0xd1, 0x08, 0x62, 0x19, + 0x79, 0x64, 0x76, 0x1c, 0x97, 0x9c, 0x52, 0x13, 0xb1, 0x64, 0x01, 0x4b, 0xc9, 0xad, 0x91, 0xd3, + 0xb7, 0xad, 0xce, 0x80, 0x91, 0xd3, 0xaa, 0x14, 0x43, 0x0e, 0x60, 0xc9, 0x9b, 0x50, 0x6c, 0xb6, + 0x1f, 0xda, 0xf6, 0xa0, 0x3d, 0xe6, 0x23, 0x2a, 0x81, 0x2a, 0x57, 0xb2, 0xc6, 0x5c, 0x93, 0xd6, + 0xba, 0xc3, 0x24, 0x15, 0x50, 0x9a, 0xed, 0x4d, 0xcb, 0xa9, 0x6a, 0x3e, 0x30, 0xaf, 0xca, 0x95, + 0x94, 0x31, 0xdf, 0xc4, 0xea, 0x29, 0x64, 0x4d, 0xf7, 0x91, 0x05, 0x55, 0xae, 0x24, 0x18, 0xb2, + 0xa6, 0x7b, 0xc8, 0x5b, 0x40, 0x9a, 0xed, 0x66, 0xff, 0xd8, 0xec, 0x8a, 0x56, 0xe7, 0x54, 0xb9, + 0x92, 0x31, 0x94, 0x26, 0x6f, 0x98, 0x81, 0x16, 0x2d, 0xcf, 0xab, 0x72, 0x25, 0xed, 0xa2, 0x05, + 0xdb, 0x37, 0x60, 0xa1, 0xd9, 0x7e, 0xb7, 0x1f, 0x1c, 0x70, 0x51, 0x95, 0x2b, 0x73, 0x46, 0xb1, + 0xc9, 0xea, 0xa7, 0xb1, 0xa2, 0x61, 0x45, 0x95, 0x2b, 0x49, 0x8e, 0x15, 0xec, 0xe2, 0xec, 0x9a, + 0x03, 0xbb, 0xe3, 0xf8, 0xd0, 0x05, 0x55, 0xae, 0xc8, 0xc6, 0x7c, 0x13, 0xab, 0x83, 0x56, 0x1f, + 0xdb, 0x47, 0xfb, 0x03, 0xd3, 0x87, 0x12, 0x55, 0xae, 0x48, 0x46, 0xb1, 0xc9, 0xea, 0x83, 0xd8, + 0x5d, 0x67, 0xdc, 0xb7, 0x7a, 0x3e, 0xf6, 0x3c, 0xea, 0xb7, 0xd8, 0x64, 0xf5, 0xc1, 0x11, 0x3c, + 0x3c, 0x71, 0xcc, 0x89, 0x0f, 0x35, 0x55, 0xb9, 0x52, 0x30, 0xe6, 0x9b, 0x58, 0x1d, 0xb2, 0x1a, + 0x5a, 0x83, 0x43, 0x55, 0xae, 0x2c, 0x50, 0xab, 0x33, 0xd6, 0x60, 0x37, 0xb4, 0x06, 0x3d, 0x55, + 0xae, 0x10, 0x8e, 0x15, 0xd6, 0x40, 0xd4, 0x0c, 0x13, 0x62, 0x69, 0x51, 0x4d, 0x08, 0x9a, 0x61, + 0x95, 0x41, 0xcd, 0x70, 0xe0, 0x6b, 0x6a, 0x42, 0xd4, 0x4c, 0x08, 0x89, 0x9d, 0x73, 0xe4, 0x05, + 0x35, 0x21, 0x6a, 0x86, 0x23, 0x43, 0x9a, 0xe1, 0xd8, 0xd7, 0xd5, 0x44, 0x50, 0x33, 0x53, 0x68, + 0xd1, 0x72, 0x49, 0x4d, 0x04, 0x35, 0xc3, 0xd1, 0x41, 0xcd, 0x70, 0xf0, 0x45, 0x35, 0x11, 0xd0, + 0x4c, 0x18, 0x2b, 0x1a, 0x5e, 0x52, 0x13, 0x01, 0xcd, 0x88, 0xb3, 0x73, 0x35, 0xc3, 0xa1, 0xcb, + 0x6a, 0x42, 0xd4, 0x8c, 0x68, 0xd5, 0xd3, 0x0c, 0x87, 0x5e, 0x52, 0x13, 0x01, 0xcd, 0x88, 0x58, + 0x4f, 0x33, 0x1c, 0x7b, 0x59, 0x4d, 0x04, 0x34, 0xc3, 0xb1, 0xd7, 0x45, 0xcd, 0x70, 0xe8, 0xc7, + 0x92, 0x9a, 0x10, 0x45, 0xc3, 0xa1, 0x37, 0x03, 0xa2, 0xe1, 0xd8, 0x4f, 0x28, 0x56, 0x54, 0x4d, + 0x18, 0x2c, 0xae, 0xc2, 0xa7, 0x14, 0x2c, 0xca, 0x86, 0x83, 0x7d, 0xd9, 0xd8, 0xdc, 0x05, 0x95, + 0xae, 0xa8, 0x92, 0x27, 0x1b, 0xd7, 0x2f, 0x89, 0xb2, 0xf1, 0x80, 0x57, 0xd1, 0xd5, 0x72, 0xd9, + 0x4c, 0x21, 0x6b, 0xba, 0x8f, 0x54, 0x55, 0xc9, 0x97, 0x8d, 0x87, 0x0c, 0xc8, 0xc6, 0xc3, 0x5e, + 0x53, 0x25, 0x51, 0x36, 0x33, 0xd0, 0xa2, 0xe5, 0xb2, 0x2a, 0x89, 0xb2, 0xf1, 0xd0, 0xa2, 0x6c, + 0x3c, 0xf0, 0x17, 0x54, 0x49, 0x90, 0xcd, 0x34, 0x56, 0x34, 0xfc, 0x45, 0x55, 0x12, 0x64, 0x13, + 0x9c, 0x1d, 0x93, 0x8d, 0x07, 0x7d, 0x43, 0x95, 0x7c, 0xd9, 0x04, 0xad, 0x72, 0xd9, 0x78, 0xd0, + 0x37, 0x55, 0x49, 0x90, 0x4d, 0x10, 0xcb, 0x65, 0xe3, 0x61, 0xdf, 0xc2, 0xf8, 0xe6, 0xca, 0xc6, + 0xc3, 0x0a, 0xb2, 0xf1, 0xa0, 0xbf, 0x43, 0x63, 0xa1, 0x27, 0x1b, 0x0f, 0x2a, 0xca, 0xc6, 0xc3, + 0xfe, 0x2e, 0xc5, 0xfa, 0xb2, 0x99, 0x06, 0x8b, 0xab, 0xf0, 0x7b, 0x14, 0xec, 0xcb, 0xc6, 0x03, + 0xaf, 0xe0, 0x20, 0xa8, 0x6c, 0xba, 0xe6, 0x61, 0xe7, 0x68, 0x40, 0x25, 0x56, 0xa1, 0xba, 0xa9, + 0x27, 0x9d, 0xf1, 0x91, 0x49, 0x47, 0x62, 0xdb, 0x83, 0xc7, 0x6e, 0x1b, 0x59, 0xa1, 0xc6, 0x99, + 0x7c, 0x7c, 0xc2, 0x75, 0xaa, 0x9f, 0xba, 0x5c, 0xd5, 0x8c, 0x22, 0xd3, 0xd0, 0x34, 0xbe, 0xa6, + 0x0b, 0xf8, 0x1b, 0x54, 0x45, 0x75, 0xb9, 0xa6, 0x33, 0x7c, 0x4d, 0xf7, 0xf1, 0x55, 0x38, 0xef, + 0x4b, 0xc9, 0x67, 0xdc, 0xa4, 0x5a, 0xaa, 0x27, 0xaa, 0xda, 0xaa, 0xb1, 0xe0, 0x0a, 0x6a, 0x16, + 0x29, 0xd0, 0xcd, 0x2d, 0x2a, 0xa9, 0x7a, 0xa2, 0xa6, 0x7b, 0x24, 0xb1, 0x27, 0x8d, 0xca, 0x90, + 0x0b, 0xcb, 0xe7, 0xdc, 0xa6, 0xca, 0xaa, 0x27, 0xab, 0xda, 0xea, 0xaa, 0xa1, 0x70, 0x7d, 0xcd, + 0xe0, 0x04, 0xfa, 0x59, 0xa1, 0x0a, 0xab, 0x27, 0x6b, 0xba, 0xc7, 0x09, 0xf6, 0xb3, 0xe0, 0x0a, + 0xcd, 0xa7, 0x7c, 0x89, 0x2a, 0xad, 0x9e, 0xae, 0xae, 0xe9, 0x6b, 0xeb, 0xf7, 0x8c, 0x22, 0x53, + 0x9c, 0xcf, 0xd1, 0x69, 0x3f, 0x5c, 0x72, 0x3e, 0x69, 0x95, 0x6a, 0xae, 0x9e, 0xd6, 0xee, 0xac, + 0xdd, 0xd5, 0xee, 0x1a, 0x0a, 0xd7, 0x9e, 0xcf, 0x7a, 0x87, 0xb2, 0xb8, 0xf8, 0x7c, 0xd6, 0x1a, + 0x55, 0x5f, 0x5d, 0x79, 0x66, 0x0e, 0x06, 0xf6, 0x2d, 0xb5, 0xfc, 0xd2, 0x1e, 0x0f, 0xba, 0xd7, + 0xca, 0x60, 0x28, 0x5c, 0x8f, 0x62, 0xaf, 0x0b, 0xae, 0x20, 0x7d, 0xfa, 0xaf, 0xd1, 0x7b, 0x58, + 0xa1, 0x9e, 0x79, 0xd8, 0xef, 0x59, 0xf6, 0xc4, 0x34, 0x8a, 0x4c, 0x9a, 0xa1, 0x35, 0xd9, 0x0d, + 0xaf, 0xe3, 0xaf, 0x53, 0xda, 0x42, 0x3d, 0x71, 0xbb, 0xaa, 0xd1, 0x9e, 0x66, 0xad, 0xe3, 0x6e, + 0x78, 0x1d, 0x7f, 0x83, 0x72, 0x48, 0x3d, 0x71, 0xbb, 0xa6, 0x73, 0x8e, 0xb8, 0x8e, 0x77, 0xe0, + 0x42, 0x28, 0x2e, 0xb6, 0x47, 0x9d, 0x83, 0xe7, 0x66, 0xb7, 0xa4, 0xd1, 0xf0, 0xf8, 0x50, 0x56, + 0x24, 0xe3, 0x7c, 0x20, 0x44, 0xee, 0x60, 0x33, 0xb9, 0x07, 0xaf, 0x87, 0x03, 0xa5, 0xcb, 0xac, + 0xd2, 0x78, 0x89, 0xcc, 0xc5, 0x60, 0xcc, 0x0c, 0x51, 0x05, 0x07, 0xec, 0x52, 0x75, 0x1a, 0x40, + 0x7d, 0xaa, 0xef, 0x89, 0x39, 0xf5, 0x67, 0xe0, 0xe2, 0x74, 0x28, 0x75, 0xc9, 0xeb, 0x34, 0xa2, + 0x22, 0xf9, 0x42, 0x38, 0xaa, 0x4e, 0xd1, 0x67, 0xf4, 0x5d, 0xa3, 0x21, 0x56, 0xa4, 0x4f, 0xf5, + 0x7e, 0x1f, 0x4a, 0x53, 0xc1, 0xd6, 0x65, 0xdf, 0xa1, 0x31, 0x17, 0xd9, 0xaf, 0x85, 0xe2, 0x6e, + 0x98, 0x3c, 0xa3, 0xeb, 0xbb, 0x34, 0x08, 0x0b, 0xe4, 0xa9, 0x9e, 0x71, 0xc9, 0x82, 0xe1, 0xd8, + 0xe5, 0xde, 0xa3, 0x51, 0x99, 0x2f, 0x59, 0x20, 0x32, 0x8b, 0xfd, 0x86, 0xe2, 0xb3, 0xcb, 0xad, + 0xd3, 0x30, 0xcd, 0xfb, 0x0d, 0x86, 0x6a, 0x4e, 0x7e, 0x9b, 0x92, 0x77, 0x67, 0xcf, 0xf8, 0xc7, + 0x09, 0x1a, 0x60, 0x39, 0x7b, 0x77, 0xd6, 0x94, 0x3d, 0xf6, 0x8c, 0x29, 0xff, 0x84, 0xb2, 0x89, + 0xc0, 0x9e, 0x9a, 0xf3, 0x63, 0x98, 0x73, 0x6f, 0x75, 0xbd, 0xb1, 0x7d, 0x34, 0x2a, 0x35, 0x55, + 0xb9, 0x02, 0xda, 0x95, 0xa9, 0xec, 0xc7, 0xbd, 0xe4, 0x6d, 0x50, 0x94, 0x11, 0x24, 0x31, 0x2b, + 0xcc, 0x2e, 0xb3, 0xb2, 0xa3, 0x26, 0x22, 0xac, 0x30, 0x94, 0x67, 0x45, 0x20, 0x51, 0x2b, 0xae, + 0xd3, 0x67, 0x56, 0x3e, 0x50, 0xa5, 0x99, 0x56, 0xdc, 0x10, 0xc0, 0xad, 0x04, 0x48, 0x4b, 0xeb, + 0x7e, 0xbe, 0x85, 0xed, 0xe4, 0x8b, 0xe1, 0x04, 0x6c, 0x03, 0xef, 0xcf, 0xc1, 0x4a, 0x46, 0x13, + 0x06, 0x37, 0x4d, 0xfb, 0xd9, 0x08, 0x5a, 0x60, 0x34, 0xd3, 0xb4, 0x9f, 0x9b, 0x41, 0x2b, 0xff, + 0xa6, 0x04, 0x49, 0x9a, 0x4f, 0x92, 0x2c, 0x24, 0xdf, 0x6b, 0x6d, 0x3e, 0x56, 0xce, 0xd1, 0x5f, + 0x0f, 0x5b, 0xad, 0xa7, 0x8a, 0x44, 0x72, 0x90, 0x7a, 0xf8, 0x95, 0xbd, 0xc6, 0xae, 0x22, 0x93, + 0x22, 0xe4, 0x9b, 0x9b, 0xdb, 0x1b, 0x0d, 0x63, 0xc7, 0xd8, 0xdc, 0xde, 0x53, 0x12, 0xb4, 0xad, + 0xf9, 0xb4, 0xf5, 0x60, 0x4f, 0x49, 0x92, 0x0c, 0x24, 0x68, 0x5d, 0x8a, 0x00, 0xa4, 0x77, 0xf7, + 0x8c, 0xcd, 0xed, 0x0d, 0x25, 0x4d, 0xad, 0xec, 0x6d, 0x6e, 0x35, 0x94, 0x0c, 0x45, 0xee, 0xbd, + 0xbb, 0xf3, 0xb4, 0xa1, 0x64, 0xe9, 0xcf, 0x07, 0x86, 0xf1, 0xe0, 0x2b, 0x4a, 0x8e, 0x92, 0xb6, + 0x1e, 0xec, 0x28, 0x80, 0xcd, 0x0f, 0x1e, 0x3e, 0x6d, 0x28, 0x79, 0x52, 0x80, 0x6c, 0xf3, 0xdd, + 0xed, 0x47, 0x7b, 0x9b, 0xad, 0x6d, 0xa5, 0x50, 0x3e, 0x81, 0x12, 0x5b, 0xe6, 0xc0, 0x2a, 0xb2, + 0xa4, 0xf0, 0x1d, 0x48, 0xb1, 0x9d, 0x91, 0x50, 0x25, 0x95, 0xf0, 0xce, 0x4c, 0x53, 0x56, 0xd8, + 0x1e, 0x31, 0xda, 0xd2, 0x65, 0x48, 0xb1, 0x55, 0x5a, 0x84, 0x14, 0x5b, 0x1d, 0x19, 0x53, 0x45, + 0x56, 0x28, 0xff, 0x96, 0x0c, 0xb0, 0x61, 0xef, 0x3e, 0xef, 0x8f, 0x30, 0x21, 0xbf, 0x0c, 0x30, + 0x79, 0xde, 0x1f, 0xb5, 0x51, 0xf5, 0x3c, 0xa9, 0xcc, 0xd1, 0x1a, 0xf4, 0x77, 0xe4, 0x1a, 0x14, + 0xb0, 0xf9, 0x90, 0x79, 0x21, 0xcc, 0x25, 0x33, 0x46, 0x9e, 0xd6, 0x71, 0xc7, 0x14, 0x84, 0xd4, + 0x74, 0x4c, 0x21, 0xd3, 0x02, 0xa4, 0xa6, 0x93, 0xab, 0x80, 0xc5, 0xf6, 0x04, 0x23, 0x0a, 0xa6, + 0x8d, 0x39, 0x03, 0xfb, 0x65, 0x31, 0x86, 0xbc, 0x0d, 0xd8, 0x27, 0x9b, 0x77, 0x71, 0xfa, 0x74, + 0xb8, 0xc3, 0x5d, 0xa1, 0x3f, 0xd8, 0x6c, 0x7d, 0xc2, 0x52, 0x0b, 0x72, 0x5e, 0x3d, 0xed, 0x0b, + 0x6b, 0xf9, 0x8c, 0x14, 0x9c, 0x11, 0x60, 0x95, 0x37, 0x25, 0x06, 0xe0, 0xa3, 0x59, 0xc0, 0xd1, + 0x30, 0x12, 0x1b, 0x4e, 0xf9, 0x32, 0xcc, 0x6d, 0xdb, 0x16, 0x3b, 0xbd, 0xb8, 0x4a, 0x05, 0x90, + 0x3a, 0x25, 0x09, 0xb3, 0x27, 0xa9, 0x53, 0xbe, 0x02, 0x20, 0xb4, 0x29, 0x20, 0xed, 0xb3, 0x36, + 0xf4, 0x01, 0xd2, 0x7e, 0xf9, 0x26, 0xa4, 0xb7, 0x3a, 0xc7, 0x7b, 0x9d, 0x1e, 0xb9, 0x06, 0x30, + 0xe8, 0x4c, 0x9c, 0xf6, 0x21, 0xee, 0xc3, 0xe7, 0x9f, 0x7f, 0xfe, 0xb9, 0x84, 0x97, 0xbd, 0x1c, + 0xad, 0x65, 0xfb, 0xf1, 0x02, 0xa0, 0x35, 0xe8, 0x6e, 0x99, 0x93, 0x49, 0xa7, 0x67, 0x92, 0x2a, + 0xa4, 0x2d, 0x73, 0x42, 0xa3, 0x9d, 0x84, 0xef, 0x08, 0xcb, 0xfe, 0x2a, 0xf8, 0xa8, 0x95, 0x6d, + 0x84, 0x18, 0x1c, 0x4a, 0x14, 0x48, 0x58, 0x47, 0x43, 0x7c, 0x27, 0x49, 0x19, 0xf4, 0xe7, 0xd2, + 0x25, 0x48, 0x33, 0x0c, 0x21, 0x90, 0xb4, 0x3a, 0x43, 0xb3, 0xc4, 0xfa, 0xc5, 0xdf, 0xe5, 0x5f, + 0x95, 0x00, 0xb6, 0xcd, 0x97, 0x67, 0xe8, 0xd3, 0x47, 0xc5, 0xf4, 0x99, 0x60, 0x7d, 0xde, 0x8f, + 0xeb, 0x93, 0xea, 0xec, 0xd0, 0xb6, 0xbb, 0x6d, 0xb6, 0xc5, 0xec, 0x49, 0x27, 0x47, 0x6b, 0x70, + 0xd7, 0xca, 0x1f, 0x40, 0x61, 0xd3, 0xb2, 0xcc, 0xb1, 0x3b, 0x26, 0x02, 0xc9, 0x67, 0xf6, 0xc4, + 0xe1, 0x6f, 0x4b, 0xf8, 0x9b, 0x94, 0x20, 0x39, 0xb2, 0xc7, 0x0e, 0x9b, 0x67, 0x3d, 0xa9, 0xaf, + 0xae, 0xae, 0x1a, 0x58, 0x43, 0x2e, 0x41, 0xee, 0xc0, 0xb6, 0x2c, 0xf3, 0x80, 0x4e, 0x22, 0x81, + 0x69, 0x8d, 0x5f, 0x51, 0xfe, 0x65, 0x09, 0x0a, 0x2d, 0xe7, 0x99, 0x6f, 0x5c, 0x81, 0xc4, 0x73, + 0xf3, 0x04, 0x87, 0x97, 0x30, 0xe8, 0x4f, 0x7a, 0x54, 0x7e, 0xbe, 0x33, 0x38, 0x62, 0x6f, 0x4d, + 0x05, 0x83, 0x15, 0xc8, 0x05, 0x48, 0xbf, 0x34, 0xfb, 0xbd, 0x67, 0x0e, 0xda, 0x94, 0x0d, 0x5e, + 0x22, 0xb7, 0x20, 0xd5, 0xa7, 0x83, 0x2d, 0x25, 0x71, 0xbd, 0x2e, 0xf8, 0xeb, 0x25, 0xce, 0xc1, + 0x60, 0xa0, 0x1b, 0xd9, 0x6c, 0x57, 0xf9, 0xe8, 0xa3, 0x8f, 0x3e, 0x92, 0xcb, 0x87, 0xb0, 0xe8, + 0x1e, 0xde, 0xc0, 0x64, 0xb7, 0xa1, 0x34, 0x30, 0xed, 0xf6, 0x61, 0xdf, 0xea, 0x0c, 0x06, 0x27, + 0xed, 0x97, 0xb6, 0xd5, 0xee, 0x58, 0x6d, 0x7b, 0x72, 0xd0, 0x19, 0xe3, 0x02, 0x44, 0x77, 0xb1, + 0x38, 0x30, 0xed, 0x26, 0xa3, 0xbd, 0x6f, 0x5b, 0x0f, 0xac, 0x16, 0xe5, 0x94, 0xff, 0x20, 0x09, + 0xb9, 0xad, 0x13, 0xd7, 0xfa, 0x22, 0xa4, 0x0e, 0xec, 0x23, 0x8b, 0xad, 0x65, 0xca, 0x60, 0x05, + 0x6f, 0x8f, 0x64, 0x61, 0x8f, 0x16, 0x21, 0xf5, 0xe2, 0xc8, 0x76, 0x4c, 0x9c, 0x6e, 0xce, 0x60, + 0x05, 0xba, 0x5a, 0x23, 0xd3, 0x29, 0x25, 0x31, 0xb9, 0xa5, 0x3f, 0xfd, 0xf9, 0xa7, 0xce, 0x30, + 0x7f, 0xb2, 0x02, 0x69, 0x9b, 0xae, 0xfe, 0xa4, 0x94, 0xc6, 0x77, 0x35, 0x01, 0x2e, 0xee, 0x8a, + 0xc1, 0x51, 0x64, 0x13, 0x16, 0x5e, 0x9a, 0xed, 0xe1, 0xd1, 0xc4, 0x69, 0xf7, 0xec, 0x76, 0xd7, + 0x34, 0x47, 0xe6, 0xb8, 0x34, 0x87, 0x3d, 0x09, 0x3e, 0x61, 0xd6, 0x42, 0x1a, 0xf3, 0x2f, 0xcd, + 0xad, 0xa3, 0x89, 0xb3, 0x61, 0x3f, 0x46, 0x16, 0xa9, 0x42, 0x6e, 0x6c, 0x52, 0x4f, 0x40, 0x07, + 0x5b, 0x08, 0xf7, 0x1e, 0xa0, 0x66, 0xc7, 0xe6, 0x08, 0x2b, 0xc8, 0x3a, 0x64, 0xf7, 0xfb, 0xcf, + 0xcd, 0xc9, 0x33, 0xb3, 0x5b, 0xca, 0xa8, 0x52, 0x65, 0x5e, 0xbb, 0xe8, 0x73, 0xbc, 0x65, 0x5d, + 0x79, 0x64, 0x0f, 0xec, 0xb1, 0xe1, 0x41, 0xc9, 0x7d, 0xc8, 0x4d, 0xec, 0xa1, 0xc9, 0xf4, 0x9d, + 0xc5, 0xa0, 0x7a, 0x79, 0x16, 0x6f, 0xd7, 0x1e, 0x9a, 0xae, 0x07, 0x73, 0xf1, 0x64, 0x99, 0x0d, + 0x74, 0x9f, 0x5e, 0x9d, 0x4b, 0x80, 0x4f, 0x03, 0x74, 0x40, 0x78, 0x95, 0x26, 0x4b, 0x74, 0x40, + 0xbd, 0x43, 0x7a, 0x23, 0x2a, 0xe5, 0x31, 0xaf, 0xf4, 0xca, 0x4b, 0xb7, 0x20, 0xe7, 0x19, 0xf4, + 0x5d, 0x1f, 0x73, 0x37, 0x39, 0xf4, 0x07, 0xcc, 0xf5, 0x31, 0x5f, 0xf3, 0x06, 0xa4, 0x70, 0xd8, + 0x34, 0x42, 0x19, 0x0d, 0x1a, 0x10, 0x73, 0x90, 0xda, 0x30, 0x1a, 0x8d, 0x6d, 0x45, 0xc2, 0xd8, + 0xf8, 0xf4, 0xdd, 0x86, 0x22, 0x0b, 0x8a, 0xfd, 0x6d, 0x09, 0x12, 0x8d, 0x63, 0x54, 0x0b, 0x9d, + 0x86, 0x7b, 0xa2, 0xe9, 0x6f, 0xad, 0x06, 0xc9, 0xa1, 0x3d, 0x36, 0xc9, 0xf9, 0x19, 0xb3, 0x2c, + 0xf5, 0x70, 0xbf, 0x84, 0x57, 0xe4, 0xc6, 0xb1, 0x63, 0x20, 0x5e, 0x7b, 0x0b, 0x92, 0x8e, 0x79, + 0xec, 0xcc, 0xe6, 0x3d, 0x63, 0x1d, 0x50, 0x80, 0x76, 0x13, 0xd2, 0xd6, 0xd1, 0x70, 0xdf, 0x1c, + 0xcf, 0x86, 0xf6, 0x71, 0x7a, 0x1c, 0x52, 0x7e, 0x0f, 0x94, 0x47, 0xf6, 0x70, 0x34, 0x30, 0x8f, + 0x1b, 0xc7, 0x8e, 0x69, 0x4d, 0xfa, 0xb6, 0x45, 0xf5, 0x7c, 0xd8, 0x1f, 0xa3, 0x17, 0xc1, 0xb7, + 0x62, 0x2c, 0xd0, 0x53, 0x3d, 0x31, 0x0f, 0x6c, 0xab, 0xcb, 0x1d, 0x26, 0x2f, 0x51, 0xb4, 0xf3, + 0xac, 0x3f, 0xa6, 0x0e, 0x84, 0xfa, 0x79, 0x56, 0x28, 0x6f, 0x40, 0x91, 0xe7, 0x18, 0x13, 0xde, + 0x71, 0xf9, 0x06, 0x14, 0xdc, 0x2a, 0x7c, 0x38, 0xcf, 0x42, 0xf2, 0x83, 0x86, 0xd1, 0x52, 0xce, + 0xd1, 0x65, 0x6d, 0x6d, 0x37, 0x14, 0x89, 0xfe, 0xd8, 0x7b, 0xbf, 0x15, 0x58, 0xca, 0x4b, 0x50, + 0xf0, 0xc6, 0xbe, 0x6b, 0x3a, 0xd8, 0x42, 0x03, 0x42, 0xa6, 0x2e, 0x67, 0xa5, 0x72, 0x06, 0x52, + 0x8d, 0xe1, 0xc8, 0x39, 0x29, 0xff, 0x22, 0xe4, 0x39, 0xe8, 0x69, 0x7f, 0xe2, 0x90, 0x3b, 0x90, + 0x19, 0xf2, 0xf9, 0x4a, 0x78, 0xdd, 0x13, 0x35, 0xe5, 0xe3, 0xdc, 0xdf, 0x86, 0x8b, 0x5e, 0xaa, + 0x42, 0x46, 0xf0, 0xa5, 0xfc, 0xa8, 0xcb, 0xe2, 0x51, 0x67, 0x4e, 0x21, 0x21, 0x38, 0x85, 0xf2, + 0x16, 0x64, 0x58, 0x04, 0x9c, 0x60, 0x54, 0x67, 0xa9, 0x22, 0x13, 0x13, 0xdb, 0xf9, 0x3c, 0xab, + 0x63, 0x17, 0x95, 0xab, 0x90, 0x47, 0xc1, 0x72, 0x04, 0x73, 0x9d, 0x80, 0x55, 0x4c, 0x6e, 0xbf, + 0x9f, 0x82, 0xac, 0xbb, 0x52, 0x64, 0x19, 0xd2, 0x2c, 0x3f, 0x43, 0x53, 0xee, 0xfb, 0x41, 0x0a, + 0x33, 0x32, 0xb2, 0x0c, 0x19, 0x9e, 0x83, 0x71, 0xef, 0x2e, 0x57, 0x35, 0x23, 0xcd, 0x72, 0x2e, + 0xaf, 0xb1, 0xa6, 0xa3, 0x63, 0x62, 0x2f, 0x03, 0x69, 0x96, 0x55, 0x11, 0x15, 0x72, 0x5e, 0x1e, + 0x85, 0xfe, 0x98, 0x3f, 0x03, 0x64, 0xdd, 0xc4, 0x49, 0x40, 0xd4, 0x74, 0xf4, 0x58, 0x3c, 0xe7, + 0xcf, 0x36, 0xfd, 0xeb, 0x49, 0xd6, 0xcd, 0x86, 0xf0, 0xf9, 0xde, 0x4d, 0xf0, 0x33, 0x3c, 0xff, + 0xf1, 0x01, 0x35, 0x1d, 0x5d, 0x82, 0x9b, 0xcd, 0x67, 0x78, 0x8e, 0x43, 0xae, 0xd2, 0x21, 0x62, + 0xce, 0x82, 0x47, 0xdf, 0x4f, 0xdd, 0xd3, 0x2c, 0x93, 0x21, 0xd7, 0xa8, 0x05, 0x96, 0x98, 0xe0, + 0xb9, 0xf4, 0xf3, 0xf4, 0x0c, 0xcf, 0x57, 0xc8, 0x4d, 0x0a, 0x61, 0xcb, 0x5f, 0x82, 0x88, 0xa4, + 0x3c, 0xc3, 0x93, 0x72, 0xa2, 0xd2, 0x0e, 0xd1, 0x3d, 0xa0, 0x4b, 0x10, 0x12, 0xf0, 0x34, 0x4b, + 0xc0, 0xc9, 0x15, 0x34, 0xc7, 0x26, 0x55, 0xf0, 0x93, 0xed, 0x0c, 0x4f, 0x70, 0xfc, 0x76, 0xbc, + 0xb2, 0x79, 0x89, 0x75, 0x86, 0xa7, 0x30, 0xa4, 0x46, 0xf7, 0x8b, 0xea, 0xbb, 0x34, 0x8f, 0x4e, + 0xb0, 0xe4, 0x0b, 0xcf, 0xdd, 0x53, 0xe6, 0x03, 0xeb, 0xcc, 0x83, 0x18, 0xa9, 0x26, 0x9e, 0x86, + 0x25, 0xca, 0xdb, 0xe9, 0x5b, 0x87, 0xa5, 0x22, 0xae, 0x44, 0xa2, 0x6f, 0x1d, 0x1a, 0xa9, 0x26, + 0xad, 0x61, 0x1a, 0xd8, 0xa6, 0x6d, 0x0a, 0xb6, 0x25, 0x6f, 0xb3, 0x46, 0x5a, 0x45, 0x4a, 0x90, + 0x6a, 0xb6, 0xb7, 0x3b, 0x56, 0x69, 0x81, 0xf1, 0xac, 0x8e, 0x65, 0x24, 0x9b, 0xdb, 0x1d, 0x8b, + 0xbc, 0x05, 0x89, 0xc9, 0xd1, 0x7e, 0x89, 0x84, 0xbf, 0xac, 0xec, 0x1e, 0xed, 0xbb, 0x43, 0x31, + 0x28, 0x82, 0x2c, 0x43, 0x76, 0xe2, 0x8c, 0xdb, 0xbf, 0x60, 0x8e, 0xed, 0xd2, 0x79, 0x5c, 0xc2, + 0x73, 0x46, 0x66, 0xe2, 0x8c, 0x3f, 0x30, 0xc7, 0xf6, 0x19, 0x9d, 0x5f, 0xf9, 0x0a, 0xe4, 0x05, + 0xbb, 0xa4, 0x08, 0x92, 0xc5, 0x6e, 0x0a, 0x75, 0xe9, 0x8e, 0x21, 0x59, 0xe5, 0x3d, 0x28, 0xb8, + 0x39, 0x0c, 0xce, 0x57, 0xa3, 0x27, 0x69, 0x60, 0x8f, 0xf1, 0x7c, 0xce, 0x6b, 0x97, 0xc4, 0x10, + 0xe5, 0xc3, 0x78, 0xb8, 0x60, 0xd0, 0xb2, 0x12, 0x1a, 0x8a, 0x54, 0xfe, 0xa1, 0x04, 0x85, 0x2d, + 0x7b, 0xec, 0x3f, 0x30, 0x2f, 0x42, 0x6a, 0xdf, 0xb6, 0x07, 0x13, 0x34, 0x9b, 0x35, 0x58, 0x81, + 0xbc, 0x01, 0x05, 0xfc, 0xe1, 0xe6, 0x9e, 0xb2, 0xf7, 0xb4, 0x91, 0xc7, 0x7a, 0x9e, 0x70, 0x12, + 0x48, 0xf6, 0x2d, 0x67, 0xc2, 0x3d, 0x19, 0xfe, 0x26, 0x5f, 0x80, 0x3c, 0xfd, 0xeb, 0x32, 0x93, + 0xde, 0x85, 0x15, 0x68, 0x35, 0x27, 0xbe, 0x05, 0x73, 0xb8, 0xfb, 0x1e, 0x2c, 0xe3, 0x3d, 0x63, + 0x14, 0x58, 0x03, 0x07, 0x96, 0x20, 0xc3, 0x5c, 0xc1, 0x04, 0xbf, 0x96, 0xe5, 0x0c, 0xb7, 0x48, + 0xdd, 0x2b, 0x66, 0x02, 0x2c, 0xdc, 0x67, 0x0c, 0x5e, 0x2a, 0x3f, 0x80, 0x2c, 0x46, 0xa9, 0xd6, + 0xa0, 0x4b, 0xca, 0x20, 0xf5, 0x4a, 0x26, 0xc6, 0xc8, 0x45, 0xe1, 0x9a, 0xcf, 0x9b, 0x57, 0x36, + 0x0c, 0xa9, 0xb7, 0xb4, 0x00, 0xd2, 0x06, 0xbd, 0x77, 0x1f, 0x73, 0x37, 0x2d, 0x1d, 0x97, 0x5b, + 0xdc, 0xc4, 0xb6, 0xf9, 0x32, 0xce, 0xc4, 0xb6, 0xf9, 0x92, 0x99, 0xb8, 0x3a, 0x65, 0x82, 0x96, + 0x4e, 0xf8, 0xa7, 0x43, 0xe9, 0xa4, 0x5c, 0x85, 0x39, 0x3c, 0x9e, 0x7d, 0xab, 0xb7, 0x63, 0xf7, + 0x2d, 0xbc, 0xe7, 0x1f, 0xe2, 0x3d, 0x49, 0x32, 0xa4, 0x43, 0xba, 0x07, 0xe6, 0x71, 0xe7, 0x80, + 0xdd, 0x38, 0xb3, 0x06, 0x2b, 0x94, 0x3f, 0x4b, 0xc2, 0x3c, 0x77, 0xad, 0xef, 0xf7, 0x9d, 0x67, + 0x5b, 0x9d, 0x11, 0x79, 0x0a, 0x05, 0xea, 0x55, 0xdb, 0xc3, 0xce, 0x68, 0x44, 0x8f, 0xaf, 0x84, + 0x57, 0x8d, 0xeb, 0x53, 0xae, 0x9a, 0xe3, 0x57, 0xb6, 0x3b, 0x43, 0x73, 0x8b, 0x61, 0x1b, 0x96, + 0x33, 0x3e, 0x31, 0xf2, 0x96, 0x5f, 0x43, 0x36, 0x21, 0x3f, 0x9c, 0xf4, 0x3c, 0x63, 0x32, 0x1a, + 0xab, 0x44, 0x1a, 0xdb, 0x9a, 0xf4, 0x02, 0xb6, 0x60, 0xe8, 0x55, 0xd0, 0x81, 0x51, 0x7f, 0xec, + 0xd9, 0x4a, 0x9c, 0x32, 0x30, 0xea, 0x3a, 0x82, 0x03, 0xdb, 0xf7, 0x6b, 0xc8, 0x63, 0x00, 0x7a, + 0xbc, 0x1c, 0x9b, 0xa6, 0x4e, 0xa8, 0xa0, 0xbc, 0xf6, 0x66, 0xa4, 0xad, 0x5d, 0x67, 0xbc, 0x67, + 0xef, 0x3a, 0x63, 0x66, 0x88, 0x1e, 0x4c, 0x2c, 0x2e, 0xbd, 0x03, 0x4a, 0x78, 0xfe, 0xe2, 0x8d, + 0x3c, 0x35, 0xe3, 0x46, 0x9e, 0xe3, 0x37, 0xf2, 0xba, 0x7c, 0x57, 0x5a, 0x7a, 0x0f, 0x8a, 0xa1, + 0x29, 0x8b, 0x74, 0xc2, 0xe8, 0xb7, 0x45, 0x7a, 0x5e, 0x7b, 0x5d, 0xf8, 0x9c, 0x2d, 0x6e, 0xb8, + 0x68, 0xf7, 0x1d, 0x50, 0xc2, 0xd3, 0x17, 0x0d, 0x67, 0x63, 0x32, 0x05, 0xe4, 0xdf, 0x87, 0xb9, + 0xc0, 0x94, 0x45, 0x72, 0xee, 0x94, 0x49, 0x95, 0x7f, 0x29, 0x05, 0xa9, 0x96, 0x65, 0xda, 0x87, + 0xe4, 0xf5, 0x60, 0x9c, 0x7c, 0x72, 0xce, 0x8d, 0x91, 0x17, 0x43, 0x31, 0xf2, 0xc9, 0x39, 0x2f, + 0x42, 0x5e, 0x0c, 0x45, 0x48, 0xb7, 0xa9, 0xa6, 0x93, 0xcb, 0x53, 0xf1, 0xf1, 0xc9, 0x39, 0x21, + 0x38, 0x5e, 0x9e, 0x0a, 0x8e, 0x7e, 0x73, 0x4d, 0xa7, 0x0e, 0x35, 0x18, 0x19, 0x9f, 0x9c, 0xf3, + 0xa3, 0xe2, 0x72, 0x38, 0x2a, 0x7a, 0x8d, 0x35, 0x9d, 0x0d, 0x49, 0x88, 0x88, 0x38, 0x24, 0x16, + 0x0b, 0x97, 0xc3, 0xb1, 0x10, 0x79, 0x3c, 0x0a, 0x2e, 0x87, 0xa3, 0x20, 0x36, 0xf2, 0xa8, 0x77, + 0x31, 0x14, 0xf5, 0xd0, 0x28, 0x0b, 0x77, 0xcb, 0xe1, 0x70, 0xc7, 0x78, 0xc2, 0x48, 0xc5, 0x58, + 0xe7, 0x35, 0xd6, 0x74, 0xa2, 0x85, 0x02, 0x5d, 0xf4, 0x6d, 0x1f, 0xf7, 0x02, 0x9d, 0xbe, 0x4e, + 0x97, 0xcd, 0xbd, 0x88, 0x16, 0x63, 0xbe, 0xf8, 0xe3, 0x6a, 0xba, 0x17, 0x31, 0x0d, 0x32, 0x87, + 0x3c, 0x01, 0x56, 0xd0, 0x73, 0x09, 0xb2, 0xc4, 0xcd, 0x5f, 0x69, 0xb6, 0xd1, 0x83, 0xd1, 0x79, + 0x1d, 0xb2, 0x3b, 0x7d, 0x05, 0xe6, 0x9a, 0xed, 0xa7, 0x9d, 0x71, 0xcf, 0x9c, 0x38, 0xed, 0xbd, + 0x4e, 0xcf, 0x7b, 0x44, 0xa0, 0xfb, 0x9f, 0x6f, 0xf2, 0x96, 0xbd, 0x4e, 0x8f, 0x5c, 0x70, 0xc5, + 0xd5, 0xc5, 0x56, 0x89, 0xcb, 0x6b, 0xe9, 0x75, 0xba, 0x68, 0xcc, 0x18, 0xfa, 0xc2, 0x05, 0xee, + 0x0b, 0x1f, 0x66, 0x20, 0x75, 0x64, 0xf5, 0x6d, 0xeb, 0x61, 0x0e, 0x32, 0x8e, 0x3d, 0x1e, 0x76, + 0x1c, 0xbb, 0xfc, 0x23, 0x09, 0xe0, 0x91, 0x3d, 0x1c, 0x1e, 0x59, 0xfd, 0x17, 0x47, 0x26, 0xb9, + 0x02, 0xf9, 0x61, 0xe7, 0xb9, 0xd9, 0x1e, 0x9a, 0xed, 0x83, 0xb1, 0x7b, 0x0e, 0x72, 0xb4, 0x6a, + 0xcb, 0x7c, 0x34, 0x3e, 0x21, 0x25, 0xf7, 0x8a, 0x8e, 0xda, 0x41, 0x49, 0xf2, 0x2b, 0xfb, 0x22, + 0xbf, 0x74, 0xa6, 0xf9, 0x1e, 0xba, 0xd7, 0x4e, 0x96, 0x47, 0x64, 0xf8, 0xee, 0x61, 0x89, 0x4a, + 0xde, 0x31, 0x87, 0xa3, 0xf6, 0x01, 0x4a, 0x85, 0xca, 0x21, 0x45, 0xcb, 0x8f, 0xc8, 0x6d, 0x48, + 0x1c, 0xd8, 0x03, 0x14, 0xc9, 0x29, 0xfb, 0x42, 0x71, 0xe4, 0x0d, 0x48, 0x0c, 0x27, 0x4c, 0x36, + 0x79, 0x6d, 0x41, 0xb8, 0x27, 0xb0, 0xd0, 0x44, 0x61, 0xc3, 0x49, 0xcf, 0x9b, 0xf7, 0x8d, 0x22, + 0x24, 0x9a, 0xad, 0x16, 0x8d, 0xfd, 0xcd, 0x56, 0x6b, 0x4d, 0x91, 0xea, 0x5f, 0x82, 0x6c, 0x6f, + 0x6c, 0x9a, 0xd4, 0x3d, 0xcc, 0xce, 0x39, 0x3e, 0xc4, 0x58, 0xe7, 0x81, 0xea, 0x5b, 0x90, 0x39, + 0x60, 0x59, 0x07, 0x89, 0x48, 0x6b, 0x4b, 0x7f, 0xc8, 0x1e, 0x55, 0x96, 0xfc, 0xe6, 0x70, 0x9e, + 0x62, 0xb8, 0x36, 0xea, 0x3b, 0x90, 0x1b, 0xb7, 0x4f, 0x33, 0xf8, 0x31, 0x8b, 0x2e, 0x71, 0x06, + 0xb3, 0x63, 0x5e, 0x55, 0x6f, 0xc0, 0x82, 0x65, 0xbb, 0xdf, 0x50, 0xda, 0x5d, 0x76, 0xc6, 0x2e, + 0x4e, 0x5f, 0xe5, 0x5c, 0xe3, 0x26, 0xfb, 0x6e, 0x69, 0xd9, 0xbc, 0x81, 0x9d, 0xca, 0xfa, 0x23, + 0x50, 0x04, 0x33, 0x98, 0x7a, 0xc6, 0x59, 0x39, 0x64, 0x1f, 0x4a, 0x3d, 0x2b, 0x78, 0xee, 0x43, + 0x46, 0xd8, 0xc9, 0x8c, 0x31, 0xd2, 0x63, 0x5f, 0x9d, 0x3d, 0x23, 0xe8, 0xea, 0xa6, 0x8d, 0x50, + 0x5f, 0x13, 0x6d, 0xe4, 0x19, 0xfb, 0x20, 0x2d, 0x1a, 0xa9, 0xe9, 0xa1, 0x55, 0x39, 0x3a, 0x75, + 0x28, 0x7d, 0xf6, 0x3d, 0xd9, 0xb3, 0xc2, 0x1c, 0xe0, 0x0c, 0x33, 0xf1, 0x83, 0xf9, 0x90, 0x7d, + 0x6a, 0x0e, 0x98, 0x99, 0x1a, 0xcd, 0xe4, 0xd4, 0xd1, 0x3c, 0x67, 0xdf, 0x75, 0x3d, 0x33, 0xbb, + 0xb3, 0x46, 0x33, 0x39, 0x75, 0x34, 0x03, 0xf6, 0xc5, 0x37, 0x60, 0xa6, 0xa6, 0xd7, 0x37, 0x80, + 0x88, 0x5b, 0xcd, 0xe3, 0x44, 0x8c, 0x9d, 0x21, 0xfb, 0x8e, 0xef, 0x6f, 0x36, 0xa3, 0xcc, 0x32, + 0x14, 0x3f, 0x20, 0x8b, 0x7d, 0xe2, 0x0f, 0x1a, 0xaa, 0xe9, 0xf5, 0x4d, 0x38, 0x2f, 0x4e, 0xec, + 0x0c, 0x43, 0xb2, 0x55, 0xa9, 0x52, 0x34, 0x16, 0xfc, 0xa9, 0x71, 0xce, 0x4c, 0x53, 0xf1, 0x83, + 0x1a, 0xa9, 0x52, 0x45, 0x99, 0x32, 0x55, 0xd3, 0xeb, 0x0f, 0xa0, 0x28, 0x98, 0xda, 0xc7, 0x08, + 0x1d, 0x6d, 0xe6, 0x05, 0xfb, 0x5f, 0x0b, 0xcf, 0x0c, 0x8d, 0xe8, 0xe1, 0x1d, 0xe3, 0x31, 0x2e, + 0xda, 0xc8, 0x98, 0xfd, 0xa3, 0x80, 0x3f, 0x16, 0x64, 0x84, 0x8e, 0x04, 0xe6, 0xdf, 0x71, 0x56, + 0x26, 0xec, 0x5f, 0x08, 0xfc, 0xa1, 0x50, 0x42, 0xbd, 0x1f, 0x98, 0x8e, 0x49, 0x83, 0x5c, 0x8c, + 0x0d, 0x07, 0x3d, 0xf2, 0x9b, 0x91, 0x80, 0x15, 0xf1, 0x81, 0x44, 0x98, 0x36, 0x2d, 0xd6, 0x37, + 0x61, 0xfe, 0xec, 0x0e, 0xe9, 0x63, 0x89, 0x65, 0xcb, 0xd5, 0x15, 0x9a, 0x50, 0x1b, 0x73, 0xdd, + 0x80, 0x5f, 0x6a, 0xc0, 0xdc, 0x99, 0x9d, 0xd2, 0x27, 0x12, 0xcb, 0x39, 0xa9, 0x25, 0xa3, 0xd0, + 0x0d, 0x7a, 0xa6, 0xb9, 0x33, 0xbb, 0xa5, 0x4f, 0x25, 0xf6, 0x40, 0xa1, 0x6b, 0x9e, 0x11, 0xd7, + 0x33, 0xcd, 0x9d, 0xd9, 0x2d, 0x7d, 0x95, 0x65, 0x94, 0xb2, 0x5e, 0x15, 0x8d, 0xa0, 0x2f, 0x98, + 0x3f, 0xbb, 0x5b, 0xfa, 0x9a, 0x84, 0x8f, 0x15, 0xb2, 0xae, 0x7b, 0xeb, 0xe2, 0x79, 0xa6, 0xf9, + 0xb3, 0xbb, 0xa5, 0xaf, 0x4b, 0xf8, 0xa4, 0x21, 0xeb, 0xeb, 0x01, 0x33, 0xc1, 0xd1, 0x9c, 0xee, + 0x96, 0xbe, 0x21, 0xe1, 0x2b, 0x83, 0xac, 0xd7, 0x3c, 0x33, 0xbb, 0x53, 0xa3, 0x39, 0xdd, 0x2d, + 0x7d, 0x13, 0x6f, 0xf1, 0x75, 0x59, 0xbf, 0x13, 0x30, 0x83, 0x9e, 0xa9, 0xf8, 0x0a, 0x6e, 0xe9, + 0x5b, 0x12, 0x3e, 0x06, 0xc9, 0xfa, 0x5d, 0xc3, 0xed, 0xdd, 0xf7, 0x4c, 0xc5, 0x57, 0x70, 0x4b, + 0x9f, 0x49, 0xf8, 0x66, 0x24, 0xeb, 0xf7, 0x82, 0x86, 0xd0, 0x33, 0x29, 0xaf, 0xe2, 0x96, 0xbe, + 0x4d, 0x2d, 0x15, 0xeb, 0xf2, 0xfa, 0xaa, 0xe1, 0x0e, 0x40, 0xf0, 0x4c, 0xca, 0xab, 0xb8, 0xa5, + 0xef, 0x50, 0x53, 0x4a, 0x5d, 0x5e, 0x5f, 0x0b, 0x99, 0xaa, 0xe9, 0xf5, 0x47, 0x50, 0x38, 0xab, + 0x5b, 0xfa, 0xae, 0xf8, 0x16, 0x97, 0xef, 0x0a, 0xbe, 0x69, 0x47, 0xd8, 0xb3, 0x53, 0x1d, 0xd3, + 0xf7, 0x30, 0xc7, 0xa9, 0xcf, 0x3d, 0x61, 0xef, 0x55, 0x8c, 0xe0, 0x6f, 0x1f, 0x73, 0x53, 0x5b, + 0xfe, 0xf9, 0x38, 0xd5, 0x47, 0x7d, 0x5f, 0xc2, 0x47, 0xad, 0x02, 0x37, 0x88, 0x78, 0xef, 0xa4, + 0x30, 0x87, 0xf5, 0xa1, 0x3f, 0xcb, 0xd3, 0xbc, 0xd5, 0x0f, 0xa4, 0x57, 0x71, 0x57, 0xf5, 0x44, + 0x6b, 0xbb, 0xe1, 0x2d, 0x06, 0xd6, 0xbc, 0x0d, 0xc9, 0x63, 0x6d, 0x75, 0x4d, 0xbc, 0x92, 0x89, + 0x6f, 0xb9, 0xcc, 0x49, 0xe5, 0xb5, 0xa2, 0xf0, 0xdc, 0x3d, 0x1c, 0x39, 0x27, 0x06, 0xb2, 0x38, + 0x5b, 0x8b, 0x64, 0x7f, 0x12, 0xc3, 0xd6, 0x38, 0xbb, 0x1a, 0xc9, 0xfe, 0x34, 0x86, 0x5d, 0xe5, + 0x6c, 0x3d, 0x92, 0xfd, 0xd5, 0x18, 0xb6, 0xce, 0xd9, 0xeb, 0x91, 0xec, 0xaf, 0xc5, 0xb0, 0xd7, + 0x39, 0xbb, 0x16, 0xc9, 0xfe, 0x7a, 0x0c, 0xbb, 0xc6, 0xd9, 0x77, 0x22, 0xd9, 0xdf, 0x88, 0x61, + 0xdf, 0xe1, 0xec, 0xbb, 0x91, 0xec, 0x6f, 0xc6, 0xb0, 0xef, 0x72, 0xf6, 0xbd, 0x48, 0xf6, 0xb7, + 0x62, 0xd8, 0xf7, 0x18, 0x7b, 0x6d, 0x35, 0x92, 0xfd, 0x59, 0x34, 0x7b, 0x6d, 0x95, 0xb3, 0xa3, + 0xb5, 0xf6, 0xed, 0x18, 0x36, 0xd7, 0xda, 0x5a, 0xb4, 0xd6, 0xbe, 0x13, 0xc3, 0xe6, 0x5a, 0x5b, + 0x8b, 0xd6, 0xda, 0x77, 0x63, 0xd8, 0x5c, 0x6b, 0x6b, 0xd1, 0x5a, 0xfb, 0x5e, 0x0c, 0x9b, 0x6b, + 0x6d, 0x2d, 0x5a, 0x6b, 0xdf, 0x8f, 0x61, 0x73, 0xad, 0xad, 0x45, 0x6b, 0xed, 0x07, 0x31, 0x6c, + 0xae, 0xb5, 0xb5, 0x68, 0xad, 0xfd, 0x51, 0x0c, 0x9b, 0x6b, 0x6d, 0x2d, 0x5a, 0x6b, 0x7f, 0x1c, + 0xc3, 0xe6, 0x5a, 0x5b, 0x8b, 0xd6, 0xda, 0x9f, 0xc4, 0xb0, 0xb9, 0xd6, 0xb4, 0x68, 0xad, 0xfd, + 0x69, 0x34, 0x5b, 0xe3, 0x5a, 0xd3, 0xa2, 0xb5, 0xf6, 0x67, 0x31, 0x6c, 0xae, 0x35, 0x2d, 0x5a, + 0x6b, 0x7f, 0x1e, 0xc3, 0xe6, 0x5a, 0xd3, 0xa2, 0xb5, 0xf6, 0xc3, 0x18, 0x36, 0xd7, 0x9a, 0x16, + 0xad, 0xb5, 0xbf, 0x88, 0x61, 0x73, 0xad, 0x69, 0xd1, 0x5a, 0xfb, 0xcb, 0x18, 0x36, 0xd7, 0x9a, + 0x16, 0xad, 0xb5, 0xbf, 0x8a, 0x61, 0x73, 0xad, 0x69, 0xd1, 0x5a, 0xfb, 0xeb, 0x18, 0x36, 0xd7, + 0x9a, 0x16, 0xad, 0xb5, 0xbf, 0x89, 0x61, 0x73, 0xad, 0x69, 0xd1, 0x5a, 0xfb, 0xdb, 0x18, 0x36, + 0xd7, 0x5a, 0x35, 0x5a, 0x6b, 0x7f, 0x17, 0xcd, 0xae, 0x72, 0xad, 0x55, 0xa3, 0xb5, 0xf6, 0xf7, + 0x31, 0x6c, 0xae, 0xb5, 0x6a, 0xb4, 0xd6, 0xfe, 0x21, 0x86, 0xcd, 0xb5, 0x56, 0x8d, 0xd6, 0xda, + 0x3f, 0xc6, 0xb0, 0xb9, 0xd6, 0xaa, 0xd1, 0x5a, 0xfb, 0x51, 0x0c, 0x9b, 0x6b, 0xad, 0x1a, 0xad, + 0xb5, 0x7f, 0x8a, 0x61, 0x73, 0xad, 0x55, 0xa3, 0xb5, 0xf6, 0xcf, 0x31, 0x6c, 0xae, 0xb5, 0x6a, + 0xb4, 0xd6, 0xfe, 0x25, 0x86, 0xcd, 0xb5, 0x56, 0x8d, 0xd6, 0xda, 0xbf, 0xc6, 0xb0, 0xb9, 0xd6, + 0xaa, 0xd1, 0x5a, 0xfb, 0xb7, 0x18, 0x36, 0xd7, 0x9a, 0x1e, 0xad, 0xb5, 0x7f, 0x8f, 0x66, 0xeb, + 0x5c, 0x6b, 0x7a, 0xb4, 0xd6, 0xfe, 0x23, 0x86, 0xcd, 0xb5, 0xa6, 0x47, 0x6b, 0xed, 0x3f, 0x63, + 0xd8, 0x5c, 0x6b, 0x7a, 0xb4, 0xd6, 0xfe, 0x2b, 0x86, 0xcd, 0xb5, 0xa6, 0x47, 0x6b, 0xed, 0xbf, + 0x63, 0xd8, 0x5c, 0x6b, 0x7a, 0xb4, 0xd6, 0xfe, 0x27, 0x86, 0xcd, 0xb5, 0xa6, 0x47, 0x6b, 0xed, + 0xc7, 0x31, 0x6c, 0xae, 0x35, 0x3d, 0x5a, 0x6b, 0x3f, 0x89, 0x61, 0x73, 0xad, 0xe9, 0xd1, 0x5a, + 0xfb, 0xdf, 0x18, 0x36, 0xd7, 0x9a, 0x1e, 0xad, 0xb5, 0xff, 0x8b, 0x61, 0x73, 0xad, 0xad, 0x47, + 0x6b, 0xed, 0xff, 0xa3, 0xd9, 0xeb, 0xab, 0x3f, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xaa, 0x00, 0xcd, + 0x32, 0x57, 0x39, 0x00, 0x00, +} diff --git a/vendor/github.com/gogo/protobuf/proto/testdata/test.pb.go.golden b/vendor/github.com/gogo/protobuf/proto/testdata/test.pb.go.golden new file mode 100644 index 000000000..0387853d5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/testdata/test.pb.go.golden @@ -0,0 +1,1737 @@ +// Code generated by protoc-gen-gogo. +// source: test.proto +// DO NOT EDIT! + +package testdata + +import proto "github.com/gogo/protobuf/proto" +import json "encoding/json" +import math "math" + +import () + +// Reference proto, json, and math imports to suppress error if they are not otherwise used. +var _ = proto.Marshal +var _ = &json.SyntaxError{} +var _ = math.Inf + +type FOO int32 + +const ( + FOO_FOO1 FOO = 1 +) + +var FOO_name = map[int32]string{ + 1: "FOO1", +} +var FOO_value = map[string]int32{ + "FOO1": 1, +} + +func (x FOO) Enum() *FOO { + p := new(FOO) + *p = x + return p +} +func (x FOO) String() string { + return proto.EnumName(FOO_name, int32(x)) +} +func (x FOO) MarshalJSON() ([]byte, error) { + return json.Marshal(x.String()) +} +func (x *FOO) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(FOO_value, data, "FOO") + if err != nil { + return err + } + *x = FOO(value) + return nil +} + +type GoTest_KIND int32 + +const ( + GoTest_VOID GoTest_KIND = 0 + GoTest_BOOL GoTest_KIND = 1 + GoTest_BYTES GoTest_KIND = 2 + GoTest_FINGERPRINT GoTest_KIND = 3 + GoTest_FLOAT GoTest_KIND = 4 + GoTest_INT GoTest_KIND = 5 + GoTest_STRING GoTest_KIND = 6 + GoTest_TIME GoTest_KIND = 7 + GoTest_TUPLE GoTest_KIND = 8 + GoTest_ARRAY GoTest_KIND = 9 + GoTest_MAP GoTest_KIND = 10 + GoTest_TABLE GoTest_KIND = 11 + GoTest_FUNCTION GoTest_KIND = 12 +) + +var GoTest_KIND_name = map[int32]string{ + 0: "VOID", + 1: "BOOL", + 2: "BYTES", + 3: "FINGERPRINT", + 4: "FLOAT", + 5: "INT", + 6: "STRING", + 7: "TIME", + 8: "TUPLE", + 9: "ARRAY", + 10: "MAP", + 11: "TABLE", + 12: "FUNCTION", +} +var GoTest_KIND_value = map[string]int32{ + "VOID": 0, + "BOOL": 1, + "BYTES": 2, + "FINGERPRINT": 3, + "FLOAT": 4, + "INT": 5, + "STRING": 6, + "TIME": 7, + "TUPLE": 8, + "ARRAY": 9, + "MAP": 10, + "TABLE": 11, + "FUNCTION": 12, +} + +func (x GoTest_KIND) Enum() *GoTest_KIND { + p := new(GoTest_KIND) + *p = x + return p +} +func (x GoTest_KIND) String() string { + return proto.EnumName(GoTest_KIND_name, int32(x)) +} +func (x GoTest_KIND) MarshalJSON() ([]byte, error) { + return json.Marshal(x.String()) +} +func (x *GoTest_KIND) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(GoTest_KIND_value, data, "GoTest_KIND") + if err != nil { + return err + } + *x = GoTest_KIND(value) + return nil +} + +type MyMessage_Color int32 + +const ( + MyMessage_RED MyMessage_Color = 0 + MyMessage_GREEN MyMessage_Color = 1 + MyMessage_BLUE MyMessage_Color = 2 +) + +var MyMessage_Color_name = map[int32]string{ + 0: "RED", + 1: "GREEN", + 2: "BLUE", +} +var MyMessage_Color_value = map[string]int32{ + "RED": 0, + "GREEN": 1, + "BLUE": 2, +} + +func (x MyMessage_Color) Enum() *MyMessage_Color { + p := new(MyMessage_Color) + *p = x + return p +} +func (x MyMessage_Color) String() string { + return proto.EnumName(MyMessage_Color_name, int32(x)) +} +func (x MyMessage_Color) MarshalJSON() ([]byte, error) { + return json.Marshal(x.String()) +} +func (x *MyMessage_Color) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(MyMessage_Color_value, data, "MyMessage_Color") + if err != nil { + return err + } + *x = MyMessage_Color(value) + return nil +} + +type Defaults_Color int32 + +const ( + Defaults_RED Defaults_Color = 0 + Defaults_GREEN Defaults_Color = 1 + Defaults_BLUE Defaults_Color = 2 +) + +var Defaults_Color_name = map[int32]string{ + 0: "RED", + 1: "GREEN", + 2: "BLUE", +} +var Defaults_Color_value = map[string]int32{ + "RED": 0, + "GREEN": 1, + "BLUE": 2, +} + +func (x Defaults_Color) Enum() *Defaults_Color { + p := new(Defaults_Color) + *p = x + return p +} +func (x Defaults_Color) String() string { + return proto.EnumName(Defaults_Color_name, int32(x)) +} +func (x Defaults_Color) MarshalJSON() ([]byte, error) { + return json.Marshal(x.String()) +} +func (x *Defaults_Color) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(Defaults_Color_value, data, "Defaults_Color") + if err != nil { + return err + } + *x = Defaults_Color(value) + return nil +} + +type RepeatedEnum_Color int32 + +const ( + RepeatedEnum_RED RepeatedEnum_Color = 1 +) + +var RepeatedEnum_Color_name = map[int32]string{ + 1: "RED", +} +var RepeatedEnum_Color_value = map[string]int32{ + "RED": 1, +} + +func (x RepeatedEnum_Color) Enum() *RepeatedEnum_Color { + p := new(RepeatedEnum_Color) + *p = x + return p +} +func (x RepeatedEnum_Color) String() string { + return proto.EnumName(RepeatedEnum_Color_name, int32(x)) +} +func (x RepeatedEnum_Color) MarshalJSON() ([]byte, error) { + return json.Marshal(x.String()) +} +func (x *RepeatedEnum_Color) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(RepeatedEnum_Color_value, data, "RepeatedEnum_Color") + if err != nil { + return err + } + *x = RepeatedEnum_Color(value) + return nil +} + +type GoEnum struct { + Foo *FOO `protobuf:"varint,1,req,name=foo,enum=testdata.FOO" json:"foo,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoEnum) Reset() { *m = GoEnum{} } +func (m *GoEnum) String() string { return proto.CompactTextString(m) } +func (*GoEnum) ProtoMessage() {} + +func (m *GoEnum) GetFoo() FOO { + if m != nil && m.Foo != nil { + return *m.Foo + } + return 0 +} + +type GoTestField struct { + Label *string `protobuf:"bytes,1,req" json:"Label,omitempty"` + Type *string `protobuf:"bytes,2,req" json:"Type,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTestField) Reset() { *m = GoTestField{} } +func (m *GoTestField) String() string { return proto.CompactTextString(m) } +func (*GoTestField) ProtoMessage() {} + +func (m *GoTestField) GetLabel() string { + if m != nil && m.Label != nil { + return *m.Label + } + return "" +} + +func (m *GoTestField) GetType() string { + if m != nil && m.Type != nil { + return *m.Type + } + return "" +} + +type GoTest struct { + Kind *GoTest_KIND `protobuf:"varint,1,req,enum=testdata.GoTest_KIND" json:"Kind,omitempty"` + Table *string `protobuf:"bytes,2,opt" json:"Table,omitempty"` + Param *int32 `protobuf:"varint,3,opt" json:"Param,omitempty"` + RequiredField *GoTestField `protobuf:"bytes,4,req" json:"RequiredField,omitempty"` + RepeatedField []*GoTestField `protobuf:"bytes,5,rep" json:"RepeatedField,omitempty"` + OptionalField *GoTestField `protobuf:"bytes,6,opt" json:"OptionalField,omitempty"` + F_BoolRequired *bool `protobuf:"varint,10,req,name=F_Bool_required" json:"F_Bool_required,omitempty"` + F_Int32Required *int32 `protobuf:"varint,11,req,name=F_Int32_required" json:"F_Int32_required,omitempty"` + F_Int64Required *int64 `protobuf:"varint,12,req,name=F_Int64_required" json:"F_Int64_required,omitempty"` + F_Fixed32Required *uint32 `protobuf:"fixed32,13,req,name=F_Fixed32_required" json:"F_Fixed32_required,omitempty"` + F_Fixed64Required *uint64 `protobuf:"fixed64,14,req,name=F_Fixed64_required" json:"F_Fixed64_required,omitempty"` + F_Uint32Required *uint32 `protobuf:"varint,15,req,name=F_Uint32_required" json:"F_Uint32_required,omitempty"` + F_Uint64Required *uint64 `protobuf:"varint,16,req,name=F_Uint64_required" json:"F_Uint64_required,omitempty"` + F_FloatRequired *float32 `protobuf:"fixed32,17,req,name=F_Float_required" json:"F_Float_required,omitempty"` + F_DoubleRequired *float64 `protobuf:"fixed64,18,req,name=F_Double_required" json:"F_Double_required,omitempty"` + F_StringRequired *string `protobuf:"bytes,19,req,name=F_String_required" json:"F_String_required,omitempty"` + F_BytesRequired []byte `protobuf:"bytes,101,req,name=F_Bytes_required" json:"F_Bytes_required,omitempty"` + F_Sint32Required *int32 `protobuf:"zigzag32,102,req,name=F_Sint32_required" json:"F_Sint32_required,omitempty"` + F_Sint64Required *int64 `protobuf:"zigzag64,103,req,name=F_Sint64_required" json:"F_Sint64_required,omitempty"` + F_BoolRepeated []bool `protobuf:"varint,20,rep,name=F_Bool_repeated" json:"F_Bool_repeated,omitempty"` + F_Int32Repeated []int32 `protobuf:"varint,21,rep,name=F_Int32_repeated" json:"F_Int32_repeated,omitempty"` + F_Int64Repeated []int64 `protobuf:"varint,22,rep,name=F_Int64_repeated" json:"F_Int64_repeated,omitempty"` + F_Fixed32Repeated []uint32 `protobuf:"fixed32,23,rep,name=F_Fixed32_repeated" json:"F_Fixed32_repeated,omitempty"` + F_Fixed64Repeated []uint64 `protobuf:"fixed64,24,rep,name=F_Fixed64_repeated" json:"F_Fixed64_repeated,omitempty"` + F_Uint32Repeated []uint32 `protobuf:"varint,25,rep,name=F_Uint32_repeated" json:"F_Uint32_repeated,omitempty"` + F_Uint64Repeated []uint64 `protobuf:"varint,26,rep,name=F_Uint64_repeated" json:"F_Uint64_repeated,omitempty"` + F_FloatRepeated []float32 `protobuf:"fixed32,27,rep,name=F_Float_repeated" json:"F_Float_repeated,omitempty"` + F_DoubleRepeated []float64 `protobuf:"fixed64,28,rep,name=F_Double_repeated" json:"F_Double_repeated,omitempty"` + F_StringRepeated []string `protobuf:"bytes,29,rep,name=F_String_repeated" json:"F_String_repeated,omitempty"` + F_BytesRepeated [][]byte `protobuf:"bytes,201,rep,name=F_Bytes_repeated" json:"F_Bytes_repeated,omitempty"` + F_Sint32Repeated []int32 `protobuf:"zigzag32,202,rep,name=F_Sint32_repeated" json:"F_Sint32_repeated,omitempty"` + F_Sint64Repeated []int64 `protobuf:"zigzag64,203,rep,name=F_Sint64_repeated" json:"F_Sint64_repeated,omitempty"` + F_BoolOptional *bool `protobuf:"varint,30,opt,name=F_Bool_optional" json:"F_Bool_optional,omitempty"` + F_Int32Optional *int32 `protobuf:"varint,31,opt,name=F_Int32_optional" json:"F_Int32_optional,omitempty"` + F_Int64Optional *int64 `protobuf:"varint,32,opt,name=F_Int64_optional" json:"F_Int64_optional,omitempty"` + F_Fixed32Optional *uint32 `protobuf:"fixed32,33,opt,name=F_Fixed32_optional" json:"F_Fixed32_optional,omitempty"` + F_Fixed64Optional *uint64 `protobuf:"fixed64,34,opt,name=F_Fixed64_optional" json:"F_Fixed64_optional,omitempty"` + F_Uint32Optional *uint32 `protobuf:"varint,35,opt,name=F_Uint32_optional" json:"F_Uint32_optional,omitempty"` + F_Uint64Optional *uint64 `protobuf:"varint,36,opt,name=F_Uint64_optional" json:"F_Uint64_optional,omitempty"` + F_FloatOptional *float32 `protobuf:"fixed32,37,opt,name=F_Float_optional" json:"F_Float_optional,omitempty"` + F_DoubleOptional *float64 `protobuf:"fixed64,38,opt,name=F_Double_optional" json:"F_Double_optional,omitempty"` + F_StringOptional *string `protobuf:"bytes,39,opt,name=F_String_optional" json:"F_String_optional,omitempty"` + F_BytesOptional []byte `protobuf:"bytes,301,opt,name=F_Bytes_optional" json:"F_Bytes_optional,omitempty"` + F_Sint32Optional *int32 `protobuf:"zigzag32,302,opt,name=F_Sint32_optional" json:"F_Sint32_optional,omitempty"` + F_Sint64Optional *int64 `protobuf:"zigzag64,303,opt,name=F_Sint64_optional" json:"F_Sint64_optional,omitempty"` + F_BoolDefaulted *bool `protobuf:"varint,40,opt,name=F_Bool_defaulted,def=1" json:"F_Bool_defaulted,omitempty"` + F_Int32Defaulted *int32 `protobuf:"varint,41,opt,name=F_Int32_defaulted,def=32" json:"F_Int32_defaulted,omitempty"` + F_Int64Defaulted *int64 `protobuf:"varint,42,opt,name=F_Int64_defaulted,def=64" json:"F_Int64_defaulted,omitempty"` + F_Fixed32Defaulted *uint32 `protobuf:"fixed32,43,opt,name=F_Fixed32_defaulted,def=320" json:"F_Fixed32_defaulted,omitempty"` + F_Fixed64Defaulted *uint64 `protobuf:"fixed64,44,opt,name=F_Fixed64_defaulted,def=640" json:"F_Fixed64_defaulted,omitempty"` + F_Uint32Defaulted *uint32 `protobuf:"varint,45,opt,name=F_Uint32_defaulted,def=3200" json:"F_Uint32_defaulted,omitempty"` + F_Uint64Defaulted *uint64 `protobuf:"varint,46,opt,name=F_Uint64_defaulted,def=6400" json:"F_Uint64_defaulted,omitempty"` + F_FloatDefaulted *float32 `protobuf:"fixed32,47,opt,name=F_Float_defaulted,def=314159" json:"F_Float_defaulted,omitempty"` + F_DoubleDefaulted *float64 `protobuf:"fixed64,48,opt,name=F_Double_defaulted,def=271828" json:"F_Double_defaulted,omitempty"` + F_StringDefaulted *string `protobuf:"bytes,49,opt,name=F_String_defaulted,def=hello, \"world!\"\n" json:"F_String_defaulted,omitempty"` + F_BytesDefaulted []byte `protobuf:"bytes,401,opt,name=F_Bytes_defaulted,def=Bignose" json:"F_Bytes_defaulted,omitempty"` + F_Sint32Defaulted *int32 `protobuf:"zigzag32,402,opt,name=F_Sint32_defaulted,def=-32" json:"F_Sint32_defaulted,omitempty"` + F_Sint64Defaulted *int64 `protobuf:"zigzag64,403,opt,name=F_Sint64_defaulted,def=-64" json:"F_Sint64_defaulted,omitempty"` + F_BoolRepeatedPacked []bool `protobuf:"varint,50,rep,packed,name=F_Bool_repeated_packed" json:"F_Bool_repeated_packed,omitempty"` + F_Int32RepeatedPacked []int32 `protobuf:"varint,51,rep,packed,name=F_Int32_repeated_packed" json:"F_Int32_repeated_packed,omitempty"` + F_Int64RepeatedPacked []int64 `protobuf:"varint,52,rep,packed,name=F_Int64_repeated_packed" json:"F_Int64_repeated_packed,omitempty"` + F_Fixed32RepeatedPacked []uint32 `protobuf:"fixed32,53,rep,packed,name=F_Fixed32_repeated_packed" json:"F_Fixed32_repeated_packed,omitempty"` + F_Fixed64RepeatedPacked []uint64 `protobuf:"fixed64,54,rep,packed,name=F_Fixed64_repeated_packed" json:"F_Fixed64_repeated_packed,omitempty"` + F_Uint32RepeatedPacked []uint32 `protobuf:"varint,55,rep,packed,name=F_Uint32_repeated_packed" json:"F_Uint32_repeated_packed,omitempty"` + F_Uint64RepeatedPacked []uint64 `protobuf:"varint,56,rep,packed,name=F_Uint64_repeated_packed" json:"F_Uint64_repeated_packed,omitempty"` + F_FloatRepeatedPacked []float32 `protobuf:"fixed32,57,rep,packed,name=F_Float_repeated_packed" json:"F_Float_repeated_packed,omitempty"` + F_DoubleRepeatedPacked []float64 `protobuf:"fixed64,58,rep,packed,name=F_Double_repeated_packed" json:"F_Double_repeated_packed,omitempty"` + F_Sint32RepeatedPacked []int32 `protobuf:"zigzag32,502,rep,packed,name=F_Sint32_repeated_packed" json:"F_Sint32_repeated_packed,omitempty"` + F_Sint64RepeatedPacked []int64 `protobuf:"zigzag64,503,rep,packed,name=F_Sint64_repeated_packed" json:"F_Sint64_repeated_packed,omitempty"` + Requiredgroup *GoTest_RequiredGroup `protobuf:"group,70,req,name=RequiredGroup" json:"requiredgroup,omitempty"` + Repeatedgroup []*GoTest_RepeatedGroup `protobuf:"group,80,rep,name=RepeatedGroup" json:"repeatedgroup,omitempty"` + Optionalgroup *GoTest_OptionalGroup `protobuf:"group,90,opt,name=OptionalGroup" json:"optionalgroup,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTest) Reset() { *m = GoTest{} } +func (m *GoTest) String() string { return proto.CompactTextString(m) } +func (*GoTest) ProtoMessage() {} + +const Default_GoTest_F_BoolDefaulted bool = true +const Default_GoTest_F_Int32Defaulted int32 = 32 +const Default_GoTest_F_Int64Defaulted int64 = 64 +const Default_GoTest_F_Fixed32Defaulted uint32 = 320 +const Default_GoTest_F_Fixed64Defaulted uint64 = 640 +const Default_GoTest_F_Uint32Defaulted uint32 = 3200 +const Default_GoTest_F_Uint64Defaulted uint64 = 6400 +const Default_GoTest_F_FloatDefaulted float32 = 314159 +const Default_GoTest_F_DoubleDefaulted float64 = 271828 +const Default_GoTest_F_StringDefaulted string = "hello, \"world!\"\n" + +var Default_GoTest_F_BytesDefaulted []byte = []byte("Bignose") + +const Default_GoTest_F_Sint32Defaulted int32 = -32 +const Default_GoTest_F_Sint64Defaulted int64 = -64 + +func (m *GoTest) GetKind() GoTest_KIND { + if m != nil && m.Kind != nil { + return *m.Kind + } + return 0 +} + +func (m *GoTest) GetTable() string { + if m != nil && m.Table != nil { + return *m.Table + } + return "" +} + +func (m *GoTest) GetParam() int32 { + if m != nil && m.Param != nil { + return *m.Param + } + return 0 +} + +func (m *GoTest) GetRequiredField() *GoTestField { + if m != nil { + return m.RequiredField + } + return nil +} + +func (m *GoTest) GetRepeatedField() []*GoTestField { + if m != nil { + return m.RepeatedField + } + return nil +} + +func (m *GoTest) GetOptionalField() *GoTestField { + if m != nil { + return m.OptionalField + } + return nil +} + +func (m *GoTest) GetF_BoolRequired() bool { + if m != nil && m.F_BoolRequired != nil { + return *m.F_BoolRequired + } + return false +} + +func (m *GoTest) GetF_Int32Required() int32 { + if m != nil && m.F_Int32Required != nil { + return *m.F_Int32Required + } + return 0 +} + +func (m *GoTest) GetF_Int64Required() int64 { + if m != nil && m.F_Int64Required != nil { + return *m.F_Int64Required + } + return 0 +} + +func (m *GoTest) GetF_Fixed32Required() uint32 { + if m != nil && m.F_Fixed32Required != nil { + return *m.F_Fixed32Required + } + return 0 +} + +func (m *GoTest) GetF_Fixed64Required() uint64 { + if m != nil && m.F_Fixed64Required != nil { + return *m.F_Fixed64Required + } + return 0 +} + +func (m *GoTest) GetF_Uint32Required() uint32 { + if m != nil && m.F_Uint32Required != nil { + return *m.F_Uint32Required + } + return 0 +} + +func (m *GoTest) GetF_Uint64Required() uint64 { + if m != nil && m.F_Uint64Required != nil { + return *m.F_Uint64Required + } + return 0 +} + +func (m *GoTest) GetF_FloatRequired() float32 { + if m != nil && m.F_FloatRequired != nil { + return *m.F_FloatRequired + } + return 0 +} + +func (m *GoTest) GetF_DoubleRequired() float64 { + if m != nil && m.F_DoubleRequired != nil { + return *m.F_DoubleRequired + } + return 0 +} + +func (m *GoTest) GetF_StringRequired() string { + if m != nil && m.F_StringRequired != nil { + return *m.F_StringRequired + } + return "" +} + +func (m *GoTest) GetF_BytesRequired() []byte { + if m != nil { + return m.F_BytesRequired + } + return nil +} + +func (m *GoTest) GetF_Sint32Required() int32 { + if m != nil && m.F_Sint32Required != nil { + return *m.F_Sint32Required + } + return 0 +} + +func (m *GoTest) GetF_Sint64Required() int64 { + if m != nil && m.F_Sint64Required != nil { + return *m.F_Sint64Required + } + return 0 +} + +func (m *GoTest) GetF_BoolRepeated() []bool { + if m != nil { + return m.F_BoolRepeated + } + return nil +} + +func (m *GoTest) GetF_Int32Repeated() []int32 { + if m != nil { + return m.F_Int32Repeated + } + return nil +} + +func (m *GoTest) GetF_Int64Repeated() []int64 { + if m != nil { + return m.F_Int64Repeated + } + return nil +} + +func (m *GoTest) GetF_Fixed32Repeated() []uint32 { + if m != nil { + return m.F_Fixed32Repeated + } + return nil +} + +func (m *GoTest) GetF_Fixed64Repeated() []uint64 { + if m != nil { + return m.F_Fixed64Repeated + } + return nil +} + +func (m *GoTest) GetF_Uint32Repeated() []uint32 { + if m != nil { + return m.F_Uint32Repeated + } + return nil +} + +func (m *GoTest) GetF_Uint64Repeated() []uint64 { + if m != nil { + return m.F_Uint64Repeated + } + return nil +} + +func (m *GoTest) GetF_FloatRepeated() []float32 { + if m != nil { + return m.F_FloatRepeated + } + return nil +} + +func (m *GoTest) GetF_DoubleRepeated() []float64 { + if m != nil { + return m.F_DoubleRepeated + } + return nil +} + +func (m *GoTest) GetF_StringRepeated() []string { + if m != nil { + return m.F_StringRepeated + } + return nil +} + +func (m *GoTest) GetF_BytesRepeated() [][]byte { + if m != nil { + return m.F_BytesRepeated + } + return nil +} + +func (m *GoTest) GetF_Sint32Repeated() []int32 { + if m != nil { + return m.F_Sint32Repeated + } + return nil +} + +func (m *GoTest) GetF_Sint64Repeated() []int64 { + if m != nil { + return m.F_Sint64Repeated + } + return nil +} + +func (m *GoTest) GetF_BoolOptional() bool { + if m != nil && m.F_BoolOptional != nil { + return *m.F_BoolOptional + } + return false +} + +func (m *GoTest) GetF_Int32Optional() int32 { + if m != nil && m.F_Int32Optional != nil { + return *m.F_Int32Optional + } + return 0 +} + +func (m *GoTest) GetF_Int64Optional() int64 { + if m != nil && m.F_Int64Optional != nil { + return *m.F_Int64Optional + } + return 0 +} + +func (m *GoTest) GetF_Fixed32Optional() uint32 { + if m != nil && m.F_Fixed32Optional != nil { + return *m.F_Fixed32Optional + } + return 0 +} + +func (m *GoTest) GetF_Fixed64Optional() uint64 { + if m != nil && m.F_Fixed64Optional != nil { + return *m.F_Fixed64Optional + } + return 0 +} + +func (m *GoTest) GetF_Uint32Optional() uint32 { + if m != nil && m.F_Uint32Optional != nil { + return *m.F_Uint32Optional + } + return 0 +} + +func (m *GoTest) GetF_Uint64Optional() uint64 { + if m != nil && m.F_Uint64Optional != nil { + return *m.F_Uint64Optional + } + return 0 +} + +func (m *GoTest) GetF_FloatOptional() float32 { + if m != nil && m.F_FloatOptional != nil { + return *m.F_FloatOptional + } + return 0 +} + +func (m *GoTest) GetF_DoubleOptional() float64 { + if m != nil && m.F_DoubleOptional != nil { + return *m.F_DoubleOptional + } + return 0 +} + +func (m *GoTest) GetF_StringOptional() string { + if m != nil && m.F_StringOptional != nil { + return *m.F_StringOptional + } + return "" +} + +func (m *GoTest) GetF_BytesOptional() []byte { + if m != nil { + return m.F_BytesOptional + } + return nil +} + +func (m *GoTest) GetF_Sint32Optional() int32 { + if m != nil && m.F_Sint32Optional != nil { + return *m.F_Sint32Optional + } + return 0 +} + +func (m *GoTest) GetF_Sint64Optional() int64 { + if m != nil && m.F_Sint64Optional != nil { + return *m.F_Sint64Optional + } + return 0 +} + +func (m *GoTest) GetF_BoolDefaulted() bool { + if m != nil && m.F_BoolDefaulted != nil { + return *m.F_BoolDefaulted + } + return Default_GoTest_F_BoolDefaulted +} + +func (m *GoTest) GetF_Int32Defaulted() int32 { + if m != nil && m.F_Int32Defaulted != nil { + return *m.F_Int32Defaulted + } + return Default_GoTest_F_Int32Defaulted +} + +func (m *GoTest) GetF_Int64Defaulted() int64 { + if m != nil && m.F_Int64Defaulted != nil { + return *m.F_Int64Defaulted + } + return Default_GoTest_F_Int64Defaulted +} + +func (m *GoTest) GetF_Fixed32Defaulted() uint32 { + if m != nil && m.F_Fixed32Defaulted != nil { + return *m.F_Fixed32Defaulted + } + return Default_GoTest_F_Fixed32Defaulted +} + +func (m *GoTest) GetF_Fixed64Defaulted() uint64 { + if m != nil && m.F_Fixed64Defaulted != nil { + return *m.F_Fixed64Defaulted + } + return Default_GoTest_F_Fixed64Defaulted +} + +func (m *GoTest) GetF_Uint32Defaulted() uint32 { + if m != nil && m.F_Uint32Defaulted != nil { + return *m.F_Uint32Defaulted + } + return Default_GoTest_F_Uint32Defaulted +} + +func (m *GoTest) GetF_Uint64Defaulted() uint64 { + if m != nil && m.F_Uint64Defaulted != nil { + return *m.F_Uint64Defaulted + } + return Default_GoTest_F_Uint64Defaulted +} + +func (m *GoTest) GetF_FloatDefaulted() float32 { + if m != nil && m.F_FloatDefaulted != nil { + return *m.F_FloatDefaulted + } + return Default_GoTest_F_FloatDefaulted +} + +func (m *GoTest) GetF_DoubleDefaulted() float64 { + if m != nil && m.F_DoubleDefaulted != nil { + return *m.F_DoubleDefaulted + } + return Default_GoTest_F_DoubleDefaulted +} + +func (m *GoTest) GetF_StringDefaulted() string { + if m != nil && m.F_StringDefaulted != nil { + return *m.F_StringDefaulted + } + return Default_GoTest_F_StringDefaulted +} + +func (m *GoTest) GetF_BytesDefaulted() []byte { + if m != nil && m.F_BytesDefaulted != nil { + return m.F_BytesDefaulted + } + return append([]byte(nil), Default_GoTest_F_BytesDefaulted...) +} + +func (m *GoTest) GetF_Sint32Defaulted() int32 { + if m != nil && m.F_Sint32Defaulted != nil { + return *m.F_Sint32Defaulted + } + return Default_GoTest_F_Sint32Defaulted +} + +func (m *GoTest) GetF_Sint64Defaulted() int64 { + if m != nil && m.F_Sint64Defaulted != nil { + return *m.F_Sint64Defaulted + } + return Default_GoTest_F_Sint64Defaulted +} + +func (m *GoTest) GetF_BoolRepeatedPacked() []bool { + if m != nil { + return m.F_BoolRepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Int32RepeatedPacked() []int32 { + if m != nil { + return m.F_Int32RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Int64RepeatedPacked() []int64 { + if m != nil { + return m.F_Int64RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Fixed32RepeatedPacked() []uint32 { + if m != nil { + return m.F_Fixed32RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Fixed64RepeatedPacked() []uint64 { + if m != nil { + return m.F_Fixed64RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Uint32RepeatedPacked() []uint32 { + if m != nil { + return m.F_Uint32RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Uint64RepeatedPacked() []uint64 { + if m != nil { + return m.F_Uint64RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_FloatRepeatedPacked() []float32 { + if m != nil { + return m.F_FloatRepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_DoubleRepeatedPacked() []float64 { + if m != nil { + return m.F_DoubleRepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Sint32RepeatedPacked() []int32 { + if m != nil { + return m.F_Sint32RepeatedPacked + } + return nil +} + +func (m *GoTest) GetF_Sint64RepeatedPacked() []int64 { + if m != nil { + return m.F_Sint64RepeatedPacked + } + return nil +} + +func (m *GoTest) GetRequiredgroup() *GoTest_RequiredGroup { + if m != nil { + return m.Requiredgroup + } + return nil +} + +func (m *GoTest) GetRepeatedgroup() []*GoTest_RepeatedGroup { + if m != nil { + return m.Repeatedgroup + } + return nil +} + +func (m *GoTest) GetOptionalgroup() *GoTest_OptionalGroup { + if m != nil { + return m.Optionalgroup + } + return nil +} + +type GoTest_RequiredGroup struct { + RequiredField *string `protobuf:"bytes,71,req" json:"RequiredField,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTest_RequiredGroup) Reset() { *m = GoTest_RequiredGroup{} } + +func (m *GoTest_RequiredGroup) GetRequiredField() string { + if m != nil && m.RequiredField != nil { + return *m.RequiredField + } + return "" +} + +type GoTest_RepeatedGroup struct { + RequiredField *string `protobuf:"bytes,81,req" json:"RequiredField,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTest_RepeatedGroup) Reset() { *m = GoTest_RepeatedGroup{} } + +func (m *GoTest_RepeatedGroup) GetRequiredField() string { + if m != nil && m.RequiredField != nil { + return *m.RequiredField + } + return "" +} + +type GoTest_OptionalGroup struct { + RequiredField *string `protobuf:"bytes,91,req" json:"RequiredField,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoTest_OptionalGroup) Reset() { *m = GoTest_OptionalGroup{} } + +func (m *GoTest_OptionalGroup) GetRequiredField() string { + if m != nil && m.RequiredField != nil { + return *m.RequiredField + } + return "" +} + +type GoSkipTest struct { + SkipInt32 *int32 `protobuf:"varint,11,req,name=skip_int32" json:"skip_int32,omitempty"` + SkipFixed32 *uint32 `protobuf:"fixed32,12,req,name=skip_fixed32" json:"skip_fixed32,omitempty"` + SkipFixed64 *uint64 `protobuf:"fixed64,13,req,name=skip_fixed64" json:"skip_fixed64,omitempty"` + SkipString *string `protobuf:"bytes,14,req,name=skip_string" json:"skip_string,omitempty"` + Skipgroup *GoSkipTest_SkipGroup `protobuf:"group,15,req,name=SkipGroup" json:"skipgroup,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoSkipTest) Reset() { *m = GoSkipTest{} } +func (m *GoSkipTest) String() string { return proto.CompactTextString(m) } +func (*GoSkipTest) ProtoMessage() {} + +func (m *GoSkipTest) GetSkipInt32() int32 { + if m != nil && m.SkipInt32 != nil { + return *m.SkipInt32 + } + return 0 +} + +func (m *GoSkipTest) GetSkipFixed32() uint32 { + if m != nil && m.SkipFixed32 != nil { + return *m.SkipFixed32 + } + return 0 +} + +func (m *GoSkipTest) GetSkipFixed64() uint64 { + if m != nil && m.SkipFixed64 != nil { + return *m.SkipFixed64 + } + return 0 +} + +func (m *GoSkipTest) GetSkipString() string { + if m != nil && m.SkipString != nil { + return *m.SkipString + } + return "" +} + +func (m *GoSkipTest) GetSkipgroup() *GoSkipTest_SkipGroup { + if m != nil { + return m.Skipgroup + } + return nil +} + +type GoSkipTest_SkipGroup struct { + GroupInt32 *int32 `protobuf:"varint,16,req,name=group_int32" json:"group_int32,omitempty"` + GroupString *string `protobuf:"bytes,17,req,name=group_string" json:"group_string,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GoSkipTest_SkipGroup) Reset() { *m = GoSkipTest_SkipGroup{} } + +func (m *GoSkipTest_SkipGroup) GetGroupInt32() int32 { + if m != nil && m.GroupInt32 != nil { + return *m.GroupInt32 + } + return 0 +} + +func (m *GoSkipTest_SkipGroup) GetGroupString() string { + if m != nil && m.GroupString != nil { + return *m.GroupString + } + return "" +} + +type NonPackedTest struct { + A []int32 `protobuf:"varint,1,rep,name=a" json:"a,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *NonPackedTest) Reset() { *m = NonPackedTest{} } +func (m *NonPackedTest) String() string { return proto.CompactTextString(m) } +func (*NonPackedTest) ProtoMessage() {} + +func (m *NonPackedTest) GetA() []int32 { + if m != nil { + return m.A + } + return nil +} + +type PackedTest struct { + B []int32 `protobuf:"varint,1,rep,packed,name=b" json:"b,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *PackedTest) Reset() { *m = PackedTest{} } +func (m *PackedTest) String() string { return proto.CompactTextString(m) } +func (*PackedTest) ProtoMessage() {} + +func (m *PackedTest) GetB() []int32 { + if m != nil { + return m.B + } + return nil +} + +type MaxTag struct { + LastField *string `protobuf:"bytes,536870911,opt,name=last_field" json:"last_field,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MaxTag) Reset() { *m = MaxTag{} } +func (m *MaxTag) String() string { return proto.CompactTextString(m) } +func (*MaxTag) ProtoMessage() {} + +func (m *MaxTag) GetLastField() string { + if m != nil && m.LastField != nil { + return *m.LastField + } + return "" +} + +type OldMessage struct { + Nested *OldMessage_Nested `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OldMessage) Reset() { *m = OldMessage{} } +func (m *OldMessage) String() string { return proto.CompactTextString(m) } +func (*OldMessage) ProtoMessage() {} + +func (m *OldMessage) GetNested() *OldMessage_Nested { + if m != nil { + return m.Nested + } + return nil +} + +type OldMessage_Nested struct { + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OldMessage_Nested) Reset() { *m = OldMessage_Nested{} } +func (m *OldMessage_Nested) String() string { return proto.CompactTextString(m) } +func (*OldMessage_Nested) ProtoMessage() {} + +func (m *OldMessage_Nested) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +type NewMessage struct { + Nested *NewMessage_Nested `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *NewMessage) Reset() { *m = NewMessage{} } +func (m *NewMessage) String() string { return proto.CompactTextString(m) } +func (*NewMessage) ProtoMessage() {} + +func (m *NewMessage) GetNested() *NewMessage_Nested { + if m != nil { + return m.Nested + } + return nil +} + +type NewMessage_Nested struct { + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + FoodGroup *string `protobuf:"bytes,2,opt,name=food_group" json:"food_group,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *NewMessage_Nested) Reset() { *m = NewMessage_Nested{} } +func (m *NewMessage_Nested) String() string { return proto.CompactTextString(m) } +func (*NewMessage_Nested) ProtoMessage() {} + +func (m *NewMessage_Nested) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +func (m *NewMessage_Nested) GetFoodGroup() string { + if m != nil && m.FoodGroup != nil { + return *m.FoodGroup + } + return "" +} + +type InnerMessage struct { + Host *string `protobuf:"bytes,1,req,name=host" json:"host,omitempty"` + Port *int32 `protobuf:"varint,2,opt,name=port,def=4000" json:"port,omitempty"` + Connected *bool `protobuf:"varint,3,opt,name=connected" json:"connected,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *InnerMessage) Reset() { *m = InnerMessage{} } +func (m *InnerMessage) String() string { return proto.CompactTextString(m) } +func (*InnerMessage) ProtoMessage() {} + +const Default_InnerMessage_Port int32 = 4000 + +func (m *InnerMessage) GetHost() string { + if m != nil && m.Host != nil { + return *m.Host + } + return "" +} + +func (m *InnerMessage) GetPort() int32 { + if m != nil && m.Port != nil { + return *m.Port + } + return Default_InnerMessage_Port +} + +func (m *InnerMessage) GetConnected() bool { + if m != nil && m.Connected != nil { + return *m.Connected + } + return false +} + +type OtherMessage struct { + Key *int64 `protobuf:"varint,1,opt,name=key" json:"key,omitempty"` + Value []byte `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"` + Weight *float32 `protobuf:"fixed32,3,opt,name=weight" json:"weight,omitempty"` + Inner *InnerMessage `protobuf:"bytes,4,opt,name=inner" json:"inner,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OtherMessage) Reset() { *m = OtherMessage{} } +func (m *OtherMessage) String() string { return proto.CompactTextString(m) } +func (*OtherMessage) ProtoMessage() {} + +func (m *OtherMessage) GetKey() int64 { + if m != nil && m.Key != nil { + return *m.Key + } + return 0 +} + +func (m *OtherMessage) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +func (m *OtherMessage) GetWeight() float32 { + if m != nil && m.Weight != nil { + return *m.Weight + } + return 0 +} + +func (m *OtherMessage) GetInner() *InnerMessage { + if m != nil { + return m.Inner + } + return nil +} + +type MyMessage struct { + Count *int32 `protobuf:"varint,1,req,name=count" json:"count,omitempty"` + Name *string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"` + Quote *string `protobuf:"bytes,3,opt,name=quote" json:"quote,omitempty"` + Pet []string `protobuf:"bytes,4,rep,name=pet" json:"pet,omitempty"` + Inner *InnerMessage `protobuf:"bytes,5,opt,name=inner" json:"inner,omitempty"` + Others []*OtherMessage `protobuf:"bytes,6,rep,name=others" json:"others,omitempty"` + Bikeshed *MyMessage_Color `protobuf:"varint,7,opt,name=bikeshed,enum=testdata.MyMessage_Color" json:"bikeshed,omitempty"` + Somegroup *MyMessage_SomeGroup `protobuf:"group,8,opt,name=SomeGroup" json:"somegroup,omitempty"` + RepBytes [][]byte `protobuf:"bytes,10,rep,name=rep_bytes" json:"rep_bytes,omitempty"` + Bigfloat *float64 `protobuf:"fixed64,11,opt,name=bigfloat" json:"bigfloat,omitempty"` + XXX_extensions map[int32]proto.Extension `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MyMessage) Reset() { *m = MyMessage{} } +func (m *MyMessage) String() string { return proto.CompactTextString(m) } +func (*MyMessage) ProtoMessage() {} + +var extRange_MyMessage = []proto.ExtensionRange{ + {100, 536870911}, +} + +func (*MyMessage) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_MyMessage +} +func (m *MyMessage) ExtensionMap() map[int32]proto.Extension { + if m.XXX_extensions == nil { + m.XXX_extensions = make(map[int32]proto.Extension) + } + return m.XXX_extensions +} + +func (m *MyMessage) GetCount() int32 { + if m != nil && m.Count != nil { + return *m.Count + } + return 0 +} + +func (m *MyMessage) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +func (m *MyMessage) GetQuote() string { + if m != nil && m.Quote != nil { + return *m.Quote + } + return "" +} + +func (m *MyMessage) GetPet() []string { + if m != nil { + return m.Pet + } + return nil +} + +func (m *MyMessage) GetInner() *InnerMessage { + if m != nil { + return m.Inner + } + return nil +} + +func (m *MyMessage) GetOthers() []*OtherMessage { + if m != nil { + return m.Others + } + return nil +} + +func (m *MyMessage) GetBikeshed() MyMessage_Color { + if m != nil && m.Bikeshed != nil { + return *m.Bikeshed + } + return 0 +} + +func (m *MyMessage) GetSomegroup() *MyMessage_SomeGroup { + if m != nil { + return m.Somegroup + } + return nil +} + +func (m *MyMessage) GetRepBytes() [][]byte { + if m != nil { + return m.RepBytes + } + return nil +} + +func (m *MyMessage) GetBigfloat() float64 { + if m != nil && m.Bigfloat != nil { + return *m.Bigfloat + } + return 0 +} + +type MyMessage_SomeGroup struct { + GroupField *int32 `protobuf:"varint,9,opt,name=group_field" json:"group_field,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MyMessage_SomeGroup) Reset() { *m = MyMessage_SomeGroup{} } + +func (m *MyMessage_SomeGroup) GetGroupField() int32 { + if m != nil && m.GroupField != nil { + return *m.GroupField + } + return 0 +} + +type Ext struct { + Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Ext) Reset() { *m = Ext{} } +func (m *Ext) String() string { return proto.CompactTextString(m) } +func (*Ext) ProtoMessage() {} + +func (m *Ext) GetData() string { + if m != nil && m.Data != nil { + return *m.Data + } + return "" +} + +var E_Ext_More = &proto.ExtensionDesc{ + ExtendedType: (*MyMessage)(nil), + ExtensionType: (*Ext)(nil), + Field: 103, + Name: "testdata.Ext.more", + Tag: "bytes,103,opt,name=more", +} + +var E_Ext_Text = &proto.ExtensionDesc{ + ExtendedType: (*MyMessage)(nil), + ExtensionType: (*string)(nil), + Field: 104, + Name: "testdata.Ext.text", + Tag: "bytes,104,opt,name=text", +} + +var E_Ext_Number = &proto.ExtensionDesc{ + ExtendedType: (*MyMessage)(nil), + ExtensionType: (*int32)(nil), + Field: 105, + Name: "testdata.Ext.number", + Tag: "varint,105,opt,name=number", +} + +type MessageList struct { + Message []*MessageList_Message `protobuf:"group,1,rep" json:"message,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MessageList) Reset() { *m = MessageList{} } +func (m *MessageList) String() string { return proto.CompactTextString(m) } +func (*MessageList) ProtoMessage() {} + +func (m *MessageList) GetMessage() []*MessageList_Message { + if m != nil { + return m.Message + } + return nil +} + +type MessageList_Message struct { + Name *string `protobuf:"bytes,2,req,name=name" json:"name,omitempty"` + Count *int32 `protobuf:"varint,3,req,name=count" json:"count,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MessageList_Message) Reset() { *m = MessageList_Message{} } + +func (m *MessageList_Message) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +func (m *MessageList_Message) GetCount() int32 { + if m != nil && m.Count != nil { + return *m.Count + } + return 0 +} + +type Strings struct { + StringField *string `protobuf:"bytes,1,opt,name=string_field" json:"string_field,omitempty"` + BytesField []byte `protobuf:"bytes,2,opt,name=bytes_field" json:"bytes_field,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Strings) Reset() { *m = Strings{} } +func (m *Strings) String() string { return proto.CompactTextString(m) } +func (*Strings) ProtoMessage() {} + +func (m *Strings) GetStringField() string { + if m != nil && m.StringField != nil { + return *m.StringField + } + return "" +} + +func (m *Strings) GetBytesField() []byte { + if m != nil { + return m.BytesField + } + return nil +} + +type Defaults struct { + F_Bool *bool `protobuf:"varint,1,opt,def=1" json:"F_Bool,omitempty"` + F_Int32 *int32 `protobuf:"varint,2,opt,def=32" json:"F_Int32,omitempty"` + F_Int64 *int64 `protobuf:"varint,3,opt,def=64" json:"F_Int64,omitempty"` + F_Fixed32 *uint32 `protobuf:"fixed32,4,opt,def=320" json:"F_Fixed32,omitempty"` + F_Fixed64 *uint64 `protobuf:"fixed64,5,opt,def=640" json:"F_Fixed64,omitempty"` + F_Uint32 *uint32 `protobuf:"varint,6,opt,def=3200" json:"F_Uint32,omitempty"` + F_Uint64 *uint64 `protobuf:"varint,7,opt,def=6400" json:"F_Uint64,omitempty"` + F_Float *float32 `protobuf:"fixed32,8,opt,def=314159" json:"F_Float,omitempty"` + F_Double *float64 `protobuf:"fixed64,9,opt,def=271828" json:"F_Double,omitempty"` + F_String *string `protobuf:"bytes,10,opt,def=hello, \"world!\"\n" json:"F_String,omitempty"` + F_Bytes []byte `protobuf:"bytes,11,opt,def=Bignose" json:"F_Bytes,omitempty"` + F_Sint32 *int32 `protobuf:"zigzag32,12,opt,def=-32" json:"F_Sint32,omitempty"` + F_Sint64 *int64 `protobuf:"zigzag64,13,opt,def=-64" json:"F_Sint64,omitempty"` + F_Enum *Defaults_Color `protobuf:"varint,14,opt,enum=testdata.Defaults_Color,def=1" json:"F_Enum,omitempty"` + F_Pinf *float32 `protobuf:"fixed32,15,opt,def=inf" json:"F_Pinf,omitempty"` + F_Ninf *float32 `protobuf:"fixed32,16,opt,def=-inf" json:"F_Ninf,omitempty"` + F_Nan *float32 `protobuf:"fixed32,17,opt,def=nan" json:"F_Nan,omitempty"` + Sub *SubDefaults `protobuf:"bytes,18,opt,name=sub" json:"sub,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Defaults) Reset() { *m = Defaults{} } +func (m *Defaults) String() string { return proto.CompactTextString(m) } +func (*Defaults) ProtoMessage() {} + +const Default_Defaults_F_Bool bool = true +const Default_Defaults_F_Int32 int32 = 32 +const Default_Defaults_F_Int64 int64 = 64 +const Default_Defaults_F_Fixed32 uint32 = 320 +const Default_Defaults_F_Fixed64 uint64 = 640 +const Default_Defaults_F_Uint32 uint32 = 3200 +const Default_Defaults_F_Uint64 uint64 = 6400 +const Default_Defaults_F_Float float32 = 314159 +const Default_Defaults_F_Double float64 = 271828 +const Default_Defaults_F_String string = "hello, \"world!\"\n" + +var Default_Defaults_F_Bytes []byte = []byte("Bignose") + +const Default_Defaults_F_Sint32 int32 = -32 +const Default_Defaults_F_Sint64 int64 = -64 +const Default_Defaults_F_Enum Defaults_Color = Defaults_GREEN + +var Default_Defaults_F_Pinf float32 = float32(math.Inf(1)) +var Default_Defaults_F_Ninf float32 = float32(math.Inf(-1)) +var Default_Defaults_F_Nan float32 = float32(math.NaN()) + +func (m *Defaults) GetF_Bool() bool { + if m != nil && m.F_Bool != nil { + return *m.F_Bool + } + return Default_Defaults_F_Bool +} + +func (m *Defaults) GetF_Int32() int32 { + if m != nil && m.F_Int32 != nil { + return *m.F_Int32 + } + return Default_Defaults_F_Int32 +} + +func (m *Defaults) GetF_Int64() int64 { + if m != nil && m.F_Int64 != nil { + return *m.F_Int64 + } + return Default_Defaults_F_Int64 +} + +func (m *Defaults) GetF_Fixed32() uint32 { + if m != nil && m.F_Fixed32 != nil { + return *m.F_Fixed32 + } + return Default_Defaults_F_Fixed32 +} + +func (m *Defaults) GetF_Fixed64() uint64 { + if m != nil && m.F_Fixed64 != nil { + return *m.F_Fixed64 + } + return Default_Defaults_F_Fixed64 +} + +func (m *Defaults) GetF_Uint32() uint32 { + if m != nil && m.F_Uint32 != nil { + return *m.F_Uint32 + } + return Default_Defaults_F_Uint32 +} + +func (m *Defaults) GetF_Uint64() uint64 { + if m != nil && m.F_Uint64 != nil { + return *m.F_Uint64 + } + return Default_Defaults_F_Uint64 +} + +func (m *Defaults) GetF_Float() float32 { + if m != nil && m.F_Float != nil { + return *m.F_Float + } + return Default_Defaults_F_Float +} + +func (m *Defaults) GetF_Double() float64 { + if m != nil && m.F_Double != nil { + return *m.F_Double + } + return Default_Defaults_F_Double +} + +func (m *Defaults) GetF_String() string { + if m != nil && m.F_String != nil { + return *m.F_String + } + return Default_Defaults_F_String +} + +func (m *Defaults) GetF_Bytes() []byte { + if m != nil && m.F_Bytes != nil { + return m.F_Bytes + } + return append([]byte(nil), Default_Defaults_F_Bytes...) +} + +func (m *Defaults) GetF_Sint32() int32 { + if m != nil && m.F_Sint32 != nil { + return *m.F_Sint32 + } + return Default_Defaults_F_Sint32 +} + +func (m *Defaults) GetF_Sint64() int64 { + if m != nil && m.F_Sint64 != nil { + return *m.F_Sint64 + } + return Default_Defaults_F_Sint64 +} + +func (m *Defaults) GetF_Enum() Defaults_Color { + if m != nil && m.F_Enum != nil { + return *m.F_Enum + } + return Default_Defaults_F_Enum +} + +func (m *Defaults) GetF_Pinf() float32 { + if m != nil && m.F_Pinf != nil { + return *m.F_Pinf + } + return Default_Defaults_F_Pinf +} + +func (m *Defaults) GetF_Ninf() float32 { + if m != nil && m.F_Ninf != nil { + return *m.F_Ninf + } + return Default_Defaults_F_Ninf +} + +func (m *Defaults) GetF_Nan() float32 { + if m != nil && m.F_Nan != nil { + return *m.F_Nan + } + return Default_Defaults_F_Nan +} + +func (m *Defaults) GetSub() *SubDefaults { + if m != nil { + return m.Sub + } + return nil +} + +type SubDefaults struct { + N *int64 `protobuf:"varint,1,opt,name=n,def=7" json:"n,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *SubDefaults) Reset() { *m = SubDefaults{} } +func (m *SubDefaults) String() string { return proto.CompactTextString(m) } +func (*SubDefaults) ProtoMessage() {} + +const Default_SubDefaults_N int64 = 7 + +func (m *SubDefaults) GetN() int64 { + if m != nil && m.N != nil { + return *m.N + } + return Default_SubDefaults_N +} + +type RepeatedEnum struct { + Color []RepeatedEnum_Color `protobuf:"varint,1,rep,name=color,enum=testdata.RepeatedEnum_Color" json:"color,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *RepeatedEnum) Reset() { *m = RepeatedEnum{} } +func (m *RepeatedEnum) String() string { return proto.CompactTextString(m) } +func (*RepeatedEnum) ProtoMessage() {} + +func (m *RepeatedEnum) GetColor() []RepeatedEnum_Color { + if m != nil { + return m.Color + } + return nil +} + +type MoreRepeated struct { + Bools []bool `protobuf:"varint,1,rep,name=bools" json:"bools,omitempty"` + BoolsPacked []bool `protobuf:"varint,2,rep,packed,name=bools_packed" json:"bools_packed,omitempty"` + Ints []int32 `protobuf:"varint,3,rep,name=ints" json:"ints,omitempty"` + IntsPacked []int32 `protobuf:"varint,4,rep,packed,name=ints_packed" json:"ints_packed,omitempty"` + Strings []string `protobuf:"bytes,5,rep,name=strings" json:"strings,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MoreRepeated) Reset() { *m = MoreRepeated{} } +func (m *MoreRepeated) String() string { return proto.CompactTextString(m) } +func (*MoreRepeated) ProtoMessage() {} + +func (m *MoreRepeated) GetBools() []bool { + if m != nil { + return m.Bools + } + return nil +} + +func (m *MoreRepeated) GetBoolsPacked() []bool { + if m != nil { + return m.BoolsPacked + } + return nil +} + +func (m *MoreRepeated) GetInts() []int32 { + if m != nil { + return m.Ints + } + return nil +} + +func (m *MoreRepeated) GetIntsPacked() []int32 { + if m != nil { + return m.IntsPacked + } + return nil +} + +func (m *MoreRepeated) GetStrings() []string { + if m != nil { + return m.Strings + } + return nil +} + +type GroupOld struct { + G *GroupOld_G `protobuf:"group,1,opt" json:"g,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GroupOld) Reset() { *m = GroupOld{} } +func (m *GroupOld) String() string { return proto.CompactTextString(m) } +func (*GroupOld) ProtoMessage() {} + +func (m *GroupOld) GetG() *GroupOld_G { + if m != nil { + return m.G + } + return nil +} + +type GroupOld_G struct { + X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GroupOld_G) Reset() { *m = GroupOld_G{} } + +func (m *GroupOld_G) GetX() int32 { + if m != nil && m.X != nil { + return *m.X + } + return 0 +} + +type GroupNew struct { + G *GroupNew_G `protobuf:"group,1,opt" json:"g,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GroupNew) Reset() { *m = GroupNew{} } +func (m *GroupNew) String() string { return proto.CompactTextString(m) } +func (*GroupNew) ProtoMessage() {} + +func (m *GroupNew) GetG() *GroupNew_G { + if m != nil { + return m.G + } + return nil +} + +type GroupNew_G struct { + X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"` + Y *int32 `protobuf:"varint,3,opt,name=y" json:"y,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *GroupNew_G) Reset() { *m = GroupNew_G{} } + +func (m *GroupNew_G) GetX() int32 { + if m != nil && m.X != nil { + return *m.X + } + return 0 +} + +func (m *GroupNew_G) GetY() int32 { + if m != nil && m.Y != nil { + return *m.Y + } + return 0 +} + +var E_Greeting = &proto.ExtensionDesc{ + ExtendedType: (*MyMessage)(nil), + ExtensionType: ([]string)(nil), + Field: 106, + Name: "testdata.greeting", + Tag: "bytes,106,rep,name=greeting", +} + +func init() { + proto.RegisterEnum("testdata.FOO", FOO_name, FOO_value) + proto.RegisterEnum("testdata.GoTest_KIND", GoTest_KIND_name, GoTest_KIND_value) + proto.RegisterEnum("testdata.MyMessage_Color", MyMessage_Color_name, MyMessage_Color_value) + proto.RegisterEnum("testdata.Defaults_Color", Defaults_Color_name, Defaults_Color_value) + proto.RegisterEnum("testdata.RepeatedEnum_Color", RepeatedEnum_Color_name, RepeatedEnum_Color_value) + proto.RegisterExtension(E_Ext_More) + proto.RegisterExtension(E_Ext_Text) + proto.RegisterExtension(E_Ext_Number) + proto.RegisterExtension(E_Greeting) +} diff --git a/vendor/github.com/gogo/protobuf/proto/testdata/test.proto b/vendor/github.com/gogo/protobuf/proto/testdata/test.proto new file mode 100644 index 000000000..70e3cfcda --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/testdata/test.proto @@ -0,0 +1,548 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// A feature-rich test file for the protocol compiler and libraries. + +syntax = "proto2"; + +package testdata; + +enum FOO { FOO1 = 1; }; + +message GoEnum { + required FOO foo = 1; +} + +message GoTestField { + required string Label = 1; + required string Type = 2; +} + +message GoTest { + // An enum, for completeness. + enum KIND { + VOID = 0; + + // Basic types + BOOL = 1; + BYTES = 2; + FINGERPRINT = 3; + FLOAT = 4; + INT = 5; + STRING = 6; + TIME = 7; + + // Groupings + TUPLE = 8; + ARRAY = 9; + MAP = 10; + + // Table types + TABLE = 11; + + // Functions + FUNCTION = 12; // last tag + }; + + // Some typical parameters + required KIND Kind = 1; + optional string Table = 2; + optional int32 Param = 3; + + // Required, repeated and optional foreign fields. + required GoTestField RequiredField = 4; + repeated GoTestField RepeatedField = 5; + optional GoTestField OptionalField = 6; + + // Required fields of all basic types + required bool F_Bool_required = 10; + required int32 F_Int32_required = 11; + required int64 F_Int64_required = 12; + required fixed32 F_Fixed32_required = 13; + required fixed64 F_Fixed64_required = 14; + required uint32 F_Uint32_required = 15; + required uint64 F_Uint64_required = 16; + required float F_Float_required = 17; + required double F_Double_required = 18; + required string F_String_required = 19; + required bytes F_Bytes_required = 101; + required sint32 F_Sint32_required = 102; + required sint64 F_Sint64_required = 103; + + // Repeated fields of all basic types + repeated bool F_Bool_repeated = 20; + repeated int32 F_Int32_repeated = 21; + repeated int64 F_Int64_repeated = 22; + repeated fixed32 F_Fixed32_repeated = 23; + repeated fixed64 F_Fixed64_repeated = 24; + repeated uint32 F_Uint32_repeated = 25; + repeated uint64 F_Uint64_repeated = 26; + repeated float F_Float_repeated = 27; + repeated double F_Double_repeated = 28; + repeated string F_String_repeated = 29; + repeated bytes F_Bytes_repeated = 201; + repeated sint32 F_Sint32_repeated = 202; + repeated sint64 F_Sint64_repeated = 203; + + // Optional fields of all basic types + optional bool F_Bool_optional = 30; + optional int32 F_Int32_optional = 31; + optional int64 F_Int64_optional = 32; + optional fixed32 F_Fixed32_optional = 33; + optional fixed64 F_Fixed64_optional = 34; + optional uint32 F_Uint32_optional = 35; + optional uint64 F_Uint64_optional = 36; + optional float F_Float_optional = 37; + optional double F_Double_optional = 38; + optional string F_String_optional = 39; + optional bytes F_Bytes_optional = 301; + optional sint32 F_Sint32_optional = 302; + optional sint64 F_Sint64_optional = 303; + + // Default-valued fields of all basic types + optional bool F_Bool_defaulted = 40 [default=true]; + optional int32 F_Int32_defaulted = 41 [default=32]; + optional int64 F_Int64_defaulted = 42 [default=64]; + optional fixed32 F_Fixed32_defaulted = 43 [default=320]; + optional fixed64 F_Fixed64_defaulted = 44 [default=640]; + optional uint32 F_Uint32_defaulted = 45 [default=3200]; + optional uint64 F_Uint64_defaulted = 46 [default=6400]; + optional float F_Float_defaulted = 47 [default=314159.]; + optional double F_Double_defaulted = 48 [default=271828.]; + optional string F_String_defaulted = 49 [default="hello, \"world!\"\n"]; + optional bytes F_Bytes_defaulted = 401 [default="Bignose"]; + optional sint32 F_Sint32_defaulted = 402 [default = -32]; + optional sint64 F_Sint64_defaulted = 403 [default = -64]; + + // Packed repeated fields (no string or bytes). + repeated bool F_Bool_repeated_packed = 50 [packed=true]; + repeated int32 F_Int32_repeated_packed = 51 [packed=true]; + repeated int64 F_Int64_repeated_packed = 52 [packed=true]; + repeated fixed32 F_Fixed32_repeated_packed = 53 [packed=true]; + repeated fixed64 F_Fixed64_repeated_packed = 54 [packed=true]; + repeated uint32 F_Uint32_repeated_packed = 55 [packed=true]; + repeated uint64 F_Uint64_repeated_packed = 56 [packed=true]; + repeated float F_Float_repeated_packed = 57 [packed=true]; + repeated double F_Double_repeated_packed = 58 [packed=true]; + repeated sint32 F_Sint32_repeated_packed = 502 [packed=true]; + repeated sint64 F_Sint64_repeated_packed = 503 [packed=true]; + + // Required, repeated, and optional groups. + required group RequiredGroup = 70 { + required string RequiredField = 71; + }; + + repeated group RepeatedGroup = 80 { + required string RequiredField = 81; + }; + + optional group OptionalGroup = 90 { + required string RequiredField = 91; + }; +} + +// For testing a group containing a required field. +message GoTestRequiredGroupField { + required group Group = 1 { + required int32 Field = 2; + }; +} + +// For testing skipping of unrecognized fields. +// Numbers are all big, larger than tag numbers in GoTestField, +// the message used in the corresponding test. +message GoSkipTest { + required int32 skip_int32 = 11; + required fixed32 skip_fixed32 = 12; + required fixed64 skip_fixed64 = 13; + required string skip_string = 14; + required group SkipGroup = 15 { + required int32 group_int32 = 16; + required string group_string = 17; + } +} + +// For testing packed/non-packed decoder switching. +// A serialized instance of one should be deserializable as the other. +message NonPackedTest { + repeated int32 a = 1; +} + +message PackedTest { + repeated int32 b = 1 [packed=true]; +} + +message MaxTag { + // Maximum possible tag number. + optional string last_field = 536870911; +} + +message OldMessage { + message Nested { + optional string name = 1; + } + optional Nested nested = 1; + + optional int32 num = 2; +} + +// NewMessage is wire compatible with OldMessage; +// imagine it as a future version. +message NewMessage { + message Nested { + optional string name = 1; + optional string food_group = 2; + } + optional Nested nested = 1; + + // This is an int32 in OldMessage. + optional int64 num = 2; +} + +// Smaller tests for ASCII formatting. + +message InnerMessage { + required string host = 1; + optional int32 port = 2 [default=4000]; + optional bool connected = 3; +} + +message OtherMessage { + optional int64 key = 1; + optional bytes value = 2; + optional float weight = 3; + optional InnerMessage inner = 4; + + extensions 100 to max; +} + +message RequiredInnerMessage { + required InnerMessage leo_finally_won_an_oscar = 1; +} + +message MyMessage { + required int32 count = 1; + optional string name = 2; + optional string quote = 3; + repeated string pet = 4; + optional InnerMessage inner = 5; + repeated OtherMessage others = 6; + optional RequiredInnerMessage we_must_go_deeper = 13; + repeated InnerMessage rep_inner = 12; + + enum Color { + RED = 0; + GREEN = 1; + BLUE = 2; + }; + optional Color bikeshed = 7; + + optional group SomeGroup = 8 { + optional int32 group_field = 9; + } + + // This field becomes [][]byte in the generated code. + repeated bytes rep_bytes = 10; + + optional double bigfloat = 11; + + extensions 100 to max; +} + +message Ext { + extend MyMessage { + optional Ext more = 103; + optional string text = 104; + optional int32 number = 105; + } + + optional string data = 1; +} + +extend MyMessage { + repeated string greeting = 106; +} + +message ComplexExtension { + optional int32 first = 1; + optional int32 second = 2; + repeated int32 third = 3; +} + +extend OtherMessage { + optional ComplexExtension complex = 200; + repeated ComplexExtension r_complex = 201; +} + +message DefaultsMessage { + enum DefaultsEnum { + ZERO = 0; + ONE = 1; + TWO = 2; + }; + extensions 100 to max; +} + +extend DefaultsMessage { + optional double no_default_double = 101; + optional float no_default_float = 102; + optional int32 no_default_int32 = 103; + optional int64 no_default_int64 = 104; + optional uint32 no_default_uint32 = 105; + optional uint64 no_default_uint64 = 106; + optional sint32 no_default_sint32 = 107; + optional sint64 no_default_sint64 = 108; + optional fixed32 no_default_fixed32 = 109; + optional fixed64 no_default_fixed64 = 110; + optional sfixed32 no_default_sfixed32 = 111; + optional sfixed64 no_default_sfixed64 = 112; + optional bool no_default_bool = 113; + optional string no_default_string = 114; + optional bytes no_default_bytes = 115; + optional DefaultsMessage.DefaultsEnum no_default_enum = 116; + + optional double default_double = 201 [default = 3.1415]; + optional float default_float = 202 [default = 3.14]; + optional int32 default_int32 = 203 [default = 42]; + optional int64 default_int64 = 204 [default = 43]; + optional uint32 default_uint32 = 205 [default = 44]; + optional uint64 default_uint64 = 206 [default = 45]; + optional sint32 default_sint32 = 207 [default = 46]; + optional sint64 default_sint64 = 208 [default = 47]; + optional fixed32 default_fixed32 = 209 [default = 48]; + optional fixed64 default_fixed64 = 210 [default = 49]; + optional sfixed32 default_sfixed32 = 211 [default = 50]; + optional sfixed64 default_sfixed64 = 212 [default = 51]; + optional bool default_bool = 213 [default = true]; + optional string default_string = 214 [default = "Hello, string"]; + optional bytes default_bytes = 215 [default = "Hello, bytes"]; + optional DefaultsMessage.DefaultsEnum default_enum = 216 [default = ONE]; +} + +message MyMessageSet { + option message_set_wire_format = true; + extensions 100 to max; +} + +message Empty { +} + +extend MyMessageSet { + optional Empty x201 = 201; + optional Empty x202 = 202; + optional Empty x203 = 203; + optional Empty x204 = 204; + optional Empty x205 = 205; + optional Empty x206 = 206; + optional Empty x207 = 207; + optional Empty x208 = 208; + optional Empty x209 = 209; + optional Empty x210 = 210; + optional Empty x211 = 211; + optional Empty x212 = 212; + optional Empty x213 = 213; + optional Empty x214 = 214; + optional Empty x215 = 215; + optional Empty x216 = 216; + optional Empty x217 = 217; + optional Empty x218 = 218; + optional Empty x219 = 219; + optional Empty x220 = 220; + optional Empty x221 = 221; + optional Empty x222 = 222; + optional Empty x223 = 223; + optional Empty x224 = 224; + optional Empty x225 = 225; + optional Empty x226 = 226; + optional Empty x227 = 227; + optional Empty x228 = 228; + optional Empty x229 = 229; + optional Empty x230 = 230; + optional Empty x231 = 231; + optional Empty x232 = 232; + optional Empty x233 = 233; + optional Empty x234 = 234; + optional Empty x235 = 235; + optional Empty x236 = 236; + optional Empty x237 = 237; + optional Empty x238 = 238; + optional Empty x239 = 239; + optional Empty x240 = 240; + optional Empty x241 = 241; + optional Empty x242 = 242; + optional Empty x243 = 243; + optional Empty x244 = 244; + optional Empty x245 = 245; + optional Empty x246 = 246; + optional Empty x247 = 247; + optional Empty x248 = 248; + optional Empty x249 = 249; + optional Empty x250 = 250; +} + +message MessageList { + repeated group Message = 1 { + required string name = 2; + required int32 count = 3; + } +} + +message Strings { + optional string string_field = 1; + optional bytes bytes_field = 2; +} + +message Defaults { + enum Color { + RED = 0; + GREEN = 1; + BLUE = 2; + } + + // Default-valued fields of all basic types. + // Same as GoTest, but copied here to make testing easier. + optional bool F_Bool = 1 [default=true]; + optional int32 F_Int32 = 2 [default=32]; + optional int64 F_Int64 = 3 [default=64]; + optional fixed32 F_Fixed32 = 4 [default=320]; + optional fixed64 F_Fixed64 = 5 [default=640]; + optional uint32 F_Uint32 = 6 [default=3200]; + optional uint64 F_Uint64 = 7 [default=6400]; + optional float F_Float = 8 [default=314159.]; + optional double F_Double = 9 [default=271828.]; + optional string F_String = 10 [default="hello, \"world!\"\n"]; + optional bytes F_Bytes = 11 [default="Bignose"]; + optional sint32 F_Sint32 = 12 [default=-32]; + optional sint64 F_Sint64 = 13 [default=-64]; + optional Color F_Enum = 14 [default=GREEN]; + + // More fields with crazy defaults. + optional float F_Pinf = 15 [default=inf]; + optional float F_Ninf = 16 [default=-inf]; + optional float F_Nan = 17 [default=nan]; + + // Sub-message. + optional SubDefaults sub = 18; + + // Redundant but explicit defaults. + optional string str_zero = 19 [default=""]; +} + +message SubDefaults { + optional int64 n = 1 [default=7]; +} + +message RepeatedEnum { + enum Color { + RED = 1; + } + repeated Color color = 1; +} + +message MoreRepeated { + repeated bool bools = 1; + repeated bool bools_packed = 2 [packed=true]; + repeated int32 ints = 3; + repeated int32 ints_packed = 4 [packed=true]; + repeated int64 int64s_packed = 7 [packed=true]; + repeated string strings = 5; + repeated fixed32 fixeds = 6; +} + +// GroupOld and GroupNew have the same wire format. +// GroupNew has a new field inside a group. + +message GroupOld { + optional group G = 101 { + optional int32 x = 2; + } +} + +message GroupNew { + optional group G = 101 { + optional int32 x = 2; + optional int32 y = 3; + } +} + +message FloatingPoint { + required double f = 1; + optional bool exact = 2; +} + +message MessageWithMap { + map name_mapping = 1; + map msg_mapping = 2; + map byte_mapping = 3; + map str_to_str = 4; +} + +message Oneof { + oneof union { + bool F_Bool = 1; + int32 F_Int32 = 2; + int64 F_Int64 = 3; + fixed32 F_Fixed32 = 4; + fixed64 F_Fixed64 = 5; + uint32 F_Uint32 = 6; + uint64 F_Uint64 = 7; + float F_Float = 8; + double F_Double = 9; + string F_String = 10; + bytes F_Bytes = 11; + sint32 F_Sint32 = 12; + sint64 F_Sint64 = 13; + MyMessage.Color F_Enum = 14; + GoTestField F_Message = 15; + group F_Group = 16 { + optional int32 x = 17; + } + int32 F_Largest_Tag = 536870911; + } + + oneof tormato { + int32 value = 100; + } +} + +message Communique { + optional bool make_me_cry = 1; + + // This is a oneof, called "union". + oneof union { + int32 number = 5; + string name = 6; + bytes data = 7; + double temp_c = 8; + MyMessage.Color col = 9; + Strings msg = 10; + } +} diff --git a/vendor/github.com/gogo/protobuf/proto/text_parser_test.go b/vendor/github.com/gogo/protobuf/proto/text_parser_test.go new file mode 100644 index 000000000..9a3a447ce --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/text_parser_test.go @@ -0,0 +1,673 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "math" + "reflect" + "testing" + + . "github.com/gogo/protobuf/proto" + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + . "github.com/gogo/protobuf/proto/testdata" +) + +type UnmarshalTextTest struct { + in string + err string // if "", no error expected + out *MyMessage +} + +func buildExtStructTest(text string) UnmarshalTextTest { + msg := &MyMessage{ + Count: Int32(42), + } + SetExtension(msg, E_Ext_More, &Ext{ + Data: String("Hello, world!"), + }) + return UnmarshalTextTest{in: text, out: msg} +} + +func buildExtDataTest(text string) UnmarshalTextTest { + msg := &MyMessage{ + Count: Int32(42), + } + SetExtension(msg, E_Ext_Text, String("Hello, world!")) + SetExtension(msg, E_Ext_Number, Int32(1729)) + return UnmarshalTextTest{in: text, out: msg} +} + +func buildExtRepStringTest(text string) UnmarshalTextTest { + msg := &MyMessage{ + Count: Int32(42), + } + if err := SetExtension(msg, E_Greeting, []string{"bula", "hola"}); err != nil { + panic(err) + } + return UnmarshalTextTest{in: text, out: msg} +} + +var unMarshalTextTests = []UnmarshalTextTest{ + // Basic + { + in: " count:42\n name:\"Dave\" ", + out: &MyMessage{ + Count: Int32(42), + Name: String("Dave"), + }, + }, + + // Empty quoted string + { + in: `count:42 name:""`, + out: &MyMessage{ + Count: Int32(42), + Name: String(""), + }, + }, + + // Quoted string concatenation with double quotes + { + in: `count:42 name: "My name is "` + "\n" + `"elsewhere"`, + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + + // Quoted string concatenation with single quotes + { + in: "count:42 name: 'My name is '\n'elsewhere'", + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + + // Quoted string concatenations with mixed quotes + { + in: "count:42 name: 'My name is '\n\"elsewhere\"", + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + { + in: "count:42 name: \"My name is \"\n'elsewhere'", + out: &MyMessage{ + Count: Int32(42), + Name: String("My name is elsewhere"), + }, + }, + + // Quoted string with escaped apostrophe + { + in: `count:42 name: "HOLIDAY - New Year\'s Day"`, + out: &MyMessage{ + Count: Int32(42), + Name: String("HOLIDAY - New Year's Day"), + }, + }, + + // Quoted string with single quote + { + in: `count:42 name: 'Roger "The Ramster" Ramjet'`, + out: &MyMessage{ + Count: Int32(42), + Name: String(`Roger "The Ramster" Ramjet`), + }, + }, + + // Quoted string with all the accepted special characters from the C++ test + { + in: `count:42 name: ` + "\"\\\"A string with \\' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"", + out: &MyMessage{ + Count: Int32(42), + Name: String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces"), + }, + }, + + // Quoted string with quoted backslash + { + in: `count:42 name: "\\'xyz"`, + out: &MyMessage{ + Count: Int32(42), + Name: String(`\'xyz`), + }, + }, + + // Quoted string with UTF-8 bytes. + { + in: "count:42 name: '\303\277\302\201\xAB'", + out: &MyMessage{ + Count: Int32(42), + Name: String("\303\277\302\201\xAB"), + }, + }, + + // Bad quoted string + { + in: `inner: < host: "\0" >` + "\n", + err: `line 1.15: invalid quoted string "\0": \0 requires 2 following digits`, + }, + + // Number too large for int64 + { + in: "count: 1 others { key: 123456789012345678901 }", + err: "line 1.23: invalid int64: 123456789012345678901", + }, + + // Number too large for int32 + { + in: "count: 1234567890123", + err: "line 1.7: invalid int32: 1234567890123", + }, + + // Number in hexadecimal + { + in: "count: 0x2beef", + out: &MyMessage{ + Count: Int32(0x2beef), + }, + }, + + // Number in octal + { + in: "count: 024601", + out: &MyMessage{ + Count: Int32(024601), + }, + }, + + // Floating point number with "f" suffix + { + in: "count: 4 others:< weight: 17.0f >", + out: &MyMessage{ + Count: Int32(4), + Others: []*OtherMessage{ + { + Weight: Float32(17), + }, + }, + }, + }, + + // Floating point positive infinity + { + in: "count: 4 bigfloat: inf", + out: &MyMessage{ + Count: Int32(4), + Bigfloat: Float64(math.Inf(1)), + }, + }, + + // Floating point negative infinity + { + in: "count: 4 bigfloat: -inf", + out: &MyMessage{ + Count: Int32(4), + Bigfloat: Float64(math.Inf(-1)), + }, + }, + + // Number too large for float32 + { + in: "others:< weight: 12345678901234567890123456789012345678901234567890 >", + err: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890", + }, + + // Number posing as a quoted string + { + in: `inner: < host: 12 >` + "\n", + err: `line 1.15: invalid string: 12`, + }, + + // Quoted string posing as int32 + { + in: `count: "12"`, + err: `line 1.7: invalid int32: "12"`, + }, + + // Quoted string posing a float32 + { + in: `others:< weight: "17.4" >`, + err: `line 1.17: invalid float32: "17.4"`, + }, + + // Enum + { + in: `count:42 bikeshed: BLUE`, + out: &MyMessage{ + Count: Int32(42), + Bikeshed: MyMessage_BLUE.Enum(), + }, + }, + + // Repeated field + { + in: `count:42 pet: "horsey" pet:"bunny"`, + out: &MyMessage{ + Count: Int32(42), + Pet: []string{"horsey", "bunny"}, + }, + }, + + // Repeated field with list notation + { + in: `count:42 pet: ["horsey", "bunny"]`, + out: &MyMessage{ + Count: Int32(42), + Pet: []string{"horsey", "bunny"}, + }, + }, + + // Repeated message with/without colon and <>/{} + { + in: `count:42 others:{} others{} others:<> others:{}`, + out: &MyMessage{ + Count: Int32(42), + Others: []*OtherMessage{ + {}, + {}, + {}, + {}, + }, + }, + }, + + // Missing colon for inner message + { + in: `count:42 inner < host: "cauchy.syd" >`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("cauchy.syd"), + }, + }, + }, + + // Missing colon for string field + { + in: `name "Dave"`, + err: `line 1.5: expected ':', found "\"Dave\""`, + }, + + // Missing colon for int32 field + { + in: `count 42`, + err: `line 1.6: expected ':', found "42"`, + }, + + // Missing required field + { + in: `name: "Pawel"`, + err: `proto: required field "testdata.MyMessage.count" not set`, + out: &MyMessage{ + Name: String("Pawel"), + }, + }, + + // Missing required field in a required submessage + { + in: `count: 42 we_must_go_deeper < leo_finally_won_an_oscar <> >`, + err: `proto: required field "testdata.InnerMessage.host" not set`, + out: &MyMessage{ + Count: Int32(42), + WeMustGoDeeper: &RequiredInnerMessage{LeoFinallyWonAnOscar: &InnerMessage{}}, + }, + }, + + // Repeated non-repeated field + { + in: `name: "Rob" name: "Russ"`, + err: `line 1.12: non-repeated field "name" was repeated`, + }, + + // Group + { + in: `count: 17 SomeGroup { group_field: 12 }`, + out: &MyMessage{ + Count: Int32(17), + Somegroup: &MyMessage_SomeGroup{ + GroupField: Int32(12), + }, + }, + }, + + // Semicolon between fields + { + in: `count:3;name:"Calvin"`, + out: &MyMessage{ + Count: Int32(3), + Name: String("Calvin"), + }, + }, + // Comma between fields + { + in: `count:4,name:"Ezekiel"`, + out: &MyMessage{ + Count: Int32(4), + Name: String("Ezekiel"), + }, + }, + + // Boolean false + { + in: `count:42 inner { host: "example.com" connected: false }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean true + { + in: `count:42 inner { host: "example.com" connected: true }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + // Boolean 0 + { + in: `count:42 inner { host: "example.com" connected: 0 }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean 1 + { + in: `count:42 inner { host: "example.com" connected: 1 }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + // Boolean f + { + in: `count:42 inner { host: "example.com" connected: f }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean t + { + in: `count:42 inner { host: "example.com" connected: t }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + // Boolean False + { + in: `count:42 inner { host: "example.com" connected: False }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(false), + }, + }, + }, + // Boolean True + { + in: `count:42 inner { host: "example.com" connected: True }`, + out: &MyMessage{ + Count: Int32(42), + Inner: &InnerMessage{ + Host: String("example.com"), + Connected: Bool(true), + }, + }, + }, + + // Extension + buildExtStructTest(`count: 42 [testdata.Ext.more]:`), + buildExtStructTest(`count: 42 [testdata.Ext.more] {data:"Hello, world!"}`), + buildExtDataTest(`count: 42 [testdata.Ext.text]:"Hello, world!" [testdata.Ext.number]:1729`), + buildExtRepStringTest(`count: 42 [testdata.greeting]:"bula" [testdata.greeting]:"hola"`), + + // Big all-in-one + { + in: "count:42 # Meaning\n" + + `name:"Dave" ` + + `quote:"\"I didn't want to go.\"" ` + + `pet:"bunny" ` + + `pet:"kitty" ` + + `pet:"horsey" ` + + `inner:<` + + ` host:"footrest.syd" ` + + ` port:7001 ` + + ` connected:true ` + + `> ` + + `others:<` + + ` key:3735928559 ` + + ` value:"\x01A\a\f" ` + + `> ` + + `others:<` + + " weight:58.9 # Atomic weight of Co\n" + + ` inner:<` + + ` host:"lesha.mtv" ` + + ` port:8002 ` + + ` >` + + `>`, + out: &MyMessage{ + Count: Int32(42), + Name: String("Dave"), + Quote: String(`"I didn't want to go."`), + Pet: []string{"bunny", "kitty", "horsey"}, + Inner: &InnerMessage{ + Host: String("footrest.syd"), + Port: Int32(7001), + Connected: Bool(true), + }, + Others: []*OtherMessage{ + { + Key: Int64(3735928559), + Value: []byte{0x1, 'A', '\a', '\f'}, + }, + { + Weight: Float32(58.9), + Inner: &InnerMessage{ + Host: String("lesha.mtv"), + Port: Int32(8002), + }, + }, + }, + }, + }, +} + +func TestUnmarshalText(t *testing.T) { + for i, test := range unMarshalTextTests { + pb := new(MyMessage) + err := UnmarshalText(test.in, pb) + if test.err == "" { + // We don't expect failure. + if err != nil { + t.Errorf("Test %d: Unexpected error: %v", i, err) + } else if !reflect.DeepEqual(pb, test.out) { + t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v", + i, pb, test.out) + } + } else { + // We do expect failure. + if err == nil { + t.Errorf("Test %d: Didn't get expected error: %v", i, test.err) + } else if err.Error() != test.err { + t.Errorf("Test %d: Incorrect error.\nHave: %v\nWant: %v", + i, err.Error(), test.err) + } else if _, ok := err.(*RequiredNotSetError); ok && test.out != nil && !reflect.DeepEqual(pb, test.out) { + t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v", + i, pb, test.out) + } + } + } +} + +func TestUnmarshalTextCustomMessage(t *testing.T) { + msg := &textMessage{} + if err := UnmarshalText("custom", msg); err != nil { + t.Errorf("Unexpected error from custom unmarshal: %v", err) + } + if UnmarshalText("not custom", msg) == nil { + t.Errorf("Didn't get expected error from custom unmarshal") + } +} + +// Regression test; this caused a panic. +func TestRepeatedEnum(t *testing.T) { + pb := new(RepeatedEnum) + if err := UnmarshalText("color: RED", pb); err != nil { + t.Fatal(err) + } + exp := &RepeatedEnum{ + Color: []RepeatedEnum_Color{RepeatedEnum_RED}, + } + if !Equal(pb, exp) { + t.Errorf("Incorrect populated \nHave: %v\nWant: %v", pb, exp) + } +} + +func TestProto3TextParsing(t *testing.T) { + m := new(proto3pb.Message) + const in = `name: "Wallace" true_scotsman: true` + want := &proto3pb.Message{ + Name: "Wallace", + TrueScotsman: true, + } + if err := UnmarshalText(in, m); err != nil { + t.Fatal(err) + } + if !Equal(m, want) { + t.Errorf("\n got %v\nwant %v", m, want) + } +} + +func TestMapParsing(t *testing.T) { + m := new(MessageWithMap) + const in = `name_mapping: name_mapping:` + + `msg_mapping:,>` + // separating commas are okay + `msg_mapping>` + // no colon after "value" + `msg_mapping:>` + // omitted key + `msg_mapping:` + // omitted value + `byte_mapping:` + + `byte_mapping:<>` // omitted key and value + want := &MessageWithMap{ + NameMapping: map[int32]string{ + 1: "Beatles", + 1234: "Feist", + }, + MsgMapping: map[int64]*FloatingPoint{ + -4: {F: Float64(2.0)}, + -2: {F: Float64(4.0)}, + 0: {F: Float64(5.0)}, + 1: nil, + }, + ByteMapping: map[bool][]byte{ + false: nil, + true: []byte("so be it"), + }, + } + if err := UnmarshalText(in, m); err != nil { + t.Fatal(err) + } + if !Equal(m, want) { + t.Errorf("\n got %v\nwant %v", m, want) + } +} + +func TestOneofParsing(t *testing.T) { + const in = `name:"Shrek"` + m := new(Communique) + want := &Communique{Union: &Communique_Name{Name: "Shrek"}} + if err := UnmarshalText(in, m); err != nil { + t.Fatal(err) + } + if !Equal(m, want) { + t.Errorf("\n got %v\nwant %v", m, want) + } + + const inOverwrite = `name:"Shrek" number:42` + m = new(Communique) + testErr := "line 1.13: field 'number' would overwrite already parsed oneof 'Union'" + if err := UnmarshalText(inOverwrite, m); err == nil { + t.Errorf("TestOneofParsing: Didn't get expected error: %v", testErr) + } else if err.Error() != testErr { + t.Errorf("TestOneofParsing: Incorrect error.\nHave: %v\nWant: %v", + err.Error(), testErr) + } + +} + +var benchInput string + +func init() { + benchInput = "count: 4\n" + for i := 0; i < 1000; i++ { + benchInput += "pet: \"fido\"\n" + } + + // Check it is valid input. + pb := new(MyMessage) + err := UnmarshalText(benchInput, pb) + if err != nil { + panic("Bad benchmark input: " + err.Error()) + } +} + +func BenchmarkUnmarshalText(b *testing.B) { + pb := new(MyMessage) + for i := 0; i < b.N; i++ { + UnmarshalText(benchInput, pb) + } + b.SetBytes(int64(len(benchInput))) +} diff --git a/vendor/github.com/gogo/protobuf/proto/text_test.go b/vendor/github.com/gogo/protobuf/proto/text_test.go new file mode 100644 index 000000000..27df6cb9b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/proto/text_test.go @@ -0,0 +1,474 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto_test + +import ( + "bytes" + "errors" + "io/ioutil" + "math" + "strings" + "testing" + + "github.com/gogo/protobuf/proto" + + proto3pb "github.com/gogo/protobuf/proto/proto3_proto" + pb "github.com/gogo/protobuf/proto/testdata" +) + +// textMessage implements the methods that allow it to marshal and unmarshal +// itself as text. +type textMessage struct { +} + +func (*textMessage) MarshalText() ([]byte, error) { + return []byte("custom"), nil +} + +func (*textMessage) UnmarshalText(bytes []byte) error { + if string(bytes) != "custom" { + return errors.New("expected 'custom'") + } + return nil +} + +func (*textMessage) Reset() {} +func (*textMessage) String() string { return "" } +func (*textMessage) ProtoMessage() {} + +func newTestMessage() *pb.MyMessage { + msg := &pb.MyMessage{ + Count: proto.Int32(42), + Name: proto.String("Dave"), + Quote: proto.String(`"I didn't want to go."`), + Pet: []string{"bunny", "kitty", "horsey"}, + Inner: &pb.InnerMessage{ + Host: proto.String("footrest.syd"), + Port: proto.Int32(7001), + Connected: proto.Bool(true), + }, + Others: []*pb.OtherMessage{ + { + Key: proto.Int64(0xdeadbeef), + Value: []byte{1, 65, 7, 12}, + }, + { + Weight: proto.Float32(6.022), + Inner: &pb.InnerMessage{ + Host: proto.String("lesha.mtv"), + Port: proto.Int32(8002), + }, + }, + }, + Bikeshed: pb.MyMessage_BLUE.Enum(), + Somegroup: &pb.MyMessage_SomeGroup{ + GroupField: proto.Int32(8), + }, + // One normally wouldn't do this. + // This is an undeclared tag 13, as a varint (wire type 0) with value 4. + XXX_unrecognized: []byte{13<<3 | 0, 4}, + } + ext := &pb.Ext{ + Data: proto.String("Big gobs for big rats"), + } + if err := proto.SetExtension(msg, pb.E_Ext_More, ext); err != nil { + panic(err) + } + greetings := []string{"adg", "easy", "cow"} + if err := proto.SetExtension(msg, pb.E_Greeting, greetings); err != nil { + panic(err) + } + + // Add an unknown extension. We marshal a pb.Ext, and fake the ID. + b, err := proto.Marshal(&pb.Ext{Data: proto.String("3G skiing")}) + if err != nil { + panic(err) + } + b = append(proto.EncodeVarint(201<<3|proto.WireBytes), b...) + proto.SetRawExtension(msg, 201, b) + + // Extensions can be plain fields, too, so let's test that. + b = append(proto.EncodeVarint(202<<3|proto.WireVarint), 19) + proto.SetRawExtension(msg, 202, b) + + return msg +} + +const text = `count: 42 +name: "Dave" +quote: "\"I didn't want to go.\"" +pet: "bunny" +pet: "kitty" +pet: "horsey" +inner: < + host: "footrest.syd" + port: 7001 + connected: true +> +others: < + key: 3735928559 + value: "\001A\007\014" +> +others: < + weight: 6.022 + inner: < + host: "lesha.mtv" + port: 8002 + > +> +bikeshed: BLUE +SomeGroup { + group_field: 8 +} +/* 2 unknown bytes */ +13: 4 +[testdata.Ext.more]: < + data: "Big gobs for big rats" +> +[testdata.greeting]: "adg" +[testdata.greeting]: "easy" +[testdata.greeting]: "cow" +/* 13 unknown bytes */ +201: "\t3G skiing" +/* 3 unknown bytes */ +202: 19 +` + +func TestMarshalText(t *testing.T) { + buf := new(bytes.Buffer) + if err := proto.MarshalText(buf, newTestMessage()); err != nil { + t.Fatalf("proto.MarshalText: %v", err) + } + s := buf.String() + if s != text { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, text) + } +} + +func TestMarshalTextCustomMessage(t *testing.T) { + buf := new(bytes.Buffer) + if err := proto.MarshalText(buf, &textMessage{}); err != nil { + t.Fatalf("proto.MarshalText: %v", err) + } + s := buf.String() + if s != "custom" { + t.Errorf("Got %q, expected %q", s, "custom") + } +} +func TestMarshalTextNil(t *testing.T) { + want := "" + tests := []proto.Message{nil, (*pb.MyMessage)(nil)} + for i, test := range tests { + buf := new(bytes.Buffer) + if err := proto.MarshalText(buf, test); err != nil { + t.Fatal(err) + } + if got := buf.String(); got != want { + t.Errorf("%d: got %q want %q", i, got, want) + } + } +} + +func TestMarshalTextUnknownEnum(t *testing.T) { + // The Color enum only specifies values 0-2. + m := &pb.MyMessage{Bikeshed: pb.MyMessage_Color(3).Enum()} + got := m.String() + const want = `bikeshed:3 ` + if got != want { + t.Errorf("\n got %q\nwant %q", got, want) + } +} + +func TestTextOneof(t *testing.T) { + tests := []struct { + m proto.Message + want string + }{ + // zero message + {&pb.Communique{}, ``}, + // scalar field + {&pb.Communique{Union: &pb.Communique_Number{Number: 4}}, `number:4`}, + // message field + {&pb.Communique{Union: &pb.Communique_Msg{ + Msg: &pb.Strings{StringField: proto.String("why hello!")}, + }}, `msg:`}, + // bad oneof (should not panic) + {&pb.Communique{Union: &pb.Communique_Msg{Msg: nil}}, `msg:/* nil */`}, + } + for _, test := range tests { + got := strings.TrimSpace(test.m.String()) + if got != test.want { + t.Errorf("\n got %s\nwant %s", got, test.want) + } + } +} + +func BenchmarkMarshalTextBuffered(b *testing.B) { + buf := new(bytes.Buffer) + m := newTestMessage() + for i := 0; i < b.N; i++ { + buf.Reset() + proto.MarshalText(buf, m) + } +} + +func BenchmarkMarshalTextUnbuffered(b *testing.B) { + w := ioutil.Discard + m := newTestMessage() + for i := 0; i < b.N; i++ { + proto.MarshalText(w, m) + } +} + +func compact(src string) string { + // s/[ \n]+/ /g; s/ $//; + dst := make([]byte, len(src)) + space, comment := false, false + j := 0 + for i := 0; i < len(src); i++ { + if strings.HasPrefix(src[i:], "/*") { + comment = true + i++ + continue + } + if comment && strings.HasPrefix(src[i:], "*/") { + comment = false + i++ + continue + } + if comment { + continue + } + c := src[i] + if c == ' ' || c == '\n' { + space = true + continue + } + if j > 0 && (dst[j-1] == ':' || dst[j-1] == '<' || dst[j-1] == '{') { + space = false + } + if c == '{' { + space = false + } + if space { + dst[j] = ' ' + j++ + space = false + } + dst[j] = c + j++ + } + if space { + dst[j] = ' ' + j++ + } + return string(dst[0:j]) +} + +var compactText = compact(text) + +func TestCompactText(t *testing.T) { + s := proto.CompactTextString(newTestMessage()) + if s != compactText { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v\n===\n", s, compactText) + } +} + +func TestStringEscaping(t *testing.T) { + testCases := []struct { + in *pb.Strings + out string + }{ + { + // Test data from C++ test (TextFormatTest.StringEscape). + // Single divergence: we don't escape apostrophes. + &pb.Strings{StringField: proto.String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces")}, + "string_field: \"\\\"A string with ' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"\n", + }, + { + // Test data from the same C++ test. + &pb.Strings{StringField: proto.String("\350\260\267\346\255\214")}, + "string_field: \"\\350\\260\\267\\346\\255\\214\"\n", + }, + { + // Some UTF-8. + &pb.Strings{StringField: proto.String("\x00\x01\xff\x81")}, + `string_field: "\000\001\377\201"` + "\n", + }, + } + + for i, tc := range testCases { + var buf bytes.Buffer + if err := proto.MarshalText(&buf, tc.in); err != nil { + t.Errorf("proto.MarsalText: %v", err) + continue + } + s := buf.String() + if s != tc.out { + t.Errorf("#%d: Got:\n%s\nExpected:\n%s\n", i, s, tc.out) + continue + } + + // Check round-trip. + pbStrings := new(pb.Strings) + if err := proto.UnmarshalText(s, pbStrings); err != nil { + t.Errorf("#%d: UnmarshalText: %v", i, err) + continue + } + if !proto.Equal(pbStrings, tc.in) { + t.Errorf("#%d: Round-trip failed:\nstart: %v\n end: %v", i, tc.in, pbStrings) + } + } +} + +// A limitedWriter accepts some output before it fails. +// This is a proxy for something like a nearly-full or imminently-failing disk, +// or a network connection that is about to die. +type limitedWriter struct { + b bytes.Buffer + limit int +} + +var outOfSpace = errors.New("proto: insufficient space") + +func (w *limitedWriter) Write(p []byte) (n int, err error) { + var avail = w.limit - w.b.Len() + if avail <= 0 { + return 0, outOfSpace + } + if len(p) <= avail { + return w.b.Write(p) + } + n, _ = w.b.Write(p[:avail]) + return n, outOfSpace +} + +func TestMarshalTextFailing(t *testing.T) { + // Try lots of different sizes to exercise more error code-paths. + for lim := 0; lim < len(text); lim++ { + buf := new(limitedWriter) + buf.limit = lim + err := proto.MarshalText(buf, newTestMessage()) + // We expect a certain error, but also some partial results in the buffer. + if err != outOfSpace { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", err, outOfSpace) + } + s := buf.b.String() + x := text[:buf.limit] + if s != x { + t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, x) + } + } +} + +func TestFloats(t *testing.T) { + tests := []struct { + f float64 + want string + }{ + {0, "0"}, + {4.7, "4.7"}, + {math.Inf(1), "inf"}, + {math.Inf(-1), "-inf"}, + {math.NaN(), "nan"}, + } + for _, test := range tests { + msg := &pb.FloatingPoint{F: &test.f} + got := strings.TrimSpace(msg.String()) + want := `f:` + test.want + if got != want { + t.Errorf("f=%f: got %q, want %q", test.f, got, want) + } + } +} + +func TestRepeatedNilText(t *testing.T) { + m := &pb.MessageList{ + Message: []*pb.MessageList_Message{ + nil, + { + Name: proto.String("Horse"), + }, + nil, + }, + } + want := `Message +Message { + name: "Horse" +} +Message +` + if s := proto.MarshalTextString(m); s != want { + t.Errorf(" got: %s\nwant: %s", s, want) + } +} + +func TestProto3Text(t *testing.T) { + tests := []struct { + m proto.Message + want string + }{ + // zero message + {&proto3pb.Message{}, ``}, + // zero message except for an empty byte slice + {&proto3pb.Message{Data: []byte{}}, ``}, + // trivial case + {&proto3pb.Message{Name: "Rob", HeightInCm: 175}, `name:"Rob" height_in_cm:175`}, + // empty map + {&pb.MessageWithMap{}, ``}, + // non-empty map; map format is the same as a repeated struct, + // and they are sorted by key (numerically for numeric keys). + { + &pb.MessageWithMap{NameMapping: map[int32]string{ + -1: "Negatory", + 7: "Lucky", + 1234: "Feist", + 6345789: "Otis", + }}, + `name_mapping: ` + + `name_mapping: ` + + `name_mapping: ` + + `name_mapping:`, + }, + // map with nil value; not well-defined, but we shouldn't crash + { + &pb.MessageWithMap{MsgMapping: map[int64]*pb.FloatingPoint{7: nil}}, + `msg_mapping:`, + }, + } + for _, test := range tests { + got := strings.TrimSpace(test.m.String()) + if got != test.want { + t.Errorf("\n got %s\nwant %s", got, test.want) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/protobuf/Makefile b/vendor/github.com/gogo/protobuf/protobuf/Makefile new file mode 100644 index 000000000..6bc7e3ad4 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/Makefile @@ -0,0 +1,35 @@ +URL="https://raw.githubusercontent.com/google/protobuf/master/src/google/protobuf/" + +update: + go install github.com/gogo/protobuf/gogoreplace + + (cd ./google/protobuf && rm descriptor.proto; wget ${URL}/descriptor.proto) + # gogoprotobuf requires users to import gogo.proto which imports descriptor.proto + # The descriptor.proto is only compatible with proto3 just because of the reserved keyword. + # We remove it to stay compatible with previous versions of protoc before proto3 + gogoreplace 'reserved 38;' '//reserved 38;' ./google/protobuf/descriptor.proto + gogoreplace 'reserved 8;' '//reserved 8;' ./google/protobuf/descriptor.proto + gogoreplace 'reserved 9;' '//reserved 9;' ./google/protobuf/descriptor.proto + gogoreplace 'reserved 4;' '//reserved 4;' ./google/protobuf/descriptor.proto + gogoreplace 'reserved 5;' '//reserved 5;' ./google/protobuf/descriptor.proto + gogoreplace 'option go_package = "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor";' 'option go_package = "descriptor";' ./google/protobuf/descriptor.proto + + (cd ./google/protobuf/compiler && rm plugin.proto; wget ${URL}/compiler/plugin.proto) + gogoreplace 'option go_package = "github.com/golang/protobuf/protoc-gen-go/plugin;plugin_go";' 'option go_package = "plugin_go";' ./google/protobuf/compiler/plugin.proto + + (cd ./google/protobuf && rm any.proto; wget ${URL}/any.proto) + gogoreplace 'go_package = "github.com/golang/protobuf/ptypes/any";' 'go_package = "types";' ./google/protobuf/any.proto + (cd ./google/protobuf && rm empty.proto; wget ${URL}/empty.proto) + gogoreplace 'go_package = "github.com/golang/protobuf/ptypes/empty";' 'go_package = "types";' ./google/protobuf/empty.proto + (cd ./google/protobuf && rm timestamp.proto; wget ${URL}/timestamp.proto) + gogoreplace 'go_package = "github.com/golang/protobuf/ptypes/timestamp";' 'go_package = "types";' ./google/protobuf/timestamp.proto + (cd ./google/protobuf && rm duration.proto; wget ${URL}/duration.proto) + gogoreplace 'go_package = "github.com/golang/protobuf/ptypes/duration";' 'go_package = "types";' ./google/protobuf/duration.proto + (cd ./google/protobuf && rm struct.proto; wget ${URL}/struct.proto) + gogoreplace 'go_package = "github.com/golang/protobuf/ptypes/struct;structpb";' 'go_package = "types";' ./google/protobuf/struct.proto + (cd ./google/protobuf && rm wrappers.proto; wget ${URL}/wrappers.proto) + gogoreplace 'go_package = "github.com/golang/protobuf/ptypes/wrappers";' 'go_package = "types";' ./google/protobuf/wrappers.proto + (cd ./google/protobuf && rm field_mask.proto; wget ${URL}/field_mask.proto) + gogoreplace 'option go_package = "google.golang.org/genproto/protobuf/field_mask;field_mask";' 'option go_package = "types";' ./google/protobuf/field_mask.proto + + diff --git a/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/any.proto b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/any.proto new file mode 100644 index 000000000..d9519f5cf --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/any.proto @@ -0,0 +1,149 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "types"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "AnyProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// `Any` contains an arbitrary serialized protocol buffer message along with a +// URL that describes the type of the serialized message. +// +// Protobuf library provides support to pack/unpack Any values in the form +// of utility functions or additional generated methods of the Any type. +// +// Example 1: Pack and unpack a message in C++. +// +// Foo foo = ...; +// Any any; +// any.PackFrom(foo); +// ... +// if (any.UnpackTo(&foo)) { +// ... +// } +// +// Example 2: Pack and unpack a message in Java. +// +// Foo foo = ...; +// Any any = Any.pack(foo); +// ... +// if (any.is(Foo.class)) { +// foo = any.unpack(Foo.class); +// } +// +// Example 3: Pack and unpack a message in Python. +// +// foo = Foo(...) +// any = Any() +// any.Pack(foo) +// ... +// if any.Is(Foo.DESCRIPTOR): +// any.Unpack(foo) +// ... +// +// Example 4: Pack and unpack a message in Go +// +// foo := &pb.Foo{...} +// any, err := ptypes.MarshalAny(foo) +// ... +// foo := &pb.Foo{} +// if err := ptypes.UnmarshalAny(any, foo); err != nil { +// ... +// } +// +// The pack methods provided by protobuf library will by default use +// 'type.googleapis.com/full.type.name' as the type URL and the unpack +// methods only use the fully qualified type name after the last '/' +// in the type URL, for example "foo.bar.com/x/y.z" will yield type +// name "y.z". +// +// +// JSON +// ==== +// The JSON representation of an `Any` value uses the regular +// representation of the deserialized, embedded message, with an +// additional field `@type` which contains the type URL. Example: +// +// package google.profile; +// message Person { +// string first_name = 1; +// string last_name = 2; +// } +// +// { +// "@type": "type.googleapis.com/google.profile.Person", +// "firstName": , +// "lastName": +// } +// +// If the embedded message type is well-known and has a custom JSON +// representation, that representation will be embedded adding a field +// `value` which holds the custom JSON in addition to the `@type` +// field. Example (for message [google.protobuf.Duration][]): +// +// { +// "@type": "type.googleapis.com/google.protobuf.Duration", +// "value": "1.212s" +// } +// +message Any { + // A URL/resource name whose content describes the type of the + // serialized protocol buffer message. + // + // For URLs which use the scheme `http`, `https`, or no scheme, the + // following restrictions and interpretations apply: + // + // * If no scheme is provided, `https` is assumed. + // * The last segment of the URL's path must represent the fully + // qualified name of the type (as in `path/google.protobuf.Duration`). + // The name should be in a canonical form (e.g., leading "." is + // not accepted). + // * An HTTP GET on the URL must yield a [google.protobuf.Type][] + // value in binary format, or produce an error. + // * Applications are allowed to cache lookup results based on the + // URL, or have them precompiled into a binary to avoid any + // lookup. Therefore, binary compatibility needs to be preserved + // on changes to types. (Use versioned type names to manage + // breaking changes.) + // + // Schemes other than `http`, `https` (or the empty scheme) might be + // used with implementation specific semantics. + // + string type_url = 1; + + // Must be a valid serialized protocol buffer of the above specified type. + bytes value = 2; +} diff --git a/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/compiler/plugin.proto b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/compiler/plugin.proto new file mode 100644 index 000000000..e85c852fc --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/compiler/plugin.proto @@ -0,0 +1,167 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// +// WARNING: The plugin interface is currently EXPERIMENTAL and is subject to +// change. +// +// protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is +// just a program that reads a CodeGeneratorRequest from stdin and writes a +// CodeGeneratorResponse to stdout. +// +// Plugins written using C++ can use google/protobuf/compiler/plugin.h instead +// of dealing with the raw protocol defined here. +// +// A plugin executable needs only to be placed somewhere in the path. The +// plugin should be named "protoc-gen-$NAME", and will then be used when the +// flag "--${NAME}_out" is passed to protoc. + +syntax = "proto2"; +package google.protobuf.compiler; +option java_package = "com.google.protobuf.compiler"; +option java_outer_classname = "PluginProtos"; + +option go_package = "plugin_go"; + +import "google/protobuf/descriptor.proto"; + +// The version number of protocol compiler. +message Version { + optional int32 major = 1; + optional int32 minor = 2; + optional int32 patch = 3; + // A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should + // be empty for mainline stable releases. + optional string suffix = 4; +} + +// An encoded CodeGeneratorRequest is written to the plugin's stdin. +message CodeGeneratorRequest { + // The .proto files that were explicitly listed on the command-line. The + // code generator should generate code only for these files. Each file's + // descriptor will be included in proto_file, below. + repeated string file_to_generate = 1; + + // The generator parameter passed on the command-line. + optional string parameter = 2; + + // FileDescriptorProtos for all files in files_to_generate and everything + // they import. The files will appear in topological order, so each file + // appears before any file that imports it. + // + // protoc guarantees that all proto_files will be written after + // the fields above, even though this is not technically guaranteed by the + // protobuf wire format. This theoretically could allow a plugin to stream + // in the FileDescriptorProtos and handle them one by one rather than read + // the entire set into memory at once. However, as of this writing, this + // is not similarly optimized on protoc's end -- it will store all fields in + // memory at once before sending them to the plugin. + // + // Type names of fields and extensions in the FileDescriptorProto are always + // fully qualified. + repeated FileDescriptorProto proto_file = 15; + + // The version number of protocol compiler. + optional Version compiler_version = 3; + +} + +// The plugin writes an encoded CodeGeneratorResponse to stdout. +message CodeGeneratorResponse { + // Error message. If non-empty, code generation failed. The plugin process + // should exit with status code zero even if it reports an error in this way. + // + // This should be used to indicate errors in .proto files which prevent the + // code generator from generating correct code. Errors which indicate a + // problem in protoc itself -- such as the input CodeGeneratorRequest being + // unparseable -- should be reported by writing a message to stderr and + // exiting with a non-zero status code. + optional string error = 1; + + // Represents a single generated file. + message File { + // The file name, relative to the output directory. The name must not + // contain "." or ".." components and must be relative, not be absolute (so, + // the file cannot lie outside the output directory). "/" must be used as + // the path separator, not "\". + // + // If the name is omitted, the content will be appended to the previous + // file. This allows the generator to break large files into small chunks, + // and allows the generated text to be streamed back to protoc so that large + // files need not reside completely in memory at one time. Note that as of + // this writing protoc does not optimize for this -- it will read the entire + // CodeGeneratorResponse before writing files to disk. + optional string name = 1; + + // If non-empty, indicates that the named file should already exist, and the + // content here is to be inserted into that file at a defined insertion + // point. This feature allows a code generator to extend the output + // produced by another code generator. The original generator may provide + // insertion points by placing special annotations in the file that look + // like: + // @@protoc_insertion_point(NAME) + // The annotation can have arbitrary text before and after it on the line, + // which allows it to be placed in a comment. NAME should be replaced with + // an identifier naming the point -- this is what other generators will use + // as the insertion_point. Code inserted at this point will be placed + // immediately above the line containing the insertion point (thus multiple + // insertions to the same point will come out in the order they were added). + // The double-@ is intended to make it unlikely that the generated code + // could contain things that look like insertion points by accident. + // + // For example, the C++ code generator places the following line in the + // .pb.h files that it generates: + // // @@protoc_insertion_point(namespace_scope) + // This line appears within the scope of the file's package namespace, but + // outside of any particular class. Another plugin can then specify the + // insertion_point "namespace_scope" to generate additional classes or + // other declarations that should be placed in this scope. + // + // Note that if the line containing the insertion point begins with + // whitespace, the same whitespace will be added to every line of the + // inserted text. This is useful for languages like Python, where + // indentation matters. In these languages, the insertion point comment + // should be indented the same amount as any inserted code will need to be + // in order to work correctly in that context. + // + // The code generator that generates the initial file and the one which + // inserts into it must both run as part of a single invocation of protoc. + // Code generators are executed in the order in which they appear on the + // command line. + // + // If |insertion_point| is present, |name| must also be present. + optional string insertion_point = 2; + + // The file contents. + optional string content = 15; + } + repeated File file = 15; +} diff --git a/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/descriptor.proto b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/descriptor.proto new file mode 100644 index 000000000..411cd9de2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/descriptor.proto @@ -0,0 +1,870 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// The messages in this file describe the definitions found in .proto files. +// A valid .proto file can be translated directly to a FileDescriptorProto +// without any other information (e.g. without reading its imports). + + +syntax = "proto2"; + +package google.protobuf; +option go_package = "descriptor"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "DescriptorProtos"; +option csharp_namespace = "Google.Protobuf.Reflection"; +option objc_class_prefix = "GPB"; +option cc_enable_arenas = true; + +// descriptor.proto must be optimized for speed because reflection-based +// algorithms don't work during bootstrapping. +option optimize_for = SPEED; + +// The protocol compiler can output a FileDescriptorSet containing the .proto +// files it parses. +message FileDescriptorSet { + repeated FileDescriptorProto file = 1; +} + +// Describes a complete .proto file. +message FileDescriptorProto { + optional string name = 1; // file name, relative to root of source tree + optional string package = 2; // e.g. "foo", "foo.bar", etc. + + // Names of files imported by this file. + repeated string dependency = 3; + // Indexes of the public imported files in the dependency list above. + repeated int32 public_dependency = 10; + // Indexes of the weak imported files in the dependency list. + // For Google-internal migration only. Do not use. + repeated int32 weak_dependency = 11; + + // All top-level definitions in this file. + repeated DescriptorProto message_type = 4; + repeated EnumDescriptorProto enum_type = 5; + repeated ServiceDescriptorProto service = 6; + repeated FieldDescriptorProto extension = 7; + + optional FileOptions options = 8; + + // This field contains optional information about the original source code. + // You may safely remove this entire field without harming runtime + // functionality of the descriptors -- the information is needed only by + // development tools. + optional SourceCodeInfo source_code_info = 9; + + // The syntax of the proto file. + // The supported values are "proto2" and "proto3". + optional string syntax = 12; +} + +// Describes a message type. +message DescriptorProto { + optional string name = 1; + + repeated FieldDescriptorProto field = 2; + repeated FieldDescriptorProto extension = 6; + + repeated DescriptorProto nested_type = 3; + repeated EnumDescriptorProto enum_type = 4; + + message ExtensionRange { + optional int32 start = 1; + optional int32 end = 2; + + optional ExtensionRangeOptions options = 3; + } + repeated ExtensionRange extension_range = 5; + + repeated OneofDescriptorProto oneof_decl = 8; + + optional MessageOptions options = 7; + + // Range of reserved tag numbers. Reserved tag numbers may not be used by + // fields or extension ranges in the same message. Reserved ranges may + // not overlap. + message ReservedRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Exclusive. + } + repeated ReservedRange reserved_range = 9; + // Reserved field names, which may not be used by fields in the same message. + // A given name may only be reserved once. + repeated string reserved_name = 10; +} + +message ExtensionRangeOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +// Describes a field within a message. +message FieldDescriptorProto { + enum Type { + // 0 is reserved for errors. + // Order is weird for historical reasons. + TYPE_DOUBLE = 1; + TYPE_FLOAT = 2; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + // negative values are likely. + TYPE_INT64 = 3; + TYPE_UINT64 = 4; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + // negative values are likely. + TYPE_INT32 = 5; + TYPE_FIXED64 = 6; + TYPE_FIXED32 = 7; + TYPE_BOOL = 8; + TYPE_STRING = 9; + // Tag-delimited aggregate. + // Group type is deprecated and not supported in proto3. However, Proto3 + // implementations should still be able to parse the group wire format and + // treat group fields as unknown fields. + TYPE_GROUP = 10; + TYPE_MESSAGE = 11; // Length-delimited aggregate. + + // New in version 2. + TYPE_BYTES = 12; + TYPE_UINT32 = 13; + TYPE_ENUM = 14; + TYPE_SFIXED32 = 15; + TYPE_SFIXED64 = 16; + TYPE_SINT32 = 17; // Uses ZigZag encoding. + TYPE_SINT64 = 18; // Uses ZigZag encoding. + }; + + enum Label { + // 0 is reserved for errors + LABEL_OPTIONAL = 1; + LABEL_REQUIRED = 2; + LABEL_REPEATED = 3; + }; + + optional string name = 1; + optional int32 number = 3; + optional Label label = 4; + + // If type_name is set, this need not be set. If both this and type_name + // are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. + optional Type type = 5; + + // For message and enum types, this is the name of the type. If the name + // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping + // rules are used to find the type (i.e. first the nested types within this + // message are searched, then within the parent, on up to the root + // namespace). + optional string type_name = 6; + + // For extensions, this is the name of the type being extended. It is + // resolved in the same manner as type_name. + optional string extendee = 2; + + // For numeric types, contains the original text representation of the value. + // For booleans, "true" or "false". + // For strings, contains the default text contents (not escaped in any way). + // For bytes, contains the C escaped value. All bytes >= 128 are escaped. + // TODO(kenton): Base-64 encode? + optional string default_value = 7; + + // If set, gives the index of a oneof in the containing type's oneof_decl + // list. This field is a member of that oneof. + optional int32 oneof_index = 9; + + // JSON name of this field. The value is set by protocol compiler. If the + // user has set a "json_name" option on this field, that option's value + // will be used. Otherwise, it's deduced from the field's name by converting + // it to camelCase. + optional string json_name = 10; + + optional FieldOptions options = 8; +} + +// Describes a oneof. +message OneofDescriptorProto { + optional string name = 1; + optional OneofOptions options = 2; +} + +// Describes an enum type. +message EnumDescriptorProto { + optional string name = 1; + + repeated EnumValueDescriptorProto value = 2; + + optional EnumOptions options = 3; + + // Range of reserved numeric values. Reserved values may not be used by + // entries in the same enum. Reserved ranges may not overlap. + // + // Note that this is distinct from DescriptorProto.ReservedRange in that it + // is inclusive such that it can appropriately represent the entire int32 + // domain. + message EnumReservedRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Inclusive. + } + + // Range of reserved numeric values. Reserved numeric values may not be used + // by enum values in the same enum declaration. Reserved ranges may not + // overlap. + repeated EnumReservedRange reserved_range = 4; + + // Reserved enum value names, which may not be reused. A given name may only + // be reserved once. + repeated string reserved_name = 5; +} + +// Describes a value within an enum. +message EnumValueDescriptorProto { + optional string name = 1; + optional int32 number = 2; + + optional EnumValueOptions options = 3; +} + +// Describes a service. +message ServiceDescriptorProto { + optional string name = 1; + repeated MethodDescriptorProto method = 2; + + optional ServiceOptions options = 3; +} + +// Describes a method of a service. +message MethodDescriptorProto { + optional string name = 1; + + // Input and output type names. These are resolved in the same way as + // FieldDescriptorProto.type_name, but must refer to a message type. + optional string input_type = 2; + optional string output_type = 3; + + optional MethodOptions options = 4; + + // Identifies if client streams multiple client messages + optional bool client_streaming = 5 [default=false]; + // Identifies if server streams multiple server messages + optional bool server_streaming = 6 [default=false]; +} + + +// =================================================================== +// Options + +// Each of the definitions above may have "options" attached. These are +// just annotations which may cause code to be generated slightly differently +// or may contain hints for code that manipulates protocol messages. +// +// Clients may define custom options as extensions of the *Options messages. +// These extensions may not yet be known at parsing time, so the parser cannot +// store the values in them. Instead it stores them in a field in the *Options +// message called uninterpreted_option. This field must have the same name +// across all *Options messages. We then use this field to populate the +// extensions when we build a descriptor, at which point all protos have been +// parsed and so all extensions are known. +// +// Extension numbers for custom options may be chosen as follows: +// * For options which will only be used within a single application or +// organization, or for experimental options, use field numbers 50000 +// through 99999. It is up to you to ensure that you do not use the +// same number for multiple options. +// * For options which will be published and used publicly by multiple +// independent entities, e-mail protobuf-global-extension-registry@google.com +// to reserve extension numbers. Simply provide your project name (e.g. +// Objective-C plugin) and your project website (if available) -- there's no +// need to explain how you intend to use them. Usually you only need one +// extension number. You can declare multiple options with only one extension +// number by putting them in a sub-message. See the Custom Options section of +// the docs for examples: +// https://developers.google.com/protocol-buffers/docs/proto#options +// If this turns out to be popular, a web service will be set up +// to automatically assign option numbers. + + +message FileOptions { + + // Sets the Java package where classes generated from this .proto will be + // placed. By default, the proto package is used, but this is often + // inappropriate because proto packages do not normally start with backwards + // domain names. + optional string java_package = 1; + + + // If set, all the classes from the .proto file are wrapped in a single + // outer class with the given name. This applies to both Proto1 + // (equivalent to the old "--one_java_file" option) and Proto2 (where + // a .proto always translates to a single class, but you may want to + // explicitly choose the class name). + optional string java_outer_classname = 8; + + // If set true, then the Java code generator will generate a separate .java + // file for each top-level message, enum, and service defined in the .proto + // file. Thus, these types will *not* be nested inside the outer class + // named by java_outer_classname. However, the outer class will still be + // generated to contain the file's getDescriptor() method as well as any + // top-level extensions defined in the file. + optional bool java_multiple_files = 10 [default=false]; + + // This option does nothing. + optional bool java_generate_equals_and_hash = 20 [deprecated=true]; + + // If set true, then the Java2 code generator will generate code that + // throws an exception whenever an attempt is made to assign a non-UTF-8 + // byte sequence to a string field. + // Message reflection will do the same. + // However, an extension field still accepts non-UTF-8 byte sequences. + // This option has no effect on when used with the lite runtime. + optional bool java_string_check_utf8 = 27 [default=false]; + + + // Generated classes can be optimized for speed or code size. + enum OptimizeMode { + SPEED = 1; // Generate complete code for parsing, serialization, + // etc. + CODE_SIZE = 2; // Use ReflectionOps to implement these methods. + LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. + } + optional OptimizeMode optimize_for = 9 [default=SPEED]; + + // Sets the Go package where structs generated from this .proto will be + // placed. If omitted, the Go package will be derived from the following: + // - The basename of the package import path, if provided. + // - Otherwise, the package statement in the .proto file, if present. + // - Otherwise, the basename of the .proto file, without extension. + optional string go_package = 11; + + + + // Should generic services be generated in each language? "Generic" services + // are not specific to any particular RPC system. They are generated by the + // main code generators in each language (without additional plugins). + // Generic services were the only kind of service generation supported by + // early versions of google.protobuf. + // + // Generic services are now considered deprecated in favor of using plugins + // that generate code specific to your particular RPC system. Therefore, + // these default to false. Old code which depends on generic services should + // explicitly set them to true. + optional bool cc_generic_services = 16 [default=false]; + optional bool java_generic_services = 17 [default=false]; + optional bool py_generic_services = 18 [default=false]; + optional bool php_generic_services = 42 [default=false]; + + // Is this file deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for everything in the file, or it will be completely ignored; in the very + // least, this is a formalization for deprecating files. + optional bool deprecated = 23 [default=false]; + + // Enables the use of arenas for the proto messages in this file. This applies + // only to generated classes for C++. + optional bool cc_enable_arenas = 31 [default=false]; + + + // Sets the objective c class prefix which is prepended to all objective c + // generated classes from this .proto. There is no default. + optional string objc_class_prefix = 36; + + // Namespace for generated classes; defaults to the package. + optional string csharp_namespace = 37; + + // By default Swift generators will take the proto package and CamelCase it + // replacing '.' with underscore and use that to prefix the types/symbols + // defined. When this options is provided, they will use this value instead + // to prefix the types/symbols defined. + optional string swift_prefix = 39; + + // Sets the php class prefix which is prepended to all php generated classes + // from this .proto. Default is empty. + optional string php_class_prefix = 40; + + // Use this option to change the namespace of php generated classes. Default + // is empty. When this option is empty, the package name will be used for + // determining the namespace. + optional string php_namespace = 41; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; + + //reserved 38; +} + +message MessageOptions { + // Set true to use the old proto1 MessageSet wire format for extensions. + // This is provided for backwards-compatibility with the MessageSet wire + // format. You should not use this for any other reason: It's less + // efficient, has fewer features, and is more complicated. + // + // The message must be defined exactly as follows: + // message Foo { + // option message_set_wire_format = true; + // extensions 4 to max; + // } + // Note that the message cannot have any defined fields; MessageSets only + // have extensions. + // + // All extensions of your type must be singular messages; e.g. they cannot + // be int32s, enums, or repeated messages. + // + // Because this is an option, the above two restrictions are not enforced by + // the protocol compiler. + optional bool message_set_wire_format = 1 [default=false]; + + // Disables the generation of the standard "descriptor()" accessor, which can + // conflict with a field of the same name. This is meant to make migration + // from proto1 easier; new code should avoid fields named "descriptor". + optional bool no_standard_descriptor_accessor = 2 [default=false]; + + // Is this message deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the message, or it will be completely ignored; in the very least, + // this is a formalization for deprecating messages. + optional bool deprecated = 3 [default=false]; + + // Whether the message is an automatically generated map entry type for the + // maps field. + // + // For maps fields: + // map map_field = 1; + // The parsed descriptor looks like: + // message MapFieldEntry { + // option map_entry = true; + // optional KeyType key = 1; + // optional ValueType value = 2; + // } + // repeated MapFieldEntry map_field = 1; + // + // Implementations may choose not to generate the map_entry=true message, but + // use a native map in the target language to hold the keys and values. + // The reflection APIs in such implementions still need to work as + // if the field is a repeated message field. + // + // NOTE: Do not set the option in .proto files. Always use the maps syntax + // instead. The option should only be implicitly set by the proto compiler + // parser. + optional bool map_entry = 7; + + //reserved 8; // javalite_serializable + //reserved 9; // javanano_as_lite + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message FieldOptions { + // The ctype option instructs the C++ code generator to use a different + // representation of the field than it normally would. See the specific + // options below. This option is not yet implemented in the open source + // release -- sorry, we'll try to include it in a future version! + optional CType ctype = 1 [default = STRING]; + enum CType { + // Default mode. + STRING = 0; + + CORD = 1; + + STRING_PIECE = 2; + } + // The packed option can be enabled for repeated primitive fields to enable + // a more efficient representation on the wire. Rather than repeatedly + // writing the tag and type for each element, the entire array is encoded as + // a single length-delimited blob. In proto3, only explicit setting it to + // false will avoid using packed encoding. + optional bool packed = 2; + + // The jstype option determines the JavaScript type used for values of the + // field. The option is permitted only for 64 bit integral and fixed types + // (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING + // is represented as JavaScript string, which avoids loss of precision that + // can happen when a large value is converted to a floating point JavaScript. + // Specifying JS_NUMBER for the jstype causes the generated JavaScript code to + // use the JavaScript "number" type. The behavior of the default option + // JS_NORMAL is implementation dependent. + // + // This option is an enum to permit additional types to be added, e.g. + // goog.math.Integer. + optional JSType jstype = 6 [default = JS_NORMAL]; + enum JSType { + // Use the default type. + JS_NORMAL = 0; + + // Use JavaScript strings. + JS_STRING = 1; + + // Use JavaScript numbers. + JS_NUMBER = 2; + } + + // Should this field be parsed lazily? Lazy applies only to message-type + // fields. It means that when the outer message is initially parsed, the + // inner message's contents will not be parsed but instead stored in encoded + // form. The inner message will actually be parsed when it is first accessed. + // + // This is only a hint. Implementations are free to choose whether to use + // eager or lazy parsing regardless of the value of this option. However, + // setting this option true suggests that the protocol author believes that + // using lazy parsing on this field is worth the additional bookkeeping + // overhead typically needed to implement it. + // + // This option does not affect the public interface of any generated code; + // all method signatures remain the same. Furthermore, thread-safety of the + // interface is not affected by this option; const methods remain safe to + // call from multiple threads concurrently, while non-const methods continue + // to require exclusive access. + // + // + // Note that implementations may choose not to check required fields within + // a lazy sub-message. That is, calling IsInitialized() on the outer message + // may return true even if the inner message has missing required fields. + // This is necessary because otherwise the inner message would have to be + // parsed in order to perform the check, defeating the purpose of lazy + // parsing. An implementation which chooses not to check required fields + // must be consistent about it. That is, for any particular sub-message, the + // implementation must either *always* check its required fields, or *never* + // check its required fields, regardless of whether or not the message has + // been parsed. + optional bool lazy = 5 [default=false]; + + // Is this field deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for accessors, or it will be completely ignored; in the very least, this + // is a formalization for deprecating fields. + optional bool deprecated = 3 [default=false]; + + // For Google-internal migration only. Do not use. + optional bool weak = 10 [default=false]; + + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; + + //reserved 4; // removed jtype +} + +message OneofOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumOptions { + + // Set this option to true to allow mapping different tag names to the same + // value. + optional bool allow_alias = 2; + + // Is this enum deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the enum, or it will be completely ignored; in the very least, this + // is a formalization for deprecating enums. + optional bool deprecated = 3 [default=false]; + + //reserved 5; // javanano_as_lite + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumValueOptions { + // Is this enum value deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the enum value, or it will be completely ignored; in the very least, + // this is a formalization for deprecating enum values. + optional bool deprecated = 1 [default=false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message ServiceOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // Is this service deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the service, or it will be completely ignored; in the very least, + // this is a formalization for deprecating services. + optional bool deprecated = 33 [default=false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message MethodOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // Is this method deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the method, or it will be completely ignored; in the very least, + // this is a formalization for deprecating methods. + optional bool deprecated = 33 [default=false]; + + // Is this method side-effect-free (or safe in HTTP parlance), or idempotent, + // or neither? HTTP based RPC implementation may choose GET verb for safe + // methods, and PUT verb for idempotent methods instead of the default POST. + enum IdempotencyLevel { + IDEMPOTENCY_UNKNOWN = 0; + NO_SIDE_EFFECTS = 1; // implies idempotent + IDEMPOTENT = 2; // idempotent, but may have side effects + } + optional IdempotencyLevel idempotency_level = + 34 [default=IDEMPOTENCY_UNKNOWN]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + + +// A message representing a option the parser does not recognize. This only +// appears in options protos created by the compiler::Parser class. +// DescriptorPool resolves these when building Descriptor objects. Therefore, +// options protos in descriptor objects (e.g. returned by Descriptor::options(), +// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions +// in them. +message UninterpretedOption { + // The name of the uninterpreted option. Each string represents a segment in + // a dot-separated name. is_extension is true iff a segment represents an + // extension (denoted with parentheses in options specs in .proto files). + // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents + // "foo.(bar.baz).qux". + message NamePart { + required string name_part = 1; + required bool is_extension = 2; + } + repeated NamePart name = 2; + + // The value of the uninterpreted option, in whatever type the tokenizer + // identified it as during parsing. Exactly one of these should be set. + optional string identifier_value = 3; + optional uint64 positive_int_value = 4; + optional int64 negative_int_value = 5; + optional double double_value = 6; + optional bytes string_value = 7; + optional string aggregate_value = 8; +} + +// =================================================================== +// Optional source code info + +// Encapsulates information about the original source file from which a +// FileDescriptorProto was generated. +message SourceCodeInfo { + // A Location identifies a piece of source code in a .proto file which + // corresponds to a particular definition. This information is intended + // to be useful to IDEs, code indexers, documentation generators, and similar + // tools. + // + // For example, say we have a file like: + // message Foo { + // optional string foo = 1; + // } + // Let's look at just the field definition: + // optional string foo = 1; + // ^ ^^ ^^ ^ ^^^ + // a bc de f ghi + // We have the following locations: + // span path represents + // [a,i) [ 4, 0, 2, 0 ] The whole field definition. + // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + // [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + // [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + // + // Notes: + // - A location may refer to a repeated field itself (i.e. not to any + // particular index within it). This is used whenever a set of elements are + // logically enclosed in a single code segment. For example, an entire + // extend block (possibly containing multiple extension definitions) will + // have an outer location whose path refers to the "extensions" repeated + // field without an index. + // - Multiple locations may have the same path. This happens when a single + // logical declaration is spread out across multiple places. The most + // obvious example is the "extend" block again -- there may be multiple + // extend blocks in the same scope, each of which will have the same path. + // - A location's span is not always a subset of its parent's span. For + // example, the "extendee" of an extension declaration appears at the + // beginning of the "extend" block and is shared by all extensions within + // the block. + // - Just because a location's span is a subset of some other location's span + // does not mean that it is a descendent. For example, a "group" defines + // both a type and a field in a single declaration. Thus, the locations + // corresponding to the type and field and their components will overlap. + // - Code which tries to interpret locations should probably be designed to + // ignore those that it doesn't understand, as more types of locations could + // be recorded in the future. + repeated Location location = 1; + message Location { + // Identifies which part of the FileDescriptorProto was defined at this + // location. + // + // Each element is a field number or an index. They form a path from + // the root FileDescriptorProto to the place where the definition. For + // example, this path: + // [ 4, 3, 2, 7, 1 ] + // refers to: + // file.message_type(3) // 4, 3 + // .field(7) // 2, 7 + // .name() // 1 + // This is because FileDescriptorProto.message_type has field number 4: + // repeated DescriptorProto message_type = 4; + // and DescriptorProto.field has field number 2: + // repeated FieldDescriptorProto field = 2; + // and FieldDescriptorProto.name has field number 1: + // optional string name = 1; + // + // Thus, the above path gives the location of a field name. If we removed + // the last element: + // [ 4, 3, 2, 7 ] + // this path refers to the whole field declaration (from the beginning + // of the label to the terminating semicolon). + repeated int32 path = 1 [packed=true]; + + // Always has exactly three or four elements: start line, start column, + // end line (optional, otherwise assumed same as start line), end column. + // These are packed into a single field for efficiency. Note that line + // and column numbers are zero-based -- typically you will want to add + // 1 to each before displaying to a user. + repeated int32 span = 2 [packed=true]; + + // If this SourceCodeInfo represents a complete declaration, these are any + // comments appearing before and after the declaration which appear to be + // attached to the declaration. + // + // A series of line comments appearing on consecutive lines, with no other + // tokens appearing on those lines, will be treated as a single comment. + // + // leading_detached_comments will keep paragraphs of comments that appear + // before (but not connected to) the current element. Each paragraph, + // separated by empty lines, will be one comment element in the repeated + // field. + // + // Only the comment content is provided; comment markers (e.g. //) are + // stripped out. For block comments, leading whitespace and an asterisk + // will be stripped from the beginning of each line other than the first. + // Newlines are included in the output. + // + // Examples: + // + // optional int32 foo = 1; // Comment attached to foo. + // // Comment attached to bar. + // optional int32 bar = 2; + // + // optional string baz = 3; + // // Comment attached to baz. + // // Another line attached to baz. + // + // // Comment attached to qux. + // // + // // Another line attached to qux. + // optional double qux = 4; + // + // // Detached comment for corge. This is not leading or trailing comments + // // to qux or corge because there are blank lines separating it from + // // both. + // + // // Detached comment for corge paragraph 2. + // + // optional string corge = 5; + // /* Block comment attached + // * to corge. Leading asterisks + // * will be removed. */ + // /* Block comment attached to + // * grault. */ + // optional int32 grault = 6; + // + // // ignored detached comments. + optional string leading_comments = 3; + optional string trailing_comments = 4; + repeated string leading_detached_comments = 6; + } +} + +// Describes the relationship between generated code and its original source +// file. A GeneratedCodeInfo message is associated with only one generated +// source file, but may contain references to different source .proto files. +message GeneratedCodeInfo { + // An Annotation connects some span of text in generated code to an element + // of its generating .proto file. + repeated Annotation annotation = 1; + message Annotation { + // Identifies the element in the original source .proto file. This field + // is formatted the same as SourceCodeInfo.Location.path. + repeated int32 path = 1 [packed=true]; + + // Identifies the filesystem path to the original source .proto. + optional string source_file = 2; + + // Identifies the starting offset in bytes in the generated code + // that relates to the identified object. + optional int32 begin = 3; + + // Identifies the ending offset in bytes in the generated code that + // relates to the identified offset. The end offset should be one past + // the last relevant byte (so the length of the text = end - begin). + optional int32 end = 4; + } +} diff --git a/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/duration.proto b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/duration.proto new file mode 100644 index 000000000..8bbaa8b62 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/duration.proto @@ -0,0 +1,117 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "types"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "DurationProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// A Duration represents a signed, fixed-length span of time represented +// as a count of seconds and fractions of seconds at nanosecond +// resolution. It is independent of any calendar and concepts like "day" +// or "month". It is related to Timestamp in that the difference between +// two Timestamp values is a Duration and it can be added or subtracted +// from a Timestamp. Range is approximately +-10,000 years. +// +// # Examples +// +// Example 1: Compute Duration from two Timestamps in pseudo code. +// +// Timestamp start = ...; +// Timestamp end = ...; +// Duration duration = ...; +// +// duration.seconds = end.seconds - start.seconds; +// duration.nanos = end.nanos - start.nanos; +// +// if (duration.seconds < 0 && duration.nanos > 0) { +// duration.seconds += 1; +// duration.nanos -= 1000000000; +// } else if (durations.seconds > 0 && duration.nanos < 0) { +// duration.seconds -= 1; +// duration.nanos += 1000000000; +// } +// +// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. +// +// Timestamp start = ...; +// Duration duration = ...; +// Timestamp end = ...; +// +// end.seconds = start.seconds + duration.seconds; +// end.nanos = start.nanos + duration.nanos; +// +// if (end.nanos < 0) { +// end.seconds -= 1; +// end.nanos += 1000000000; +// } else if (end.nanos >= 1000000000) { +// end.seconds += 1; +// end.nanos -= 1000000000; +// } +// +// Example 3: Compute Duration from datetime.timedelta in Python. +// +// td = datetime.timedelta(days=3, minutes=10) +// duration = Duration() +// duration.FromTimedelta(td) +// +// # JSON Mapping +// +// In JSON format, the Duration type is encoded as a string rather than an +// object, where the string ends in the suffix "s" (indicating seconds) and +// is preceded by the number of seconds, with nanoseconds expressed as +// fractional seconds. For example, 3 seconds with 0 nanoseconds should be +// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should +// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 +// microsecond should be expressed in JSON format as "3.000001s". +// +// +message Duration { + + // Signed seconds of the span of time. Must be from -315,576,000,000 + // to +315,576,000,000 inclusive. Note: these bounds are computed from: + // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + int64 seconds = 1; + + // Signed fractions of a second at nanosecond resolution of the span + // of time. Durations less than one second are represented with a 0 + // `seconds` field and a positive or negative `nanos` field. For durations + // of one second or more, a non-zero value for the `nanos` field must be + // of the same sign as the `seconds` field. Must be from -999,999,999 + // to +999,999,999 inclusive. + int32 nanos = 2; +} diff --git a/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/empty.proto b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/empty.proto new file mode 100644 index 000000000..6057c8522 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/empty.proto @@ -0,0 +1,52 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "types"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "EmptyProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option cc_enable_arenas = true; + +// A generic empty message that you can re-use to avoid defining duplicated +// empty messages in your APIs. A typical example is to use it as the request +// or the response type of an API method. For instance: +// +// service Foo { +// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); +// } +// +// The JSON representation for `Empty` is empty JSON object `{}`. +message Empty {} diff --git a/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/field_mask.proto b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/field_mask.proto new file mode 100644 index 000000000..994af79f0 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/field_mask.proto @@ -0,0 +1,246 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "FieldMaskProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option go_package = "types"; + +// `FieldMask` represents a set of symbolic field paths, for example: +// +// paths: "f.a" +// paths: "f.b.d" +// +// Here `f` represents a field in some root message, `a` and `b` +// fields in the message found in `f`, and `d` a field found in the +// message in `f.b`. +// +// Field masks are used to specify a subset of fields that should be +// returned by a get operation or modified by an update operation. +// Field masks also have a custom JSON encoding (see below). +// +// # Field Masks in Projections +// +// When used in the context of a projection, a response message or +// sub-message is filtered by the API to only contain those fields as +// specified in the mask. For example, if the mask in the previous +// example is applied to a response message as follows: +// +// f { +// a : 22 +// b { +// d : 1 +// x : 2 +// } +// y : 13 +// } +// z: 8 +// +// The result will not contain specific values for fields x,y and z +// (their value will be set to the default, and omitted in proto text +// output): +// +// +// f { +// a : 22 +// b { +// d : 1 +// } +// } +// +// A repeated field is not allowed except at the last position of a +// paths string. +// +// If a FieldMask object is not present in a get operation, the +// operation applies to all fields (as if a FieldMask of all fields +// had been specified). +// +// Note that a field mask does not necessarily apply to the +// top-level response message. In case of a REST get operation, the +// field mask applies directly to the response, but in case of a REST +// list operation, the mask instead applies to each individual message +// in the returned resource list. In case of a REST custom method, +// other definitions may be used. Where the mask applies will be +// clearly documented together with its declaration in the API. In +// any case, the effect on the returned resource/resources is required +// behavior for APIs. +// +// # Field Masks in Update Operations +// +// A field mask in update operations specifies which fields of the +// targeted resource are going to be updated. The API is required +// to only change the values of the fields as specified in the mask +// and leave the others untouched. If a resource is passed in to +// describe the updated values, the API ignores the values of all +// fields not covered by the mask. +// +// If a repeated field is specified for an update operation, the existing +// repeated values in the target resource will be overwritten by the new values. +// Note that a repeated field is only allowed in the last position of a `paths` +// string. +// +// If a sub-message is specified in the last position of the field mask for an +// update operation, then the existing sub-message in the target resource is +// overwritten. Given the target message: +// +// f { +// b { +// d : 1 +// x : 2 +// } +// c : 1 +// } +// +// And an update message: +// +// f { +// b { +// d : 10 +// } +// } +// +// then if the field mask is: +// +// paths: "f.b" +// +// then the result will be: +// +// f { +// b { +// d : 10 +// } +// c : 1 +// } +// +// However, if the update mask was: +// +// paths: "f.b.d" +// +// then the result would be: +// +// f { +// b { +// d : 10 +// x : 2 +// } +// c : 1 +// } +// +// In order to reset a field's value to the default, the field must +// be in the mask and set to the default value in the provided resource. +// Hence, in order to reset all fields of a resource, provide a default +// instance of the resource and set all fields in the mask, or do +// not provide a mask as described below. +// +// If a field mask is not present on update, the operation applies to +// all fields (as if a field mask of all fields has been specified). +// Note that in the presence of schema evolution, this may mean that +// fields the client does not know and has therefore not filled into +// the request will be reset to their default. If this is unwanted +// behavior, a specific service may require a client to always specify +// a field mask, producing an error if not. +// +// As with get operations, the location of the resource which +// describes the updated values in the request message depends on the +// operation kind. In any case, the effect of the field mask is +// required to be honored by the API. +// +// ## Considerations for HTTP REST +// +// The HTTP kind of an update operation which uses a field mask must +// be set to PATCH instead of PUT in order to satisfy HTTP semantics +// (PUT must only be used for full updates). +// +// # JSON Encoding of Field Masks +// +// In JSON, a field mask is encoded as a single string where paths are +// separated by a comma. Fields name in each path are converted +// to/from lower-camel naming conventions. +// +// As an example, consider the following message declarations: +// +// message Profile { +// User user = 1; +// Photo photo = 2; +// } +// message User { +// string display_name = 1; +// string address = 2; +// } +// +// In proto a field mask for `Profile` may look as such: +// +// mask { +// paths: "user.display_name" +// paths: "photo" +// } +// +// In JSON, the same mask is represented as below: +// +// { +// mask: "user.displayName,photo" +// } +// +// # Field Masks and Oneof Fields +// +// Field masks treat fields in oneofs just as regular fields. Consider the +// following message: +// +// message SampleMessage { +// oneof test_oneof { +// string name = 4; +// SubMessage sub_message = 9; +// } +// } +// +// The field mask can be: +// +// mask { +// paths: "name" +// } +// +// Or: +// +// mask { +// paths: "sub_message" +// } +// +// Note that oneof type names ("test_oneof" in this case) cannot be used in +// paths. +message FieldMask { + // The set of field mask paths. + repeated string paths = 1; +} diff --git a/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/struct.proto b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/struct.proto new file mode 100644 index 000000000..4f78641fa --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/struct.proto @@ -0,0 +1,96 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "types"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "StructProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + + +// `Struct` represents a structured data value, consisting of fields +// which map to dynamically typed values. In some languages, `Struct` +// might be supported by a native representation. For example, in +// scripting languages like JS a struct is represented as an +// object. The details of that representation are described together +// with the proto support for the language. +// +// The JSON representation for `Struct` is JSON object. +message Struct { + // Unordered map of dynamically typed values. + map fields = 1; +} + +// `Value` represents a dynamically typed value which can be either +// null, a number, a string, a boolean, a recursive struct value, or a +// list of values. A producer of value is expected to set one of that +// variants, absence of any variant indicates an error. +// +// The JSON representation for `Value` is JSON value. +message Value { + // The kind of value. + oneof kind { + // Represents a null value. + NullValue null_value = 1; + // Represents a double value. + double number_value = 2; + // Represents a string value. + string string_value = 3; + // Represents a boolean value. + bool bool_value = 4; + // Represents a structured value. + Struct struct_value = 5; + // Represents a repeated `Value`. + ListValue list_value = 6; + } +} + +// `NullValue` is a singleton enumeration to represent the null value for the +// `Value` type union. +// +// The JSON representation for `NullValue` is JSON `null`. +enum NullValue { + // Null value. + NULL_VALUE = 0; +} + +// `ListValue` is a wrapper around a repeated field of values. +// +// The JSON representation for `ListValue` is JSON array. +message ListValue { + // Repeated field of dynamically typed values. + repeated Value values = 1; +} diff --git a/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/timestamp.proto b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/timestamp.proto new file mode 100644 index 000000000..4ba0b97b2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/timestamp.proto @@ -0,0 +1,133 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "types"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "TimestampProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// A Timestamp represents a point in time independent of any time zone +// or calendar, represented as seconds and fractions of seconds at +// nanosecond resolution in UTC Epoch time. It is encoded using the +// Proleptic Gregorian Calendar which extends the Gregorian calendar +// backwards to year one. It is encoded assuming all minutes are 60 +// seconds long, i.e. leap seconds are "smeared" so that no leap second +// table is needed for interpretation. Range is from +// 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. +// By restricting to that range, we ensure that we can convert to +// and from RFC 3339 date strings. +// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). +// +// # Examples +// +// Example 1: Compute Timestamp from POSIX `time()`. +// +// Timestamp timestamp; +// timestamp.set_seconds(time(NULL)); +// timestamp.set_nanos(0); +// +// Example 2: Compute Timestamp from POSIX `gettimeofday()`. +// +// struct timeval tv; +// gettimeofday(&tv, NULL); +// +// Timestamp timestamp; +// timestamp.set_seconds(tv.tv_sec); +// timestamp.set_nanos(tv.tv_usec * 1000); +// +// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. +// +// FILETIME ft; +// GetSystemTimeAsFileTime(&ft); +// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; +// +// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z +// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. +// Timestamp timestamp; +// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); +// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); +// +// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. +// +// long millis = System.currentTimeMillis(); +// +// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) +// .setNanos((int) ((millis % 1000) * 1000000)).build(); +// +// +// Example 5: Compute Timestamp from current time in Python. +// +// timestamp = Timestamp() +// timestamp.GetCurrentTime() +// +// # JSON Mapping +// +// In JSON format, the Timestamp type is encoded as a string in the +// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the +// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" +// where {year} is always expressed using four digits while {month}, {day}, +// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional +// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), +// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone +// is required, though only UTC (as indicated by "Z") is presently supported. +// +// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past +// 01:30 UTC on January 15, 2017. +// +// In JavaScript, one can convert a Date object to this format using the +// standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString] +// method. In Python, a standard `datetime.datetime` object can be converted +// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) +// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one +// can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( +// http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()) +// to obtain a formatter capable of generating timestamps in this format. +// +// +message Timestamp { + + // Represents seconds of UTC time since Unix epoch + // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + // 9999-12-31T23:59:59Z inclusive. + int64 seconds = 1; + + // Non-negative fractions of a second at nanosecond resolution. Negative + // second values with fractions must still have non-negative nanos values + // that count forward in time. Must be from 0 to 999,999,999 + // inclusive. + int32 nanos = 2; +} diff --git a/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/wrappers.proto b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/wrappers.proto new file mode 100644 index 000000000..c5632e5ca --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protobuf/google/protobuf/wrappers.proto @@ -0,0 +1,118 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Wrappers for primitive (non-message) types. These types are useful +// for embedding primitives in the `google.protobuf.Any` type and for places +// where we need to distinguish between the absence of a primitive +// typed field and its default value. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "types"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "WrappersProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// Wrapper message for `double`. +// +// The JSON representation for `DoubleValue` is JSON number. +message DoubleValue { + // The double value. + double value = 1; +} + +// Wrapper message for `float`. +// +// The JSON representation for `FloatValue` is JSON number. +message FloatValue { + // The float value. + float value = 1; +} + +// Wrapper message for `int64`. +// +// The JSON representation for `Int64Value` is JSON string. +message Int64Value { + // The int64 value. + int64 value = 1; +} + +// Wrapper message for `uint64`. +// +// The JSON representation for `UInt64Value` is JSON string. +message UInt64Value { + // The uint64 value. + uint64 value = 1; +} + +// Wrapper message for `int32`. +// +// The JSON representation for `Int32Value` is JSON number. +message Int32Value { + // The int32 value. + int32 value = 1; +} + +// Wrapper message for `uint32`. +// +// The JSON representation for `UInt32Value` is JSON number. +message UInt32Value { + // The uint32 value. + uint32 value = 1; +} + +// Wrapper message for `bool`. +// +// The JSON representation for `BoolValue` is JSON `true` and `false`. +message BoolValue { + // The bool value. + bool value = 1; +} + +// Wrapper message for `string`. +// +// The JSON representation for `StringValue` is JSON string. +message StringValue { + // The string value. + string value = 1; +} + +// Wrapper message for `bytes`. +// +// The JSON representation for `BytesValue` is JSON string. +message BytesValue { + // The bytes value. + bytes value = 1; +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/Makefile b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/Makefile new file mode 100644 index 000000000..a42cc3717 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/Makefile @@ -0,0 +1,33 @@ +# Go support for Protocol Buffers - Google's data interchange format +# +# Copyright 2010 The Go Authors. All rights reserved. +# https://github.com/golang/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +test: + cd testdata && make test diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/Makefile b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/Makefile new file mode 100644 index 000000000..3496dc99d --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/Makefile @@ -0,0 +1,36 @@ +# Go support for Protocol Buffers - Google's data interchange format +# +# Copyright 2010 The Go Authors. All rights reserved. +# https://github.com/golang/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + go install github.com/gogo/protobuf/protoc-gen-gostring + protoc --gogo_out=. -I=../../protobuf/google/protobuf ../../protobuf/google/protobuf/descriptor.proto + protoc --gostring_out=. -I=../../protobuf/google/protobuf ../../protobuf/google/protobuf/descriptor.proto diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/descriptor_test.go b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/descriptor_test.go new file mode 100644 index 000000000..d4248b483 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor/descriptor_test.go @@ -0,0 +1,31 @@ +package descriptor_test + +import ( + "fmt" + "testing" + + tpb "github.com/gogo/protobuf/proto/testdata" + "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" +) + +func TestMessage(t *testing.T) { + var msg *descriptor.DescriptorProto + fd, md := descriptor.ForMessage(msg) + if pkg, want := fd.GetPackage(), "google.protobuf"; pkg != want { + t.Errorf("descriptor.ForMessage(%T).GetPackage() = %q; want %q", msg, pkg, want) + } + if name, want := md.GetName(), "DescriptorProto"; name != want { + t.Fatalf("descriptor.ForMessage(%T).GetName() = %q; want %q", msg, name, want) + } +} + +func Example_Options() { + var msg *tpb.MyMessageSet + _, md := descriptor.ForMessage(msg) + if md.GetOptions().GetMessageSetWireFormat() { + fmt.Printf("%v uses option message_set_wire_format.\n", md.GetName()) + } + + // Output: + // MyMessageSet uses option message_set_wire_format. +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/generator/name_test.go b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/generator/name_test.go new file mode 100644 index 000000000..b3b60a3c6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/generator/name_test.go @@ -0,0 +1,114 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2013 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package generator + +import ( + "testing" + + "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" +) + +func TestCamelCase(t *testing.T) { + tests := []struct { + in, want string + }{ + {"one", "One"}, + {"one_two", "OneTwo"}, + {"_my_field_name_2", "XMyFieldName_2"}, + {"Something_Capped", "Something_Capped"}, + {"my_Name", "My_Name"}, + {"OneTwo", "OneTwo"}, + {"_", "X"}, + {"_a_", "XA_"}, + } + for _, tc := range tests { + if got := CamelCase(tc.in); got != tc.want { + t.Errorf("CamelCase(%q) = %q, want %q", tc.in, got, tc.want) + } + } +} + +func TestGoPackageOption(t *testing.T) { + tests := []struct { + in string + impPath, pkg string + ok bool + }{ + {"", "", "", false}, + {"foo", "", "foo", true}, + {"github.com/golang/bar", "github.com/golang/bar", "bar", true}, + {"github.com/golang/bar;baz", "github.com/golang/bar", "baz", true}, + } + for _, tc := range tests { + d := &FileDescriptor{ + FileDescriptorProto: &descriptor.FileDescriptorProto{ + Options: &descriptor.FileOptions{ + GoPackage: &tc.in, + }, + }, + } + impPath, pkg, ok := d.goPackageOption() + if impPath != tc.impPath || pkg != tc.pkg || ok != tc.ok { + t.Errorf("go_package = %q => (%q, %q, %t), want (%q, %q, %t)", tc.in, + impPath, pkg, ok, tc.impPath, tc.pkg, tc.ok) + } + } +} + +func TestUnescape(t *testing.T) { + tests := []struct { + in string + out string + }{ + // successful cases, including all kinds of escapes + {"", ""}, + {"foo bar baz frob nitz", "foo bar baz frob nitz"}, + {`\000\001\002\003\004\005\006\007`, string([]byte{0, 1, 2, 3, 4, 5, 6, 7})}, + {`\a\b\f\n\r\t\v\\\?\'\"`, string([]byte{'\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '?', '\'', '"'})}, + {`\x10\x20\x30\x40\x50\x60\x70\x80`, string([]byte{16, 32, 48, 64, 80, 96, 112, 128})}, + // variable length octal escapes + {`\0\018\222\377\3\04\005\6\07`, string([]byte{0, 1, '8', 0222, 255, 3, 4, 5, 6, 7})}, + // malformed escape sequences left as is + {"foo \\g bar", "foo \\g bar"}, + {"foo \\xg0 bar", "foo \\xg0 bar"}, + {"\\", "\\"}, + {"\\x", "\\x"}, + {"\\xf", "\\xf"}, + {"\\777", "\\777"}, // overflows byte + } + for _, tc := range tests { + s := unescape(tc.in) + if s != tc.out { + t.Errorf("doUnescape(%q) = %q; should have been %q", tc.in, s, tc.out) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/plugin/Makefile b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/plugin/Makefile new file mode 100644 index 000000000..95234a755 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/plugin/Makefile @@ -0,0 +1,37 @@ +# Go support for Protocol Buffers - Google's data interchange format +# +# Copyright 2010 The Go Authors. All rights reserved. +# https://github.com/golang/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Not stored here, but plugin.proto is in https://github.com/google/protobuf/ +# at src/google/protobuf/compiler/plugin.proto +# Also we need to fix an import. +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc --gogo_out=Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor:. -I=../../protobuf/google/protobuf/compiler/:../../protobuf/ ../../protobuf/google/protobuf/compiler/plugin.proto diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/Makefile b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/Makefile new file mode 100644 index 000000000..ce21a1861 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/Makefile @@ -0,0 +1,64 @@ +# Go support for Protocol Buffers - Google's data interchange format +# +# Copyright 2010 The Go Authors. All rights reserved. +# https://github.com/golang/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + @echo run make test + +test: regenerate testbuild + +#test: regenerate testbuild extension_test +# ./extension_test +# @echo PASS + +regenerate: + go install github.com/gogo/protobuf/protoc-min-version + protoc-min-version --version="3.0.0" --gogo_out=Mmulti/multi1.proto=github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi:. ./my_test/test.proto + +nuke: clean + +testbuild: buildprotos + go test + +buildprotos: + # Invoke protoc once to generate three independent .pb.go files in the same package. + protoc --gogo_out=. multi/multi1.proto multi/multi2.proto multi/multi3.proto + +#extension_test: extension_test.$O +# $(LD) -L. -o $@ $< + +#multi.a: multi3.pb.$O multi2.pb.$O multi1.pb.$O +# rm -f multi.a +# $(QUOTED_GOBIN)/gopack grc $@ $< + +#test.pb.go: imp.pb.go +#multi1.pb.go: multi2.pb.go multi3.pb.go +#main.$O: imp.pb.$O test.pb.$O multi.a +#extension_test.$O: extension_base.pb.$O extension_extra.pb.$O extension_user.pb.$O diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_base.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_base.proto new file mode 100644 index 000000000..94acfc1bc --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_base.proto @@ -0,0 +1,46 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package extension_base; + +message BaseMessage { + optional int32 height = 1; + extensions 4 to 9; + extensions 16 to max; +} + +// Another message that may be extended, using message_set_wire_format. +message OldStyleMessage { + option message_set_wire_format = true; + extensions 100 to max; +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_extra.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_extra.proto new file mode 100644 index 000000000..fca7f600c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_extra.proto @@ -0,0 +1,38 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2011 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package extension_extra; + +message ExtraMessage { + optional int32 width = 1; +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_test.go b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_test.go new file mode 100644 index 000000000..86e9c118a --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_test.go @@ -0,0 +1,210 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Test that we can use protocol buffers that use extensions. + +package testdata + +/* + +import ( + "bytes" + "regexp" + "testing" + + "github.com/golang/protobuf/proto" + base "extension_base.pb" + user "extension_user.pb" +) + +func TestSingleFieldExtension(t *testing.T) { + bm := &base.BaseMessage{ + Height: proto.Int32(178), + } + + // Use extension within scope of another type. + vol := proto.Uint32(11) + err := proto.SetExtension(bm, user.E_LoudMessage_Volume, vol) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + buf, err := proto.Marshal(bm) + if err != nil { + t.Fatal("Failed encoding message with extension:", err) + } + bm_new := new(base.BaseMessage) + if err := proto.Unmarshal(buf, bm_new); err != nil { + t.Fatal("Failed decoding message with extension:", err) + } + if !proto.HasExtension(bm_new, user.E_LoudMessage_Volume) { + t.Fatal("Decoded message didn't contain extension.") + } + vol_out, err := proto.GetExtension(bm_new, user.E_LoudMessage_Volume) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + if v := vol_out.(*uint32); *v != *vol { + t.Errorf("vol_out = %v, expected %v", *v, *vol) + } + proto.ClearExtension(bm_new, user.E_LoudMessage_Volume) + if proto.HasExtension(bm_new, user.E_LoudMessage_Volume) { + t.Fatal("Failed clearing extension.") + } +} + +func TestMessageExtension(t *testing.T) { + bm := &base.BaseMessage{ + Height: proto.Int32(179), + } + + // Use extension that is itself a message. + um := &user.UserMessage{ + Name: proto.String("Dave"), + Rank: proto.String("Major"), + } + err := proto.SetExtension(bm, user.E_LoginMessage_UserMessage, um) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + buf, err := proto.Marshal(bm) + if err != nil { + t.Fatal("Failed encoding message with extension:", err) + } + bm_new := new(base.BaseMessage) + if err := proto.Unmarshal(buf, bm_new); err != nil { + t.Fatal("Failed decoding message with extension:", err) + } + if !proto.HasExtension(bm_new, user.E_LoginMessage_UserMessage) { + t.Fatal("Decoded message didn't contain extension.") + } + um_out, err := proto.GetExtension(bm_new, user.E_LoginMessage_UserMessage) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + if n := um_out.(*user.UserMessage).Name; *n != *um.Name { + t.Errorf("um_out.Name = %q, expected %q", *n, *um.Name) + } + if r := um_out.(*user.UserMessage).Rank; *r != *um.Rank { + t.Errorf("um_out.Rank = %q, expected %q", *r, *um.Rank) + } + proto.ClearExtension(bm_new, user.E_LoginMessage_UserMessage) + if proto.HasExtension(bm_new, user.E_LoginMessage_UserMessage) { + t.Fatal("Failed clearing extension.") + } +} + +func TestTopLevelExtension(t *testing.T) { + bm := &base.BaseMessage{ + Height: proto.Int32(179), + } + + width := proto.Int32(17) + err := proto.SetExtension(bm, user.E_Width, width) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + buf, err := proto.Marshal(bm) + if err != nil { + t.Fatal("Failed encoding message with extension:", err) + } + bm_new := new(base.BaseMessage) + if err := proto.Unmarshal(buf, bm_new); err != nil { + t.Fatal("Failed decoding message with extension:", err) + } + if !proto.HasExtension(bm_new, user.E_Width) { + t.Fatal("Decoded message didn't contain extension.") + } + width_out, err := proto.GetExtension(bm_new, user.E_Width) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + if w := width_out.(*int32); *w != *width { + t.Errorf("width_out = %v, expected %v", *w, *width) + } + proto.ClearExtension(bm_new, user.E_Width) + if proto.HasExtension(bm_new, user.E_Width) { + t.Fatal("Failed clearing extension.") + } +} + +func TestMessageSetWireFormat(t *testing.T) { + osm := new(base.OldStyleMessage) + osp := &user.OldStyleParcel{ + Name: proto.String("Dave"), + Height: proto.Int32(178), + } + + err := proto.SetExtension(osm, user.E_OldStyleParcel_MessageSetExtension, osp) + if err != nil { + t.Fatal("Failed setting extension:", err) + } + + buf, err := proto.Marshal(osm) + if err != nil { + t.Fatal("Failed encoding message:", err) + } + + // Data generated from Python implementation. + expected := []byte{ + 11, 16, 209, 15, 26, 9, 10, 4, 68, 97, 118, 101, 16, 178, 1, 12, + } + + if !bytes.Equal(expected, buf) { + t.Errorf("Encoding mismatch.\nwant %+v\n got %+v", expected, buf) + } + + // Check that it is restored correctly. + osm = new(base.OldStyleMessage) + if err := proto.Unmarshal(buf, osm); err != nil { + t.Fatal("Failed decoding message:", err) + } + osp_out, err := proto.GetExtension(osm, user.E_OldStyleParcel_MessageSetExtension) + if err != nil { + t.Fatal("Failed getting extension:", err) + } + osp = osp_out.(*user.OldStyleParcel) + if *osp.Name != "Dave" || *osp.Height != 178 { + t.Errorf("Retrieved extension from decoded message is not correct: %+v", osp) + } +} + +func main() { + // simpler than rigging up gotest + testing.Main(regexp.MatchString, []testing.InternalTest{ + {"TestSingleFieldExtension", TestSingleFieldExtension}, + {"TestMessageExtension", TestMessageExtension}, + {"TestTopLevelExtension", TestTopLevelExtension}, + }, + []testing.InternalBenchmark{}, + []testing.InternalExample{}) +} + +*/ diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_user.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_user.proto new file mode 100644 index 000000000..ff65873dd --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/extension_user.proto @@ -0,0 +1,100 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +import "extension_base.proto"; +import "extension_extra.proto"; + +package extension_user; + +message UserMessage { + optional string name = 1; + optional string rank = 2; +} + +// Extend with a message +extend extension_base.BaseMessage { + optional UserMessage user_message = 5; +} + +// Extend with a foreign message +extend extension_base.BaseMessage { + optional extension_extra.ExtraMessage extra_message = 9; +} + +// Extend with some primitive types +extend extension_base.BaseMessage { + optional int32 width = 6; + optional int64 area = 7; +} + +// Extend inside the scope of another type +message LoudMessage { + extend extension_base.BaseMessage { + optional uint32 volume = 8; + } + extensions 100 to max; +} + +// Extend inside the scope of another type, using a message. +message LoginMessage { + extend extension_base.BaseMessage { + optional UserMessage user_message = 16; + } +} + +// Extend with a repeated field +extend extension_base.BaseMessage { + repeated Detail detail = 17; +} + +message Detail { + optional string color = 1; +} + +// An extension of an extension +message Announcement { + optional string words = 1; + extend LoudMessage { + optional Announcement loud_ext = 100; + } +} + +// Something that can be put in a message set. +message OldStyleParcel { + extend extension_base.OldStyleMessage { + optional OldStyleParcel message_set_extension = 2001; + } + + required string name = 1; + optional int32 height = 2; +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/grpc.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/grpc.proto new file mode 100644 index 000000000..b8bc41acd --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/grpc.proto @@ -0,0 +1,59 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2015 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package grpc.testing; + +message SimpleRequest { +} + +message SimpleResponse { +} + +message StreamMsg { +} + +message StreamMsg2 { +} + +service Test { + rpc UnaryCall(SimpleRequest) returns (SimpleResponse); + + // This RPC streams from the server only. + rpc Downstream(SimpleRequest) returns (stream StreamMsg); + + // This RPC streams from the client. + rpc Upstream(stream StreamMsg) returns (SimpleResponse); + + // This one streams in both directions. + rpc Bidi(stream StreamMsg) returns (stream StreamMsg2); +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp.pb.go.golden b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp.pb.go.golden new file mode 100644 index 000000000..784a4f865 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp.pb.go.golden @@ -0,0 +1,113 @@ +// Code generated by protoc-gen-go. +// source: imp.proto +// DO NOT EDIT! + +package imp + +import proto "github.com/golang/protobuf/proto" +import "math" +import "os" +import imp1 "imp2.pb" + +// Reference proto & math imports to suppress error if they are not otherwise used. +var _ = proto.GetString +var _ = math.Inf + +// Types from public import imp2.proto +type PubliclyImportedMessage imp1.PubliclyImportedMessage + +func (this *PubliclyImportedMessage) Reset() { (*imp1.PubliclyImportedMessage)(this).Reset() } +func (this *PubliclyImportedMessage) String() string { + return (*imp1.PubliclyImportedMessage)(this).String() +} + +// PubliclyImportedMessage from public import imp.proto + +type ImportedMessage_Owner int32 + +const ( + ImportedMessage_DAVE ImportedMessage_Owner = 1 + ImportedMessage_MIKE ImportedMessage_Owner = 2 +) + +var ImportedMessage_Owner_name = map[int32]string{ + 1: "DAVE", + 2: "MIKE", +} +var ImportedMessage_Owner_value = map[string]int32{ + "DAVE": 1, + "MIKE": 2, +} + +// NewImportedMessage_Owner is deprecated. Use x.Enum() instead. +func NewImportedMessage_Owner(x ImportedMessage_Owner) *ImportedMessage_Owner { + e := ImportedMessage_Owner(x) + return &e +} +func (x ImportedMessage_Owner) Enum() *ImportedMessage_Owner { + p := new(ImportedMessage_Owner) + *p = x + return p +} +func (x ImportedMessage_Owner) String() string { + return proto.EnumName(ImportedMessage_Owner_name, int32(x)) +} + +type ImportedMessage struct { + Field *int64 `protobuf:"varint,1,req,name=field" json:"field,omitempty"` + XXX_extensions map[int32][]byte `json:",omitempty"` + XXX_unrecognized []byte `json:",omitempty"` +} + +func (this *ImportedMessage) Reset() { *this = ImportedMessage{} } +func (this *ImportedMessage) String() string { return proto.CompactTextString(this) } + +var extRange_ImportedMessage = []proto.ExtensionRange{ + proto.ExtensionRange{90, 100}, +} + +func (*ImportedMessage) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_ImportedMessage +} +func (this *ImportedMessage) ExtensionMap() map[int32][]byte { + if this.XXX_extensions == nil { + this.XXX_extensions = make(map[int32][]byte) + } + return this.XXX_extensions +} + +type ImportedExtendable struct { + XXX_extensions map[int32][]byte `json:",omitempty"` + XXX_unrecognized []byte `json:",omitempty"` +} + +func (this *ImportedExtendable) Reset() { *this = ImportedExtendable{} } +func (this *ImportedExtendable) String() string { return proto.CompactTextString(this) } + +func (this *ImportedExtendable) Marshal() ([]byte, error) { + return proto.MarshalMessageSet(this.ExtensionMap()) +} +func (this *ImportedExtendable) Unmarshal(buf []byte) error { + return proto.UnmarshalMessageSet(buf, this.ExtensionMap()) +} +// ensure ImportedExtendable satisfies proto.Marshaler and proto.Unmarshaler +var _ proto.Marshaler = (*ImportedExtendable)(nil) +var _ proto.Unmarshaler = (*ImportedExtendable)(nil) + +var extRange_ImportedExtendable = []proto.ExtensionRange{ + proto.ExtensionRange{100, 536870911}, +} + +func (*ImportedExtendable) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_ImportedExtendable +} +func (this *ImportedExtendable) ExtensionMap() map[int32][]byte { + if this.XXX_extensions == nil { + this.XXX_extensions = make(map[int32][]byte) + } + return this.XXX_extensions +} + +func init() { + proto.RegisterEnum("imp.ImportedMessage_Owner", ImportedMessage_Owner_name, ImportedMessage_Owner_value) +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp.proto new file mode 100644 index 000000000..156e078d1 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp.proto @@ -0,0 +1,70 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package imp; + +import "imp2.proto"; +import "imp3.proto"; + +message ImportedMessage { + required int64 field = 1; + + // The forwarded getters for these fields are fiddly to get right. + optional ImportedMessage2 local_msg = 2; + optional ForeignImportedMessage foreign_msg = 3; // in imp3.proto + optional Owner enum_field = 4; + oneof union { + int32 state = 9; + } + + repeated string name = 5; + repeated Owner boss = 6; + repeated ImportedMessage2 memo = 7; + + map msg_map = 8; + + enum Owner { + DAVE = 1; + MIKE = 2; + } + + extensions 90 to 100; +} + +message ImportedMessage2 { +} + +message ImportedExtendable { + option message_set_wire_format = true; + extensions 100 to max; +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp2.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp2.proto new file mode 100644 index 000000000..3bb0632b2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp2.proto @@ -0,0 +1,43 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2011 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package imp; + +message PubliclyImportedMessage { + optional int64 field = 1; +} + +enum PubliclyImportedEnum { + GLASSES = 1; + HAIR = 2; +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp3.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp3.proto new file mode 100644 index 000000000..58fc7598b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/imp3.proto @@ -0,0 +1,38 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2012 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package imp; + +message ForeignImportedMessage { + optional string tuber = 1; +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/main_test.go b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/main_test.go new file mode 100644 index 000000000..271d9639d --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/main_test.go @@ -0,0 +1,46 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// A simple binary to link together the protocol buffers in this test. + +package testdata + +import ( + "testing" + + mytestpb "./my_test" + multipb "github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi" +) + +func TestLink(t *testing.T) { + _ = &multipb.Multi1{} + _ = &mytestpb.Request{} +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/.gitignore b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/.gitignore new file mode 100644 index 000000000..c61a5e8b0 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/.gitignore @@ -0,0 +1 @@ +*.pb.go diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/multi1.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/multi1.proto new file mode 100644 index 000000000..0da6e0af4 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/multi1.proto @@ -0,0 +1,44 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +import "multi/multi2.proto"; +import "multi/multi3.proto"; + +package multitest; + +message Multi1 { + required Multi2 multi2 = 1; + optional Multi2.Color color = 2; + optional Multi3.HatType hat_type = 3; +} + diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/multi2.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/multi2.proto new file mode 100644 index 000000000..e6bfc71b3 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/multi2.proto @@ -0,0 +1,46 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package multitest; + +message Multi2 { + required int32 required_value = 1; + + enum Color { + BLUE = 1; + GREEN = 2; + RED = 3; + }; + optional Color color = 2; +} + diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/multi3.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/multi3.proto new file mode 100644 index 000000000..146c255bd --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi/multi3.proto @@ -0,0 +1,43 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package multitest; + +message Multi3 { + enum HatType { + FEDORA = 1; + FEZ = 2; + }; + optional HatType hat_type = 1; +} + diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/my_test/test.pb.go b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/my_test/test.pb.go new file mode 100644 index 000000000..a266a709f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/my_test/test.pb.go @@ -0,0 +1,953 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: my_test/test.proto + +/* +Package my_test is a generated protocol buffer package. + +This package holds interesting messages. + +It is generated from these files: + my_test/test.proto + +It has these top-level messages: + Request + Reply + OtherBase + ReplyExtensions + OtherReplyExtensions + OldReply + Communique +*/ +package my_test + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/protoc-gen-gogo/testdata/multi" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type HatType int32 + +const ( + // deliberately skipping 0 + HatType_FEDORA HatType = 1 + HatType_FEZ HatType = 2 +) + +var HatType_name = map[int32]string{ + 1: "FEDORA", + 2: "FEZ", +} +var HatType_value = map[string]int32{ + "FEDORA": 1, + "FEZ": 2, +} + +func (x HatType) Enum() *HatType { + p := new(HatType) + *p = x + return p +} +func (x HatType) String() string { + return proto.EnumName(HatType_name, int32(x)) +} +func (x *HatType) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(HatType_value, data, "HatType") + if err != nil { + return err + } + *x = HatType(value) + return nil +} +func (HatType) EnumDescriptor() ([]byte, []int) { return fileDescriptorTest, []int{0} } + +// This enum represents days of the week. +type Days int32 + +const ( + Days_MONDAY Days = 1 + Days_TUESDAY Days = 2 + Days_LUNDI Days = 1 +) + +var Days_name = map[int32]string{ + 1: "MONDAY", + 2: "TUESDAY", + // Duplicate value: 1: "LUNDI", +} +var Days_value = map[string]int32{ + "MONDAY": 1, + "TUESDAY": 2, + "LUNDI": 1, +} + +func (x Days) Enum() *Days { + p := new(Days) + *p = x + return p +} +func (x Days) String() string { + return proto.EnumName(Days_name, int32(x)) +} +func (x *Days) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(Days_value, data, "Days") + if err != nil { + return err + } + *x = Days(value) + return nil +} +func (Days) EnumDescriptor() ([]byte, []int) { return fileDescriptorTest, []int{1} } + +type Request_Color int32 + +const ( + Request_RED Request_Color = 0 + Request_GREEN Request_Color = 1 + Request_BLUE Request_Color = 2 +) + +var Request_Color_name = map[int32]string{ + 0: "RED", + 1: "GREEN", + 2: "BLUE", +} +var Request_Color_value = map[string]int32{ + "RED": 0, + "GREEN": 1, + "BLUE": 2, +} + +func (x Request_Color) Enum() *Request_Color { + p := new(Request_Color) + *p = x + return p +} +func (x Request_Color) String() string { + return proto.EnumName(Request_Color_name, int32(x)) +} +func (x *Request_Color) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(Request_Color_value, data, "Request_Color") + if err != nil { + return err + } + *x = Request_Color(value) + return nil +} +func (Request_Color) EnumDescriptor() ([]byte, []int) { return fileDescriptorTest, []int{0, 0} } + +type Reply_Entry_Game int32 + +const ( + Reply_Entry_FOOTBALL Reply_Entry_Game = 1 + Reply_Entry_TENNIS Reply_Entry_Game = 2 +) + +var Reply_Entry_Game_name = map[int32]string{ + 1: "FOOTBALL", + 2: "TENNIS", +} +var Reply_Entry_Game_value = map[string]int32{ + "FOOTBALL": 1, + "TENNIS": 2, +} + +func (x Reply_Entry_Game) Enum() *Reply_Entry_Game { + p := new(Reply_Entry_Game) + *p = x + return p +} +func (x Reply_Entry_Game) String() string { + return proto.EnumName(Reply_Entry_Game_name, int32(x)) +} +func (x *Reply_Entry_Game) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(Reply_Entry_Game_value, data, "Reply_Entry_Game") + if err != nil { + return err + } + *x = Reply_Entry_Game(value) + return nil +} +func (Reply_Entry_Game) EnumDescriptor() ([]byte, []int) { return fileDescriptorTest, []int{1, 0, 0} } + +// This is a message that might be sent somewhere. +type Request struct { + Key []int64 `protobuf:"varint,1,rep,name=key" json:"key,omitempty"` + // optional imp.ImportedMessage imported_message = 2; + Hue *Request_Color `protobuf:"varint,3,opt,name=hue,enum=my.test.Request_Color" json:"hue,omitempty"` + Hat *HatType `protobuf:"varint,4,opt,name=hat,enum=my.test.HatType,def=1" json:"hat,omitempty"` + // optional imp.ImportedMessage.Owner owner = 6; + Deadline *float32 `protobuf:"fixed32,7,opt,name=deadline,def=inf" json:"deadline,omitempty"` + Somegroup *Request_SomeGroup `protobuf:"group,8,opt,name=SomeGroup,json=somegroup" json:"somegroup,omitempty"` + // This is a map field. It will generate map[int32]string. + NameMapping map[int32]string `protobuf:"bytes,14,rep,name=name_mapping,json=nameMapping" json:"name_mapping,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + // This is a map field whose value type is a message. + MsgMapping map[int64]*Reply `protobuf:"bytes,15,rep,name=msg_mapping,json=msgMapping" json:"msg_mapping,omitempty" protobuf_key:"zigzag64,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + Reset_ *int32 `protobuf:"varint,12,opt,name=reset" json:"reset,omitempty"` + // This field should not conflict with any getters. + GetKey_ *string `protobuf:"bytes,16,opt,name=get_key,json=getKey" json:"get_key,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Request) Reset() { *m = Request{} } +func (m *Request) String() string { return proto.CompactTextString(m) } +func (*Request) ProtoMessage() {} +func (*Request) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{0} } + +const Default_Request_Hat HatType = HatType_FEDORA + +var Default_Request_Deadline float32 = float32(math.Inf(1)) + +func (m *Request) GetKey() []int64 { + if m != nil { + return m.Key + } + return nil +} + +func (m *Request) GetHue() Request_Color { + if m != nil && m.Hue != nil { + return *m.Hue + } + return Request_RED +} + +func (m *Request) GetHat() HatType { + if m != nil && m.Hat != nil { + return *m.Hat + } + return Default_Request_Hat +} + +func (m *Request) GetDeadline() float32 { + if m != nil && m.Deadline != nil { + return *m.Deadline + } + return Default_Request_Deadline +} + +func (m *Request) GetSomegroup() *Request_SomeGroup { + if m != nil { + return m.Somegroup + } + return nil +} + +func (m *Request) GetNameMapping() map[int32]string { + if m != nil { + return m.NameMapping + } + return nil +} + +func (m *Request) GetMsgMapping() map[int64]*Reply { + if m != nil { + return m.MsgMapping + } + return nil +} + +func (m *Request) GetReset_() int32 { + if m != nil && m.Reset_ != nil { + return *m.Reset_ + } + return 0 +} + +func (m *Request) GetGetKey_() string { + if m != nil && m.GetKey_ != nil { + return *m.GetKey_ + } + return "" +} + +type Request_SomeGroup struct { + GroupField *int32 `protobuf:"varint,9,opt,name=group_field,json=groupField" json:"group_field,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Request_SomeGroup) Reset() { *m = Request_SomeGroup{} } +func (m *Request_SomeGroup) String() string { return proto.CompactTextString(m) } +func (*Request_SomeGroup) ProtoMessage() {} +func (*Request_SomeGroup) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{0, 0} } + +func (m *Request_SomeGroup) GetGroupField() int32 { + if m != nil && m.GroupField != nil { + return *m.GroupField + } + return 0 +} + +type Reply struct { + Found []*Reply_Entry `protobuf:"bytes,1,rep,name=found" json:"found,omitempty"` + CompactKeys []int32 `protobuf:"varint,2,rep,packed,name=compact_keys,json=compactKeys" json:"compact_keys,omitempty"` + proto.XXX_InternalExtensions `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Reply) Reset() { *m = Reply{} } +func (m *Reply) String() string { return proto.CompactTextString(m) } +func (*Reply) ProtoMessage() {} +func (*Reply) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{1} } + +var extRange_Reply = []proto.ExtensionRange{ + {Start: 100, End: 536870911}, +} + +func (*Reply) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_Reply +} + +func (m *Reply) GetFound() []*Reply_Entry { + if m != nil { + return m.Found + } + return nil +} + +func (m *Reply) GetCompactKeys() []int32 { + if m != nil { + return m.CompactKeys + } + return nil +} + +type Reply_Entry struct { + KeyThatNeeds_1234Camel_CasIng *int64 `protobuf:"varint,1,req,name=key_that_needs_1234camel_CasIng,json=keyThatNeeds1234camelCasIng" json:"key_that_needs_1234camel_CasIng,omitempty"` + Value *int64 `protobuf:"varint,2,opt,name=value,def=7" json:"value,omitempty"` + XMyFieldName_2 *int64 `protobuf:"varint,3,opt,name=_my_field_name_2,json=MyFieldName2" json:"_my_field_name_2,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Reply_Entry) Reset() { *m = Reply_Entry{} } +func (m *Reply_Entry) String() string { return proto.CompactTextString(m) } +func (*Reply_Entry) ProtoMessage() {} +func (*Reply_Entry) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{1, 0} } + +const Default_Reply_Entry_Value int64 = 7 + +func (m *Reply_Entry) GetKeyThatNeeds_1234Camel_CasIng() int64 { + if m != nil && m.KeyThatNeeds_1234Camel_CasIng != nil { + return *m.KeyThatNeeds_1234Camel_CasIng + } + return 0 +} + +func (m *Reply_Entry) GetValue() int64 { + if m != nil && m.Value != nil { + return *m.Value + } + return Default_Reply_Entry_Value +} + +func (m *Reply_Entry) GetXMyFieldName_2() int64 { + if m != nil && m.XMyFieldName_2 != nil { + return *m.XMyFieldName_2 + } + return 0 +} + +type OtherBase struct { + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + proto.XXX_InternalExtensions `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OtherBase) Reset() { *m = OtherBase{} } +func (m *OtherBase) String() string { return proto.CompactTextString(m) } +func (*OtherBase) ProtoMessage() {} +func (*OtherBase) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{2} } + +var extRange_OtherBase = []proto.ExtensionRange{ + {Start: 100, End: 536870911}, +} + +func (*OtherBase) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_OtherBase +} + +func (m *OtherBase) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +type ReplyExtensions struct { + XXX_unrecognized []byte `json:"-"` +} + +func (m *ReplyExtensions) Reset() { *m = ReplyExtensions{} } +func (m *ReplyExtensions) String() string { return proto.CompactTextString(m) } +func (*ReplyExtensions) ProtoMessage() {} +func (*ReplyExtensions) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{3} } + +var E_ReplyExtensions_Time = &proto.ExtensionDesc{ + ExtendedType: (*Reply)(nil), + ExtensionType: (*float64)(nil), + Field: 101, + Name: "my.test.ReplyExtensions.time", + Tag: "fixed64,101,opt,name=time", + Filename: "my_test/test.proto", +} + +var E_ReplyExtensions_Carrot = &proto.ExtensionDesc{ + ExtendedType: (*Reply)(nil), + ExtensionType: (*ReplyExtensions)(nil), + Field: 105, + Name: "my.test.ReplyExtensions.carrot", + Tag: "bytes,105,opt,name=carrot", + Filename: "my_test/test.proto", +} + +var E_ReplyExtensions_Donut = &proto.ExtensionDesc{ + ExtendedType: (*OtherBase)(nil), + ExtensionType: (*ReplyExtensions)(nil), + Field: 101, + Name: "my.test.ReplyExtensions.donut", + Tag: "bytes,101,opt,name=donut", + Filename: "my_test/test.proto", +} + +type OtherReplyExtensions struct { + Key *int32 `protobuf:"varint,1,opt,name=key" json:"key,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OtherReplyExtensions) Reset() { *m = OtherReplyExtensions{} } +func (m *OtherReplyExtensions) String() string { return proto.CompactTextString(m) } +func (*OtherReplyExtensions) ProtoMessage() {} +func (*OtherReplyExtensions) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{4} } + +func (m *OtherReplyExtensions) GetKey() int32 { + if m != nil && m.Key != nil { + return *m.Key + } + return 0 +} + +type OldReply struct { + proto.XXX_InternalExtensions `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OldReply) Reset() { *m = OldReply{} } +func (m *OldReply) String() string { return proto.CompactTextString(m) } +func (*OldReply) ProtoMessage() {} +func (*OldReply) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{5} } + +func (m *OldReply) Marshal() ([]byte, error) { + return proto.MarshalMessageSet(&m.XXX_InternalExtensions) +} +func (m *OldReply) Unmarshal(buf []byte) error { + return proto.UnmarshalMessageSet(buf, &m.XXX_InternalExtensions) +} +func (m *OldReply) MarshalJSON() ([]byte, error) { + return proto.MarshalMessageSetJSON(&m.XXX_InternalExtensions) +} +func (m *OldReply) UnmarshalJSON(buf []byte) error { + return proto.UnmarshalMessageSetJSON(buf, &m.XXX_InternalExtensions) +} + +// ensure OldReply satisfies proto.Marshaler and proto.Unmarshaler +var _ proto.Marshaler = (*OldReply)(nil) +var _ proto.Unmarshaler = (*OldReply)(nil) + +var extRange_OldReply = []proto.ExtensionRange{ + {Start: 100, End: 2147483646}, +} + +func (*OldReply) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_OldReply +} + +type Communique struct { + MakeMeCry *bool `protobuf:"varint,1,opt,name=make_me_cry,json=makeMeCry" json:"make_me_cry,omitempty"` + // This is a oneof, called "union". + // + // Types that are valid to be assigned to Union: + // *Communique_Number + // *Communique_Name + // *Communique_Data + // *Communique_TempC + // *Communique_Height + // *Communique_Today + // *Communique_Maybe + // *Communique_Delta_ + // *Communique_Msg + // *Communique_Somegroup + Union isCommunique_Union `protobuf_oneof:"union"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Communique) Reset() { *m = Communique{} } +func (m *Communique) String() string { return proto.CompactTextString(m) } +func (*Communique) ProtoMessage() {} +func (*Communique) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{6} } + +type isCommunique_Union interface { + isCommunique_Union() +} + +type Communique_Number struct { + Number int32 `protobuf:"varint,5,opt,name=number,oneof"` +} +type Communique_Name struct { + Name string `protobuf:"bytes,6,opt,name=name,oneof"` +} +type Communique_Data struct { + Data []byte `protobuf:"bytes,7,opt,name=data,oneof"` +} +type Communique_TempC struct { + TempC float64 `protobuf:"fixed64,8,opt,name=temp_c,json=tempC,oneof"` +} +type Communique_Height struct { + Height float32 `protobuf:"fixed32,9,opt,name=height,oneof"` +} +type Communique_Today struct { + Today Days `protobuf:"varint,10,opt,name=today,enum=my.test.Days,oneof"` +} +type Communique_Maybe struct { + Maybe bool `protobuf:"varint,11,opt,name=maybe,oneof"` +} +type Communique_Delta_ struct { + Delta int32 `protobuf:"zigzag32,12,opt,name=delta,oneof"` +} +type Communique_Msg struct { + Msg *Reply `protobuf:"bytes,13,opt,name=msg,oneof"` +} +type Communique_Somegroup struct { + Somegroup *Communique_SomeGroup `protobuf:"group,14,opt,name=SomeGroup,json=somegroup,oneof"` +} + +func (*Communique_Number) isCommunique_Union() {} +func (*Communique_Name) isCommunique_Union() {} +func (*Communique_Data) isCommunique_Union() {} +func (*Communique_TempC) isCommunique_Union() {} +func (*Communique_Height) isCommunique_Union() {} +func (*Communique_Today) isCommunique_Union() {} +func (*Communique_Maybe) isCommunique_Union() {} +func (*Communique_Delta_) isCommunique_Union() {} +func (*Communique_Msg) isCommunique_Union() {} +func (*Communique_Somegroup) isCommunique_Union() {} + +func (m *Communique) GetUnion() isCommunique_Union { + if m != nil { + return m.Union + } + return nil +} + +func (m *Communique) GetMakeMeCry() bool { + if m != nil && m.MakeMeCry != nil { + return *m.MakeMeCry + } + return false +} + +func (m *Communique) GetNumber() int32 { + if x, ok := m.GetUnion().(*Communique_Number); ok { + return x.Number + } + return 0 +} + +func (m *Communique) GetName() string { + if x, ok := m.GetUnion().(*Communique_Name); ok { + return x.Name + } + return "" +} + +func (m *Communique) GetData() []byte { + if x, ok := m.GetUnion().(*Communique_Data); ok { + return x.Data + } + return nil +} + +func (m *Communique) GetTempC() float64 { + if x, ok := m.GetUnion().(*Communique_TempC); ok { + return x.TempC + } + return 0 +} + +func (m *Communique) GetHeight() float32 { + if x, ok := m.GetUnion().(*Communique_Height); ok { + return x.Height + } + return 0 +} + +func (m *Communique) GetToday() Days { + if x, ok := m.GetUnion().(*Communique_Today); ok { + return x.Today + } + return Days_MONDAY +} + +func (m *Communique) GetMaybe() bool { + if x, ok := m.GetUnion().(*Communique_Maybe); ok { + return x.Maybe + } + return false +} + +func (m *Communique) GetDelta() int32 { + if x, ok := m.GetUnion().(*Communique_Delta_); ok { + return x.Delta + } + return 0 +} + +func (m *Communique) GetMsg() *Reply { + if x, ok := m.GetUnion().(*Communique_Msg); ok { + return x.Msg + } + return nil +} + +func (m *Communique) GetSomegroup() *Communique_SomeGroup { + if x, ok := m.GetUnion().(*Communique_Somegroup); ok { + return x.Somegroup + } + return nil +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*Communique) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { + return _Communique_OneofMarshaler, _Communique_OneofUnmarshaler, _Communique_OneofSizer, []interface{}{ + (*Communique_Number)(nil), + (*Communique_Name)(nil), + (*Communique_Data)(nil), + (*Communique_TempC)(nil), + (*Communique_Height)(nil), + (*Communique_Today)(nil), + (*Communique_Maybe)(nil), + (*Communique_Delta_)(nil), + (*Communique_Msg)(nil), + (*Communique_Somegroup)(nil), + } +} + +func _Communique_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*Communique) + // union + switch x := m.Union.(type) { + case *Communique_Number: + _ = b.EncodeVarint(5<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.Number)) + case *Communique_Name: + _ = b.EncodeVarint(6<<3 | proto.WireBytes) + _ = b.EncodeStringBytes(x.Name) + case *Communique_Data: + _ = b.EncodeVarint(7<<3 | proto.WireBytes) + _ = b.EncodeRawBytes(x.Data) + case *Communique_TempC: + _ = b.EncodeVarint(8<<3 | proto.WireFixed64) + _ = b.EncodeFixed64(math.Float64bits(x.TempC)) + case *Communique_Height: + _ = b.EncodeVarint(9<<3 | proto.WireFixed32) + _ = b.EncodeFixed32(uint64(math.Float32bits(x.Height))) + case *Communique_Today: + _ = b.EncodeVarint(10<<3 | proto.WireVarint) + _ = b.EncodeVarint(uint64(x.Today)) + case *Communique_Maybe: + t := uint64(0) + if x.Maybe { + t = 1 + } + _ = b.EncodeVarint(11<<3 | proto.WireVarint) + _ = b.EncodeVarint(t) + case *Communique_Delta_: + _ = b.EncodeVarint(12<<3 | proto.WireVarint) + _ = b.EncodeZigzag32(uint64(x.Delta)) + case *Communique_Msg: + _ = b.EncodeVarint(13<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.Msg); err != nil { + return err + } + case *Communique_Somegroup: + _ = b.EncodeVarint(14<<3 | proto.WireStartGroup) + if err := b.Marshal(x.Somegroup); err != nil { + return err + } + _ = b.EncodeVarint(14<<3 | proto.WireEndGroup) + case nil: + default: + return fmt.Errorf("Communique.Union has unexpected type %T", x) + } + return nil +} + +func _Communique_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*Communique) + switch tag { + case 5: // union.number + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Communique_Number{int32(x)} + return true, err + case 6: // union.name + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.Union = &Communique_Name{x} + return true, err + case 7: // union.data + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeRawBytes(true) + m.Union = &Communique_Data{x} + return true, err + case 8: // union.temp_c + if wire != proto.WireFixed64 { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeFixed64() + m.Union = &Communique_TempC{math.Float64frombits(x)} + return true, err + case 9: // union.height + if wire != proto.WireFixed32 { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeFixed32() + m.Union = &Communique_Height{math.Float32frombits(uint32(x))} + return true, err + case 10: // union.today + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Communique_Today{Days(x)} + return true, err + case 11: // union.maybe + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeVarint() + m.Union = &Communique_Maybe{x != 0} + return true, err + case 12: // union.delta + if wire != proto.WireVarint { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeZigzag32() + m.Union = &Communique_Delta_{int32(x)} + return true, err + case 13: // union.msg + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(Reply) + err := b.DecodeMessage(msg) + m.Union = &Communique_Msg{msg} + return true, err + case 14: // union.somegroup + if wire != proto.WireStartGroup { + return true, proto.ErrInternalBadWireType + } + msg := new(Communique_SomeGroup) + err := b.DecodeGroup(msg) + m.Union = &Communique_Somegroup{msg} + return true, err + default: + return false, nil + } +} + +func _Communique_OneofSizer(msg proto.Message) (n int) { + m := msg.(*Communique) + // union + switch x := m.Union.(type) { + case *Communique_Number: + n += proto.SizeVarint(5<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.Number)) + case *Communique_Name: + n += proto.SizeVarint(6<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.Name))) + n += len(x.Name) + case *Communique_Data: + n += proto.SizeVarint(7<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(len(x.Data))) + n += len(x.Data) + case *Communique_TempC: + n += proto.SizeVarint(8<<3 | proto.WireFixed64) + n += 8 + case *Communique_Height: + n += proto.SizeVarint(9<<3 | proto.WireFixed32) + n += 4 + case *Communique_Today: + n += proto.SizeVarint(10<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64(x.Today)) + case *Communique_Maybe: + n += proto.SizeVarint(11<<3 | proto.WireVarint) + n += 1 + case *Communique_Delta_: + n += proto.SizeVarint(12<<3 | proto.WireVarint) + n += proto.SizeVarint(uint64((uint32(x.Delta) << 1) ^ uint32((int32(x.Delta) >> 31)))) + case *Communique_Msg: + s := proto.Size(x.Msg) + n += proto.SizeVarint(13<<3 | proto.WireBytes) + n += proto.SizeVarint(uint64(s)) + n += s + case *Communique_Somegroup: + n += proto.SizeVarint(14<<3 | proto.WireStartGroup) + n += proto.Size(x.Somegroup) + n += proto.SizeVarint(14<<3 | proto.WireEndGroup) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + +type Communique_SomeGroup struct { + Member *string `protobuf:"bytes,15,opt,name=member" json:"member,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Communique_SomeGroup) Reset() { *m = Communique_SomeGroup{} } +func (m *Communique_SomeGroup) String() string { return proto.CompactTextString(m) } +func (*Communique_SomeGroup) ProtoMessage() {} +func (*Communique_SomeGroup) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{6, 0} } + +func (m *Communique_SomeGroup) GetMember() string { + if m != nil && m.Member != nil { + return *m.Member + } + return "" +} + +type Communique_Delta struct { + XXX_unrecognized []byte `json:"-"` +} + +func (m *Communique_Delta) Reset() { *m = Communique_Delta{} } +func (m *Communique_Delta) String() string { return proto.CompactTextString(m) } +func (*Communique_Delta) ProtoMessage() {} +func (*Communique_Delta) Descriptor() ([]byte, []int) { return fileDescriptorTest, []int{6, 1} } + +var E_Tag = &proto.ExtensionDesc{ + ExtendedType: (*Reply)(nil), + ExtensionType: (*string)(nil), + Field: 103, + Name: "my.test.tag", + Tag: "bytes,103,opt,name=tag", + Filename: "my_test/test.proto", +} + +var E_Donut = &proto.ExtensionDesc{ + ExtendedType: (*Reply)(nil), + ExtensionType: (*OtherReplyExtensions)(nil), + Field: 106, + Name: "my.test.donut", + Tag: "bytes,106,opt,name=donut", + Filename: "my_test/test.proto", +} + +func init() { + proto.RegisterType((*Request)(nil), "my.test.Request") + proto.RegisterType((*Request_SomeGroup)(nil), "my.test.Request.SomeGroup") + proto.RegisterType((*Reply)(nil), "my.test.Reply") + proto.RegisterType((*Reply_Entry)(nil), "my.test.Reply.Entry") + proto.RegisterType((*OtherBase)(nil), "my.test.OtherBase") + proto.RegisterType((*ReplyExtensions)(nil), "my.test.ReplyExtensions") + proto.RegisterType((*OtherReplyExtensions)(nil), "my.test.OtherReplyExtensions") + proto.RegisterType((*OldReply)(nil), "my.test.OldReply") + proto.RegisterType((*Communique)(nil), "my.test.Communique") + proto.RegisterType((*Communique_SomeGroup)(nil), "my.test.Communique.SomeGroup") + proto.RegisterType((*Communique_Delta)(nil), "my.test.Communique.Delta") + proto.RegisterEnum("my.test.HatType", HatType_name, HatType_value) + proto.RegisterEnum("my.test.Days", Days_name, Days_value) + proto.RegisterEnum("my.test.Request_Color", Request_Color_name, Request_Color_value) + proto.RegisterEnum("my.test.Reply_Entry_Game", Reply_Entry_Game_name, Reply_Entry_Game_value) + proto.RegisterExtension(E_ReplyExtensions_Time) + proto.RegisterExtension(E_ReplyExtensions_Carrot) + proto.RegisterExtension(E_ReplyExtensions_Donut) + proto.RegisterExtension(E_Tag) + proto.RegisterExtension(E_Donut) +} + +func init() { proto.RegisterFile("my_test/test.proto", fileDescriptorTest) } + +var fileDescriptorTest = []byte{ + // 988 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xdd, 0x6e, 0xe3, 0x44, + 0x14, 0xce, 0xd8, 0x71, 0x7e, 0x4e, 0xb2, 0xad, 0x19, 0x55, 0xad, 0x15, 0xb4, 0x5b, 0x13, 0x28, + 0x32, 0x15, 0xca, 0x6a, 0x0d, 0x12, 0xab, 0x48, 0x20, 0x9a, 0x9f, 0x36, 0xd5, 0x36, 0x89, 0x34, + 0x6d, 0x2f, 0xe0, 0xc6, 0x9a, 0x8d, 0xa7, 0x8e, 0x69, 0xc6, 0xce, 0xda, 0x63, 0x84, 0xef, 0xfa, + 0x14, 0xf0, 0x1a, 0xdc, 0xf3, 0x42, 0xbc, 0x45, 0xd1, 0x8c, 0x43, 0x92, 0x36, 0xab, 0xbd, 0xb1, + 0x7c, 0xbe, 0xf9, 0xce, 0xe7, 0x39, 0x3f, 0xfe, 0x00, 0xf3, 0xdc, 0x13, 0x2c, 0x15, 0xaf, 0xe5, + 0xa3, 0xb3, 0x4c, 0x62, 0x11, 0xe3, 0x2a, 0xcf, 0x3b, 0x32, 0x6c, 0x61, 0x9e, 0x2d, 0x44, 0xf8, + 0x5a, 0x3d, 0xdf, 0x14, 0x87, 0xed, 0x7f, 0xcb, 0x50, 0x25, 0xec, 0x43, 0xc6, 0x52, 0x81, 0x4d, + 0xd0, 0xef, 0x59, 0x6e, 0x21, 0x5b, 0x77, 0x74, 0x22, 0x5f, 0xb1, 0x03, 0xfa, 0x3c, 0x63, 0x96, + 0x6e, 0x23, 0x67, 0xcf, 0x3d, 0xec, 0xac, 0x84, 0x3a, 0xab, 0x84, 0x4e, 0x3f, 0x5e, 0xc4, 0x09, + 0x91, 0x14, 0x7c, 0x0a, 0xfa, 0x9c, 0x0a, 0xab, 0xac, 0x98, 0xe6, 0x9a, 0x39, 0xa2, 0xe2, 0x26, + 0x5f, 0xb2, 0x6e, 0xe5, 0x7c, 0x38, 0x98, 0x92, 0x33, 0x22, 0x49, 0xf8, 0x18, 0x6a, 0x3e, 0xa3, + 0xfe, 0x22, 0x8c, 0x98, 0x55, 0xb5, 0x91, 0xa3, 0x75, 0xf5, 0x30, 0xba, 0x23, 0x6b, 0x10, 0xbf, + 0x85, 0x7a, 0x1a, 0x73, 0x16, 0x24, 0x71, 0xb6, 0xb4, 0x6a, 0x36, 0x72, 0xc0, 0x6d, 0xed, 0x7c, + 0xfc, 0x3a, 0xe6, 0xec, 0x42, 0x32, 0xc8, 0x86, 0x8c, 0x07, 0xd0, 0x8c, 0x28, 0x67, 0x1e, 0xa7, + 0xcb, 0x65, 0x18, 0x05, 0xd6, 0x9e, 0xad, 0x3b, 0x0d, 0xf7, 0x8b, 0x9d, 0xe4, 0x09, 0xe5, 0x6c, + 0x5c, 0x70, 0x86, 0x91, 0x48, 0x72, 0xd2, 0x88, 0x36, 0x08, 0x3e, 0x83, 0x06, 0x4f, 0x83, 0xb5, + 0xc8, 0xbe, 0x12, 0xb1, 0x77, 0x44, 0xc6, 0x69, 0xf0, 0x44, 0x03, 0xf8, 0x1a, 0xc0, 0x07, 0x60, + 0x24, 0x2c, 0x65, 0xc2, 0x6a, 0xda, 0xc8, 0x31, 0x48, 0x11, 0xe0, 0x23, 0xa8, 0x06, 0x4c, 0x78, + 0xb2, 0xcb, 0xa6, 0x8d, 0x9c, 0x3a, 0xa9, 0x04, 0x4c, 0xbc, 0x63, 0x79, 0xeb, 0x5b, 0xa8, 0xaf, + 0xeb, 0xc1, 0xc7, 0xd0, 0x50, 0xd5, 0x78, 0x77, 0x21, 0x5b, 0xf8, 0x56, 0x5d, 0x29, 0x80, 0x82, + 0xce, 0x25, 0xd2, 0xfa, 0x09, 0xcc, 0xe7, 0x05, 0x6c, 0x86, 0x27, 0xc9, 0x6a, 0x78, 0x07, 0x60, + 0xfc, 0x4e, 0x17, 0x19, 0xb3, 0x34, 0xf5, 0xa9, 0x22, 0xe8, 0x6a, 0x6f, 0x51, 0x6b, 0x0c, 0xfb, + 0xcf, 0xee, 0xbe, 0x9d, 0x8e, 0x8b, 0xf4, 0xaf, 0xb6, 0xd3, 0x1b, 0xee, 0xde, 0x56, 0xf9, 0xcb, + 0x45, 0xbe, 0x25, 0xd7, 0x3e, 0x01, 0x43, 0x6d, 0x02, 0xae, 0x82, 0x4e, 0x86, 0x03, 0xb3, 0x84, + 0xeb, 0x60, 0x5c, 0x90, 0xe1, 0x70, 0x62, 0x22, 0x5c, 0x83, 0x72, 0xef, 0xea, 0x76, 0x68, 0x6a, + 0xed, 0xbf, 0x34, 0x30, 0x54, 0x2e, 0x3e, 0x05, 0xe3, 0x2e, 0xce, 0x22, 0x5f, 0xad, 0x5a, 0xc3, + 0x3d, 0x78, 0x2a, 0xdd, 0x29, 0xba, 0x59, 0x50, 0xf0, 0x09, 0x34, 0x67, 0x31, 0x5f, 0xd2, 0x99, + 0x6a, 0x5b, 0x6a, 0x69, 0xb6, 0xee, 0x18, 0x3d, 0xcd, 0x44, 0xa4, 0xb1, 0xc2, 0xdf, 0xb1, 0x3c, + 0x6d, 0xfd, 0x8d, 0xc0, 0x28, 0x2a, 0x19, 0xc0, 0xf1, 0x3d, 0xcb, 0x3d, 0x31, 0xa7, 0xc2, 0x8b, + 0x18, 0xf3, 0x53, 0xef, 0x8d, 0xfb, 0xdd, 0xf7, 0x33, 0xca, 0xd9, 0xc2, 0xeb, 0xd3, 0xf4, 0x32, + 0x0a, 0x2c, 0x64, 0x6b, 0x8e, 0x4e, 0x3e, 0xbf, 0x67, 0xf9, 0xcd, 0x9c, 0x8a, 0x89, 0x24, 0xad, + 0x39, 0x05, 0x05, 0x1f, 0x6d, 0x57, 0xaf, 0x77, 0xd1, 0x0f, 0xab, 0x82, 0xf1, 0xd7, 0x60, 0x7a, + 0x3c, 0x2f, 0x46, 0xe3, 0xa9, 0x5d, 0x73, 0xd5, 0xff, 0xa1, 0x93, 0xe6, 0x38, 0x57, 0xe3, 0x91, + 0xa3, 0x71, 0xdb, 0x36, 0x94, 0x2f, 0x28, 0x67, 0xb8, 0x09, 0xb5, 0xf3, 0xe9, 0xf4, 0xa6, 0x77, + 0x76, 0x75, 0x65, 0x22, 0x0c, 0x50, 0xb9, 0x19, 0x4e, 0x26, 0x97, 0xd7, 0xa6, 0x76, 0x5a, 0xab, + 0xf9, 0xe6, 0xc3, 0xc3, 0xc3, 0x83, 0xd6, 0xfe, 0x06, 0xea, 0x53, 0x31, 0x67, 0x49, 0x8f, 0xa6, + 0x0c, 0x63, 0x28, 0x4b, 0x59, 0x35, 0x8a, 0x3a, 0x51, 0xef, 0x5b, 0xd4, 0x7f, 0x10, 0xec, 0xab, + 0x2e, 0x0d, 0xff, 0x10, 0x2c, 0x4a, 0xc3, 0x38, 0x4a, 0xdd, 0x36, 0x94, 0x45, 0xc8, 0x19, 0x7e, + 0x36, 0x22, 0x8b, 0xd9, 0xc8, 0x41, 0x44, 0x9d, 0xb9, 0x3f, 0x43, 0x65, 0x46, 0x93, 0x24, 0x16, + 0x3b, 0xac, 0x50, 0x8d, 0xd7, 0x7a, 0x8a, 0x6e, 0xd4, 0xc9, 0x2a, 0xcf, 0xed, 0x81, 0xe1, 0xc7, + 0x51, 0x26, 0x30, 0x5e, 0x53, 0xd7, 0x97, 0x56, 0x9f, 0xfa, 0x94, 0x48, 0x91, 0xda, 0x76, 0xe0, + 0x40, 0xe5, 0x3c, 0x3b, 0xde, 0x5d, 0xde, 0xb6, 0x05, 0xb5, 0xe9, 0xc2, 0x57, 0x3c, 0x55, 0xfd, + 0xe3, 0xe3, 0xe3, 0x63, 0xb5, 0xab, 0xd5, 0x50, 0xfb, 0x4f, 0x1d, 0xa0, 0x1f, 0x73, 0x9e, 0x45, + 0xe1, 0x87, 0x8c, 0xe1, 0x57, 0xd0, 0xe0, 0xf4, 0x9e, 0x79, 0x9c, 0x79, 0xb3, 0xa4, 0x90, 0xa8, + 0x91, 0xba, 0x84, 0xc6, 0xac, 0x9f, 0xe4, 0xd8, 0x82, 0x4a, 0x94, 0xf1, 0xf7, 0x2c, 0xb1, 0x0c, + 0xa9, 0x3e, 0x2a, 0x91, 0x55, 0x8c, 0x0f, 0x56, 0x8d, 0xae, 0xc8, 0x46, 0x8f, 0x4a, 0x45, 0xab, + 0x25, 0xea, 0x53, 0x41, 0x95, 0x31, 0x35, 0x25, 0x2a, 0x23, 0x7c, 0x04, 0x15, 0xc1, 0xf8, 0xd2, + 0x9b, 0x29, 0x3b, 0x42, 0xa3, 0x12, 0x31, 0x64, 0xdc, 0x97, 0xf2, 0x73, 0x16, 0x06, 0x73, 0xa1, + 0x7e, 0x53, 0x4d, 0xca, 0x17, 0x31, 0x3e, 0x01, 0x43, 0xc4, 0x3e, 0xcd, 0x2d, 0x50, 0x9e, 0xf8, + 0x62, 0xdd, 0x9b, 0x01, 0xcd, 0x53, 0x25, 0x20, 0x4f, 0xf1, 0x21, 0x18, 0x9c, 0xe6, 0xef, 0x99, + 0xd5, 0x90, 0x37, 0x97, 0xb8, 0x0a, 0x25, 0xee, 0xb3, 0x85, 0xa0, 0xca, 0x40, 0x3e, 0x93, 0xb8, + 0x0a, 0x71, 0x1b, 0x74, 0x9e, 0x06, 0xd6, 0x8b, 0x8f, 0xfd, 0x94, 0xa3, 0x12, 0x91, 0x87, 0xf8, + 0xc7, 0x6d, 0xff, 0xdc, 0x53, 0xfe, 0xf9, 0x72, 0xcd, 0xdc, 0xf4, 0x6e, 0x63, 0xa1, 0xa3, 0xd2, + 0x96, 0x89, 0xb6, 0xbe, 0xdc, 0x36, 0xa3, 0x43, 0xa8, 0x70, 0xa6, 0xfa, 0xb7, 0x5f, 0x38, 0x56, + 0x11, 0xb5, 0xaa, 0x60, 0x0c, 0xe4, 0x85, 0x7a, 0x55, 0x30, 0xb2, 0x28, 0x8c, 0xa3, 0xd3, 0x57, + 0x50, 0x5d, 0xd9, 0xbd, 0x5c, 0xf3, 0xc2, 0xf0, 0x4d, 0x24, 0x4d, 0xe1, 0x7c, 0xf8, 0xab, 0xa9, + 0x9d, 0x76, 0xa0, 0x2c, 0x4b, 0x97, 0x87, 0xe3, 0xe9, 0x64, 0x70, 0xf6, 0x8b, 0x89, 0x70, 0x03, + 0xaa, 0x37, 0xb7, 0xc3, 0x6b, 0x19, 0x68, 0xd2, 0x35, 0xae, 0x6e, 0x27, 0x83, 0x4b, 0x13, 0xb5, + 0x34, 0x13, 0x75, 0x6d, 0xd0, 0x05, 0x0d, 0x76, 0xf6, 0x35, 0x50, 0xd7, 0x90, 0x47, 0xdd, 0xfe, + 0xff, 0x2b, 0xf9, 0x9c, 0xf3, 0x9b, 0xea, 0xce, 0xcb, 0xa7, 0x8b, 0xfa, 0xf1, 0x9d, 0xfc, 0x2f, + 0x00, 0x00, 0xff, 0xff, 0x43, 0x23, 0x7b, 0xca, 0x33, 0x07, 0x00, 0x00, +} diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/my_test/test.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/my_test/test.proto new file mode 100644 index 000000000..8e7094632 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/my_test/test.proto @@ -0,0 +1,156 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +// This package holds interesting messages. +package my.test; // dotted package name + +//import "imp.proto"; +import "multi/multi1.proto"; // unused import + +enum HatType { + // deliberately skipping 0 + FEDORA = 1; + FEZ = 2; +} + +// This enum represents days of the week. +enum Days { + option allow_alias = true; + + MONDAY = 1; + TUESDAY = 2; + LUNDI = 1; // same value as MONDAY +} + +// This is a message that might be sent somewhere. +message Request { + enum Color { + RED = 0; + GREEN = 1; + BLUE = 2; + } + repeated int64 key = 1; +// optional imp.ImportedMessage imported_message = 2; + optional Color hue = 3; // no default + optional HatType hat = 4 [default=FEDORA]; +// optional imp.ImportedMessage.Owner owner = 6; + optional float deadline = 7 [default=inf]; + optional group SomeGroup = 8 { + optional int32 group_field = 9; + } + + // These foreign types are in imp2.proto, + // which is publicly imported by imp.proto. +// optional imp.PubliclyImportedMessage pub = 10; +// optional imp.PubliclyImportedEnum pub_enum = 13 [default=HAIR]; + + + // This is a map field. It will generate map[int32]string. + map name_mapping = 14; + // This is a map field whose value type is a message. + map msg_mapping = 15; + + optional int32 reset = 12; + // This field should not conflict with any getters. + optional string get_key = 16; +} + +message Reply { + message Entry { + required int64 key_that_needs_1234camel_CasIng = 1; + optional int64 value = 2 [default=7]; + optional int64 _my_field_name_2 = 3; + enum Game { + FOOTBALL = 1; + TENNIS = 2; + } + } + repeated Entry found = 1; + repeated int32 compact_keys = 2 [packed=true]; + extensions 100 to max; +} + +message OtherBase { + optional string name = 1; + extensions 100 to max; +} + +message ReplyExtensions { + extend Reply { + optional double time = 101; + optional ReplyExtensions carrot = 105; + } + extend OtherBase { + optional ReplyExtensions donut = 101; + } +} + +message OtherReplyExtensions { + optional int32 key = 1; +} + +// top-level extension +extend Reply { + optional string tag = 103; + optional OtherReplyExtensions donut = 106; +// optional imp.ImportedMessage elephant = 107; // extend with message from another file. +} + +message OldReply { + // Extensions will be encoded in MessageSet wire format. + option message_set_wire_format = true; + extensions 100 to max; +} + +message Communique { + optional bool make_me_cry = 1; + + // This is a oneof, called "union". + oneof union { + int32 number = 5; + string name = 6; + bytes data = 7; + double temp_c = 8; + float height = 9; + Days today = 10; + bool maybe = 11; + sint32 delta = 12; // name will conflict with Delta below + Reply msg = 13; + group SomeGroup = 14 { + optional string member = 15; + } + } + + message Delta {} +} + diff --git a/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/proto3.proto b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/proto3.proto new file mode 100644 index 000000000..869b9af5a --- /dev/null +++ b/vendor/github.com/gogo/protobuf/protoc-gen-gogo/testdata/proto3.proto @@ -0,0 +1,53 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package proto3; + +message Request { + enum Flavour { + SWEET = 0; + SOUR = 1; + UMAMI = 2; + GOPHERLICIOUS = 3; + } + string name = 1; + repeated int64 key = 2; + Flavour taste = 3; + Book book = 4; + repeated int64 unpacked = 5 [packed=false]; +} + +message Book { + string title = 1; + bytes raw_data = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/.gitignore b/vendor/github.com/gogo/protobuf/test/.gitignore new file mode 100644 index 000000000..773a6df9b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/.gitignore @@ -0,0 +1 @@ +*.dat diff --git a/vendor/github.com/gogo/protobuf/test/Makefile b/vendor/github.com/gogo/protobuf/test/Makefile new file mode 100644 index 000000000..e3002d180 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/Makefile @@ -0,0 +1,39 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + go install github.com/gogo/protobuf/protoc-gen-combo + protoc --gogo_out=. --proto_path=../:../../../../:../protobuf/:. thetest.proto + protoc-gen-combo --default=false --gogo_out=. --proto_path=../:../../../../:../protobuf/:. thetest.proto + cp uuid.go ./combos/both/ + cp uuid.go ./combos/marshaler/ + cp uuid.go ./combos/unmarshaler/ + cp bug_test.go ./combos/both/ + cp bug_test.go ./combos/marshaler/ + cp bug_test.go ./combos/unmarshaler/ diff --git a/vendor/github.com/gogo/protobuf/test/asymetric-issue125/Makefile b/vendor/github.com/gogo/protobuf/test/asymetric-issue125/Makefile new file mode 100644 index 000000000..c42b8cf66 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/asymetric-issue125/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. asym.proto) diff --git a/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym.proto b/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym.proto new file mode 100644 index 000000000..eb3ab9566 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym.proto @@ -0,0 +1,52 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package asym; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.testgen_all) = true; + +message M { + repeated bytes arr = 1 [(gogoproto.customtype) = "MyType", (gogoproto.nullable) = false]; +} + +message MyType { + option (gogoproto.marshaler) = false; + option (gogoproto.sizer) = false; + option (gogoproto.populate) = false; + option (gogoproto.testgen) = false; +} diff --git a/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym_test.go b/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym_test.go new file mode 100644 index 000000000..c99b7cad3 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asym_test.go @@ -0,0 +1,40 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package asym + +import ( + "testing" +) + +func TestAsym(t *testing.T) { + m := &M{[]MyType{{}, {}}, nil} + if err := m.VerboseEqual(m); err != nil { + t.Fatalf("should be equal: %v", err) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asympb_test.go b/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asympb_test.go new file mode 100644 index 000000000..8d968b941 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/asymetric-issue125/asympb_test.go @@ -0,0 +1,184 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: asym.proto + +/* +Package asym is a generated protocol buffer package. + +It is generated from these files: + asym.proto + +It has these top-level messages: + M + MyType +*/ +package asym + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &M{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + dAtA := proto.CompactTextString(p) + msg := &M{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &M{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/bug_test.go b/vendor/github.com/gogo/protobuf/test/bug_test.go new file mode 100644 index 000000000..53f720e96 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/bug_test.go @@ -0,0 +1,252 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "fmt" + "math" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +//http://code.google.com/p/goprotobuf/issues/detail?id=39 +func TestBugUint32VarintSize(t *testing.T) { + temp := uint32(math.MaxUint32) + n := &NinOptNative{} + n.Field5 = &temp + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != 6 { + t.Fatalf("data should be length 6, but its %#v", data) + } +} + +func TestBugZeroLengthSliceSize(t *testing.T) { + n := &NinRepPackedNative{ + Field8: []int64{}, + } + size := n.Size() + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v", len(data), size) + } +} + +//http://code.google.com/p/goprotobuf/issues/detail?id=40 +func TestBugPackedProtoSize(t *testing.T) { + n := &NinRepPackedNative{ + Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711}, + Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361}, + Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8}, + Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84}, + Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243}, + } + size := proto.Size(n) + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size) + } +} + +func testSize(m interface { + proto.Message + Size() int +}, desc string, expected int) ([]byte, error) { + data, err := proto.Marshal(m) + if err != nil { + return nil, err + } + protoSize := proto.Size(m) + mSize := m.Size() + lenData := len(data) + if protoSize != mSize || protoSize != lenData || mSize != lenData { + return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData) + } + if got := protoSize; got != expected { + return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected) + } + if got := mSize; got != expected { + return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected) + } + if got := lenData; got != expected { + return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected) + } + return data, nil +} + +func TestInt32Int64Compatibility(t *testing.T) { + + //test nullable int32 and int64 + + data1, err := testSize(&NinOptNative{ + Field3: proto.Int32(-1), + }, "nullable", 11) + if err != nil { + t.Error(err) + } + //change marshaled data1 to unmarshal into 4th field which is an int64 + data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + u1 := &NinOptNative{} + if err = proto.Unmarshal(data1, u1); err != nil { + t.Error(err) + } + if !u1.Equal(&NinOptNative{ + Field4: proto.Int64(-1), + }) { + t.Error("nullable unmarshaled int32 is not the same int64") + } + + //test non-nullable int32 and int64 + + data2, err := testSize(&NidOptNative{ + Field3: -1, + }, "non nullable", 67) + if err != nil { + t.Error(err) + } + //change marshaled data2 to unmarshal into 4th field which is an int64 + field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + for i, c := range data2 { + if c == field4 { + data2[i] = field3 + } else if c == field3 { + data2[i] = field4 + } + } + u2 := &NidOptNative{} + if err = proto.Unmarshal(data2, u2); err != nil { + t.Error(err) + } + if !u2.Equal(&NidOptNative{ + Field4: -1, + }) { + t.Error("non nullable unmarshaled int32 is not the same int64") + } + + //test packed repeated int32 and int64 + + m4 := &NinRepPackedNative{ + Field3: []int32{-1}, + } + data4, err := testSize(m4, "packed", 12) + if err != nil { + t.Error(err) + } + u4 := &NinRepPackedNative{} + if err := proto.Unmarshal(data4, u4); err != nil { + t.Error(err) + } + if err := u4.VerboseEqual(m4); err != nil { + t.Fatalf("%#v", u4) + } + + //test repeated int32 and int64 + + if _, err := testSize(&NinRepNative{ + Field3: []int32{-1}, + }, "repeated", 11); err != nil { + t.Error(err) + } + + t.Logf("tested all") +} + +func TestRepeatedExtensionsMsgsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + nins := make([]*NinOptNative, rep) + for i := range nins { + nins[i] = NewPopulatedNinOptNative(r, true) + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldE, nins); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} + +func TestRepeatedExtensionsFieldsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + ints := make([]int64, rep) + for i := range ints { + ints[i] = r.Int63() + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldD, ints); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} diff --git a/vendor/github.com/gogo/protobuf/test/casttype/Makefile b/vendor/github.com/gogo/protobuf/test/casttype/Makefile new file mode 100644 index 000000000..684c2e460 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/Makefile @@ -0,0 +1,32 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2015, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-combo + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-gen-combo --gogo_out=. --version="3.0.0" --proto_path=../../../../../:../../protobuf/:. casttype.proto diff --git a/vendor/github.com/gogo/protobuf/test/casttype/casttype.proto b/vendor/github.com/gogo/protobuf/test/casttype/casttype.proto new file mode 100644 index 000000000..c726b9ef4 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/casttype.proto @@ -0,0 +1,80 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package casttype; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Castaway { + optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"]; + optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false]; + optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false]; + optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"]; + optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false]; + optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"]; + optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false]; + optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"]; + optional bytes NormalBytes = 10; + repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"]; + map MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"]; + map MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false]; + optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"]; +} + +message Wilson { + optional int64 Int64 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttype.proto b/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttype.proto new file mode 100644 index 000000000..f4cb9547c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttype.proto @@ -0,0 +1,80 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package casttype; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Castaway { + optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"]; + optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false]; + optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false]; + optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"]; + optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false]; + optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"]; + optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false]; + optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"]; + optional bytes NormalBytes = 10; + repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"]; + map MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"]; + map MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false]; + optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"]; +} + +message Wilson { + optional int64 Int64 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttypepb_test.go b/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttypepb_test.go new file mode 100644 index 000000000..91b5b5076 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/combos/both/casttypepb_test.go @@ -0,0 +1,511 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/casttype.proto + +/* +Package casttype is a generated protocol buffer package. + +It is generated from these files: + combos/both/casttype.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package casttype + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastawayMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestWilsonMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCasttypeDescription(t *testing.T) { + CasttypeDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttype.proto b/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttype.proto new file mode 100644 index 000000000..5da2b7340 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttype.proto @@ -0,0 +1,80 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package casttype; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Castaway { + optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"]; + optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false]; + optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false]; + optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"]; + optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false]; + optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"]; + optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false]; + optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"]; + optional bytes NormalBytes = 10; + repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"]; + map MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"]; + map MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false]; + optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"]; +} + +message Wilson { + optional int64 Int64 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttypepb_test.go b/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttypepb_test.go new file mode 100644 index 000000000..ef0b9bc30 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttypepb_test.go @@ -0,0 +1,511 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/casttype.proto + +/* +Package casttype is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/casttype.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package casttype + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastawayMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestWilsonMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCasttypeDescription(t *testing.T) { + CasttypeDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttype.proto b/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttype.proto new file mode 100644 index 000000000..c726b9ef4 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttype.proto @@ -0,0 +1,80 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package casttype; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Castaway { + optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"]; + optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false]; + optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false]; + optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"]; + optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false]; + optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"]; + optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false]; + optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"]; + optional bytes NormalBytes = 10; + repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"]; + map MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"]; + map MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false]; + optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"]; +} + +message Wilson { + optional int64 Int64 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttypepb_test.go b/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttypepb_test.go new file mode 100644 index 000000000..053f29a39 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/combos/neither/casttypepb_test.go @@ -0,0 +1,455 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/casttype.proto + +/* +Package casttype is a generated protocol buffer package. + +It is generated from these files: + combos/neither/casttype.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package casttype + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCasttypeDescription(t *testing.T) { + CasttypeDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttype.proto b/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttype.proto new file mode 100644 index 000000000..f43d2c25f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttype.proto @@ -0,0 +1,80 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package casttype; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Castaway { + optional int64 Int32Ptr = 1 [(gogoproto.casttype) = "int32"]; + optional int64 Int32 = 2 [(gogoproto.casttype) = "int32", (gogoproto.nullable) = false]; + optional uint64 MyUint64Ptr = 3 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + optional uint64 MyUint64 = 4 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type", (gogoproto.nullable) = false]; + optional float MyFloat32Ptr = 5 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type"]; + optional float MyFloat32 = 6 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat32Type", (gogoproto.nullable) = false]; + optional double MyFloat64Ptr = 7 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type"]; + optional double MyFloat64 = 8 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyFloat64Type", (gogoproto.nullable) = false]; + optional bytes MyBytes = 9 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.Bytes"]; + optional bytes NormalBytes = 10; + repeated uint64 MyUint64s = 11 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyMap = 12 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyMapType"]; + map MyCustomMap = 13 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyStringType", (gogoproto.castvalue) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + map MyNullableMap = 14 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type"]; + map MyEmbeddedMap = 15 [(gogoproto.castkey) = "github.com/gogo/protobuf/test/casttype.MyInt32Type", (gogoproto.nullable) = false]; + optional string String = 16 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyStringType"]; +} + +message Wilson { + optional int64 Int64 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttypepb_test.go b/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttypepb_test.go new file mode 100644 index 000000000..6ddb5e555 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/casttype/combos/unmarshaler/casttypepb_test.go @@ -0,0 +1,455 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/casttype.proto + +/* +Package casttype is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/casttype.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package casttype + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCasttypeDescription(t *testing.T) { + CasttypeDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/castvalue/Makefile b/vendor/github.com/gogo/protobuf/test/castvalue/Makefile new file mode 100644 index 000000000..eeaad892c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/castvalue/Makefile @@ -0,0 +1,40 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + rm -rf combos + go install github.com/gogo/protobuf/protoc-gen-combo + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. castvalue.proto + protoc-gen-combo --default=false --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. castvalue.proto + cp mytypes.go ./combos/both/ || true + cp mytypes.go ./combos/marshaler/ || true + cp mytypes.go ./combos/unmarshaler/ || true + cp mytypes.go ./combos/unsafeboth/ || true + cp mytypes.go ./combos/unsafemarshaler/ || true + cp mytypes.go ./combos/unsafeunmarshaler/ || true diff --git a/vendor/github.com/gogo/protobuf/test/castvalue/castvalue.proto b/vendor/github.com/gogo/protobuf/test/castvalue/castvalue.proto new file mode 100644 index 000000000..35e474361 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/castvalue/castvalue.proto @@ -0,0 +1,66 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package castvalue; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Castaway { + map CastMapValueMessage = 1 [(gogoproto.castvalue) = "MyWilson", (gogoproto.nullable) = false]; + map CastMapValueMessageNullable = 2 [(gogoproto.castvalue) = "MyWilson"]; +} + +message Wilson { + optional int64 Int64 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/castvalue/castvaluepb_test.go b/vendor/github.com/gogo/protobuf/test/castvalue/castvaluepb_test.go new file mode 100644 index 000000000..ddee017e1 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/castvalue/castvaluepb_test.go @@ -0,0 +1,455 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: castvalue.proto + +/* +Package castvalue is a generated protocol buffer package. + +It is generated from these files: + castvalue.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package castvalue + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastvalueDescription(t *testing.T) { + CastvalueDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvalue.proto b/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvalue.proto new file mode 100644 index 000000000..156639577 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvalue.proto @@ -0,0 +1,66 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package castvalue; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Castaway { + map CastMapValueMessage = 1 [(gogoproto.castvalue) = "MyWilson", (gogoproto.nullable) = false]; + map CastMapValueMessageNullable = 2 [(gogoproto.castvalue) = "MyWilson"]; +} + +message Wilson { + optional int64 Int64 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvaluepb_test.go b/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvaluepb_test.go new file mode 100644 index 000000000..6eccd274f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/castvalue/combos/both/castvaluepb_test.go @@ -0,0 +1,511 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/castvalue.proto + +/* +Package castvalue is a generated protocol buffer package. + +It is generated from these files: + combos/both/castvalue.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package castvalue + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastawayMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestWilsonMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastvalueDescription(t *testing.T) { + CastvalueDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvalue.proto b/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvalue.proto new file mode 100644 index 000000000..728312b86 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvalue.proto @@ -0,0 +1,66 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package castvalue; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Castaway { + map CastMapValueMessage = 1 [(gogoproto.castvalue) = "MyWilson", (gogoproto.nullable) = false]; + map CastMapValueMessageNullable = 2 [(gogoproto.castvalue) = "MyWilson"]; +} + +message Wilson { + optional int64 Int64 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvaluepb_test.go b/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvaluepb_test.go new file mode 100644 index 000000000..23e086c50 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvaluepb_test.go @@ -0,0 +1,511 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/castvalue.proto + +/* +Package castvalue is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/castvalue.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package castvalue + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastawayMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestWilsonMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastvalueDescription(t *testing.T) { + CastvalueDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvalue.proto b/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvalue.proto new file mode 100644 index 000000000..2f046a716 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvalue.proto @@ -0,0 +1,66 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package castvalue; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Castaway { + map CastMapValueMessage = 1 [(gogoproto.castvalue) = "MyWilson", (gogoproto.nullable) = false]; + map CastMapValueMessageNullable = 2 [(gogoproto.castvalue) = "MyWilson"]; +} + +message Wilson { + optional int64 Int64 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvaluepb_test.go b/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvaluepb_test.go new file mode 100644 index 000000000..278e50cb3 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/castvalue/combos/unmarshaler/castvaluepb_test.go @@ -0,0 +1,455 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/castvalue.proto + +/* +Package castvalue is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/castvalue.proto + +It has these top-level messages: + Castaway + Wilson +*/ +package castvalue + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestCastawayProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCastawayProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastawayProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCastaway(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Castaway{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkWilsonProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkWilsonProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedWilson(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Wilson{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Castaway{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestWilsonJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Wilson{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastawayProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastawayProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Castaway{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestWilsonProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Wilson{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastvalueDescription(t *testing.T) { + CastvalueDescription() +} +func TestCastawayVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Castaway{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestWilsonVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Wilson{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastawayFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestWilsonFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCastawayGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestWilsonGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastawaySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastaway(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastawaySize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Castaway, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastaway(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestWilsonSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedWilson(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkWilsonSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Wilson, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedWilson(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastawayStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastaway(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestWilsonStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedWilson(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/combos/both/bug_test.go b/vendor/github.com/gogo/protobuf/test/combos/both/bug_test.go new file mode 100644 index 000000000..53f720e96 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/combos/both/bug_test.go @@ -0,0 +1,252 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "fmt" + "math" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +//http://code.google.com/p/goprotobuf/issues/detail?id=39 +func TestBugUint32VarintSize(t *testing.T) { + temp := uint32(math.MaxUint32) + n := &NinOptNative{} + n.Field5 = &temp + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != 6 { + t.Fatalf("data should be length 6, but its %#v", data) + } +} + +func TestBugZeroLengthSliceSize(t *testing.T) { + n := &NinRepPackedNative{ + Field8: []int64{}, + } + size := n.Size() + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v", len(data), size) + } +} + +//http://code.google.com/p/goprotobuf/issues/detail?id=40 +func TestBugPackedProtoSize(t *testing.T) { + n := &NinRepPackedNative{ + Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711}, + Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361}, + Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8}, + Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84}, + Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243}, + } + size := proto.Size(n) + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size) + } +} + +func testSize(m interface { + proto.Message + Size() int +}, desc string, expected int) ([]byte, error) { + data, err := proto.Marshal(m) + if err != nil { + return nil, err + } + protoSize := proto.Size(m) + mSize := m.Size() + lenData := len(data) + if protoSize != mSize || protoSize != lenData || mSize != lenData { + return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData) + } + if got := protoSize; got != expected { + return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected) + } + if got := mSize; got != expected { + return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected) + } + if got := lenData; got != expected { + return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected) + } + return data, nil +} + +func TestInt32Int64Compatibility(t *testing.T) { + + //test nullable int32 and int64 + + data1, err := testSize(&NinOptNative{ + Field3: proto.Int32(-1), + }, "nullable", 11) + if err != nil { + t.Error(err) + } + //change marshaled data1 to unmarshal into 4th field which is an int64 + data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + u1 := &NinOptNative{} + if err = proto.Unmarshal(data1, u1); err != nil { + t.Error(err) + } + if !u1.Equal(&NinOptNative{ + Field4: proto.Int64(-1), + }) { + t.Error("nullable unmarshaled int32 is not the same int64") + } + + //test non-nullable int32 and int64 + + data2, err := testSize(&NidOptNative{ + Field3: -1, + }, "non nullable", 67) + if err != nil { + t.Error(err) + } + //change marshaled data2 to unmarshal into 4th field which is an int64 + field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + for i, c := range data2 { + if c == field4 { + data2[i] = field3 + } else if c == field3 { + data2[i] = field4 + } + } + u2 := &NidOptNative{} + if err = proto.Unmarshal(data2, u2); err != nil { + t.Error(err) + } + if !u2.Equal(&NidOptNative{ + Field4: -1, + }) { + t.Error("non nullable unmarshaled int32 is not the same int64") + } + + //test packed repeated int32 and int64 + + m4 := &NinRepPackedNative{ + Field3: []int32{-1}, + } + data4, err := testSize(m4, "packed", 12) + if err != nil { + t.Error(err) + } + u4 := &NinRepPackedNative{} + if err := proto.Unmarshal(data4, u4); err != nil { + t.Error(err) + } + if err := u4.VerboseEqual(m4); err != nil { + t.Fatalf("%#v", u4) + } + + //test repeated int32 and int64 + + if _, err := testSize(&NinRepNative{ + Field3: []int32{-1}, + }, "repeated", 11); err != nil { + t.Error(err) + } + + t.Logf("tested all") +} + +func TestRepeatedExtensionsMsgsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + nins := make([]*NinOptNative, rep) + for i := range nins { + nins[i] = NewPopulatedNinOptNative(r, true) + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldE, nins); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} + +func TestRepeatedExtensionsFieldsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + ints := make([]int64, rep) + for i := range ints { + ints[i] = r.Int63() + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldD, ints); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} diff --git a/vendor/github.com/gogo/protobuf/test/combos/both/thetest.proto b/vendor/github.com/gogo/protobuf/test/combos/both/thetest.proto new file mode 100644 index 000000000..70d33c47f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/combos/both/thetest.proto @@ -0,0 +1,649 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package test; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.protosizer_all) = false; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +option (gogoproto.compare_all) = true; + +message NidOptNative { + optional double Field1 = 1 [(gogoproto.nullable) = false]; + optional float Field2 = 2 [(gogoproto.nullable) = false]; + optional int32 Field3 = 3 [(gogoproto.nullable) = false]; + optional int64 Field4 = 4 [(gogoproto.nullable) = false]; + optional uint32 Field5 = 5 [(gogoproto.nullable) = false]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false]; + optional sint64 Field8 = 8 [(gogoproto.nullable) = false]; + optional fixed32 Field9 = 9 [(gogoproto.nullable) = false]; + optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false]; + optional fixed64 Field11 = 11 [(gogoproto.nullable) = false]; + optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false]; + optional bool Field13 = 13 [(gogoproto.nullable) = false]; + optional string Field14 = 14 [(gogoproto.nullable) = false]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinOptNative { + optional double Field1 = 1; + optional float Field2 = 2; + optional int32 Field3 = 3; + optional int64 Field4 = 4; + optional uint32 Field5 = 5; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional sint64 Field8 = 8; + optional fixed32 Field9 = 9; + optional sfixed32 Field10 = 10; + optional fixed64 Field11 = 11; + optional sfixed64 Field12 = 12; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NidRepNative { + repeated double Field1 = 1 [(gogoproto.nullable) = false]; + repeated float Field2 = 2 [(gogoproto.nullable) = false]; + repeated int32 Field3 = 3 [(gogoproto.nullable) = false]; + repeated int64 Field4 = 4 [(gogoproto.nullable) = false]; + repeated uint32 Field5 = 5 [(gogoproto.nullable) = false]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false]; + repeated sint64 Field8 = 8 [(gogoproto.nullable) = false]; + repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false]; + repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false]; + repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false]; + repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false]; + repeated string Field14 = 14 [(gogoproto.nullable) = false]; + repeated bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinRepNative { + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated int32 Field3 = 3; + repeated int64 Field4 = 4; + repeated uint32 Field5 = 5; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated sint64 Field8 = 8; + repeated fixed32 Field9 = 9; + repeated sfixed32 Field10 = 10; + repeated fixed64 Field11 = 11; + repeated sfixed64 Field12 = 12; + repeated bool Field13 = 13; + repeated string Field14 = 14; + repeated bytes Field15 = 15; +} + +message NidRepPackedNative { + repeated double Field1 = 1 [(gogoproto.nullable) = false, packed = true]; + repeated float Field2 = 2 [(gogoproto.nullable) = false, packed = true]; + repeated int32 Field3 = 3 [(gogoproto.nullable) = false, packed = true]; + repeated int64 Field4 = 4 [(gogoproto.nullable) = false, packed = true]; + repeated uint32 Field5 = 5 [(gogoproto.nullable) = false, packed = true]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false, packed = true]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false, packed = true]; + repeated sint64 Field8 = 8 [(gogoproto.nullable) = false, packed = true]; + repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false, packed = true]; + repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false, packed = true]; + repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false, packed = true]; + repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false, packed = true]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false, packed = true]; +} + +message NinRepPackedNative { + repeated double Field1 = 1 [packed = true]; + repeated float Field2 = 2 [packed = true]; + repeated int32 Field3 = 3 [packed = true]; + repeated int64 Field4 = 4 [packed = true]; + repeated uint32 Field5 = 5 [packed = true]; + repeated uint64 Field6 = 6 [packed = true]; + repeated sint32 Field7 = 7 [packed = true]; + repeated sint64 Field8 = 8 [packed = true]; + repeated fixed32 Field9 = 9 [packed = true]; + repeated sfixed32 Field10 = 10 [packed = true]; + repeated fixed64 Field11 = 11 [packed = true]; + repeated sfixed64 Field12 = 12 [packed = true]; + repeated bool Field13 = 13 [packed = true]; +} + +message NidOptStruct { + optional double Field1 = 1 [(gogoproto.nullable) = false]; + optional float Field2 = 2 [(gogoproto.nullable) = false]; + optional NidOptNative Field3 = 3 [(gogoproto.nullable) = false]; + optional NinOptNative Field4 = 4 [(gogoproto.nullable) = false]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false]; + optional NidOptNative Field8 = 8 [(gogoproto.nullable) = false]; + optional bool Field13 = 13 [(gogoproto.nullable) = false]; + optional string Field14 = 14 [(gogoproto.nullable) = false]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinOptStruct { + optional double Field1 = 1; + optional float Field2 = 2; + optional NidOptNative Field3 = 3; + optional NinOptNative Field4 = 4; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional NidOptNative Field8 = 8; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NidRepStruct { + repeated double Field1 = 1 [(gogoproto.nullable) = false]; + repeated float Field2 = 2 [(gogoproto.nullable) = false]; + repeated NidOptNative Field3 = 3 [(gogoproto.nullable) = false]; + repeated NinOptNative Field4 = 4 [(gogoproto.nullable) = false]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false]; + repeated NidOptNative Field8 = 8 [(gogoproto.nullable) = false]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false]; + repeated string Field14 = 14 [(gogoproto.nullable) = false]; + repeated bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinRepStruct { + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated NidOptNative Field3 = 3; + repeated NinOptNative Field4 = 4; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated NidOptNative Field8 = 8; + repeated bool Field13 = 13; + repeated string Field14 = 14; + repeated bytes Field15 = 15; +} + +message NidEmbeddedStruct { + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NidOptNative Field200 = 200 [(gogoproto.nullable) = false]; + optional bool Field210 = 210 [(gogoproto.nullable) = false]; +} + +message NinEmbeddedStruct { + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NidOptNative Field200 = 200; + optional bool Field210 = 210; +} + +message NidNestedStruct { + optional NidOptStruct Field1 = 1 [(gogoproto.nullable) = false]; + repeated NidRepStruct Field2 = 2 [(gogoproto.nullable) = false]; +} + +message NinNestedStruct { + optional NinOptStruct Field1 = 1; + repeated NinRepStruct Field2 = 2; +} + +message NidOptCustom { + optional bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false]; + optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; +} + +message CustomDash { + optional bytes Value = 1 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom-dash-type.Bytes"]; +} + +message NinOptCustom { + optional bytes Id = 1 [(gogoproto.customtype) = "Uuid"]; + optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message NidRepCustom { + repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false]; + repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; +} + +message NinRepCustom { + repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid"]; + repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message NinOptNativeUnion { + option (gogoproto.onlyone) = true; + optional double Field1 = 1; + optional float Field2 = 2; + optional int32 Field3 = 3; + optional int64 Field4 = 4; + optional uint32 Field5 = 5; + optional uint64 Field6 = 6; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NinOptStructUnion { + option (gogoproto.onlyone) = true; + optional double Field1 = 1; + optional float Field2 = 2; + optional NidOptNative Field3 = 3; + optional NinOptNative Field4 = 4; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NinEmbeddedStructUnion { + option (gogoproto.onlyone) = true; + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NinOptNative Field200 = 200; + optional bool Field210 = 210; +} + +message NinNestedStructUnion { + option (gogoproto.onlyone) = true; + optional NinOptNativeUnion Field1 = 1; + optional NinOptStructUnion Field2 = 2; + optional NinEmbeddedStructUnion Field3 = 3; +} + +message Tree { + option (gogoproto.onlyone) = true; + optional OrBranch Or = 1; + optional AndBranch And = 2; + optional Leaf Leaf = 3; +} + +message OrBranch { + optional Tree Left = 1 [(gogoproto.nullable) = false]; + optional Tree Right = 2 [(gogoproto.nullable) = false]; +} + +message AndBranch { + optional Tree Left = 1 [(gogoproto.nullable) = false]; + optional Tree Right = 2 [(gogoproto.nullable) = false]; +} + +message Leaf { + optional int64 Value = 1 [(gogoproto.nullable) = false]; + optional string StrValue = 2 [(gogoproto.nullable) = false]; +} + +message DeepTree { + option (gogoproto.onlyone) = true; + optional ADeepBranch Down = 1; + optional AndDeepBranch And = 2; + optional DeepLeaf Leaf = 3; +} + +message ADeepBranch { + optional DeepTree Down = 2 [(gogoproto.nullable) = false]; +} + +message AndDeepBranch { + optional DeepTree Left = 1 [(gogoproto.nullable) = false]; + optional DeepTree Right = 2 [(gogoproto.nullable) = false]; +} + +message DeepLeaf { + optional Tree Tree = 1 [(gogoproto.nullable) = false]; +} + +message Nil { + +} + +enum TheTestEnum { + A = 0; + B = 1; + C = 2; +} + +enum AnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = false; + D = 10; + E = 11; +} + +// YetAnotherTestEnum is used to test cross-package import of custom name +// fields and default resolution. +enum YetAnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = false; + AA = 0; + BB = 1 [(gogoproto.enumvalue_customname) = "BetterYetBB"]; +} + +// YetAnotherTestEnum is used to test cross-package import of custom name +// fields and default resolution. +enum YetYetAnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = true; + CC = 0; + DD = 1 [(gogoproto.enumvalue_customname) = "BetterYetDD"]; +} + +message NidOptEnum { + optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; +} + +message NinOptEnum { + optional TheTestEnum Field1 = 1; + optional YetAnotherTestEnum Field2 = 2; + optional YetYetAnotherTestEnum Field3 = 3; +} + +message NidRepEnum { + repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; + repeated YetAnotherTestEnum Field2 = 2 [(gogoproto.nullable) = false]; + repeated YetYetAnotherTestEnum Field3 = 3 [(gogoproto.nullable) = false]; +} + +message NinRepEnum { + repeated TheTestEnum Field1 = 1; + repeated YetAnotherTestEnum Field2 = 2; + repeated YetYetAnotherTestEnum Field3 = 3; +} + +message NinOptEnumDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional TheTestEnum Field1 = 1 [default=C]; + optional YetAnotherTestEnum Field2 = 2 [default=BB]; + optional YetYetAnotherTestEnum Field3 = 3 [default=CC]; +} + +message AnotherNinOptEnum { + optional AnotherTestEnum Field1 = 1; + optional YetAnotherTestEnum Field2 = 2; + optional YetYetAnotherTestEnum Field3 = 3; +} + +message AnotherNinOptEnumDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional AnotherTestEnum Field1 = 1 [default=E]; + optional YetAnotherTestEnum Field2 = 2 [default=BB]; + optional YetYetAnotherTestEnum Field3 = 3 [default=CC]; +} + + +message Timer { + optional sfixed64 Time1 = 1 [(gogoproto.nullable) = false]; + optional sfixed64 Time2 = 2 [(gogoproto.nullable) = false]; + optional bytes Data = 3 [(gogoproto.nullable) = false]; +} + +message MyExtendable { + option (gogoproto.face) = false; + optional int64 Field1 = 1; + extensions 100 to 199; +} + +extend MyExtendable { + optional double FieldA = 100; + optional NinOptNative FieldB = 101; + optional NinEmbeddedStruct FieldC = 102; + repeated int64 FieldD = 104; + repeated NinOptNative FieldE = 105; +} + +message OtherExtenable { + option (gogoproto.face) = false; + optional int64 Field2 = 2; + extensions 14 to 16; + optional int64 Field13 = 13; + extensions 10 to 12; + optional MyExtendable M = 1; +} + +message NestedDefinition { + optional int64 Field1 = 1; + message NestedMessage { + optional fixed64 NestedField1 = 1; + optional NestedNestedMsg NNM = 2; + message NestedNestedMsg { + optional string NestedNestedField1 = 10; + } + } + enum NestedEnum { + TYPE_NESTED = 1; + } + optional NestedEnum EnumField = 2; + optional NestedMessage.NestedNestedMsg NNM = 3; + optional NestedMessage NM = 4; +} + +message NestedScope { + optional NestedDefinition.NestedMessage.NestedNestedMsg A = 1; + optional NestedDefinition.NestedEnum B = 2; + optional NestedDefinition.NestedMessage C = 3; +} + +message NinOptNativeDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional double Field1 = 1 [default = 1234.1234]; + optional float Field2 = 2 [default = 1234.1234]; + optional int32 Field3 = 3 [default = 1234]; + optional int64 Field4 = 4 [default = 1234]; + optional uint32 Field5 = 5 [default = 1234]; + optional uint64 Field6 = 6 [default = 1234]; + optional sint32 Field7 = 7 [default = 1234]; + optional sint64 Field8 = 8 [default = 1234]; + optional fixed32 Field9 = 9 [default = 1234]; + optional sfixed32 Field10 = 10 [default = 1234]; + optional fixed64 Field11 = 11 [default = 1234]; + optional sfixed64 Field12 = 12 [default = 1234]; + optional bool Field13 = 13 [default = true]; + optional string Field14 = 14 [default = "1234"]; + optional bytes Field15 = 15; +} + +message CustomContainer { + optional NidOptCustom CustomStruct = 1 [(gogoproto.nullable) = false]; +} + +message CustomNameNidOptNative { + optional double Field1 = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldB"]; + optional int32 Field3 = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldC"]; + optional int64 Field4 = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldD"]; + optional uint32 Field5 = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldE"]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldF"]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldG"]; + optional sint64 Field8 = 8 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldH"]; + optional fixed32 Field9 = 9 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldI"]; + optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldJ"]; + optional fixed64 Field11 = 11 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldK"]; + optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldL"]; + optional bool Field13 = 13 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldM"]; + optional string Field14 = 14 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldN"]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinOptNative { + optional double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + optional int32 Field3 = 3 [(gogoproto.customname) = "FieldC"]; + optional int64 Field4 = 4 [(gogoproto.customname) = "FieldD"]; + optional uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"]; + optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"]; + optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"]; + optional sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"]; + optional fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"]; + optional sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"]; + optional fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"]; + optional sfixed64 Field12 = 12 [(gogoproto.customname) = "FielL"]; + optional bool Field13 = 13 [(gogoproto.customname) = "FieldM"]; + optional string Field14 = 14 [(gogoproto.customname) = "FieldN"]; + optional bytes Field15 = 15 [(gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinRepNative { + repeated double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + repeated float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + repeated int32 Field3 = 3 [(gogoproto.customname) = "FieldC"]; + repeated int64 Field4 = 4 [(gogoproto.customname) = "FieldD"]; + repeated uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"]; + repeated uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"]; + repeated sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"]; + repeated sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"]; + repeated fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"]; + repeated sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"]; + repeated fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"]; + repeated sfixed64 Field12 = 12 [(gogoproto.customname) = "FieldL"]; + repeated bool Field13 = 13 [(gogoproto.customname) = "FieldM"]; + repeated string Field14 = 14 [(gogoproto.customname) = "FieldN"]; + repeated bytes Field15 = 15 [(gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinStruct { + optional double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + optional NidOptNative Field3 = 3 [(gogoproto.customname) = "FieldC"]; + repeated NinOptNative Field4 = 4 [(gogoproto.customname) = "FieldD"]; + optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldE"]; + optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldF"]; + optional NidOptNative Field8 = 8 [(gogoproto.customname) = "FieldG"]; + optional bool Field13 = 13 [(gogoproto.customname) = "FieldH"]; + optional string Field14 = 14 [(gogoproto.customname) = "FieldI"]; + optional bytes Field15 = 15 [(gogoproto.customname) = "FieldJ"]; +} + +message CustomNameCustomType { + optional bytes Id = 1 [(gogoproto.customname) = "FieldA", (gogoproto.customtype) = "Uuid"]; + optional bytes Value = 2 [(gogoproto.customname) = "FieldB", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + repeated bytes Ids = 3 [(gogoproto.customname) = "FieldC", (gogoproto.customtype) = "Uuid"]; + repeated bytes Values = 4 [(gogoproto.customname) = "FieldD", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message CustomNameNinEmbeddedStructUnion { + option (gogoproto.onlyone) = true; + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NinOptNative Field200 = 200 [(gogoproto.customname) = "FieldA"]; + optional bool Field210 = 210 [(gogoproto.customname) = "FieldB"]; +} + +message CustomNameEnum { + optional TheTestEnum Field1 = 1 [(gogoproto.customname) = "FieldA"]; + repeated TheTestEnum Field2 = 2 [(gogoproto.customname) = "FieldB"]; +} + +message NoExtensionsMap { + option (gogoproto.face) = false; + option (gogoproto.goproto_extensions_map) = false; + optional int64 Field1 = 1; + extensions 100 to 199; +} + +extend NoExtensionsMap { + optional double FieldA1 = 100; + optional NinOptNative FieldB1 = 101; + optional NinEmbeddedStruct FieldC1 = 102; +} + +message Unrecognized { + option (gogoproto.goproto_unrecognized) = false; + optional string Field1 = 1; +} + +message UnrecognizedWithInner { + message Inner { + option (gogoproto.goproto_unrecognized) = false; + optional uint32 Field1 = 1; + } + + repeated Inner embedded = 1; + optional string Field2 = 2; +} + +message UnrecognizedWithEmbed { + message Embedded { + option (gogoproto.goproto_unrecognized) = false; + optional uint32 Field1 = 1; + } + + optional Embedded embedded = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; + optional string Field2 = 2; +} + +message Node { + optional string Label = 1; + repeated Node Children = 2; +} + +message NonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message NidOptNonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false]; +} + +message NinOptNonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message NidRepNonByteCustomType { + repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false]; +} + +message NinRepNonByteCustomType { + repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message ProtoType { + optional string Field2 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/combos/both/thetestpb_test.go b/vendor/github.com/gogo/protobuf/test/combos/both/thetestpb_test.go new file mode 100644 index 000000000..4c2020853 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/combos/both/thetestpb_test.go @@ -0,0 +1,17949 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/thetest.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + combos/both/thetest.proto + +It has these top-level messages: + NidOptNative + NinOptNative + NidRepNative + NinRepNative + NidRepPackedNative + NinRepPackedNative + NidOptStruct + NinOptStruct + NidRepStruct + NinRepStruct + NidEmbeddedStruct + NinEmbeddedStruct + NidNestedStruct + NinNestedStruct + NidOptCustom + CustomDash + NinOptCustom + NidRepCustom + NinRepCustom + NinOptNativeUnion + NinOptStructUnion + NinEmbeddedStructUnion + NinNestedStructUnion + Tree + OrBranch + AndBranch + Leaf + DeepTree + ADeepBranch + AndDeepBranch + DeepLeaf + Nil + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum + NinOptEnumDefault + AnotherNinOptEnum + AnotherNinOptEnumDefault + Timer + MyExtendable + OtherExtenable + NestedDefinition + NestedScope + NinOptNativeDefault + CustomContainer + CustomNameNidOptNative + CustomNameNinOptNative + CustomNameNinRepNative + CustomNameNinStruct + CustomNameCustomType + CustomNameNinEmbeddedStructUnion + CustomNameEnum + NoExtensionsMap + Unrecognized + UnrecognizedWithInner + UnrecognizedWithEmbed + Node + NonByteCustomType + NidOptNonByteCustomType + NinOptNonByteCustomType + NidRepNonByteCustomType + NinRepNonByteCustomType + ProtoType +*/ +package test + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepPackedNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepPackedNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepPackedNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepPackedNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidEmbeddedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidEmbeddedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinEmbeddedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinEmbeddedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidNestedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidNestedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidNestedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinNestedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinNestedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomDashMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomDashProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomDashProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomDash(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomDash{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNativeUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinEmbeddedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinNestedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinNestedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinNestedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTreeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkTreeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTreeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Tree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOrBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOrBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOrBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOrBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OrBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAndBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAndBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAndBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestLeafMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkLeafProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkLeafProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Leaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDeepTreeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDeepTreeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepTreeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDeepTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepTree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestADeepBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkADeepBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkADeepBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedADeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ADeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAndDeepBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAndDeepBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndDeepBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAndDeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndDeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDeepLeafMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDeepLeafProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepLeafProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDeepLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepLeaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNilMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNilProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNilProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNil(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nil{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAnotherNinOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAnotherNinOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAnotherNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAnotherNinOptEnumDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAnotherNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAnotherNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTimerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkTimerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTimerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedTimer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Timer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMyExtendableMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMyExtendableProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyExtendableProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMyExtendable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyExtendable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOtherExtenableMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOtherExtenableProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOtherExtenableProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOtherExtenable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OtherExtenable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinitionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinitionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinitionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinition_NestedMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinition_NestedMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition_NestedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedScopeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedScopeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedScopeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedScope(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedScope{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNativeDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomContainerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomContainerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomContainerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomContainer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomContainer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNidOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNidOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNidOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinEmbeddedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNoExtensionsMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNoExtensionsMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNoExtensionsMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNoExtensionsMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NoExtensionsMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognized(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Unrecognized{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithInnerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithInnerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInnerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithInner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithInner_InnerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithInner_InnerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithInner_Inner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner_Inner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithEmbedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithEmbedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithEmbed(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed_Embedded{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNodeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNodeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Node, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNodeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNode(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Node{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestProtoTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkProtoTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedProtoType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomDashJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOrBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestADeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndDeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNilJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTimerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyExtendableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOtherExtenableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinitionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedScopeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomContainerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNoExtensionsMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInner_InnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNodeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomDash{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomDash{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNativeUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNativeUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinNestedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinNestedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Tree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Tree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OrBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OrBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AndBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AndBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Leaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Leaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DeepTree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DeepTree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ADeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ADeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AndDeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AndDeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DeepLeaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DeepLeaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Nil{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Nil{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AnotherNinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AnotherNinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Timer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Timer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MyExtendable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MyExtendable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OtherExtenable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OtherExtenable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedScope{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedScope{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNativeDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNativeDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomContainer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomContainer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NoExtensionsMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NoExtensionsMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Unrecognized{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Unrecognized{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithInner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithInner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Node{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Node{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ProtoType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ProtoType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepPackedNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepPackedNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidEmbeddedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidNestedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomDashCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomDash(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTreeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOrBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOrBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestLeafCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepTreeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestADeepBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedADeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndDeepBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndDeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepLeafCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNilCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNil(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTimerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTimer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestMyExtendableCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedMyExtendable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOtherExtenableCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOtherExtenable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinitionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessageCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedScopeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedScope(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomContainerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomContainer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNidOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinEmbeddedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNoExtensionsMapCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNoExtensionsMap(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognized(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInnerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInner_InnerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNodeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNode(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestThetestDescription(t *testing.T) { + ThetestDescription() +} +func TestNidOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepPackedNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepPackedNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidEmbeddedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidNestedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomDashVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTreeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOrBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestLeafVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepTreeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestADeepBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndDeepBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepLeafVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNilVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTimerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyExtendableVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOtherExtenableVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinitionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedScopeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomContainerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNidOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNoExtensionsMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInnerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInner_InnerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNodeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepPackedNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepPackedNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidEmbeddedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidNestedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomDashFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTreeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestOrBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestLeafFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepTreeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestADeepBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndDeepBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepLeafFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNilFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAnotherNinOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTimerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinitionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessageFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedScopeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomContainerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNidOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInnerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInner_InnerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNodeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestProtoTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepPackedNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepPackedNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidEmbeddedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidNestedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomDashGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTreeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOrBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestLeafGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepTreeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestADeepBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndDeepBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepLeafGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNilGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTimerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyExtendableGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOtherExtenableGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinitionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessageGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedScopeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomContainerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNidOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinEmbeddedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNoExtensionsMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInnerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInner_InnerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNodeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestProtoTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepPackedNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepPackedNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidEmbeddedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidNestedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomDashSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTreeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOrBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkLeafSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepTreeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkADeepBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndDeepBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepLeafSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNilSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTimerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyExtendableSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOtherExtenableSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinitionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedScopeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomContainerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNidOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNoExtensionsMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInnerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInner_InnerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNodeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Node, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepPackedNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepPackedNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidEmbeddedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidNestedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomDashStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTreeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOrBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestLeafStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepTreeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestADeepBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndDeepBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepLeafStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNilStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTimerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMyExtendableStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOtherExtenableStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinitionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessageStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedScopeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomContainerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNidOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinEmbeddedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNoExtensionsMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInnerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInner_InnerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNodeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestProtoTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + v := p.GetValue() + msg := &NinOptNativeUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinOptStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + v := p.GetValue() + msg := &NinOptStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &NinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + v := p.GetValue() + msg := &NinNestedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestTreeOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + v := p.GetValue() + msg := &Tree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestDeepTreeOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + v := p.GetValue() + msg := &DeepTree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &CustomNameNinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/combos/marshaler/bug_test.go b/vendor/github.com/gogo/protobuf/test/combos/marshaler/bug_test.go new file mode 100644 index 000000000..53f720e96 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/combos/marshaler/bug_test.go @@ -0,0 +1,252 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "fmt" + "math" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +//http://code.google.com/p/goprotobuf/issues/detail?id=39 +func TestBugUint32VarintSize(t *testing.T) { + temp := uint32(math.MaxUint32) + n := &NinOptNative{} + n.Field5 = &temp + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != 6 { + t.Fatalf("data should be length 6, but its %#v", data) + } +} + +func TestBugZeroLengthSliceSize(t *testing.T) { + n := &NinRepPackedNative{ + Field8: []int64{}, + } + size := n.Size() + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v", len(data), size) + } +} + +//http://code.google.com/p/goprotobuf/issues/detail?id=40 +func TestBugPackedProtoSize(t *testing.T) { + n := &NinRepPackedNative{ + Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711}, + Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361}, + Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8}, + Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84}, + Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243}, + } + size := proto.Size(n) + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size) + } +} + +func testSize(m interface { + proto.Message + Size() int +}, desc string, expected int) ([]byte, error) { + data, err := proto.Marshal(m) + if err != nil { + return nil, err + } + protoSize := proto.Size(m) + mSize := m.Size() + lenData := len(data) + if protoSize != mSize || protoSize != lenData || mSize != lenData { + return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData) + } + if got := protoSize; got != expected { + return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected) + } + if got := mSize; got != expected { + return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected) + } + if got := lenData; got != expected { + return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected) + } + return data, nil +} + +func TestInt32Int64Compatibility(t *testing.T) { + + //test nullable int32 and int64 + + data1, err := testSize(&NinOptNative{ + Field3: proto.Int32(-1), + }, "nullable", 11) + if err != nil { + t.Error(err) + } + //change marshaled data1 to unmarshal into 4th field which is an int64 + data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + u1 := &NinOptNative{} + if err = proto.Unmarshal(data1, u1); err != nil { + t.Error(err) + } + if !u1.Equal(&NinOptNative{ + Field4: proto.Int64(-1), + }) { + t.Error("nullable unmarshaled int32 is not the same int64") + } + + //test non-nullable int32 and int64 + + data2, err := testSize(&NidOptNative{ + Field3: -1, + }, "non nullable", 67) + if err != nil { + t.Error(err) + } + //change marshaled data2 to unmarshal into 4th field which is an int64 + field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + for i, c := range data2 { + if c == field4 { + data2[i] = field3 + } else if c == field3 { + data2[i] = field4 + } + } + u2 := &NidOptNative{} + if err = proto.Unmarshal(data2, u2); err != nil { + t.Error(err) + } + if !u2.Equal(&NidOptNative{ + Field4: -1, + }) { + t.Error("non nullable unmarshaled int32 is not the same int64") + } + + //test packed repeated int32 and int64 + + m4 := &NinRepPackedNative{ + Field3: []int32{-1}, + } + data4, err := testSize(m4, "packed", 12) + if err != nil { + t.Error(err) + } + u4 := &NinRepPackedNative{} + if err := proto.Unmarshal(data4, u4); err != nil { + t.Error(err) + } + if err := u4.VerboseEqual(m4); err != nil { + t.Fatalf("%#v", u4) + } + + //test repeated int32 and int64 + + if _, err := testSize(&NinRepNative{ + Field3: []int32{-1}, + }, "repeated", 11); err != nil { + t.Error(err) + } + + t.Logf("tested all") +} + +func TestRepeatedExtensionsMsgsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + nins := make([]*NinOptNative, rep) + for i := range nins { + nins[i] = NewPopulatedNinOptNative(r, true) + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldE, nins); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} + +func TestRepeatedExtensionsFieldsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + ints := make([]int64, rep) + for i := range ints { + ints[i] = r.Int63() + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldD, ints); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} diff --git a/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetest.proto b/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetest.proto new file mode 100644 index 000000000..ce6cc599e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetest.proto @@ -0,0 +1,649 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package test; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.protosizer_all) = false; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +option (gogoproto.compare_all) = true; + +message NidOptNative { + optional double Field1 = 1 [(gogoproto.nullable) = false]; + optional float Field2 = 2 [(gogoproto.nullable) = false]; + optional int32 Field3 = 3 [(gogoproto.nullable) = false]; + optional int64 Field4 = 4 [(gogoproto.nullable) = false]; + optional uint32 Field5 = 5 [(gogoproto.nullable) = false]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false]; + optional sint64 Field8 = 8 [(gogoproto.nullable) = false]; + optional fixed32 Field9 = 9 [(gogoproto.nullable) = false]; + optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false]; + optional fixed64 Field11 = 11 [(gogoproto.nullable) = false]; + optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false]; + optional bool Field13 = 13 [(gogoproto.nullable) = false]; + optional string Field14 = 14 [(gogoproto.nullable) = false]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinOptNative { + optional double Field1 = 1; + optional float Field2 = 2; + optional int32 Field3 = 3; + optional int64 Field4 = 4; + optional uint32 Field5 = 5; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional sint64 Field8 = 8; + optional fixed32 Field9 = 9; + optional sfixed32 Field10 = 10; + optional fixed64 Field11 = 11; + optional sfixed64 Field12 = 12; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NidRepNative { + repeated double Field1 = 1 [(gogoproto.nullable) = false]; + repeated float Field2 = 2 [(gogoproto.nullable) = false]; + repeated int32 Field3 = 3 [(gogoproto.nullable) = false]; + repeated int64 Field4 = 4 [(gogoproto.nullable) = false]; + repeated uint32 Field5 = 5 [(gogoproto.nullable) = false]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false]; + repeated sint64 Field8 = 8 [(gogoproto.nullable) = false]; + repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false]; + repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false]; + repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false]; + repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false]; + repeated string Field14 = 14 [(gogoproto.nullable) = false]; + repeated bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinRepNative { + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated int32 Field3 = 3; + repeated int64 Field4 = 4; + repeated uint32 Field5 = 5; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated sint64 Field8 = 8; + repeated fixed32 Field9 = 9; + repeated sfixed32 Field10 = 10; + repeated fixed64 Field11 = 11; + repeated sfixed64 Field12 = 12; + repeated bool Field13 = 13; + repeated string Field14 = 14; + repeated bytes Field15 = 15; +} + +message NidRepPackedNative { + repeated double Field1 = 1 [(gogoproto.nullable) = false, packed = true]; + repeated float Field2 = 2 [(gogoproto.nullable) = false, packed = true]; + repeated int32 Field3 = 3 [(gogoproto.nullable) = false, packed = true]; + repeated int64 Field4 = 4 [(gogoproto.nullable) = false, packed = true]; + repeated uint32 Field5 = 5 [(gogoproto.nullable) = false, packed = true]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false, packed = true]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false, packed = true]; + repeated sint64 Field8 = 8 [(gogoproto.nullable) = false, packed = true]; + repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false, packed = true]; + repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false, packed = true]; + repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false, packed = true]; + repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false, packed = true]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false, packed = true]; +} + +message NinRepPackedNative { + repeated double Field1 = 1 [packed = true]; + repeated float Field2 = 2 [packed = true]; + repeated int32 Field3 = 3 [packed = true]; + repeated int64 Field4 = 4 [packed = true]; + repeated uint32 Field5 = 5 [packed = true]; + repeated uint64 Field6 = 6 [packed = true]; + repeated sint32 Field7 = 7 [packed = true]; + repeated sint64 Field8 = 8 [packed = true]; + repeated fixed32 Field9 = 9 [packed = true]; + repeated sfixed32 Field10 = 10 [packed = true]; + repeated fixed64 Field11 = 11 [packed = true]; + repeated sfixed64 Field12 = 12 [packed = true]; + repeated bool Field13 = 13 [packed = true]; +} + +message NidOptStruct { + optional double Field1 = 1 [(gogoproto.nullable) = false]; + optional float Field2 = 2 [(gogoproto.nullable) = false]; + optional NidOptNative Field3 = 3 [(gogoproto.nullable) = false]; + optional NinOptNative Field4 = 4 [(gogoproto.nullable) = false]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false]; + optional NidOptNative Field8 = 8 [(gogoproto.nullable) = false]; + optional bool Field13 = 13 [(gogoproto.nullable) = false]; + optional string Field14 = 14 [(gogoproto.nullable) = false]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinOptStruct { + optional double Field1 = 1; + optional float Field2 = 2; + optional NidOptNative Field3 = 3; + optional NinOptNative Field4 = 4; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional NidOptNative Field8 = 8; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NidRepStruct { + repeated double Field1 = 1 [(gogoproto.nullable) = false]; + repeated float Field2 = 2 [(gogoproto.nullable) = false]; + repeated NidOptNative Field3 = 3 [(gogoproto.nullable) = false]; + repeated NinOptNative Field4 = 4 [(gogoproto.nullable) = false]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false]; + repeated NidOptNative Field8 = 8 [(gogoproto.nullable) = false]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false]; + repeated string Field14 = 14 [(gogoproto.nullable) = false]; + repeated bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinRepStruct { + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated NidOptNative Field3 = 3; + repeated NinOptNative Field4 = 4; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated NidOptNative Field8 = 8; + repeated bool Field13 = 13; + repeated string Field14 = 14; + repeated bytes Field15 = 15; +} + +message NidEmbeddedStruct { + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NidOptNative Field200 = 200 [(gogoproto.nullable) = false]; + optional bool Field210 = 210 [(gogoproto.nullable) = false]; +} + +message NinEmbeddedStruct { + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NidOptNative Field200 = 200; + optional bool Field210 = 210; +} + +message NidNestedStruct { + optional NidOptStruct Field1 = 1 [(gogoproto.nullable) = false]; + repeated NidRepStruct Field2 = 2 [(gogoproto.nullable) = false]; +} + +message NinNestedStruct { + optional NinOptStruct Field1 = 1; + repeated NinRepStruct Field2 = 2; +} + +message NidOptCustom { + optional bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false]; + optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; +} + +message CustomDash { + optional bytes Value = 1 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom-dash-type.Bytes"]; +} + +message NinOptCustom { + optional bytes Id = 1 [(gogoproto.customtype) = "Uuid"]; + optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message NidRepCustom { + repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false]; + repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; +} + +message NinRepCustom { + repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid"]; + repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message NinOptNativeUnion { + option (gogoproto.onlyone) = true; + optional double Field1 = 1; + optional float Field2 = 2; + optional int32 Field3 = 3; + optional int64 Field4 = 4; + optional uint32 Field5 = 5; + optional uint64 Field6 = 6; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NinOptStructUnion { + option (gogoproto.onlyone) = true; + optional double Field1 = 1; + optional float Field2 = 2; + optional NidOptNative Field3 = 3; + optional NinOptNative Field4 = 4; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NinEmbeddedStructUnion { + option (gogoproto.onlyone) = true; + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NinOptNative Field200 = 200; + optional bool Field210 = 210; +} + +message NinNestedStructUnion { + option (gogoproto.onlyone) = true; + optional NinOptNativeUnion Field1 = 1; + optional NinOptStructUnion Field2 = 2; + optional NinEmbeddedStructUnion Field3 = 3; +} + +message Tree { + option (gogoproto.onlyone) = true; + optional OrBranch Or = 1; + optional AndBranch And = 2; + optional Leaf Leaf = 3; +} + +message OrBranch { + optional Tree Left = 1 [(gogoproto.nullable) = false]; + optional Tree Right = 2 [(gogoproto.nullable) = false]; +} + +message AndBranch { + optional Tree Left = 1 [(gogoproto.nullable) = false]; + optional Tree Right = 2 [(gogoproto.nullable) = false]; +} + +message Leaf { + optional int64 Value = 1 [(gogoproto.nullable) = false]; + optional string StrValue = 2 [(gogoproto.nullable) = false]; +} + +message DeepTree { + option (gogoproto.onlyone) = true; + optional ADeepBranch Down = 1; + optional AndDeepBranch And = 2; + optional DeepLeaf Leaf = 3; +} + +message ADeepBranch { + optional DeepTree Down = 2 [(gogoproto.nullable) = false]; +} + +message AndDeepBranch { + optional DeepTree Left = 1 [(gogoproto.nullable) = false]; + optional DeepTree Right = 2 [(gogoproto.nullable) = false]; +} + +message DeepLeaf { + optional Tree Tree = 1 [(gogoproto.nullable) = false]; +} + +message Nil { + +} + +enum TheTestEnum { + A = 0; + B = 1; + C = 2; +} + +enum AnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = false; + D = 10; + E = 11; +} + +// YetAnotherTestEnum is used to test cross-package import of custom name +// fields and default resolution. +enum YetAnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = false; + AA = 0; + BB = 1 [(gogoproto.enumvalue_customname) = "BetterYetBB"]; +} + +// YetAnotherTestEnum is used to test cross-package import of custom name +// fields and default resolution. +enum YetYetAnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = true; + CC = 0; + DD = 1 [(gogoproto.enumvalue_customname) = "BetterYetDD"]; +} + +message NidOptEnum { + optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; +} + +message NinOptEnum { + optional TheTestEnum Field1 = 1; + optional YetAnotherTestEnum Field2 = 2; + optional YetYetAnotherTestEnum Field3 = 3; +} + +message NidRepEnum { + repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; + repeated YetAnotherTestEnum Field2 = 2 [(gogoproto.nullable) = false]; + repeated YetYetAnotherTestEnum Field3 = 3 [(gogoproto.nullable) = false]; +} + +message NinRepEnum { + repeated TheTestEnum Field1 = 1; + repeated YetAnotherTestEnum Field2 = 2; + repeated YetYetAnotherTestEnum Field3 = 3; +} + +message NinOptEnumDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional TheTestEnum Field1 = 1 [default=C]; + optional YetAnotherTestEnum Field2 = 2 [default=BB]; + optional YetYetAnotherTestEnum Field3 = 3 [default=CC]; +} + +message AnotherNinOptEnum { + optional AnotherTestEnum Field1 = 1; + optional YetAnotherTestEnum Field2 = 2; + optional YetYetAnotherTestEnum Field3 = 3; +} + +message AnotherNinOptEnumDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional AnotherTestEnum Field1 = 1 [default=E]; + optional YetAnotherTestEnum Field2 = 2 [default=BB]; + optional YetYetAnotherTestEnum Field3 = 3 [default=CC]; +} + + +message Timer { + optional sfixed64 Time1 = 1 [(gogoproto.nullable) = false]; + optional sfixed64 Time2 = 2 [(gogoproto.nullable) = false]; + optional bytes Data = 3 [(gogoproto.nullable) = false]; +} + +message MyExtendable { + option (gogoproto.face) = false; + optional int64 Field1 = 1; + extensions 100 to 199; +} + +extend MyExtendable { + optional double FieldA = 100; + optional NinOptNative FieldB = 101; + optional NinEmbeddedStruct FieldC = 102; + repeated int64 FieldD = 104; + repeated NinOptNative FieldE = 105; +} + +message OtherExtenable { + option (gogoproto.face) = false; + optional int64 Field2 = 2; + extensions 14 to 16; + optional int64 Field13 = 13; + extensions 10 to 12; + optional MyExtendable M = 1; +} + +message NestedDefinition { + optional int64 Field1 = 1; + message NestedMessage { + optional fixed64 NestedField1 = 1; + optional NestedNestedMsg NNM = 2; + message NestedNestedMsg { + optional string NestedNestedField1 = 10; + } + } + enum NestedEnum { + TYPE_NESTED = 1; + } + optional NestedEnum EnumField = 2; + optional NestedMessage.NestedNestedMsg NNM = 3; + optional NestedMessage NM = 4; +} + +message NestedScope { + optional NestedDefinition.NestedMessage.NestedNestedMsg A = 1; + optional NestedDefinition.NestedEnum B = 2; + optional NestedDefinition.NestedMessage C = 3; +} + +message NinOptNativeDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional double Field1 = 1 [default = 1234.1234]; + optional float Field2 = 2 [default = 1234.1234]; + optional int32 Field3 = 3 [default = 1234]; + optional int64 Field4 = 4 [default = 1234]; + optional uint32 Field5 = 5 [default = 1234]; + optional uint64 Field6 = 6 [default = 1234]; + optional sint32 Field7 = 7 [default = 1234]; + optional sint64 Field8 = 8 [default = 1234]; + optional fixed32 Field9 = 9 [default = 1234]; + optional sfixed32 Field10 = 10 [default = 1234]; + optional fixed64 Field11 = 11 [default = 1234]; + optional sfixed64 Field12 = 12 [default = 1234]; + optional bool Field13 = 13 [default = true]; + optional string Field14 = 14 [default = "1234"]; + optional bytes Field15 = 15; +} + +message CustomContainer { + optional NidOptCustom CustomStruct = 1 [(gogoproto.nullable) = false]; +} + +message CustomNameNidOptNative { + optional double Field1 = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldB"]; + optional int32 Field3 = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldC"]; + optional int64 Field4 = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldD"]; + optional uint32 Field5 = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldE"]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldF"]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldG"]; + optional sint64 Field8 = 8 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldH"]; + optional fixed32 Field9 = 9 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldI"]; + optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldJ"]; + optional fixed64 Field11 = 11 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldK"]; + optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldL"]; + optional bool Field13 = 13 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldM"]; + optional string Field14 = 14 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldN"]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinOptNative { + optional double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + optional int32 Field3 = 3 [(gogoproto.customname) = "FieldC"]; + optional int64 Field4 = 4 [(gogoproto.customname) = "FieldD"]; + optional uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"]; + optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"]; + optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"]; + optional sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"]; + optional fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"]; + optional sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"]; + optional fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"]; + optional sfixed64 Field12 = 12 [(gogoproto.customname) = "FielL"]; + optional bool Field13 = 13 [(gogoproto.customname) = "FieldM"]; + optional string Field14 = 14 [(gogoproto.customname) = "FieldN"]; + optional bytes Field15 = 15 [(gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinRepNative { + repeated double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + repeated float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + repeated int32 Field3 = 3 [(gogoproto.customname) = "FieldC"]; + repeated int64 Field4 = 4 [(gogoproto.customname) = "FieldD"]; + repeated uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"]; + repeated uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"]; + repeated sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"]; + repeated sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"]; + repeated fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"]; + repeated sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"]; + repeated fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"]; + repeated sfixed64 Field12 = 12 [(gogoproto.customname) = "FieldL"]; + repeated bool Field13 = 13 [(gogoproto.customname) = "FieldM"]; + repeated string Field14 = 14 [(gogoproto.customname) = "FieldN"]; + repeated bytes Field15 = 15 [(gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinStruct { + optional double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + optional NidOptNative Field3 = 3 [(gogoproto.customname) = "FieldC"]; + repeated NinOptNative Field4 = 4 [(gogoproto.customname) = "FieldD"]; + optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldE"]; + optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldF"]; + optional NidOptNative Field8 = 8 [(gogoproto.customname) = "FieldG"]; + optional bool Field13 = 13 [(gogoproto.customname) = "FieldH"]; + optional string Field14 = 14 [(gogoproto.customname) = "FieldI"]; + optional bytes Field15 = 15 [(gogoproto.customname) = "FieldJ"]; +} + +message CustomNameCustomType { + optional bytes Id = 1 [(gogoproto.customname) = "FieldA", (gogoproto.customtype) = "Uuid"]; + optional bytes Value = 2 [(gogoproto.customname) = "FieldB", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + repeated bytes Ids = 3 [(gogoproto.customname) = "FieldC", (gogoproto.customtype) = "Uuid"]; + repeated bytes Values = 4 [(gogoproto.customname) = "FieldD", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message CustomNameNinEmbeddedStructUnion { + option (gogoproto.onlyone) = true; + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NinOptNative Field200 = 200 [(gogoproto.customname) = "FieldA"]; + optional bool Field210 = 210 [(gogoproto.customname) = "FieldB"]; +} + +message CustomNameEnum { + optional TheTestEnum Field1 = 1 [(gogoproto.customname) = "FieldA"]; + repeated TheTestEnum Field2 = 2 [(gogoproto.customname) = "FieldB"]; +} + +message NoExtensionsMap { + option (gogoproto.face) = false; + option (gogoproto.goproto_extensions_map) = false; + optional int64 Field1 = 1; + extensions 100 to 199; +} + +extend NoExtensionsMap { + optional double FieldA1 = 100; + optional NinOptNative FieldB1 = 101; + optional NinEmbeddedStruct FieldC1 = 102; +} + +message Unrecognized { + option (gogoproto.goproto_unrecognized) = false; + optional string Field1 = 1; +} + +message UnrecognizedWithInner { + message Inner { + option (gogoproto.goproto_unrecognized) = false; + optional uint32 Field1 = 1; + } + + repeated Inner embedded = 1; + optional string Field2 = 2; +} + +message UnrecognizedWithEmbed { + message Embedded { + option (gogoproto.goproto_unrecognized) = false; + optional uint32 Field1 = 1; + } + + optional Embedded embedded = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; + optional string Field2 = 2; +} + +message Node { + optional string Label = 1; + repeated Node Children = 2; +} + +message NonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message NidOptNonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false]; +} + +message NinOptNonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message NidRepNonByteCustomType { + repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false]; +} + +message NinRepNonByteCustomType { + repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message ProtoType { + optional string Field2 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetestpb_test.go b/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetestpb_test.go new file mode 100644 index 000000000..60ffaa87f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/combos/marshaler/thetestpb_test.go @@ -0,0 +1,17949 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/thetest.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/thetest.proto + +It has these top-level messages: + NidOptNative + NinOptNative + NidRepNative + NinRepNative + NidRepPackedNative + NinRepPackedNative + NidOptStruct + NinOptStruct + NidRepStruct + NinRepStruct + NidEmbeddedStruct + NinEmbeddedStruct + NidNestedStruct + NinNestedStruct + NidOptCustom + CustomDash + NinOptCustom + NidRepCustom + NinRepCustom + NinOptNativeUnion + NinOptStructUnion + NinEmbeddedStructUnion + NinNestedStructUnion + Tree + OrBranch + AndBranch + Leaf + DeepTree + ADeepBranch + AndDeepBranch + DeepLeaf + Nil + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum + NinOptEnumDefault + AnotherNinOptEnum + AnotherNinOptEnumDefault + Timer + MyExtendable + OtherExtenable + NestedDefinition + NestedScope + NinOptNativeDefault + CustomContainer + CustomNameNidOptNative + CustomNameNinOptNative + CustomNameNinRepNative + CustomNameNinStruct + CustomNameCustomType + CustomNameNinEmbeddedStructUnion + CustomNameEnum + NoExtensionsMap + Unrecognized + UnrecognizedWithInner + UnrecognizedWithEmbed + Node + NonByteCustomType + NidOptNonByteCustomType + NinOptNonByteCustomType + NidRepNonByteCustomType + NinRepNonByteCustomType + ProtoType +*/ +package test + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepPackedNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepPackedNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepPackedNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepPackedNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidEmbeddedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidEmbeddedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinEmbeddedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinEmbeddedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidNestedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidNestedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidNestedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinNestedStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinNestedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomDashMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomDashProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomDashProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomDash(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomDash{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepCustomMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNativeUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinEmbeddedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinNestedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinNestedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinNestedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTreeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkTreeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTreeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Tree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOrBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOrBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOrBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOrBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OrBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAndBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAndBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAndBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestLeafMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkLeafProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkLeafProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Leaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDeepTreeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDeepTreeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepTreeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDeepTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepTree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestADeepBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkADeepBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkADeepBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedADeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ADeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAndDeepBranchMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAndDeepBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndDeepBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAndDeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndDeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDeepLeafMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDeepLeafProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepLeafProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDeepLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepLeaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNilMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNilProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNilProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNil(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nil{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAnotherNinOptEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAnotherNinOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAnotherNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAnotherNinOptEnumDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAnotherNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAnotherNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTimerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkTimerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTimerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedTimer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Timer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMyExtendableMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMyExtendableProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyExtendableProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMyExtendable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyExtendable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOtherExtenableMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOtherExtenableProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOtherExtenableProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOtherExtenable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OtherExtenable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinitionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinitionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinitionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinition_NestedMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinition_NestedMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition_NestedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedScopeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedScopeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedScopeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedScope(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedScope{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNativeDefaultMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNativeDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNativeDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomContainerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomContainerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomContainerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomContainer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomContainer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNidOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNidOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNidOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinOptNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinRepNativeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinStructMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameNinEmbeddedStructUnionMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomNameEnumMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomNameEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNoExtensionsMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNoExtensionsMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNoExtensionsMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNoExtensionsMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NoExtensionsMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognized(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Unrecognized{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithInnerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithInnerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInnerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithInner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithInner_InnerMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithInner_InnerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithInner_Inner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner_Inner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithEmbedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithEmbedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithEmbed(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed_Embedded{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNodeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNodeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Node, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNodeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNode(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Node{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNidRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepNonByteCustomTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNinRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestProtoTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkProtoTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedProtoType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomDashJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOrBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestADeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndDeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNilJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTimerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyExtendableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOtherExtenableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinitionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedScopeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomContainerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNoExtensionsMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInner_InnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNodeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomDash{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomDash{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNativeUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNativeUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinNestedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinNestedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Tree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Tree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OrBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OrBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AndBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AndBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Leaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Leaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DeepTree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DeepTree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ADeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ADeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AndDeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AndDeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DeepLeaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DeepLeaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Nil{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Nil{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AnotherNinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AnotherNinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Timer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Timer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MyExtendable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MyExtendable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OtherExtenable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OtherExtenable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedScope{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedScope{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNativeDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNativeDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomContainer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomContainer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NoExtensionsMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NoExtensionsMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Unrecognized{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Unrecognized{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithInner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithInner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Node{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Node{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ProtoType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ProtoType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepPackedNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepPackedNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidEmbeddedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidNestedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomDashCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomDash(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTreeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOrBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOrBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestLeafCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepTreeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestADeepBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedADeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndDeepBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndDeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepLeafCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNilCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNil(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTimerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTimer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestMyExtendableCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedMyExtendable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOtherExtenableCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOtherExtenable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinitionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessageCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedScopeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedScope(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomContainerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomContainer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNidOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinEmbeddedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNoExtensionsMapCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNoExtensionsMap(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognized(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInnerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInner_InnerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNodeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNode(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestThetestDescription(t *testing.T) { + ThetestDescription() +} +func TestNidOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepPackedNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepPackedNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidEmbeddedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidNestedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomDashVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTreeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOrBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestLeafVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepTreeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestADeepBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndDeepBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepLeafVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNilVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTimerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyExtendableVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOtherExtenableVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinitionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedScopeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomContainerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNidOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNoExtensionsMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInnerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInner_InnerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNodeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepPackedNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepPackedNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidEmbeddedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidNestedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomDashFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTreeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestOrBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestLeafFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepTreeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestADeepBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndDeepBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepLeafFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNilFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAnotherNinOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTimerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinitionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessageFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedScopeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomContainerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNidOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInnerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInner_InnerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNodeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestProtoTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepPackedNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepPackedNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidEmbeddedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidNestedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomDashGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTreeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOrBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestLeafGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepTreeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestADeepBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndDeepBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepLeafGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNilGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTimerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyExtendableGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOtherExtenableGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinitionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessageGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedScopeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomContainerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNidOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinEmbeddedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNoExtensionsMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInnerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInner_InnerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNodeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestProtoTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepPackedNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepPackedNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidEmbeddedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidNestedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomDashSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTreeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOrBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkLeafSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepTreeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkADeepBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndDeepBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepLeafSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNilSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTimerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyExtendableSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOtherExtenableSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinitionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedScopeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomContainerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNidOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNoExtensionsMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInnerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInner_InnerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNodeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Node, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepPackedNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepPackedNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidEmbeddedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidNestedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomDashStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTreeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOrBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestLeafStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepTreeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestADeepBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndDeepBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepLeafStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNilStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTimerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMyExtendableStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOtherExtenableStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinitionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessageStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedScopeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomContainerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNidOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinEmbeddedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNoExtensionsMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInnerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInner_InnerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNodeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestProtoTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + v := p.GetValue() + msg := &NinOptNativeUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinOptStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + v := p.GetValue() + msg := &NinOptStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &NinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + v := p.GetValue() + msg := &NinNestedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestTreeOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + v := p.GetValue() + msg := &Tree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestDeepTreeOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + v := p.GetValue() + msg := &DeepTree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &CustomNameNinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/bug_test.go b/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/bug_test.go new file mode 100644 index 000000000..53f720e96 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/bug_test.go @@ -0,0 +1,252 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "fmt" + "math" + "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +//http://code.google.com/p/goprotobuf/issues/detail?id=39 +func TestBugUint32VarintSize(t *testing.T) { + temp := uint32(math.MaxUint32) + n := &NinOptNative{} + n.Field5 = &temp + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != 6 { + t.Fatalf("data should be length 6, but its %#v", data) + } +} + +func TestBugZeroLengthSliceSize(t *testing.T) { + n := &NinRepPackedNative{ + Field8: []int64{}, + } + size := n.Size() + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v", len(data), size) + } +} + +//http://code.google.com/p/goprotobuf/issues/detail?id=40 +func TestBugPackedProtoSize(t *testing.T) { + n := &NinRepPackedNative{ + Field4: []int64{172960727389894724, 2360337516664475010, 860833876131988189, 9068073014890763245, 7794843386260381831, 4023536436053141786, 8992311247496919020, 4330096163611305776, 4490411416244976467, 7873947349172707443, 2754969595834279669, 1360667855926938684, 4771480785172657389, 4875578924966668055, 8070579869808877481, 9128179594766551001, 4630419407064527516, 863844540220372892, 8208727650143073487, 7086117356301045838, 7779695211931506151, 5493835345187563535, 9119767633370806007, 9054342025895349248, 1887303228838508438, 7624573031734528281, 1874668389749611225, 3517684643468970593, 6677697606628877758, 7293473953189936168, 444475066704085538, 8594971141363049302, 1146643249094989673, 733393306232853371, 7721178528893916886, 7784452000911004429, 6436373110242711440, 6897422461738321237, 8772249155667732778, 6211871464311393541, 3061903718310406883, 7845488913176136641, 8342255034663902574, 3443058984649725748, 8410801047334832902, 7496541071517841153, 4305416923521577765, 7814967600020476457, 8671843803465481186, 3490266370361096855, 1447425664719091336, 653218597262334239, 8306243902880091940, 7851896059762409081, 5936760560798954978, 5755724498441478025, 7022701569985035966, 3707709584811468220, 529069456924666920, 7986469043681522462, 3092513330689518836, 5103541550470476202, 3577384161242626406, 3733428084624703294, 8388690542440473117, 3262468785346149388, 8788358556558007570, 5476276940198542020, 7277903243119461239, 5065861426928605020, 7533460976202697734, 1749213838654236956, 557497603941617931, 5496307611456481108, 6444547750062831720, 6992758776744205596, 7356719693428537399, 2896328872476734507, 381447079530132038, 598300737753233118, 3687980626612697715, 7240924191084283349, 8172414415307971170, 4847024388701257185, 2081764168600256551, 3394217778539123488, 6244660626429310923, 8301712215675381614, 5360615125359461174, 8410140945829785773, 3152963269026381373, 6197275282781459633, 4419829061407546410, 6262035523070047537, 2837207483933463885, 2158105736666826128, 8150764172235490711}, + Field7: []int32{249451845, 1409974015, 393609128, 435232428, 1817529040, 91769006, 861170933, 1556185603, 1568580279, 1236375273, 512276621, 693633711, 967580535, 1950715977, 853431462, 1362390253, 159591204, 111900629, 322985263, 279671129, 1592548430, 465651370, 733849989, 1172059400, 1574824441, 263541092, 1271612397, 1520584358, 467078791, 117698716, 1098255064, 2054264846, 1766452305, 1267576395, 1557505617, 1187833560, 956187431, 1970977586, 1160235159, 1610259028, 489585797, 459139078, 566263183, 954319278, 1545018565, 1753946743, 948214318, 422878159, 883926576, 1424009347, 824732372, 1290433180, 80297942, 417294230, 1402647904, 2078392782, 220505045, 787368129, 463781454, 293083578, 808156928, 293976361}, + Field9: []uint32{0xaa4976e8, 0x3da8cc4c, 0x8c470d83, 0x344d964e, 0x5b90925, 0xa4c4d34e, 0x666eff19, 0xc238e552, 0x9be53bb6, 0x56364245, 0x33ee079d, 0x96bf0ede, 0x7941b74f, 0xdb07cb47, 0x6d76d827, 0x9b211d5d, 0x2798adb6, 0xe48b0c3b, 0x87061b21, 0x48f4e4d2, 0x3e5d5c12, 0x5ee91288, 0x336d4f35, 0xe1d44941, 0xc065548d, 0x2953d73f, 0x873af451, 0xfc769db, 0x9f1bf8da, 0x9baafdfc, 0xf1d3d770, 0x5bb5d2b4, 0xc2c67c48, 0x6845c4c1, 0xa48f32b0, 0xbb04bb70, 0xa5b1ca36, 0x8d98356a, 0x2171f654, 0x5ae279b0, 0x6c4a3d6b, 0x4fff5468, 0xcf9bf851, 0x68513614, 0xdbecd9b0, 0x9553ed3c, 0xa494a736, 0x42205438, 0xbf8e5caa, 0xd3283c6, 0x76d20788, 0x9179826f, 0x96b24f85, 0xbc2eacf4, 0xe4afae0b, 0x4bca85cb, 0x35e63b5b, 0xd7ccee0c, 0x2b506bb9, 0xe78e9f44, 0x9ad232f1, 0x99a37335, 0xa5d6ffc8}, + Field11: []uint64{0x53c01ebc, 0x4fb85ba6, 0x8805eea1, 0xb20ec896, 0x93b63410, 0xec7c9492, 0x50765a28, 0x19592106, 0x2ecc59b3, 0x39cd474f, 0xe4c9e47, 0x444f48c5, 0xe7731d32, 0xf3f43975, 0x603caedd, 0xbb05a1af, 0xa808e34e, 0x88580b07, 0x4c96bbd1, 0x730b4ab9, 0xed126e2b, 0x6db48205, 0x154ba1b9, 0xc26bfb6a, 0x389aa052, 0x869d966c, 0x7c86b366, 0xcc8edbcd, 0xfa8d6dad, 0xcf5857d9, 0x2d9cda0f, 0x1218a0b8, 0x41bf997, 0xf0ca65ac, 0xa610d4b9, 0x8d362e28, 0xb7212d87, 0x8e0fe109, 0xbee041d9, 0x759be2f6, 0x35fef4f3, 0xaeacdb71, 0x10888852, 0xf4e28117, 0xe2a14812, 0x73b748dc, 0xd1c3c6b2, 0xfef41bf0, 0xc9b43b62, 0x810e4faa, 0xcaa41c06, 0x1893fe0d, 0xedc7c850, 0xd12b9eaa, 0x467ee1a9, 0xbe84756b, 0xda7b1680, 0xdc069ffe, 0xf1e7e9f9, 0xb3d95370, 0xa92b77df, 0x5693ac41, 0xd04b7287, 0x27aebf15, 0x837b316e, 0x4dbe2263, 0xbab70c67, 0x547dab21, 0x3c346c1f, 0xb8ef0e4e, 0xfe2d03ce, 0xe1d75955, 0xfec1306, 0xba35c23e, 0xb784ed04, 0x2a4e33aa, 0x7e19d09a, 0x3827c1fe, 0xf3a51561, 0xef765e2b, 0xb044256c, 0x62b322be, 0xf34d56be, 0xeb71b369, 0xffe1294f, 0x237fe8d0, 0x77a1473b, 0x239e1196, 0xdd19bf3d, 0x82c91fe1, 0x95361c57, 0xffea3f1b, 0x1a094c84}, + Field12: []int64{8308420747267165049, 3664160795077875961, 7868970059161834817, 7237335984251173739, 5254748003907196506, 3362259627111837480, 430460752854552122, 5119635556501066533, 1277716037866233522, 9185775384759813768, 833932430882717888, 7986528304451297640, 6792233378368656337, 2074207091120609721, 1788723326198279432, 7756514594746453657, 2283775964901597324, 3061497730110517191, 7733947890656120277, 626967303632386244, 7822928600388582821, 3489658753000061230, 168869995163005961, 248814782163480763, 477885608911386247, 4198422415674133867, 3379354662797976109, 9925112544736939, 1486335136459138480, 4561560414032850671, 1010864164014091267, 186722821683803084, 5106357936724819318, 1298160820191228988, 4675403242419953145, 7130634540106489752, 7101280006672440929, 7176058292431955718, 9109875054097770321, 6810974877085322872, 4736707874303993641, 8993135362721382187, 6857881554990254283, 3704748883307461680, 1099360832887634994, 5207691918707192633, 5984721695043995243}, + } + size := proto.Size(n) + data, err := proto.Marshal(n) + if err != nil { + panic(err) + } + if len(data) != size { + t.Fatalf("expected %v, but got %v diff is %v", len(data), size, len(data)-size) + } +} + +func testSize(m interface { + proto.Message + Size() int +}, desc string, expected int) ([]byte, error) { + data, err := proto.Marshal(m) + if err != nil { + return nil, err + } + protoSize := proto.Size(m) + mSize := m.Size() + lenData := len(data) + if protoSize != mSize || protoSize != lenData || mSize != lenData { + return nil, fmt.Errorf("%s proto.Size(m){%d} != m.Size(){%d} != len(data){%d}", desc, protoSize, mSize, lenData) + } + if got := protoSize; got != expected { + return nil, fmt.Errorf("%s proto.Size(m) got %d expected %d", desc, got, expected) + } + if got := mSize; got != expected { + return nil, fmt.Errorf("%s m.Size() got %d expected %d", desc, got, expected) + } + if got := lenData; got != expected { + return nil, fmt.Errorf("%s len(data) got %d expected %d", desc, got, expected) + } + return data, nil +} + +func TestInt32Int64Compatibility(t *testing.T) { + + //test nullable int32 and int64 + + data1, err := testSize(&NinOptNative{ + Field3: proto.Int32(-1), + }, "nullable", 11) + if err != nil { + t.Error(err) + } + //change marshaled data1 to unmarshal into 4th field which is an int64 + data1[0] = uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + u1 := &NinOptNative{} + if err = proto.Unmarshal(data1, u1); err != nil { + t.Error(err) + } + if !u1.Equal(&NinOptNative{ + Field4: proto.Int64(-1), + }) { + t.Error("nullable unmarshaled int32 is not the same int64") + } + + //test non-nullable int32 and int64 + + data2, err := testSize(&NidOptNative{ + Field3: -1, + }, "non nullable", 67) + if err != nil { + t.Error(err) + } + //change marshaled data2 to unmarshal into 4th field which is an int64 + field3 := uint8(uint32(3 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + field4 := uint8(uint32(4 /*fieldNumber*/)<<3 | uint32(0 /*wireType*/)) + for i, c := range data2 { + if c == field4 { + data2[i] = field3 + } else if c == field3 { + data2[i] = field4 + } + } + u2 := &NidOptNative{} + if err = proto.Unmarshal(data2, u2); err != nil { + t.Error(err) + } + if !u2.Equal(&NidOptNative{ + Field4: -1, + }) { + t.Error("non nullable unmarshaled int32 is not the same int64") + } + + //test packed repeated int32 and int64 + + m4 := &NinRepPackedNative{ + Field3: []int32{-1}, + } + data4, err := testSize(m4, "packed", 12) + if err != nil { + t.Error(err) + } + u4 := &NinRepPackedNative{} + if err := proto.Unmarshal(data4, u4); err != nil { + t.Error(err) + } + if err := u4.VerboseEqual(m4); err != nil { + t.Fatalf("%#v", u4) + } + + //test repeated int32 and int64 + + if _, err := testSize(&NinRepNative{ + Field3: []int32{-1}, + }, "repeated", 11); err != nil { + t.Error(err) + } + + t.Logf("tested all") +} + +func TestRepeatedExtensionsMsgsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + nins := make([]*NinOptNative, rep) + for i := range nins { + nins[i] = NewPopulatedNinOptNative(r, true) + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldE, nins); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} + +func TestRepeatedExtensionsFieldsIssue161(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rep := 10 + ints := make([]int64, rep) + for i := range ints { + ints[i] = r.Int63() + } + input := &MyExtendable{} + if err := proto.SetExtension(input, E_FieldD, ints); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(input) + if err != nil { + t.Fatal(err) + } + output := &MyExtendable{} + if err := proto.Unmarshal(data, output); err != nil { + t.Fatal(err) + } + if !input.Equal(output) { + t.Fatal("expected equal") + } + data2, err2 := proto.Marshal(output) + if err2 != nil { + t.Fatal(err2) + } + if len(data) != len(data2) { + t.Fatal("expected equal length buffers") + } +} diff --git a/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetest.proto b/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetest.proto new file mode 100644 index 000000000..af269a3be --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetest.proto @@ -0,0 +1,649 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package test; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; +option (gogoproto.protosizer_all) = false; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +option (gogoproto.compare_all) = true; + +message NidOptNative { + optional double Field1 = 1 [(gogoproto.nullable) = false]; + optional float Field2 = 2 [(gogoproto.nullable) = false]; + optional int32 Field3 = 3 [(gogoproto.nullable) = false]; + optional int64 Field4 = 4 [(gogoproto.nullable) = false]; + optional uint32 Field5 = 5 [(gogoproto.nullable) = false]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false]; + optional sint64 Field8 = 8 [(gogoproto.nullable) = false]; + optional fixed32 Field9 = 9 [(gogoproto.nullable) = false]; + optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false]; + optional fixed64 Field11 = 11 [(gogoproto.nullable) = false]; + optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false]; + optional bool Field13 = 13 [(gogoproto.nullable) = false]; + optional string Field14 = 14 [(gogoproto.nullable) = false]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinOptNative { + optional double Field1 = 1; + optional float Field2 = 2; + optional int32 Field3 = 3; + optional int64 Field4 = 4; + optional uint32 Field5 = 5; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional sint64 Field8 = 8; + optional fixed32 Field9 = 9; + optional sfixed32 Field10 = 10; + optional fixed64 Field11 = 11; + optional sfixed64 Field12 = 12; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NidRepNative { + repeated double Field1 = 1 [(gogoproto.nullable) = false]; + repeated float Field2 = 2 [(gogoproto.nullable) = false]; + repeated int32 Field3 = 3 [(gogoproto.nullable) = false]; + repeated int64 Field4 = 4 [(gogoproto.nullable) = false]; + repeated uint32 Field5 = 5 [(gogoproto.nullable) = false]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false]; + repeated sint64 Field8 = 8 [(gogoproto.nullable) = false]; + repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false]; + repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false]; + repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false]; + repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false]; + repeated string Field14 = 14 [(gogoproto.nullable) = false]; + repeated bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinRepNative { + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated int32 Field3 = 3; + repeated int64 Field4 = 4; + repeated uint32 Field5 = 5; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated sint64 Field8 = 8; + repeated fixed32 Field9 = 9; + repeated sfixed32 Field10 = 10; + repeated fixed64 Field11 = 11; + repeated sfixed64 Field12 = 12; + repeated bool Field13 = 13; + repeated string Field14 = 14; + repeated bytes Field15 = 15; +} + +message NidRepPackedNative { + repeated double Field1 = 1 [(gogoproto.nullable) = false, packed = true]; + repeated float Field2 = 2 [(gogoproto.nullable) = false, packed = true]; + repeated int32 Field3 = 3 [(gogoproto.nullable) = false, packed = true]; + repeated int64 Field4 = 4 [(gogoproto.nullable) = false, packed = true]; + repeated uint32 Field5 = 5 [(gogoproto.nullable) = false, packed = true]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false, packed = true]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false, packed = true]; + repeated sint64 Field8 = 8 [(gogoproto.nullable) = false, packed = true]; + repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false, packed = true]; + repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false, packed = true]; + repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false, packed = true]; + repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false, packed = true]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false, packed = true]; +} + +message NinRepPackedNative { + repeated double Field1 = 1 [packed = true]; + repeated float Field2 = 2 [packed = true]; + repeated int32 Field3 = 3 [packed = true]; + repeated int64 Field4 = 4 [packed = true]; + repeated uint32 Field5 = 5 [packed = true]; + repeated uint64 Field6 = 6 [packed = true]; + repeated sint32 Field7 = 7 [packed = true]; + repeated sint64 Field8 = 8 [packed = true]; + repeated fixed32 Field9 = 9 [packed = true]; + repeated sfixed32 Field10 = 10 [packed = true]; + repeated fixed64 Field11 = 11 [packed = true]; + repeated sfixed64 Field12 = 12 [packed = true]; + repeated bool Field13 = 13 [packed = true]; +} + +message NidOptStruct { + optional double Field1 = 1 [(gogoproto.nullable) = false]; + optional float Field2 = 2 [(gogoproto.nullable) = false]; + optional NidOptNative Field3 = 3 [(gogoproto.nullable) = false]; + optional NinOptNative Field4 = 4 [(gogoproto.nullable) = false]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false]; + optional NidOptNative Field8 = 8 [(gogoproto.nullable) = false]; + optional bool Field13 = 13 [(gogoproto.nullable) = false]; + optional string Field14 = 14 [(gogoproto.nullable) = false]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinOptStruct { + optional double Field1 = 1; + optional float Field2 = 2; + optional NidOptNative Field3 = 3; + optional NinOptNative Field4 = 4; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional NidOptNative Field8 = 8; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NidRepStruct { + repeated double Field1 = 1 [(gogoproto.nullable) = false]; + repeated float Field2 = 2 [(gogoproto.nullable) = false]; + repeated NidOptNative Field3 = 3 [(gogoproto.nullable) = false]; + repeated NinOptNative Field4 = 4 [(gogoproto.nullable) = false]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false]; + repeated NidOptNative Field8 = 8 [(gogoproto.nullable) = false]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false]; + repeated string Field14 = 14 [(gogoproto.nullable) = false]; + repeated bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinRepStruct { + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated NidOptNative Field3 = 3; + repeated NinOptNative Field4 = 4; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated NidOptNative Field8 = 8; + repeated bool Field13 = 13; + repeated string Field14 = 14; + repeated bytes Field15 = 15; +} + +message NidEmbeddedStruct { + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NidOptNative Field200 = 200 [(gogoproto.nullable) = false]; + optional bool Field210 = 210 [(gogoproto.nullable) = false]; +} + +message NinEmbeddedStruct { + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NidOptNative Field200 = 200; + optional bool Field210 = 210; +} + +message NidNestedStruct { + optional NidOptStruct Field1 = 1 [(gogoproto.nullable) = false]; + repeated NidRepStruct Field2 = 2 [(gogoproto.nullable) = false]; +} + +message NinNestedStruct { + optional NinOptStruct Field1 = 1; + repeated NinRepStruct Field2 = 2; +} + +message NidOptCustom { + optional bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false]; + optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; +} + +message CustomDash { + optional bytes Value = 1 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom-dash-type.Bytes"]; +} + +message NinOptCustom { + optional bytes Id = 1 [(gogoproto.customtype) = "Uuid"]; + optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message NidRepCustom { + repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false]; + repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; +} + +message NinRepCustom { + repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid"]; + repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message NinOptNativeUnion { + option (gogoproto.onlyone) = true; + optional double Field1 = 1; + optional float Field2 = 2; + optional int32 Field3 = 3; + optional int64 Field4 = 4; + optional uint32 Field5 = 5; + optional uint64 Field6 = 6; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NinOptStructUnion { + option (gogoproto.onlyone) = true; + optional double Field1 = 1; + optional float Field2 = 2; + optional NidOptNative Field3 = 3; + optional NinOptNative Field4 = 4; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NinEmbeddedStructUnion { + option (gogoproto.onlyone) = true; + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NinOptNative Field200 = 200; + optional bool Field210 = 210; +} + +message NinNestedStructUnion { + option (gogoproto.onlyone) = true; + optional NinOptNativeUnion Field1 = 1; + optional NinOptStructUnion Field2 = 2; + optional NinEmbeddedStructUnion Field3 = 3; +} + +message Tree { + option (gogoproto.onlyone) = true; + optional OrBranch Or = 1; + optional AndBranch And = 2; + optional Leaf Leaf = 3; +} + +message OrBranch { + optional Tree Left = 1 [(gogoproto.nullable) = false]; + optional Tree Right = 2 [(gogoproto.nullable) = false]; +} + +message AndBranch { + optional Tree Left = 1 [(gogoproto.nullable) = false]; + optional Tree Right = 2 [(gogoproto.nullable) = false]; +} + +message Leaf { + optional int64 Value = 1 [(gogoproto.nullable) = false]; + optional string StrValue = 2 [(gogoproto.nullable) = false]; +} + +message DeepTree { + option (gogoproto.onlyone) = true; + optional ADeepBranch Down = 1; + optional AndDeepBranch And = 2; + optional DeepLeaf Leaf = 3; +} + +message ADeepBranch { + optional DeepTree Down = 2 [(gogoproto.nullable) = false]; +} + +message AndDeepBranch { + optional DeepTree Left = 1 [(gogoproto.nullable) = false]; + optional DeepTree Right = 2 [(gogoproto.nullable) = false]; +} + +message DeepLeaf { + optional Tree Tree = 1 [(gogoproto.nullable) = false]; +} + +message Nil { + +} + +enum TheTestEnum { + A = 0; + B = 1; + C = 2; +} + +enum AnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = false; + D = 10; + E = 11; +} + +// YetAnotherTestEnum is used to test cross-package import of custom name +// fields and default resolution. +enum YetAnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = false; + AA = 0; + BB = 1 [(gogoproto.enumvalue_customname) = "BetterYetBB"]; +} + +// YetAnotherTestEnum is used to test cross-package import of custom name +// fields and default resolution. +enum YetYetAnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = true; + CC = 0; + DD = 1 [(gogoproto.enumvalue_customname) = "BetterYetDD"]; +} + +message NidOptEnum { + optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; +} + +message NinOptEnum { + optional TheTestEnum Field1 = 1; + optional YetAnotherTestEnum Field2 = 2; + optional YetYetAnotherTestEnum Field3 = 3; +} + +message NidRepEnum { + repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; + repeated YetAnotherTestEnum Field2 = 2 [(gogoproto.nullable) = false]; + repeated YetYetAnotherTestEnum Field3 = 3 [(gogoproto.nullable) = false]; +} + +message NinRepEnum { + repeated TheTestEnum Field1 = 1; + repeated YetAnotherTestEnum Field2 = 2; + repeated YetYetAnotherTestEnum Field3 = 3; +} + +message NinOptEnumDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional TheTestEnum Field1 = 1 [default=C]; + optional YetAnotherTestEnum Field2 = 2 [default=BB]; + optional YetYetAnotherTestEnum Field3 = 3 [default=CC]; +} + +message AnotherNinOptEnum { + optional AnotherTestEnum Field1 = 1; + optional YetAnotherTestEnum Field2 = 2; + optional YetYetAnotherTestEnum Field3 = 3; +} + +message AnotherNinOptEnumDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional AnotherTestEnum Field1 = 1 [default=E]; + optional YetAnotherTestEnum Field2 = 2 [default=BB]; + optional YetYetAnotherTestEnum Field3 = 3 [default=CC]; +} + + +message Timer { + optional sfixed64 Time1 = 1 [(gogoproto.nullable) = false]; + optional sfixed64 Time2 = 2 [(gogoproto.nullable) = false]; + optional bytes Data = 3 [(gogoproto.nullable) = false]; +} + +message MyExtendable { + option (gogoproto.face) = false; + optional int64 Field1 = 1; + extensions 100 to 199; +} + +extend MyExtendable { + optional double FieldA = 100; + optional NinOptNative FieldB = 101; + optional NinEmbeddedStruct FieldC = 102; + repeated int64 FieldD = 104; + repeated NinOptNative FieldE = 105; +} + +message OtherExtenable { + option (gogoproto.face) = false; + optional int64 Field2 = 2; + extensions 14 to 16; + optional int64 Field13 = 13; + extensions 10 to 12; + optional MyExtendable M = 1; +} + +message NestedDefinition { + optional int64 Field1 = 1; + message NestedMessage { + optional fixed64 NestedField1 = 1; + optional NestedNestedMsg NNM = 2; + message NestedNestedMsg { + optional string NestedNestedField1 = 10; + } + } + enum NestedEnum { + TYPE_NESTED = 1; + } + optional NestedEnum EnumField = 2; + optional NestedMessage.NestedNestedMsg NNM = 3; + optional NestedMessage NM = 4; +} + +message NestedScope { + optional NestedDefinition.NestedMessage.NestedNestedMsg A = 1; + optional NestedDefinition.NestedEnum B = 2; + optional NestedDefinition.NestedMessage C = 3; +} + +message NinOptNativeDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional double Field1 = 1 [default = 1234.1234]; + optional float Field2 = 2 [default = 1234.1234]; + optional int32 Field3 = 3 [default = 1234]; + optional int64 Field4 = 4 [default = 1234]; + optional uint32 Field5 = 5 [default = 1234]; + optional uint64 Field6 = 6 [default = 1234]; + optional sint32 Field7 = 7 [default = 1234]; + optional sint64 Field8 = 8 [default = 1234]; + optional fixed32 Field9 = 9 [default = 1234]; + optional sfixed32 Field10 = 10 [default = 1234]; + optional fixed64 Field11 = 11 [default = 1234]; + optional sfixed64 Field12 = 12 [default = 1234]; + optional bool Field13 = 13 [default = true]; + optional string Field14 = 14 [default = "1234"]; + optional bytes Field15 = 15; +} + +message CustomContainer { + optional NidOptCustom CustomStruct = 1 [(gogoproto.nullable) = false]; +} + +message CustomNameNidOptNative { + optional double Field1 = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldB"]; + optional int32 Field3 = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldC"]; + optional int64 Field4 = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldD"]; + optional uint32 Field5 = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldE"]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldF"]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldG"]; + optional sint64 Field8 = 8 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldH"]; + optional fixed32 Field9 = 9 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldI"]; + optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldJ"]; + optional fixed64 Field11 = 11 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldK"]; + optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldL"]; + optional bool Field13 = 13 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldM"]; + optional string Field14 = 14 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldN"]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinOptNative { + optional double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + optional int32 Field3 = 3 [(gogoproto.customname) = "FieldC"]; + optional int64 Field4 = 4 [(gogoproto.customname) = "FieldD"]; + optional uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"]; + optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"]; + optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"]; + optional sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"]; + optional fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"]; + optional sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"]; + optional fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"]; + optional sfixed64 Field12 = 12 [(gogoproto.customname) = "FielL"]; + optional bool Field13 = 13 [(gogoproto.customname) = "FieldM"]; + optional string Field14 = 14 [(gogoproto.customname) = "FieldN"]; + optional bytes Field15 = 15 [(gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinRepNative { + repeated double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + repeated float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + repeated int32 Field3 = 3 [(gogoproto.customname) = "FieldC"]; + repeated int64 Field4 = 4 [(gogoproto.customname) = "FieldD"]; + repeated uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"]; + repeated uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"]; + repeated sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"]; + repeated sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"]; + repeated fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"]; + repeated sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"]; + repeated fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"]; + repeated sfixed64 Field12 = 12 [(gogoproto.customname) = "FieldL"]; + repeated bool Field13 = 13 [(gogoproto.customname) = "FieldM"]; + repeated string Field14 = 14 [(gogoproto.customname) = "FieldN"]; + repeated bytes Field15 = 15 [(gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinStruct { + optional double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + optional NidOptNative Field3 = 3 [(gogoproto.customname) = "FieldC"]; + repeated NinOptNative Field4 = 4 [(gogoproto.customname) = "FieldD"]; + optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldE"]; + optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldF"]; + optional NidOptNative Field8 = 8 [(gogoproto.customname) = "FieldG"]; + optional bool Field13 = 13 [(gogoproto.customname) = "FieldH"]; + optional string Field14 = 14 [(gogoproto.customname) = "FieldI"]; + optional bytes Field15 = 15 [(gogoproto.customname) = "FieldJ"]; +} + +message CustomNameCustomType { + optional bytes Id = 1 [(gogoproto.customname) = "FieldA", (gogoproto.customtype) = "Uuid"]; + optional bytes Value = 2 [(gogoproto.customname) = "FieldB", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + repeated bytes Ids = 3 [(gogoproto.customname) = "FieldC", (gogoproto.customtype) = "Uuid"]; + repeated bytes Values = 4 [(gogoproto.customname) = "FieldD", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message CustomNameNinEmbeddedStructUnion { + option (gogoproto.onlyone) = true; + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NinOptNative Field200 = 200 [(gogoproto.customname) = "FieldA"]; + optional bool Field210 = 210 [(gogoproto.customname) = "FieldB"]; +} + +message CustomNameEnum { + optional TheTestEnum Field1 = 1 [(gogoproto.customname) = "FieldA"]; + repeated TheTestEnum Field2 = 2 [(gogoproto.customname) = "FieldB"]; +} + +message NoExtensionsMap { + option (gogoproto.face) = false; + option (gogoproto.goproto_extensions_map) = false; + optional int64 Field1 = 1; + extensions 100 to 199; +} + +extend NoExtensionsMap { + optional double FieldA1 = 100; + optional NinOptNative FieldB1 = 101; + optional NinEmbeddedStruct FieldC1 = 102; +} + +message Unrecognized { + option (gogoproto.goproto_unrecognized) = false; + optional string Field1 = 1; +} + +message UnrecognizedWithInner { + message Inner { + option (gogoproto.goproto_unrecognized) = false; + optional uint32 Field1 = 1; + } + + repeated Inner embedded = 1; + optional string Field2 = 2; +} + +message UnrecognizedWithEmbed { + message Embedded { + option (gogoproto.goproto_unrecognized) = false; + optional uint32 Field1 = 1; + } + + optional Embedded embedded = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; + optional string Field2 = 2; +} + +message Node { + optional string Label = 1; + repeated Node Children = 2; +} + +message NonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message NidOptNonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false]; +} + +message NinOptNonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message NidRepNonByteCustomType { + repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false]; +} + +message NinRepNonByteCustomType { + repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message ProtoType { + optional string Field2 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetestpb_test.go b/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetestpb_test.go new file mode 100644 index 000000000..d851b45ad --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/combos/unmarshaler/thetestpb_test.go @@ -0,0 +1,16045 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/thetest.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/thetest.proto + +It has these top-level messages: + NidOptNative + NinOptNative + NidRepNative + NinRepNative + NidRepPackedNative + NinRepPackedNative + NidOptStruct + NinOptStruct + NidRepStruct + NinRepStruct + NidEmbeddedStruct + NinEmbeddedStruct + NidNestedStruct + NinNestedStruct + NidOptCustom + CustomDash + NinOptCustom + NidRepCustom + NinRepCustom + NinOptNativeUnion + NinOptStructUnion + NinEmbeddedStructUnion + NinNestedStructUnion + Tree + OrBranch + AndBranch + Leaf + DeepTree + ADeepBranch + AndDeepBranch + DeepLeaf + Nil + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum + NinOptEnumDefault + AnotherNinOptEnum + AnotherNinOptEnumDefault + Timer + MyExtendable + OtherExtenable + NestedDefinition + NestedScope + NinOptNativeDefault + CustomContainer + CustomNameNidOptNative + CustomNameNinOptNative + CustomNameNinRepNative + CustomNameNinStruct + CustomNameCustomType + CustomNameNinEmbeddedStructUnion + CustomNameEnum + NoExtensionsMap + Unrecognized + UnrecognizedWithInner + UnrecognizedWithEmbed + Node + NonByteCustomType + NidOptNonByteCustomType + NinOptNonByteCustomType + NidRepNonByteCustomType + NinRepNonByteCustomType + ProtoType +*/ +package test + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepPackedNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepPackedNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidEmbeddedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinEmbeddedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidNestedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidNestedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinNestedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomDashProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomDashProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomDash(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomDash{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNativeUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinNestedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinNestedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkTreeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTreeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Tree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOrBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOrBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOrBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OrBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAndBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAndBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkLeafProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkLeafProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Leaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkDeepTreeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepTreeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDeepTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepTree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkADeepBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkADeepBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedADeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ADeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAndDeepBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndDeepBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAndDeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndDeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkDeepLeafProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepLeafProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDeepLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepLeaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNilProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNilProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNil(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nil{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAnotherNinOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAnotherNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAnotherNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAnotherNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkTimerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTimerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedTimer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Timer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMyExtendableProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyExtendableProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMyExtendable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyExtendable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOtherExtenableProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOtherExtenableProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOtherExtenable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OtherExtenable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinitionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinitionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinition_NestedMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition_NestedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedScopeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedScopeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedScope(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedScope{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNativeDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomContainerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomContainerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomContainer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomContainer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNidOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNidOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNoExtensionsMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNoExtensionsMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNoExtensionsMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NoExtensionsMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognized(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Unrecognized{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithInnerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInnerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithInner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithInner_InnerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithInner_Inner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner_Inner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithEmbedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithEmbed(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed_Embedded{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNodeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Node, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNodeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNode(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Node{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkProtoTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedProtoType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomDashJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOrBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestADeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndDeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNilJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTimerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyExtendableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOtherExtenableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinitionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedScopeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomContainerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNoExtensionsMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInner_InnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNodeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomDash{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomDash{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNativeUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNativeUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinNestedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinNestedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Tree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Tree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OrBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OrBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AndBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AndBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Leaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Leaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DeepTree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DeepTree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ADeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ADeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AndDeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AndDeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DeepLeaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DeepLeaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Nil{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Nil{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AnotherNinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AnotherNinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Timer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Timer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MyExtendable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MyExtendable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OtherExtenable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OtherExtenable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedScope{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedScope{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNativeDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNativeDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomContainer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomContainer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NoExtensionsMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NoExtensionsMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Unrecognized{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Unrecognized{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithInner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithInner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Node{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Node{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ProtoType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ProtoType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepPackedNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepPackedNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidEmbeddedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidNestedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomDashCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomDash(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTreeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOrBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOrBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestLeafCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepTreeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestADeepBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedADeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndDeepBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndDeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepLeafCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNilCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNil(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTimerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTimer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestMyExtendableCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedMyExtendable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOtherExtenableCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOtherExtenable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinitionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessageCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedScopeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedScope(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomContainerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomContainer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNidOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinEmbeddedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNoExtensionsMapCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNoExtensionsMap(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognized(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInnerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInner_InnerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNodeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNode(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestThetestDescription(t *testing.T) { + ThetestDescription() +} +func TestNidOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepPackedNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepPackedNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidEmbeddedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidNestedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomDashVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTreeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOrBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestLeafVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepTreeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestADeepBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndDeepBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepLeafVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNilVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTimerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyExtendableVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOtherExtenableVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinitionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedScopeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomContainerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNidOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNoExtensionsMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInnerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInner_InnerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNodeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepPackedNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepPackedNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidEmbeddedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidNestedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomDashFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTreeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestOrBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestLeafFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepTreeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestADeepBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndDeepBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepLeafFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNilFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAnotherNinOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTimerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinitionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessageFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedScopeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomContainerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNidOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInnerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInner_InnerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNodeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestProtoTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepPackedNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepPackedNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidEmbeddedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidNestedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomDashGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTreeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOrBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestLeafGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepTreeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestADeepBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndDeepBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepLeafGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNilGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTimerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyExtendableGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOtherExtenableGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinitionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessageGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedScopeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomContainerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNidOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinEmbeddedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNoExtensionsMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInnerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInner_InnerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNodeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestProtoTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepPackedNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepPackedNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidEmbeddedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidNestedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomDashSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTreeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOrBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkLeafSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepTreeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkADeepBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndDeepBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepLeafSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNilSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTimerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyExtendableSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOtherExtenableSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinitionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedScopeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomContainerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNidOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNoExtensionsMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInnerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInner_InnerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNodeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Node, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepPackedNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepPackedNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidEmbeddedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidNestedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomDashStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTreeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOrBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestLeafStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepTreeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestADeepBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndDeepBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepLeafStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNilStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTimerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMyExtendableStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOtherExtenableStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinitionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessageStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedScopeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomContainerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNidOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinEmbeddedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNoExtensionsMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInnerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInner_InnerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNodeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestProtoTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + v := p.GetValue() + msg := &NinOptNativeUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinOptStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + v := p.GetValue() + msg := &NinOptStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &NinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + v := p.GetValue() + msg := &NinNestedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestTreeOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + v := p.GetValue() + msg := &Tree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestDeepTreeOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + v := p.GetValue() + msg := &DeepTree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &CustomNameNinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/custom/custom_test.go b/vendor/github.com/gogo/protobuf/test/custom/custom_test.go new file mode 100644 index 000000000..d4fe7bd48 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/custom/custom_test.go @@ -0,0 +1,43 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package custom + +import ( + "testing" +) + +func TestUint128(t *testing.T) { + var uint128a = Uint128{0, 1} + buf := make([]byte, 16) + PutLittleEndianUint128(buf, 0, uint128a) + uint128b := GetLittleEndianUint128(buf, 0) + if !uint128a.Equal(uint128b) { + t.Fatalf("%v != %v", uint128a, uint128b) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/Makefile b/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/Makefile new file mode 100644 index 000000000..ecb3e74ea --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. proto.proto) diff --git a/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/custombytesnonstruct_test.go b/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/custombytesnonstruct_test.go new file mode 100644 index 000000000..2e29d2a0f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/custombytesnonstruct_test.go @@ -0,0 +1,34 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package custombytesnonstruct + +import testing "testing" + +func TestCustomBytesNonStruct(t *testing.T) { +} diff --git a/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/proto.proto b/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/proto.proto new file mode 100644 index 000000000..343b457a7 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/custombytesnonstruct/proto.proto @@ -0,0 +1,39 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package custombytesnonstruct; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.unmarshaler_all) = true; + +message Object { + optional bytes CustomField1 = 1 [(gogoproto.customtype) = "CustomType"]; + repeated bytes CustomField2 = 2 [(gogoproto.customtype) = "CustomType"]; +} diff --git a/vendor/github.com/gogo/protobuf/test/dashfilename/dash-filename.proto b/vendor/github.com/gogo/protobuf/test/dashfilename/dash-filename.proto new file mode 100644 index 000000000..90efda369 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/dashfilename/dash-filename.proto @@ -0,0 +1,38 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package dashfilename; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.marshaler_all) = true; + +message test { + +} diff --git a/vendor/github.com/gogo/protobuf/test/dashfilename/df_test.go b/vendor/github.com/gogo/protobuf/test/dashfilename/df_test.go new file mode 100644 index 000000000..6266b21bc --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/dashfilename/df_test.go @@ -0,0 +1,48 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package dashfilename + +import ( + "os" + "os/exec" + "testing" +) + +//Issue 16 : https://github.com/gogo/protobuf/issues/detail?id=16 +func TestDashFilename(t *testing.T) { + name := "dash-filename" + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", name+".proto") + data, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("err = %v: %s", err, string(data)) + } + if err := os.Remove(name + ".pb.go"); err != nil { + panic(err) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/data/Makefile b/vendor/github.com/gogo/protobuf/test/data/Makefile new file mode 100644 index 000000000..eeb3f5091 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/data/Makefile @@ -0,0 +1,33 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2016, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-min-version + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=. \ + --proto_path=../../../../../:../../protobuf/:. data.proto diff --git a/vendor/github.com/gogo/protobuf/test/data/data.proto b/vendor/github.com/gogo/protobuf/test/data/data.proto new file mode 100644 index 000000000..ff6dcd30b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/data/data.proto @@ -0,0 +1,49 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package data; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.gostring_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.stringer_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.testgen_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.unmarshaler_all) = true; + +message MyMessage { + uint32 my_data = 1; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/data/datapb_test.go b/vendor/github.com/gogo/protobuf/test/data/datapb_test.go new file mode 100644 index 000000000..d9f656a39 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/data/datapb_test.go @@ -0,0 +1,261 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: data.proto + +/* +Package data is a generated protocol buffer package. + +It is generated from these files: + data.proto + +It has these top-level messages: + MyMessage +*/ +package data + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMyMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMyMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMyMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMyMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyMessage{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MyMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MyMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyMessageGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyMessageStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/defaultconflict/df.proto b/vendor/github.com/gogo/protobuf/test/defaultconflict/df.proto new file mode 100644 index 000000000..9ec763d32 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/defaultconflict/df.proto @@ -0,0 +1,40 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package defaultcheck; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.face_all) = true; +option (gogoproto.goproto_getters_all) = false; + +message A { + optional int64 Field1 = 1 [default=1234]; +} + diff --git a/vendor/github.com/gogo/protobuf/test/defaultconflict/dg.proto b/vendor/github.com/gogo/protobuf/test/defaultconflict/dg.proto new file mode 100644 index 000000000..2d251e278 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/defaultconflict/dg.proto @@ -0,0 +1,39 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package defaultcheck; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_getters_all) = false; + +message A { + optional int64 Field1 = 1 [default=1234]; +} + diff --git a/vendor/github.com/gogo/protobuf/test/defaultconflict/nc.proto b/vendor/github.com/gogo/protobuf/test/defaultconflict/nc.proto new file mode 100644 index 000000000..6bddd0794 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/defaultconflict/nc.proto @@ -0,0 +1,37 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package defaultcheck; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message A { + optional int64 Field1 = 1 [default = 1234, (gogoproto.nullable) = false];; +} + diff --git a/vendor/github.com/gogo/protobuf/test/defaultconflict/nc_test.go b/vendor/github.com/gogo/protobuf/test/defaultconflict/nc_test.go new file mode 100644 index 000000000..522ce9c1c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/defaultconflict/nc_test.go @@ -0,0 +1,68 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package defaultcheck + +import ( + "os" + "os/exec" + "strings" + "testing" +) + +func testDefaultConflict(t *testing.T, name string) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", name+".proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove(name + ".pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} + +func TestNullableDefault(t *testing.T) { + testDefaultConflict(t, "nc") +} + +func TestNullableExtension(t *testing.T) { + testDefaultConflict(t, "nx") +} + +func TestNullableEnum(t *testing.T) { + testDefaultConflict(t, "ne") +} + +func TestFaceDefault(t *testing.T) { + testDefaultConflict(t, "df") +} + +func TestNoGettersDefault(t *testing.T) { + testDefaultConflict(t, "dg") +} diff --git a/vendor/github.com/gogo/protobuf/test/defaultconflict/ne.proto b/vendor/github.com/gogo/protobuf/test/defaultconflict/ne.proto new file mode 100644 index 000000000..c5664d7a1 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/defaultconflict/ne.proto @@ -0,0 +1,42 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package defaultcheck; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +enum E { + P = 10; + Q = 11; +} + +message A { + optional E Field1 = 1 [(gogoproto.nullable) = false]; +} + diff --git a/vendor/github.com/gogo/protobuf/test/defaultconflict/nx.proto b/vendor/github.com/gogo/protobuf/test/defaultconflict/nx.proto new file mode 100644 index 000000000..1f074e337 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/defaultconflict/nx.proto @@ -0,0 +1,41 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package defaultcheck; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message A { + extensions 1 to max; +} + +extend A { + optional int64 Field1 = 1 [(gogoproto.nullable) = false]; +} + diff --git a/vendor/github.com/gogo/protobuf/test/embedconflict/.gitignore b/vendor/github.com/gogo/protobuf/test/embedconflict/.gitignore new file mode 100644 index 000000000..c61a5e8b0 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/embedconflict/.gitignore @@ -0,0 +1 @@ +*.pb.go diff --git a/vendor/github.com/gogo/protobuf/test/embedconflict/eb.proto b/vendor/github.com/gogo/protobuf/test/embedconflict/eb.proto new file mode 100644 index 000000000..80bedac67 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/embedconflict/eb.proto @@ -0,0 +1,38 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package embedconflict; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message TakesLongTooDebug { + optional bytes Field1 = 1; + optional bytes Field2 = 2 [(gogoproto.nullable)=false, (gogoproto.embed)=true]; +} diff --git a/vendor/github.com/gogo/protobuf/test/embedconflict/ec.proto b/vendor/github.com/gogo/protobuf/test/embedconflict/ec.proto new file mode 100644 index 000000000..cbf0cd4cf --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/embedconflict/ec.proto @@ -0,0 +1,40 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package embedconflict; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message A { + optional int64 Field1 = 1; + optional B B = 2 [(gogoproto.embed) = true]; +} + +message B { + optional double Field1 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/embedconflict/ec_test.go b/vendor/github.com/gogo/protobuf/test/embedconflict/ec_test.go new file mode 100644 index 000000000..94e0e2573 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/embedconflict/ec_test.go @@ -0,0 +1,119 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package embedconflict + +import ( + "os" + "os/exec" + "strings" + "testing" +) + +func TestEmbedConflict(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "ec.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("ec.pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} + +func TestEmbedMarshaler(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "em.proto") + data, err := cmd.CombinedOutput() + dataStr := string(data) + t.Logf("received error = %v and output = %v", err, dataStr) + if !strings.Contains(dataStr, "WARNING: found non-") || !strings.Contains(dataStr, "unsafe_marshaler") { + t.Errorf("Expected WARNING: found non-[marshaler unsafe_marshaler] C with embedded marshaler D") + } + if err = os.Remove("em.pb.go"); err != nil { + t.Error(err) + } +} + +func TestEmbedExtend(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "ee.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("ee.pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} + +func TestCustomName(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "en.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("en.pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} + +func TestRepeatedEmbed(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "er.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("er.pb.go"); err != nil { + t.Error(err) + } + } + dataStr := string(data) + t.Logf("received error = %v and output = %v", err, dataStr) + warning := "ERROR: found repeated embedded field B in message A" + if !strings.Contains(dataStr, warning) { + t.Errorf("Expected " + warning) + } +} + +func TestTakesTooLongToDebug(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "eb.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("eb.pb.go"); err != nil { + t.Error(err) + } + } + dataStr := string(data) + t.Logf("received error = %v and output = %v", err, dataStr) + warning := "ERROR: found embedded bytes field" + if !strings.Contains(dataStr, warning) { + t.Errorf("Expected " + warning) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/embedconflict/ee.proto b/vendor/github.com/gogo/protobuf/test/embedconflict/ee.proto new file mode 100644 index 000000000..9f5bc38cb --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/embedconflict/ee.proto @@ -0,0 +1,41 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package embedconflict; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message E { + optional int64 Field1 = 1; + extensions 100 to 199; +} + +extend E { + optional int64 Field1 = 100 [(gogoproto.embed) = true]; +} diff --git a/vendor/github.com/gogo/protobuf/test/embedconflict/em.proto b/vendor/github.com/gogo/protobuf/test/embedconflict/em.proto new file mode 100644 index 000000000..f03c1dcd5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/embedconflict/em.proto @@ -0,0 +1,42 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package embedconflict; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message C { + optional int64 Field1 = 1; + optional D D = 2 [(gogoproto.embed) = true]; +} + +message D { + option (gogoproto.marshaler) = true; + optional double Field2 = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/embedconflict/en.proto b/vendor/github.com/gogo/protobuf/test/embedconflict/en.proto new file mode 100644 index 000000000..c11bfd629 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/embedconflict/en.proto @@ -0,0 +1,40 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package embedconflict; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message F { + optional G G = 2 [(gogoproto.embed) = true, (gogoproto.customname) = "G"]; +} + +message G { + optional int64 Field1 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/embedconflict/er.proto b/vendor/github.com/gogo/protobuf/test/embedconflict/er.proto new file mode 100644 index 000000000..da89a622b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/embedconflict/er.proto @@ -0,0 +1,41 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package embedconflict; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message A { + optional int64 Field1 = 1; + repeated B B = 2 [(gogoproto.embed) = true]; +} + +message B { + optional double Field2 = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/empty-issue70/Makefile b/vendor/github.com/gogo/protobuf/test/empty-issue70/Makefile new file mode 100644 index 000000000..770f107ce --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/empty-issue70/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. empty.proto) diff --git a/vendor/github.com/gogo/protobuf/test/empty-issue70/empty.proto b/vendor/github.com/gogo/protobuf/test/empty-issue70/empty.proto new file mode 100644 index 000000000..eacfded1f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/empty-issue70/empty.proto @@ -0,0 +1,39 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax="proto2"; + +package empty; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.unmarshaler_all) = true; + +message TestRequest { + +} diff --git a/vendor/github.com/gogo/protobuf/test/empty-issue70/empty_test.go b/vendor/github.com/gogo/protobuf/test/empty-issue70/empty_test.go new file mode 100644 index 000000000..19e12c215 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/empty-issue70/empty_test.go @@ -0,0 +1,37 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package empty + +import ( + "testing" +) + +func TestEmpty(t *testing.T) { + +} diff --git a/vendor/github.com/gogo/protobuf/test/enumcustomname/Makefile b/vendor/github.com/gogo/protobuf/test/enumcustomname/Makefile new file mode 100644 index 000000000..b5da30775 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumcustomname/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. enumcustomname.proto) diff --git a/vendor/github.com/gogo/protobuf/test/enumcustomname/enumcustomname.proto b/vendor/github.com/gogo/protobuf/test/enumcustomname/enumcustomname.proto new file mode 100644 index 000000000..0230ddbad --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumcustomname/enumcustomname.proto @@ -0,0 +1,75 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +// Package enumcustomname tests the behavior of enum_customname and +// enumvalue_customname extensions. +package enumcustomname; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/gogo/protobuf/test/thetest.proto"; + +enum MyEnum { + option (gogoproto.enum_customname) = "MyCustomEnum"; + + // The following field will take on the custom name and the prefix, joined + // by an underscore. + A = 0 [(gogoproto.enumvalue_customname) = "MyBetterNameA"]; + B = 1; // Should be MyCustomEnum_B +} + +enum MyUnprefixedEnum { + option (gogoproto.goproto_enum_prefix) = false; + option (gogoproto.goproto_enum_stringer) = false; // ensure it behaves correctly without stringer. + option (gogoproto.enum_customname) = "MyCustomUnprefixedEnum"; // no prefix added but type gets name + UNPREFIXED_A = 0 [(gogoproto.enumvalue_customname) = "MyBetterNameUnprefixedA"]; + UNPREFIXED_B = 1 ; // Should not pick up prefix above +} + +enum MyEnumWithEnumStringer { + option (gogoproto.goproto_enum_stringer) = false; // ensure it behaves correctly without stringer. + option (gogoproto.enum_stringer) = true; // ensure it behaves correctly without stringer. + STRINGER_A = 0 [(gogoproto.enumvalue_customname) = "EnumValueStringerA"]; + STRINGER_B = 1; +} + +message OnlyEnums { + optional MyEnum my_enum = 1; + optional MyEnum my_enum_default_a = 2 [default=A]; + optional MyEnum my_enum_default_b = 3 [default=B]; + optional MyUnprefixedEnum my_unprefixed_enum = 4; + optional MyUnprefixedEnum my_unprefixed_enum_default_a = 5 [default=UNPREFIXED_A]; + optional MyUnprefixedEnum my_unprefixed_enum_default_b = 6 [default=UNPREFIXED_B]; + optional test.YetAnotherTestEnum yet_another_test_enum = 7; + optional test.YetAnotherTestEnum yet_another_test_enum_default_aa = 8 [default=AA]; + optional test.YetAnotherTestEnum yet_another_test_enum_default_bb = 9 [default=BB]; + optional test.YetYetAnotherTestEnum yet_yet_another_test_enum = 10; + optional test.YetYetAnotherTestEnum yet_yet_another_test_enum_default_cc = 11 [default=CC]; + optional test.YetYetAnotherTestEnum yet_yet_another_test_enum_default_dd = 12 [default=DD]; +} diff --git a/vendor/github.com/gogo/protobuf/test/enumdecl/Makefile b/vendor/github.com/gogo/protobuf/test/enumdecl/Makefile new file mode 100644 index 000000000..75d9417ab --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumdecl/Makefile @@ -0,0 +1,3 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. enumdecl.proto diff --git a/vendor/github.com/gogo/protobuf/test/enumdecl/enumdecl.proto b/vendor/github.com/gogo/protobuf/test/enumdecl/enumdecl.proto new file mode 100644 index 000000000..54be1b0ee --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumdecl/enumdecl.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package enumdecl; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +enum MyEnum { + option (gogoproto.enumdecl) = false; + option (gogoproto.goproto_enum_prefix) = false; + A = 0; + B = 1; +} + +message Message { + MyEnum enumerated_field = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/enumdecl/enumdeclpb_test.go b/vendor/github.com/gogo/protobuf/test/enumdecl/enumdeclpb_test.go new file mode 100644 index 000000000..ac51724ec --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumdecl/enumdeclpb_test.go @@ -0,0 +1,237 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: enumdecl.proto + +/* +Package enumdecl is a generated protocol buffer package. + +It is generated from these files: + enumdecl.proto + +It has these top-level messages: + Message +*/ +package enumdecl + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/enumdecl_all/Makefile b/vendor/github.com/gogo/protobuf/test/enumdecl_all/Makefile new file mode 100644 index 000000000..56316b509 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumdecl_all/Makefile @@ -0,0 +1,3 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. enumdeclall.proto diff --git a/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclall.proto b/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclall.proto new file mode 100644 index 000000000..38b16b6e6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclall.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; + +package enumdeclall; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; +option (gogoproto.enumdecl_all) = false; + +enum MyEnum { + option (gogoproto.goproto_enum_prefix) = false; + A = 0; + B = 1; +} + +enum MyOtherEnum { + option (gogoproto.enumdecl) = true; + option (gogoproto.goproto_enum_prefix) = false; + C = 0; + D = 1; +} + +message Message { + MyEnum enumerated_field = 1; + MyOtherEnum otherenumerated_field = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclallpb_test.go b/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclallpb_test.go new file mode 100644 index 000000000..0b1b5b46e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumdecl_all/enumdeclallpb_test.go @@ -0,0 +1,237 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: enumdeclall.proto + +/* +Package enumdeclall is a generated protocol buffer package. + +It is generated from these files: + enumdeclall.proto + +It has these top-level messages: + Message +*/ +package enumdeclall + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/enumprefix/Makefile b/vendor/github.com/gogo/protobuf/test/enumprefix/Makefile new file mode 100644 index 000000000..fbb7b0301 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumprefix/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. enumprefix.proto) diff --git a/vendor/github.com/gogo/protobuf/test/enumprefix/enumprefix.proto b/vendor/github.com/gogo/protobuf/test/enumprefix/enumprefix.proto new file mode 100644 index 000000000..67f779f9b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumprefix/enumprefix.proto @@ -0,0 +1,37 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package enumprefix; + +import "github.com/gogo/protobuf/test/thetest.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message MyMessage { + optional test.TheTestEnum TheField = 1 [(gogoproto.nullable) = false]; +} diff --git a/vendor/github.com/gogo/protobuf/test/enumstringer/Makefile b/vendor/github.com/gogo/protobuf/test/enumstringer/Makefile new file mode 100644 index 000000000..67b569859 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumstringer/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. enumstringer.proto) diff --git a/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringer.proto b/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringer.proto new file mode 100644 index 000000000..7147ccfb6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringer.proto @@ -0,0 +1,62 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package enumstringer; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_enum_stringer_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; + +enum TheTestEnum { + A = 0; + B = 1; + C = 2; +} + +message NidOptEnum { + optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; +} + +message NinOptEnum { + optional TheTestEnum Field1 = 1; +} + +message NidRepEnum { + repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; +} + +message NinRepEnum { + repeated TheTestEnum Field1 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringerpb_test.go b/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringerpb_test.go new file mode 100644 index 000000000..c370ae4da --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/enumstringer/enumstringerpb_test.go @@ -0,0 +1,449 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: enumstringer.proto + +/* +Package enumstringer is a generated protocol buffer package. + +It is generated from these files: + enumstringer.proto + +It has these top-level messages: + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum +*/ +package enumstringer + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/example/Makefile b/vendor/github.com/gogo/protobuf/test/example/Makefile new file mode 100644 index 000000000..251767a00 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/example/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc -I=. -I=$(GOPATH)/src -I=$(GOPATH)/src/github.com/gogo/protobuf/protobuf --gogo_out=. example.proto) diff --git a/vendor/github.com/gogo/protobuf/test/example/example.proto b/vendor/github.com/gogo/protobuf/test/example/example.proto new file mode 100644 index 000000000..e90aa48dd --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/example/example.proto @@ -0,0 +1,83 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package test; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.gostring_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.stringer_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.testgen_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.unmarshaler_all) = true; + +message A { + option (gogoproto.face) = true; + option (gogoproto.goproto_getters) = false; + optional string Description = 1 [(gogoproto.nullable) = false]; + optional int64 Number = 2 [(gogoproto.nullable) = false]; + optional bytes Id = 3 [(gogoproto.customtype) = "github.com/gogo/protobuf/test.Uuid", (gogoproto.nullable) = false]; +} + +message B { + option (gogoproto.description) = true; + optional A A = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true]; + repeated bytes G = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; +} + +message C { + optional int64 size = 1 [(gogoproto.customname) = "MySize"]; +} + +message U { + option (gogoproto.onlyone) = true; + optional A A = 1; + optional B B = 2; +} + +message E { + option (gogoproto.goproto_extensions_map) = false; + extensions 1 to max; +} + +message R { + option (gogoproto.goproto_unrecognized) = false; + optional uint32 recognized = 1; +} + +message CastType { + optional int64 Int32 = 1 [(gogoproto.casttype)="int32"]; +} diff --git a/vendor/github.com/gogo/protobuf/test/example/example_test.go b/vendor/github.com/gogo/protobuf/test/example/example_test.go new file mode 100644 index 000000000..34f4c4367 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/example/example_test.go @@ -0,0 +1,35 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import "testing" + +func TestGetterExists(t *testing.T) { + _ = (&CastType{}).GetInt32() +} diff --git a/vendor/github.com/gogo/protobuf/test/example/examplepb_test.go b/vendor/github.com/gogo/protobuf/test/example/examplepb_test.go new file mode 100644 index 000000000..068231783 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/example/examplepb_test.go @@ -0,0 +1,1670 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: example.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + example.proto + +It has these top-level messages: + A + B + C + U + E + R + CastType +*/ +package test + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*A, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedA(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedA(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &A{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestBProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestBMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkBProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*B, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedB(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkBProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedB(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &B{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*C, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedC(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedC(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &C{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*U, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedU(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedU(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &U{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestEProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedE(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &E{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestEMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedE(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &E{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkEProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*E, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedE(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkEProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedE(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &E{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedR(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &R{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedR(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &R{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*R, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedR(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedR(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &R{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CastType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCastTypeMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastType(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CastType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCastTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CastType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCastType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCastTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCastType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CastType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestEJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedE(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &E{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedR(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &R{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCastTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CastType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &A{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := proto.CompactTextString(p) + msg := &A{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &B{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + dAtA := proto.CompactTextString(p) + msg := &B{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &C{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + dAtA := proto.CompactTextString(p) + msg := &C{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &U{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + dAtA := proto.CompactTextString(p) + msg := &U{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedE(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &E{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedE(popr, true) + dAtA := proto.CompactTextString(p) + msg := &E{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedR(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &R{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedR(popr, true) + dAtA := proto.CompactTextString(p) + msg := &R{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CastType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCastTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CastType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestExampleDescription(t *testing.T) { + ExampleDescription() +} +func TestAVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &A{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestBVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &B{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &C{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &U{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestEVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedE(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &E{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedR(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &R{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCastTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CastType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestBGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestEGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedE(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestRGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedR(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCastTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestASize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkASize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*A, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedA(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestBSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkBSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*B, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedB(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*C, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedC(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*U, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedU(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestESize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedE(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkESize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*E, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedE(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedR(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*R, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedR(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCastTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCastType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCastTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CastType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCastType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestBStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestEStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedE(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestRStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedR(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCastTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCastType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, true) + v := p.GetValue() + msg := &U{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/extension_test.go b/vendor/github.com/gogo/protobuf/test/extension_test.go new file mode 100644 index 000000000..54046d4dc --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/extension_test.go @@ -0,0 +1,164 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "github.com/gogo/protobuf/proto" + "math" + math_rand "math/rand" + "testing" + "time" +) + +//func SetRawExtension(base extendableProto, id int32, b []byte) { +//func HasExtension(pb extendableProto, extension *ExtensionDesc) bool { +//func ClearExtension(pb extendableProto, extension *ExtensionDesc) { +//func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, error) { +//func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) { +//func SetExtension(pb extendableProto, extension *ExtensionDesc, value interface{}) error { + +type extendable interface { + proto.Message + ExtensionRangeArray() []proto.ExtensionRange +} + +func check(t *testing.T, m extendable, fieldA float64, ext *proto.ExtensionDesc) { + if !proto.HasExtension(m, ext) { + t.Fatalf("expected extension to be set") + } + fieldA2Interface, err := proto.GetExtension(m, ext) + if err != nil { + panic(err) + } + fieldA2 := fieldA2Interface.(*float64) + if fieldA != *fieldA2 { + t.Fatalf("Expected %f got %f", fieldA, *fieldA2) + } + fieldA3Interface, err := proto.GetUnsafeExtension(m, ext.Field) + if err != nil { + panic(err) + } + fieldA3 := fieldA3Interface.(*float64) + if fieldA != *fieldA3 { + t.Fatalf("Expected %f got %f", fieldA, *fieldA3) + } + proto.ClearExtension(m, ext) + if proto.HasExtension(m, ext) { + t.Fatalf("expected extension to be cleared") + } +} + +var fieldA float64 +var fieldABytes []byte +var extr = math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + +func init() { + fieldA = float64(1.1) + fieldABits := math.Float64bits(fieldA) + x := uint64(uint32(100)<<3 | uint32(proto.WireFixed64)) + fieldABytes = encodeVarintPopulateThetest(nil, x) + fieldABytes = append(fieldABytes, uint8(fieldABits)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>8)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>16)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>24)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>32)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>40)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>48)) + fieldABytes = append(fieldABytes, uint8(fieldABits>>56)) +} + +func TestExtensionsMyExtendable(t *testing.T) { + m := NewPopulatedMyExtendable(extr, false) + err := proto.SetExtension(m, E_FieldA, &fieldA) + if err != nil { + panic(err) + } + check(t, m, fieldA, E_FieldA) + proto.SetRawExtension(m, 100, fieldABytes) + check(t, m, fieldA, E_FieldA) +} + +func TestExtensionsNoExtensionsMapSetExtension(t *testing.T) { + m := NewPopulatedNoExtensionsMap(extr, false) + err := proto.SetExtension(m, E_FieldA1, &fieldA) + if err != nil { + panic(err) + } + check(t, m, fieldA, E_FieldA1) +} + +func TestExtensionsNoExtensionsMapSetRawExtension(t *testing.T) { + m := NewPopulatedNoExtensionsMap(extr, false) + proto.SetRawExtension(m, 100, fieldABytes) + check(t, m, fieldA, E_FieldA1) +} + +func TestUnsafeExtension(t *testing.T) { + m := NewPopulatedMyExtendable(extr, false) + err := proto.SetUnsafeExtension(m, E_FieldA.Field, &fieldA) + if err != nil { + panic(err) + } + check(t, m, fieldA, E_FieldA) +} + +//See another version of this test in proto/extensions_test.go +func TestGetExtensionStability(t *testing.T) { + check := func(m *NoExtensionsMap) bool { + ext1, err := proto.GetExtension(m, E_FieldB1) + if err != nil { + t.Fatalf("GetExtension() failed: %s", err) + } + ext2, err := proto.GetExtension(m, E_FieldB1) + if err != nil { + t.Fatalf("GetExtension() failed: %s", err) + } + return ext1.(*NinOptNative).Equal(ext2) + } + msg := &NoExtensionsMap{Field1: proto.Int64(2)} + ext0 := &NinOptNative{Field1: proto.Float64(1)} + if err := proto.SetExtension(msg, E_FieldB1, ext0); err != nil { + t.Fatalf("Could not set ext1: %s", ext0) + } + if !check(msg) { + t.Errorf("GetExtension() not stable before marshaling") + } + bb, err := proto.Marshal(msg) + if err != nil { + t.Fatalf("Marshal() failed: %s", err) + } + msg1 := &NoExtensionsMap{} + err = proto.Unmarshal(bb, msg1) + if err != nil { + t.Fatalf("Unmarshal() failed: %s", err) + } + if !check(msg1) { + t.Errorf("GetExtension() not stable after unmarshaling") + } +} diff --git a/vendor/github.com/gogo/protobuf/test/filedotname/Makefile b/vendor/github.com/gogo/protobuf/test/filedotname/Makefile new file mode 100644 index 000000000..2833183ce --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/filedotname/Makefile @@ -0,0 +1,31 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2016, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc --gogo_out=. --proto_path=../../../../../:../../protobuf/:. file.dot.proto diff --git a/vendor/github.com/gogo/protobuf/test/filedotname/file.dot.proto b/vendor/github.com/gogo/protobuf/test/filedotname/file.dot.proto new file mode 100644 index 000000000..e1a047c48 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/filedotname/file.dot.proto @@ -0,0 +1,62 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package filedotname; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message M { + optional string a = 1; +} + diff --git a/vendor/github.com/gogo/protobuf/test/filedotname/file.dotpb_test.go b/vendor/github.com/gogo/protobuf/test/filedotname/file.dotpb_test.go new file mode 100644 index 000000000..063602822 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/filedotname/file.dotpb_test.go @@ -0,0 +1,244 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: file.dot.proto + +/* +Package filedotname is a generated protocol buffer package. + +It is generated from these files: + file.dot.proto + +It has these top-level messages: + M +*/ +package filedotname + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*M, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedM(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedM(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &M{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &M{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &M{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + dAtA := proto.CompactTextString(p) + msg := &M{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFileDotDescription(t *testing.T) { + FileDotDescription() +} +func TestMVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &M{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedM(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*M, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedM(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedM(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/fuzztests/Makefile b/vendor/github.com/gogo/protobuf/test/fuzztests/Makefile new file mode 100644 index 000000000..aa82b00fc --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/fuzztests/Makefile @@ -0,0 +1,31 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2015, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogofast + protoc --proto_path=../../../../../:../../protobuf/:. --gogofast_out=. fuzz.proto diff --git a/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz.proto b/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz.proto new file mode 100644 index 000000000..eb01e63c7 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz.proto @@ -0,0 +1,86 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +syntax = "proto2"; +package fuzztests; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.gostring_all) = true; + +message Nil { + +} + +message NinRepPackedNative { + repeated double Field1 = 1 [packed = true]; + repeated float Field2 = 2 [packed = true]; + repeated int32 Field3 = 3 [packed = true]; + repeated int64 Field4 = 4 [packed = true]; + repeated uint32 Field5 = 5 [packed = true]; + repeated uint64 Field6 = 6 [packed = true]; + repeated sint32 Field7 = 7 [packed = true]; + repeated sint64 Field8 = 8 [packed = true]; + repeated fixed32 Field9 = 9 [packed = true]; + repeated sfixed32 Field10 = 10 [packed = true]; + repeated fixed64 Field11 = 11 [packed = true]; + repeated sfixed64 Field12 = 12 [packed = true]; + repeated bool Field13 = 13 [packed = true]; +} + +message NinOptNative { + optional double Field1 = 1; + optional float Field2 = 2; + optional int32 Field3 = 3; + optional int64 Field4 = 4; + optional uint32 Field5 = 5; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional sint64 Field8 = 8; + optional fixed32 Field9 = 9; + optional sfixed32 Field10 = 10; + optional fixed64 Field11 = 11; + optional sfixed64 Field12 = 12; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NinOptStruct { + optional double Field1 = 1; + optional float Field2 = 2; + optional NinOptNative Field3 = 3; + optional NinOptNative Field4 = 4; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional NinOptNative Field8 = 8; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} diff --git a/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz_test.go b/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz_test.go new file mode 100644 index 000000000..81c8793e8 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/fuzztests/fuzz_test.go @@ -0,0 +1,136 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package fuzztests + +import ( + "github.com/gogo/protobuf/proto" + "testing" +) + +func TestFuzzUnrecognized(t *testing.T) { + msg := &Nil{} + input := []byte{0x8, 0xaf, 0x81, 0xc9, 0xb3, 0x97, 0xd1, 0xb5, 0xc2, 0x4f, 0x1a, 0x4a, 0x52, 0x48, 0x4e, 0x44, 0x65, 0x51, 0x4b, 0x46, 0x44, 0x33, 0x5a, 0x44, 0x72, 0x38, 0x58, 0x4c, 0x58, 0x70, 0x59, 0x45, 0x71, 0x45, 0x4f, 0x6d, 0x45, 0x4d, 0x54, 0x59, 0x4c, 0x6b, 0x55, 0x7a, 0x6f, 0x6b, 0x5a, 0x69, 0x56, 0x64, 0x46, 0x45, 0x56, 0x4d, 0x70, 0x6a, 0x39, 0x7a, 0x4b, 0x43, 0x4d, 0x6d, 0x76, 0x63, 0x46, 0x4f, 0x31, 0x4a, 0x5a, 0x6b, 0x66, 0x4a, 0x75, 0x51, 0x38, 0x54, 0x54, 0x30, 0x53, 0x61, 0x36, 0x6e, 0x4f, 0x6b, 0x35, 0x54, 0x95, 0x0, 0x0, 0x0, 0x0, 0x12, 0x38, 0x52, 0x36, 0x66, 0x76, 0x41, 0x74, 0x73, 0x7a, 0x39, 0x43, 0x6a, 0x4f, 0x64, 0x59, 0x77, 0x33, 0x30, 0x36, 0x58, 0x75, 0x65, 0x46, 0x4b, 0x46, 0x55, 0x56, 0x71, 0x6d, 0x49, 0x73, 0x4a, 0x4b, 0x78, 0x76, 0x41, 0x65, 0x42, 0x61, 0x5a, 0x30, 0x41, 0x37, 0x45, 0x76, 0x72, 0x31, 0x30, 0x4e, 0x78, 0x6d, 0x33, 0x63, 0x65, 0x66, 0x6b, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatal("expected error") + } +} + +func DisabledTestFuzzPackedIsNotIdempotent(t *testing.T) { + msg := &NinRepPackedNative{} + //original := []byte{0x9, 0xa3, 0xae, 0xab, 0xd2, 0xbe, 0x1c, 0xed, 0xbf, 0x15, 0x22, 0x1, 0x6e, 0x3f, 0x22, 0x81, 0x1, 0x9, 0x21, 0x84, 0x36, 0x21, 0x6a, 0xff, 0xd3, 0x3f, 0x15, 0x15, 0x71, 0x4b, 0xbd, 0x52, 0x70, 0x49, 0x6e, 0x48, 0x54, 0x6a, 0x61, 0x37, 0x63, 0x78, 0x47, 0x58, 0x31, 0x7a, 0x43, 0x4d, 0x7a, 0x48, 0x58, 0x56, 0xcb, 0x9c, 0x34, 0xdf, 0xc6, 0x3c, 0xa4, 0x33, 0xac, 0xba, 0xa7, 0xeb, 0x4, 0xa8, 0x8a, 0x48, 0x75, 0x67, 0x71, 0x31, 0x4a, 0x5b, 0xe1, 0xcf, 0x21, 0x88, 0xd3, 0xec, 0xac, 0x13, 0x28, 0xec, 0xa9, 0x51, 0xc8, 0xe9, 0x5e, 0xca, 0xbe, 0xea, 0x9c, 0x0, 0x6b, 0x44, 0x63, 0xc4, 0x32, 0xaa, 0x36, 0x4e, 0xfc, 0xbd, 0x7, 0xef, 0x5e, 0x47, 0x2, 0xfc, 0xd8, 0x83, 0x85, 0x9c, 0xca, 0x7c, 0xd2, 0xdb, 0xf5, 0x5d, 0xcc, 0x5a, 0x72, 0x1f, 0x66, 0x55, 0x74, 0x46, 0x47, 0x73, 0x75, 0x54, 0x30, 0x39, 0x53, 0x34, 0x4c, 0x61, 0x78, 0x59, 0x31, 0x51, 0x44, 0x30, 0x53, 0x51, 0x71, 0x44, 0x65, 0x6f, 0x53, 0x30, 0x44, 0x6a, 0x58, 0x7a, 0x1b, 0x65, 0x62, 0x9c, 0x95, 0xc5, 0x41, 0xcb, 0x48, 0xa, 0x47, 0xf6, 0xd8, 0xd2, 0xd5, 0x8d, 0x6, 0x69, 0x8f, 0xbe, 0x7c, 0xf3, 0xe9, 0x79, 0x3c, 0xca, 0x6, 0x5b} + input := []byte{0x9, 0xa3, 0xae, 0xab, 0xd2, 0xbe, 0x1c, 0xed, 0xbf, 0x15, 0x22, 0x1, 0x6e, 0x3f, 0x22, 0x81, 0x1, 0x9, 0x21, 0x84, 0x36, 0x21, 0x6a, 0xff, 0xd3, 0x3f, 0x15, 0x15, 0x71, 0x4b, 0xbd, 0x52, 0x70, 0x49, 0x6e, 0x48, 0x54, 0x6a, 0x61, 0x37, 0x63, 0x78, 0x47, 0x58, 0x31, 0x7a, 0x43, 0x4d, 0x7a, 0x48, 0x58, 0x56, 0xcb, 0x9c, 0x34, 0xdf, 0xc6, 0x3c, 0xa4, 0x33, 0xac, 0xba, 0xa7, 0xeb, 0x4, 0xa8, 0x8a, 0x48, 0x75, 0x67, 0x71, 0x31, 0x4a, 0x5b, 0xe1, 0xcf, 0x21, 0x88, 0xd3, 0xec, 0xac, 0x13, 0x28, 0xec, 0xa9, 0x51, 0xc8, 0xe9, 0x5e, 0xca, 0xbe, 0xea, 0x9c, 0x0, 0x6b, 0x44, 0x63, 0xc4, 0x32, 0xaa, 0x36, 0x4e, 0xfc, 0xbd, 0x7, 0xef, 0x5e, 0x47, 0x2, 0xfc, 0xd8, 0x83, 0x85, 0x9c, 0xca, 0x7c, 0xd2, 0xdb, 0xf5, 0x5d, 0xcc, 0x5a, 0x72, 0x1f, 0x66, 0x55, 0x74, 0x46, 0x47, 0x73, 0x75, 0x54, 0x30, 0x39, 0x53, 0x34, 0x4c, 0x61, 0x78, 0x59, 0x31, 0x51, 0x44, 0x30, 0x53, 0x51} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatal("expected error") + } +} + +func DisabledTestFuzzFieldOrder(t *testing.T) { + msg := &NinOptStruct{} + input := []byte{0x52, 0x57, 0x52, 0x6a, 0x33, 0x56, 0x43, 0x76, 0x32, 0x54, 0x49, 0x4a, 0x55, 0x66, 0x39, 0x52, 0x32, 0x32, 0x73, 0x69, 0x4f, 0x67, 0x66, 0x79, 0x4b, 0x79, 0x5a, 0x55, 0x42, 0x53, 0x38, 0x68, 0x6c, 0x46, 0x79, 0x6b, 0x54, 0x43, 0x63, 0x66, 0x30, 0x6a, 0x33, 0x35, 0x33, 0x7a, 0x41, 0x66, 0x68, 0x57, 0x61, 0x78, 0x51, 0x37, 0x76, 0x52, 0x78, 0x34, 0x56, 0x43, 0x54, 0x31, 0x73, 0x6a, 0x77, 0x63, 0x45, 0x62, 0x62, 0x67, 0x34, 0x6f, 0x64, 0x35, 0x6c, 0x41, 0x45, 0x50, 0x64, 0x6f, 0x46, 0x38, 0x41, 0x4b, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30} + if err := proto.Unmarshal(input, msg); err != nil { + t.Fatal(err) + } +} + +func TestFuzzSint64Overflow(t *testing.T) { + msg := &NinOptNative{} + //original := []byte{0x9, 0x65, 0xb4, 0xfd, 0xbc, 0x5, 0xc7, 0xee, 0x3f, 0x15, 0x48, 0xec, 0x67, 0x3f, 0x18, 0xca, 0xa4, 0xe0, 0xa9, 0x5, 0x20, 0x8e, 0xb7, 0x9f, 0xf5, 0xcf, 0xe9, 0xea, 0xad, 0xfd, 0x1, 0x28, 0xc9, 0xf1, 0xbc, 0x88, 0xc, 0x30, 0xeb, 0x99, 0xbd, 0xa8, 0xe, 0x38, 0xc0, 0xd4, 0xb7, 0xba, 0x7, 0x40, 0xc8, 0xe4, 0xf6, 0xe2, 0xb8, 0xdd, 0xa7, 0xf2, 0x82, 0xba, 0x16, 0x9d, 0x59, 0xf9, 0x31, 0xe0, 0x99, 0x0, 0x0, 0x0, 0x0, 0x61, 0x59, 0x5b, 0xb5, 0x57, 0x56, 0x93, 0x70, 0xde, 0x68, 0x0, 0x72, 0x40, 0x64, 0x5a, 0x5a, 0x61, 0x57, 0x78, 0x68, 0x53, 0x65, 0x66, 0x67, 0x38, 0x38, 0x61, 0x48, 0x44, 0x32, 0x6c, 0x36, 0x50, 0x31, 0x4d, 0x43, 0x39, 0x31, 0x6d, 0x37, 0x34, 0x32, 0x48, 0x6b, 0x4d, 0x70, 0x31, 0x45, 0x73, 0x48, 0x71, 0x4a, 0x69, 0x37, 0x56, 0x53, 0x44, 0x6b, 0x48, 0x45, 0x50, 0x4b, 0x7a, 0x52, 0x49, 0x4c, 0x50, 0x69, 0x44, 0x72, 0x42, 0x56, 0x50, 0x78, 0x62, 0x56, 0x55, 0x7a, 0x5b, 0xb3, 0x6c, 0x59, 0x4c, 0xf1, 0x31, 0xeb, 0xb6, 0x25, 0x1a, 0x26, 0x67, 0x66, 0x97, 0x79, 0xb8, 0x37, 0x8, 0xe1, 0x32, 0x45, 0x6e, 0x6, 0x90, 0x4f, 0xde, 0x26, 0x7a, 0xc6, 0x29, 0x65, 0x4a, 0x69, 0xa7, 0x21, 0xfb, 0x42, 0xda, 0x43, 0x89, 0x27, 0x70, 0x71, 0xde, 0x66, 0xa4, 0x75, 0x2b, 0x5c, 0x96, 0x9f, 0x25, 0x3b, 0xc1, 0x64, 0x14, 0x4, 0x60, 0x8c, 0x58, 0x7e, 0xa1, 0x59, 0x7b, 0x47, 0x18, 0xc, 0x5b, 0x18, 0x63, 0x9, 0xb4, 0xc9, 0x7, 0xf9, 0xae, 0x33, 0xae, 0x2, 0x4a, 0x8b, 0x34, 0x92, 0x40, 0xb, 0xd7, 0x80, 0x60, 0xdb, 0x44, 0x5} + input := []byte{0x40, 0xc8, 0xe4, 0xf6, 0xe2, 0xb8, 0xdd, 0xa7, 0xf2, 0x82, 0xba, 0x16} + if err := proto.Unmarshal(input, msg); err != nil { + return + } +} + +func DisabledTestFuzzOverrideField(t *testing.T) { + msg := &NinOptNative{} + //original := []byte{0x9, 0x73, 0x78, 0x5a, 0xf2, 0xb4, 0x66, 0xe8, 0x3f, 0x15, 0x71, 0xdc, 0x4, 0x3f, 0x18, 0xe5, 0x8e, 0xab, 0xdb, 0x3, 0x20, 0xbe, 0xed, 0xe6, 0xc0, 0xb9, 0xb8, 0xa7, 0xb5, 0x12, 0x28, 0xcb, 0x8c, 0x91, 0xef, 0xc, 0x30, 0x9a, 0xc1, 0xc3, 0xc0, 0xf, 0x38, 0xe8, 0x9b, 0xf0, 0xca, 0x5, 0x40, 0xd2, 0xd7, 0xdd, 0xa3, 0xea, 0xab, 0xec, 0xc2, 0xaa, 0x1, 0x4d, 0xc9, 0x15, 0x0, 0xea, 0x55, 0x72, 0x3e, 0x92, 0xa8, 0x59, 0x3e, 0x87, 0x7d, 0xf5, 0x0, 0x0, 0x0, 0x0, 0x61, 0xca, 0xe7, 0xdb, 0x57, 0xa1, 0xb6, 0x41, 0xf4, 0x72, 0x3e, 0x63, 0x36, 0x43, 0x73, 0x32, 0x68, 0x64, 0x75, 0x75, 0x70, 0x4f, 0x39, 0x67, 0x77, 0x42, 0x6a, 0x78, 0x63, 0x57, 0x64, 0x77, 0x6b, 0x74, 0x44, 0x4d, 0x79, 0x36, 0x30, 0x68, 0x38, 0x53, 0x31, 0x79, 0x33, 0x38, 0x4b, 0x7a, 0x76, 0x36, 0x48, 0x4a, 0x35, 0x37, 0x59, 0x48, 0x6c, 0x74, 0x72, 0x61, 0x33, 0x4c, 0x74, 0x45, 0x4a, 0x51, 0x68, 0x71, 0x31, 0x70, 0x50, 0x70, 0x6a, 0x4d, 0x15, 0x51, 0xce, 0xea, 0x82, 0x1, 0x23, 0xed, 0x7a, 0x3, 0x78, 0xee, 0x56, 0x46, 0xd0, 0xe1, 0x17, 0x18, 0x30, 0x9d, 0x2f, 0xac, 0x1c, 0xa, 0x30, 0xa9, 0x8d, 0x10, 0xed, 0xb5, 0x44, 0x36, 0x5e, 0x84, 0x73, 0x5d, 0x38, 0x51, 0x2b, 0x6e, 0xc6, 0xb5} + input := []byte{0x4d, 0xc9, 0x15, 0x0, 0xea, 0x72, 0x3e, 0x63, 0x36, 0x43, 0x73, 0x32, 0x68, 0x64, 0x75, 0x75, 0x70, 0x4f, 0x39, 0x67, 0x77, 0x42, 0x6a, 0x78, 0x63, 0x57, 0x64, 0x77, 0x6b, 0x74, 0x44, 0x4d, 0x79, 0x36, 0x30, 0x68, 0x38, 0x53, 0x31, 0x79, 0x33, 0x38, 0x4b, 0x7a, 0x76, 0x36, 0x48, 0x4a, 0x35, 0x37, 0x59, 0x48, 0x6c, 0x74, 0x72, 0x61, 0x33, 0x4c, 0x74, 0x45, 0x4a, 0x51, 0x68, 0x71, 0x31, 0x70, 0x50, 0x70, 0x6a, 0x4d, 0x15, 0x51, 0xce, 0xea} + if err := proto.Unmarshal(input, msg); err != nil { + panic(err) + } + output, err := proto.Marshal(msg) + if err != nil { + t.Fatal(err) + } + if len(input) != len(output) { + t.Logf("%#v", msg) + msg2 := &NinOptNative{} + if err := proto.Unmarshal(output, msg2); err == nil { + t.Logf("%#v", msg2) + } + t.Errorf("expected %#v got %#v", input, output) + } +} + +//Generated code is correct, non generated returns an incorrect error +func DisabledTestFuzzBadWireType(t *testing.T) { + msg := &NinRepPackedNative{} + //input := []byte("j\x160\xfc0000\xf6\xfa000\xc1\xaf\xf5000\xcf" + "00\xb90z\r0\x850\xd30000'0000") + input := []byte{0x6a, 0x16, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0xf6, 0xfa, 0x30, 0x30, 0x30, 0xc1, 0xaf, 0xf5, 0x30, 0x30, 0x30, 0xcf, 0x30, 0x30, 0xb9, 0x30, 0x7a, 0xd, 0x30, 0x85, 0x30, 0xd3, 0x30, 0x30, 0x30, 0x30, 0x27, 0x30, 0x30, 0x30, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatalf("expected bad wiretype for Field4 error got %#v", msg) + } else { + t.Log(err) + } +} + +func TestFuzzIntegerOverflow(t *testing.T) { + msg := &Nil{} + //input := []byte("\x1500000\x8b\x9b\xa3\xa8\xb6\xe1\xe1\xfe\u061c0") + input := []byte{0x15, 0x30, 0x30, 0x30, 0x30, 0x30, 0x8b, 0x9b, 0xa3, 0xa8, 0xb6, 0xe1, 0xe1, 0xfe, 0xd8, 0x9c, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatalf("expected integer overflow error %#v", msg) + } else { + t.Log(err) + } +} + +//Generated code is correct, non generated returns an incorrect error +func DisabledTestFuzzUnexpectedEOF(t *testing.T) { + msg := &NinRepPackedNative{} + //input := []byte("j\x16000000000000000000" + "00\xb90") + input := []byte{0x6a, 0x16, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0xb9, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatalf("expected unexpected eof error got %#v", msg) + } else { + t.Log(err) + } +} + +//Generated code is correct, non generated returns an incorrect error +func DisabledTestFuzzCantSkipWireType(t *testing.T) { + msg := &NinRepPackedNative{} + //input := []byte("j\x160\xfc0000\xf6\xfa000\xc1\xaf\xf5000\xcf" + "00\xb90z\r0\x850\xd3000\xa80\xa7000") + input := []byte{0x6a, 0x16, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0xf6, 0xfa, 0x30, 0x30, 0x30, 0xc1, 0xaf, 0xf5, 0x30, 0x30, 0x30, 0xcf, 0x30, 0x30, 0xb9, 0x30, 0x7a, 0xd, 0x30, 0x85, 0x30, 0xd3, 0x30, 0x30, 0x30, 0xa8, 0x30, 0xa7, 0x30, 0x30, 0x30} + if err := proto.Unmarshal(input, msg); err == nil { + t.Fatalf("expected cant skip wiretype error got %#v", msg) + } else { + t.Log(err) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/group/Makefile b/vendor/github.com/gogo/protobuf/test/group/Makefile new file mode 100644 index 000000000..ebbbbd2c2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/group/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. group.proto) diff --git a/vendor/github.com/gogo/protobuf/test/group/group.proto b/vendor/github.com/gogo/protobuf/test/group/group.proto new file mode 100644 index 000000000..0dad6569a --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/group/group.proto @@ -0,0 +1,65 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package group; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; + +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = false; + +message Groups1 { + repeated group G = 1 { + optional int64 Field1 = 1; + optional double Field2 = 2; + } +} + +message Groups2 { + optional group G = 1 { + optional int64 Field1 = 1; + repeated double Field2 = 2; + } +} + diff --git a/vendor/github.com/gogo/protobuf/test/group/grouppb_test.go b/vendor/github.com/gogo/protobuf/test/group/grouppb_test.go new file mode 100644 index 000000000..0ca768486 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/group/grouppb_test.go @@ -0,0 +1,539 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: group.proto + +/* +Package group is a generated protocol buffer package. + +It is generated from these files: + group.proto + +It has these top-level messages: + Groups1 + Groups2 +*/ +package group + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestGroups1Proto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups1(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups1{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestGroups1_GProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups1_G(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups1_G{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestGroups2Proto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups2(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups2{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestGroups2_GProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups2_G(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups2_G{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestGroups1JSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups1(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups1{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestGroups1_GJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups1_G(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups1_G{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestGroups2JSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups2(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups2{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestGroups2_GJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups2_G(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Groups2_G{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestGroups1ProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups1(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Groups1{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups1ProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups1(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Groups1{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups1_GProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups1_G(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Groups1_G{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups1_GProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups1_G(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Groups1_G{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups2ProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups2(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Groups2{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups2ProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups2(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Groups2{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups2_GProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups2_G(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Groups2_G{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroups2_GProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedGroups2_G(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Groups2_G{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestGroupDescription(t *testing.T) { + GroupDescription() +} +func TestGroups1VerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Groups1{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestGroups1_GVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1_G(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Groups1_G{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestGroups2VerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Groups2{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestGroups2_GVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2_G(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Groups2_G{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestGroups1GoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestGroups1_GGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1_G(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestGroups2GoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestGroups2_GGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2_G(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestGroups1Stringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestGroups1_GStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups1_G(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestGroups2Stringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestGroups2_GStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedGroups2_G(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/importdedup/Makefile b/vendor/github.com/gogo/protobuf/test/importdedup/Makefile new file mode 100644 index 000000000..21d823a67 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importdedup/Makefile @@ -0,0 +1,31 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. proto.proto) + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. subpkg/subproto.proto) diff --git a/vendor/github.com/gogo/protobuf/test/importdedup/importdedup_test.go b/vendor/github.com/gogo/protobuf/test/importdedup/importdedup_test.go new file mode 100644 index 000000000..8bdcc6238 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importdedup/importdedup_test.go @@ -0,0 +1,34 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package importdedup + +import testing "testing" + +func TestImportDedup(t *testing.T) { +} diff --git a/vendor/github.com/gogo/protobuf/test/importdedup/proto.proto b/vendor/github.com/gogo/protobuf/test/importdedup/proto.proto new file mode 100644 index 000000000..5d9c9c827 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importdedup/proto.proto @@ -0,0 +1,40 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package importdedup; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "github.com/gogo/protobuf/test/importdedup/subpkg/subproto.proto"; + +message Object { + optional bytes CustomField = 1 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/importdedup/subpkg.CustomType"]; + optional subpkg.SubObject SubObject = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/importdedup/subpkg/subproto.proto b/vendor/github.com/gogo/protobuf/test/importdedup/subpkg/subproto.proto new file mode 100644 index 000000000..b8df5e478 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importdedup/subpkg/subproto.proto @@ -0,0 +1,36 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package subpkg; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message SubObject { + +} diff --git a/vendor/github.com/gogo/protobuf/test/importduplicate/Makefile b/vendor/github.com/gogo/protobuf/test/importduplicate/Makefile new file mode 100644 index 000000000..efd3ea248 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importduplicate/Makefile @@ -0,0 +1,40 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-min-version + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=:. \ + --proto_path=../../../../../:../../protobuf/:. importduplicate.proto + protoc-min-version --version="3.0.0" --gogo_out=:. \ + --proto_path=../../../../../:../../protobuf/:. sortkeys/sortable.proto + protoc-min-version --version="3.0.0" --gogo_out=:. \ + --proto_path=../../../../../:../../protobuf/:. proto/proto.proto + +test: + go test diff --git a/vendor/github.com/gogo/protobuf/test/importduplicate/importduplicate.proto b/vendor/github.com/gogo/protobuf/test/importduplicate/importduplicate.proto new file mode 100644 index 000000000..024cc6ecb --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importduplicate/importduplicate.proto @@ -0,0 +1,45 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package importduplicate; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/gogo/protobuf/test/importduplicate/sortkeys/sortable.proto"; +import "github.com/gogo/protobuf/test/importduplicate/proto/proto.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.gostring_all) = true; + +message MapAndSortKeys { + sortkeys.Object key = 1; + map keyValue = 2; + proto.Subject value = 3; +} diff --git a/vendor/github.com/gogo/protobuf/test/importduplicate/importduplicate_test.go b/vendor/github.com/gogo/protobuf/test/importduplicate/importduplicate_test.go new file mode 100644 index 000000000..be385489c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importduplicate/importduplicate_test.go @@ -0,0 +1,34 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package importduplicate + +import testing "testing" + +func TestImportDuplicate(t *testing.T) { +} diff --git a/vendor/github.com/gogo/protobuf/test/importduplicate/importduplicatepb_test.go b/vendor/github.com/gogo/protobuf/test/importduplicate/importduplicatepb_test.go new file mode 100644 index 000000000..03f354114 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importduplicate/importduplicatepb_test.go @@ -0,0 +1,123 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: importduplicate.proto + +/* +Package importduplicate is a generated protocol buffer package. + +It is generated from these files: + importduplicate.proto + +It has these top-level messages: + MapAndSortKeys +*/ +package importduplicate + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/importduplicate/sortkeys" +import _ "github.com/gogo/protobuf/test/importduplicate/proto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMapAndSortKeysProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapAndSortKeys(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapAndSortKeys{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapAndSortKeysJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapAndSortKeys(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapAndSortKeys{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapAndSortKeysProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapAndSortKeys(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapAndSortKeys{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapAndSortKeysProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapAndSortKeys(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapAndSortKeys{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapAndSortKeysGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapAndSortKeys(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/importduplicate/proto/proto.proto b/vendor/github.com/gogo/protobuf/test/importduplicate/proto/proto.proto new file mode 100644 index 000000000..122e21a45 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importduplicate/proto/proto.proto @@ -0,0 +1,41 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package proto; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.gostring_all) = true; + +message Subject { + +} diff --git a/vendor/github.com/gogo/protobuf/test/importduplicate/proto/protopb_test.go b/vendor/github.com/gogo/protobuf/test/importduplicate/proto/protopb_test.go new file mode 100644 index 000000000..4a7f0c8e0 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importduplicate/proto/protopb_test.go @@ -0,0 +1,121 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: proto/proto.proto + +/* +Package proto is a generated protocol buffer package. + +It is generated from these files: + proto/proto.proto + +It has these top-level messages: + Subject +*/ +package proto + +import testing "testing" +import rand "math/rand" +import time "time" +import proto1 "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto1.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubjectProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubject(popr, false) + dAtA, err := proto1.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subject{} + if err := proto1.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto1.Unmarshal(littlefuzz, msg) + } +} + +func TestSubjectJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubject(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subject{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubjectProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubject(popr, true) + dAtA := proto1.MarshalTextString(p) + msg := &Subject{} + if err := proto1.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubjectProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubject(popr, true) + dAtA := proto1.CompactTextString(p) + msg := &Subject{} + if err := proto1.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubjectGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubject(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/importduplicate/sortkeys/sortable.proto b/vendor/github.com/gogo/protobuf/test/importduplicate/sortkeys/sortable.proto new file mode 100644 index 000000000..5052b2c3b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importduplicate/sortkeys/sortable.proto @@ -0,0 +1,41 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package sortkeys; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.gostring_all) = true; + +message Object { + +} diff --git a/vendor/github.com/gogo/protobuf/test/importduplicate/sortkeys/sortablepb_test.go b/vendor/github.com/gogo/protobuf/test/importduplicate/sortkeys/sortablepb_test.go new file mode 100644 index 000000000..f039061f2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/importduplicate/sortkeys/sortablepb_test.go @@ -0,0 +1,121 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sortkeys/sortable.proto + +/* +Package sortkeys is a generated protocol buffer package. + +It is generated from these files: + sortkeys/sortable.proto + +It has these top-level messages: + Object +*/ +package sortkeys + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestObjectProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestObjectJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestObjectProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Object{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Object{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedObject(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/indeximport-issue72/Makefile b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/Makefile new file mode 100644 index 000000000..0a2f73ac4 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/Makefile @@ -0,0 +1,31 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (cd index && protoc --proto_path=../../../../../../:../../../protobuf/:. --gogo_out=. index.proto) + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. indeximport.proto) diff --git a/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/index.proto b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/index.proto new file mode 100644 index 000000000..3f79b4aa6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/index.proto @@ -0,0 +1,45 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package index; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.testgen_all) = true; + +message IndexQuery { + optional string Key = 1; + optional string Value = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/indexpb_test.go b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/indexpb_test.go new file mode 100644 index 000000000..57d4d9a37 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/index/indexpb_test.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: index.proto + +/* +Package index is a generated protocol buffer package. + +It is generated from these files: + index.proto + +It has these top-level messages: + IndexQuery +*/ +package index + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestIndexQueryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQuery{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestIndexQueryMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQuery{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQuery{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestIndexQueryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &IndexQuery{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, true) + dAtA := proto.CompactTextString(p) + msg := &IndexQuery{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQuerySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQuery(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximport.proto b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximport.proto new file mode 100644 index 000000000..6358b0bf9 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximport.proto @@ -0,0 +1,46 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package indeximport; + +import "github.com/gogo/protobuf/test/indeximport-issue72/index/index.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.testgen_all) = true; + +message IndexQueries { + repeated index.IndexQuery Queries = 1; +} + diff --git a/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximportpb_test.go b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximportpb_test.go new file mode 100644 index 000000000..62712a79f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/indeximport-issue72/indeximportpb_test.go @@ -0,0 +1,154 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: indeximport.proto + +/* +Package indeximport is a generated protocol buffer package. + +It is generated from these files: + indeximport.proto + +It has these top-level messages: + IndexQueries +*/ +package indeximport + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/test/indeximport-issue72/index" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestIndexQueriesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQueries{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestIndexQueriesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQueries{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueriesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IndexQueries{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestIndexQueriesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &IndexQueries{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueriesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, true) + dAtA := proto.CompactTextString(p) + msg := &IndexQueries{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIndexQueriesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIndexQueries(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/int64support/Makefile b/vendor/github.com/gogo/protobuf/test/int64support/Makefile new file mode 100644 index 000000000..356ac1214 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/int64support/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc -I=. -I=../../../../../ -I=../../protobuf/ --gogo_out=. object.proto) diff --git a/vendor/github.com/gogo/protobuf/test/int64support/object.proto b/vendor/github.com/gogo/protobuf/test/int64support/object.proto new file mode 100644 index 000000000..68e256a0c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/int64support/object.proto @@ -0,0 +1,24 @@ +package int64support; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option go_package = "int64support"; +option (gogoproto.benchgen_all) = true; +option (gogoproto.enum_stringer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_unrecognized_all) = false; +option (gogoproto.gostring_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.testgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.verbose_equal_all) = true; + +message Object { + optional int64 optional_number = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/int64support/object_js_test.go b/vendor/github.com/gogo/protobuf/test/int64support/object_js_test.go new file mode 100644 index 000000000..d769a2841 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/int64support/object_js_test.go @@ -0,0 +1,47 @@ +package int64support + +import ( + "encoding/json" + "testing" +) + +func TestMarshaler(t *testing.T) { + n := int64(1) + b, err := json.Marshal(&Object{&n}) + if err != nil { + t.Fatal(err) + } + const expected = "{\"optional_number\":1}" + if string(b) != expected { + t.Fatalf("expected '%s' instead of '%s'", expected, string(b)) + } + + b, err = json.Marshal(new(Object)) + if err != nil { + t.Fatal(err) + } + const expected2 = "{}" + if string(b) != expected2 { + t.Fatalf("expected '%s' instead of '%s'", expected2, string(b)) + } +} + +func TestUnmarshaler(t *testing.T) { + o := new(Object) + err := json.Unmarshal(([]byte)("{\"optional_number\": 1}"), o) + if err != nil { + t.Fatal(err) + } + if n := o.GetOptionalNumber(); n != 1 { + t.Fatalf("expected 1 instead of %d", n) + } + + o = new(Object) + err = json.Unmarshal(([]byte)("{}"), o) + if err != nil { + t.Fatal(err) + } + if o.OptionalNumber != nil { + t.Fatalf("expected nil OptionalNumber instead of %d", *o.OptionalNumber) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/int64support/objectpb_test.go b/vendor/github.com/gogo/protobuf/test/int64support/objectpb_test.go new file mode 100644 index 000000000..ae7afd07d --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/int64support/objectpb_test.go @@ -0,0 +1,261 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: object.proto + +/* +Package int64support is a generated protocol buffer package. + +It is generated from these files: + object.proto + +It has these top-level messages: + Object +*/ +package int64support + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestObjectProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestObjectMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkObjectProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Object, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedObject(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkObjectProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedObject(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Object{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestObjectJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestObjectProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Object{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Object{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedObject(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Object{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestObjectGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedObject(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestObjectSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkObjectSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Object, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedObject(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestObjectStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedObject(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/issue260/Makefile b/vendor/github.com/gogo/protobuf/test/issue260/Makefile new file mode 100644 index 000000000..a0f5e5294 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue260/Makefile @@ -0,0 +1,3 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types:. --proto_path=../../../../../:../../protobuf/:. issue260.proto diff --git a/vendor/github.com/gogo/protobuf/test/issue260/README.md b/vendor/github.com/gogo/protobuf/test/issue260/README.md new file mode 100644 index 000000000..d25084786 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue260/README.md @@ -0,0 +1,11 @@ +# The Bug + +If in a message the following options are set: + +* `typedecl` `false` +* `go_getters` `false` +* `marshaller` `true` + +And one of the fields is using the `stdtime` and `nullable` `false` extension (to +use `time.Time` instead of the protobuf type), then an import to the _time_ package +is added even if it is not needed. diff --git a/vendor/github.com/gogo/protobuf/test/issue260/issue260.proto b/vendor/github.com/gogo/protobuf/test/issue260/issue260.proto new file mode 100644 index 000000000..bd44c1cfb --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue260/issue260.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; + +package issue260; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Dropped { + option (gogoproto.typedecl) = false; + string name = 1; + int32 age = 2; +} + +message DroppedWithoutGetters { + option (gogoproto.typedecl) = false; + option (gogoproto.goproto_getters) = false; + int64 height = 1; + int64 width = 2; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; +} + +message Kept { + string name = 1; + int32 age = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/issue260/issue260pb_test.go b/vendor/github.com/gogo/protobuf/test/issue260/issue260pb_test.go new file mode 100644 index 000000000..cb45d7ee2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue260/issue260pb_test.go @@ -0,0 +1,656 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: issue260.proto + +/* +Package issue260 is a generated protocol buffer package. + +It is generated from these files: + issue260.proto + +It has these top-level messages: + Dropped + DroppedWithoutGetters + Kept +*/ +package issue260 + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestDroppedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDropped(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Dropped{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedWithoutGettersMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedWithoutGettersProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedWithoutGettersProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDroppedWithoutGetters(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DroppedWithoutGetters{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKeptMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKeptProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKeptProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedKept(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Kept{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedWithoutGettersJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKeptJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Dropped{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Dropped{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DroppedWithoutGetters{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DroppedWithoutGetters{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Kept{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Kept{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDropped(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Dropped{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedWithoutGettersVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DroppedWithoutGetters{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKeptVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKept(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Kept{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedWithoutGettersSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKeptSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/issue261/Makefile b/vendor/github.com/gogo/protobuf/test/issue261/Makefile new file mode 100644 index 000000000..8e2d9a597 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue261/Makefile @@ -0,0 +1,7 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-min-version + go install github.com/gogo/protobuf/protoc-gen-gogoslick + protoc-min-version --version="3.0.0" --gogoslick_out=\ + Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\ + :. \ + --proto_path=../../../../../:../../protobuf/:. issue261.proto diff --git a/vendor/github.com/gogo/protobuf/test/issue261/issue261.proto b/vendor/github.com/gogo/protobuf/test/issue261/issue261.proto new file mode 100644 index 000000000..6f33793f1 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue261/issue261.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package issue261; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "google/protobuf/duration.proto"; + +message MapStdTypes { + map nullableDuration = 3 [(gogoproto.stdduration) = true]; +} diff --git a/vendor/github.com/gogo/protobuf/test/issue262/Makefile b/vendor/github.com/gogo/protobuf/test/issue262/Makefile new file mode 100644 index 000000000..555477909 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue262/Makefile @@ -0,0 +1,5 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-min-version + go install github.com/gogo/protobuf/protoc-gen-gogoslick + protoc-min-version --version="3.0.0" --proto_path=.:$(GOPATH)/src/:$(GOPATH)/src/github.com/gogo/protobuf/protobuf/ \ + --gogoslick_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types:. timefail.proto diff --git a/vendor/github.com/gogo/protobuf/test/issue262/timefail.proto b/vendor/github.com/gogo/protobuf/test/issue262/timefail.proto new file mode 100644 index 000000000..06bce8bef --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue262/timefail.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +package timefail; + +message TimeFail { + google.protobuf.Timestamp time_test = 1 [(gogoproto.stdtime) = true]; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/issue270/a/a1.proto b/vendor/github.com/gogo/protobuf/test/issue270/a/a1.proto new file mode 100644 index 000000000..59dff1394 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue270/a/a1.proto @@ -0,0 +1,12 @@ +syntax = "proto2"; + +package issue270.a; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/gogo/protobuf/test/issue270/a/a2.proto"; + +option (gogoproto.populate_all) = true; + +message A1 { + optional A2 a2 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/issue270/a/a2.proto b/vendor/github.com/gogo/protobuf/test/issue270/a/a2.proto new file mode 100644 index 000000000..1d16ff79a --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue270/a/a2.proto @@ -0,0 +1,12 @@ +syntax = "proto2"; + +package issue270.a; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/gogo/protobuf/test/issue270/b/b.proto"; + +option (gogoproto.populate_all) = true; + +message A2 { + optional issue270.b.B b = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/issue270/b/b.proto b/vendor/github.com/gogo/protobuf/test/issue270/b/b.proto new file mode 100644 index 000000000..cb71c2480 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue270/b/b.proto @@ -0,0 +1,6 @@ +syntax = "proto2"; + +package issue270.b; + +message B { +} diff --git a/vendor/github.com/gogo/protobuf/test/issue270/issue270_test.go b/vendor/github.com/gogo/protobuf/test/issue270/issue270_test.go new file mode 100644 index 000000000..b3faaa56e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue270/issue270_test.go @@ -0,0 +1,51 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package issue270 + +import ( + "os" + "os/exec" + "strings" + "testing" +) + +func TestPopulateWarning(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:.", "a/a1.proto") + data, err := cmd.CombinedOutput() + dataStr := string(data) + t.Logf("received error = %v and output = %v", err, dataStr) + if err != nil { + t.Error(err) + } else if strings.Contains(dataStr, "WARNING") { + t.Errorf("Unexpected WARNING: %s", dataStr) + } + if err = os.Remove("a/a1.pb.go"); err != nil && !os.IsNotExist(err) { + t.Error(err) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/issue312/Makefile b/vendor/github.com/gogo/protobuf/test/issue312/Makefile new file mode 100644 index 000000000..db17d4adf --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue312/Makefile @@ -0,0 +1,4 @@ +regenerate: + protoc --proto_path=.:$(GOPATH)/src/:$(GOPATH)/src/github.com/gogo/protobuf/protobuf/ \ + --gogo_out=. issue312.proto + (cd events && make regenerate) diff --git a/vendor/github.com/gogo/protobuf/test/issue312/events/Makefile b/vendor/github.com/gogo/protobuf/test/issue312/events/Makefile new file mode 100644 index 000000000..fc6be53f5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue312/events/Makefile @@ -0,0 +1,4 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc --proto_path=.:$(GOPATH)/src/:$(GOPATH)/src/github.com/gogo/protobuf/protobuf/ \ + --gogo_out=. events.proto diff --git a/vendor/github.com/gogo/protobuf/test/issue312/events/events.proto b/vendor/github.com/gogo/protobuf/test/issue312/events/events.proto new file mode 100644 index 000000000..23bd12999 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue312/events/events.proto @@ -0,0 +1,17 @@ +syntax = "proto2"; + +package issue312.events; + +import "github.com/gogo/protobuf/test/issue312/issue312.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option go_package = "events"; +option (gogoproto.gostring_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.testgen_all) = true; + +message Subtype { + optional issue312.TaskState state = 4; +} + diff --git a/vendor/github.com/gogo/protobuf/test/issue312/events/eventspb_test.go b/vendor/github.com/gogo/protobuf/test/issue312/events/eventspb_test.go new file mode 100644 index 000000000..577053695 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue312/events/eventspb_test.go @@ -0,0 +1,122 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: events.proto + +/* +Package events is a generated protocol buffer package. + +It is generated from these files: + events.proto + +It has these top-level messages: + Subtype +*/ +package events + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/test/issue312" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubtypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubtype(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subtype{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubtypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubtype(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subtype{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubtypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubtype(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Subtype{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubtypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubtype(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Subtype{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubtypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubtype(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/issue312/issue312.proto b/vendor/github.com/gogo/protobuf/test/issue312/issue312.proto new file mode 100644 index 000000000..d409d7dfe --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue312/issue312.proto @@ -0,0 +1,17 @@ +syntax = "proto2"; + +package issue312; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option go_package = "issue312"; +option (gogoproto.gostring_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.testgen_all) = true; + +enum TaskState { + TASK_STAGING = 6; + TASK_STARTING = 0; + TASK_RUNNING = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/issue322/Makefile b/vendor/github.com/gogo/protobuf/test/issue322/Makefile new file mode 100644 index 000000000..c7748e443 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue322/Makefile @@ -0,0 +1,3 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogofast + protoc-min-version --version="3.0.0" --gogofast_out=Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor:. --proto_path=../../../../../:../../protobuf/:. *.proto diff --git a/vendor/github.com/gogo/protobuf/test/issue322/issue322.proto b/vendor/github.com/gogo/protobuf/test/issue322/issue322.proto new file mode 100644 index 000000000..e3045de10 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue322/issue322.proto @@ -0,0 +1,15 @@ +syntax = "proto2"; +package test; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.gostring_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.testgen_all) = true; + +message OneofTest { + oneof union { + int32 i = 1 [default = 4]; + } +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/issue322/issue322pb_test.go b/vendor/github.com/gogo/protobuf/test/issue322/issue322pb_test.go new file mode 100644 index 000000000..4e5550ff5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue322/issue322pb_test.go @@ -0,0 +1,167 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: issue322.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + issue322.proto + +It has these top-level messages: + OneofTest +*/ +package test + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestOneofTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofTestMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofTest{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofTestGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOneofTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofTest(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/issue330/Makefile b/vendor/github.com/gogo/protobuf/test/issue330/Makefile new file mode 100644 index 000000000..e085e13d2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue330/Makefile @@ -0,0 +1,3 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor:. --proto_path=../../../../../:../../protobuf/:. *.proto diff --git a/vendor/github.com/gogo/protobuf/test/issue330/issue330.proto b/vendor/github.com/gogo/protobuf/test/issue330/issue330.proto new file mode 100644 index 000000000..4bfdda457 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue330/issue330.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package issue330; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.benchgen_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.testgen_all) = true; +option (gogoproto.unmarshaler_all) = true; + +message Object { + uint32 type = 1 [(gogoproto.casttype) = "TypeIdentifier"]; +} diff --git a/vendor/github.com/gogo/protobuf/test/issue330/issue330pb_test.go b/vendor/github.com/gogo/protobuf/test/issue330/issue330pb_test.go new file mode 100644 index 000000000..e24c30dda --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue330/issue330pb_test.go @@ -0,0 +1,207 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: issue330.proto + +/* +Package issue330 is a generated protocol buffer package. + +It is generated from these files: + issue330.proto + +It has these top-level messages: + Object +*/ +package issue330 + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestObjectProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestObjectMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkObjectProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Object, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedObject(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkObjectProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedObject(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Object{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestObjectJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Object{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestObjectProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Object{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Object{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestObjectSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedObject(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkObjectSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Object, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedObject(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/issue34/Makefile b/vendor/github.com/gogo/protobuf/test/issue34/Makefile new file mode 100644 index 000000000..ecb3e74ea --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue34/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. proto.proto) diff --git a/vendor/github.com/gogo/protobuf/test/issue34/issue34_test.go b/vendor/github.com/gogo/protobuf/test/issue34/issue34_test.go new file mode 100644 index 000000000..a9fbde489 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue34/issue34_test.go @@ -0,0 +1,82 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package issue34 + +import ( + "bytes" + "github.com/gogo/protobuf/proto" + "testing" +) + +func TestZeroLengthOptionalBytes(t *testing.T) { + roundtrip := func(f *Foo) *Foo { + data, err := proto.Marshal(f) + if err != nil { + panic(err) + } + newF := &Foo{} + err = proto.Unmarshal(data, newF) + if err != nil { + panic(err) + } + return newF + } + + f := &Foo{} + roundtrippedF := roundtrip(f) + if roundtrippedF.Bar != nil { + t.Fatalf("should be nil") + } + + f.Bar = []byte{} + roundtrippedF = roundtrip(f) + if roundtrippedF.Bar == nil { + t.Fatalf("should not be nil") + } + if len(roundtrippedF.Bar) != 0 { + t.Fatalf("should be empty") + } +} + +func TestRepeatedOptional(t *testing.T) { + repeated := &FooWithRepeated{Bar: [][]byte{[]byte("a"), []byte("b")}} + data, err := proto.Marshal(repeated) + if err != nil { + panic(err) + } + optional := &Foo{} + err = proto.Unmarshal(data, optional) + if err != nil { + panic(err) + } + + if !bytes.Equal(optional.Bar, []byte("b")) { + t.Fatalf("should return the last entry") + } +} diff --git a/vendor/github.com/gogo/protobuf/test/issue34/proto.proto b/vendor/github.com/gogo/protobuf/test/issue34/proto.proto new file mode 100644 index 000000000..5531befbb --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue34/proto.proto @@ -0,0 +1,43 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package issue34; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.unmarshaler_all) = true; + +message Foo { + optional bytes bar = 1; +} + +message FooWithRepeated { + repeated bytes bar = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/issue42order/Makefile b/vendor/github.com/gogo/protobuf/test/issue42order/Makefile new file mode 100644 index 000000000..5b8e59bdb --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue42order/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. issue42.proto) diff --git a/vendor/github.com/gogo/protobuf/test/issue42order/issue42.proto b/vendor/github.com/gogo/protobuf/test/issue42order/issue42.proto new file mode 100644 index 000000000..5e8b77be5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue42order/issue42.proto @@ -0,0 +1,48 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package issue42; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.sizer_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.populate_all) = true; + +message UnorderedFields { + optional int64 A = 10; + optional fixed64 B = 1; +} + +message OrderedFields { + optional fixed64 B = 1; + optional int64 A = 10; +} diff --git a/vendor/github.com/gogo/protobuf/test/issue42order/order_test.go b/vendor/github.com/gogo/protobuf/test/issue42order/order_test.go new file mode 100644 index 000000000..571731c7c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue42order/order_test.go @@ -0,0 +1,56 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package issue42 + +import ( + "bytes" + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + time "time" +) + +func TestIssue42Order(t *testing.T) { + unordered := NewPopulatedUnorderedFields(math_rand.New(math_rand.NewSource(time.Now().UnixNano())), false) + udata, err := proto.Marshal(unordered) + if err != nil { + t.Fatal(err) + } + ordered := &OrderedFields{} + if err = proto.Unmarshal(udata, ordered); err != nil { + t.Fatal(err) + } + data, err := proto.Marshal(ordered) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(udata, data) { + t.Fatalf("expected data to be marshaled in the same order, please sort fields before marshaling") + } +} diff --git a/vendor/github.com/gogo/protobuf/test/issue8/Makefile b/vendor/github.com/gogo/protobuf/test/issue8/Makefile new file mode 100644 index 000000000..ecb3e74ea --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue8/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. proto.proto) diff --git a/vendor/github.com/gogo/protobuf/test/issue8/proto.proto b/vendor/github.com/gogo/protobuf/test/issue8/proto.proto new file mode 100644 index 000000000..2c9bcf46f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue8/proto.proto @@ -0,0 +1,42 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package proto; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; + +message Foo { + required uint64 bar = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/issue8/protopb_test.go b/vendor/github.com/gogo/protobuf/test/issue8/protopb_test.go new file mode 100644 index 000000000..502c16ff5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/issue8/protopb_test.go @@ -0,0 +1,106 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: proto.proto + +/* +Package proto is a generated protocol buffer package. + +It is generated from these files: + proto.proto + +It has these top-level messages: + Foo +*/ +package proto + +import testing "testing" +import rand "math/rand" +import time "time" +import proto1 "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto1.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFooProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFoo(popr, false) + dAtA, err := proto1.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Foo{} + if err := proto1.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto1.Unmarshal(littlefuzz, msg) + } +} + +func TestFooJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Foo{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFooProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + dAtA := proto1.MarshalTextString(p) + msg := &Foo{} + if err := proto1.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFooProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + dAtA := proto1.CompactTextString(p) + msg := &Foo{} + if err := proto1.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo.go b/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo.go new file mode 100644 index 000000000..1e0b08d22 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo.go @@ -0,0 +1 @@ +package jsonpb_gogo diff --git a/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo_test.go b/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo_test.go new file mode 100644 index 000000000..ec2558773 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/jsonpb-gogo/jsonpb_gogo_test.go @@ -0,0 +1,36 @@ +package jsonpb_gogo + +import ( + "testing" + + "github.com/gogo/protobuf/jsonpb" +) + +// customFieldMessage implements protobuf.Message but is not a normal generated message type. +type customFieldMessage struct { + someField string //this is not a proto field +} + +func (m *customFieldMessage) Reset() { + m.someField = "hello" +} + +func (m *customFieldMessage) String() string { + return m.someField +} + +func (m *customFieldMessage) ProtoMessage() { +} + +func TestUnmarshalWithJSONPBUnmarshaler(t *testing.T) { + rawJson := `{}` + marshaler := &jsonpb.Marshaler{} + msg := &customFieldMessage{someField: "Ignore me"} + str, err := marshaler.MarshalToString(msg) + if err != nil { + t.Errorf("an unexpected error occurred when marshaling message: %v", err) + } + if str != rawJson { + t.Errorf("marshaled JSON was incorrect: got %s, wanted %s", str, rawJson) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/Makefile b/vendor/github.com/gogo/protobuf/test/mapdefaults/Makefile new file mode 100644 index 000000000..80a46900c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/Makefile @@ -0,0 +1,33 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2017, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-combo + go install github.com/gogo/protobuf/protoc-gen-gogofast + protoc-gen-combo --version="3.0.0" --proto_path=../../../../../:../../protobuf/:. --gogo_out=. map.proto + find combos -type d -not -name combos -exec cp map_test.go.in {}/map_test.go \; diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map.proto b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map.proto new file mode 100644 index 000000000..2de9cdd7f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map.proto @@ -0,0 +1,70 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package mapdefaults; + + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + + +message MapTest { + map str_str = 1; +} + +message FakeMap { + repeated FakeMapEntry entries = 1; +} + +message FakeMapEntry { + string key = 1; + string value = 2; + string other = 3; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map_test.go b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map_test.go new file mode 100644 index 000000000..9998ead10 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/map_test.go @@ -0,0 +1,180 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package mapdefaults + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestUnmarshalImplicitDefaultKeyValue1(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "foo", + Value: "", + }, + { + Key: "", + Value: "bar", + }, + { + Key: "as", + Value: "df", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 3 { + t.Fatal("StrStr map should have 3 key/value pairs") + } + + val, ok := strStr["foo"] + if !ok { + t.Fatal("\"foo\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"foo\": %s", val) + } + + val, ok = strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "bar" { + t.Fatalf("Unexpected value for \"\": %s", val) + } + + val, ok = strStr["as"] + if !ok { + t.Fatal("\"as\" not found in StrStr map.") + } + if val != "df" { + t.Fatalf("Unexpected value for \"as\": %s", val) + } +} + +func TestUnmarshalImplicitDefaultKeyValue2(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "", + Value: "", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + // Sanity check + if string(serializedMsg) != "\n\x00" { + t.Fatal("Serialized bytes mismatched") + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"\": %s", val) + } +} + +func TestUnmarshalIgnoreUnknownField(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "key", + Value: "value", + Other: "other", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := &MapTest{} + err = proto.Unmarshal(serializedMsg, msg) + + if err != nil { + var pb proto.Message = msg + _, ok := pb.(proto.Unmarshaler) + if !ok { + // non-codegen implementation returns error when extra tags are + // present. + return + } + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr["key"] + if !ok { + t.Fatal("\"key\" not found in StrStr map.") + } + if val != "value" { + t.Fatalf("Unexpected value for \"value\": %s", val) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/mappb_test.go b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/mappb_test.go new file mode 100644 index 000000000..1bd17f59d --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/both/mappb_test.go @@ -0,0 +1,564 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/map.proto + +/* +Package mapdefaults is a generated protocol buffer package. + +It is generated from these files: + combos/both/map.proto + +It has these top-level messages: + MapTest + FakeMap + FakeMapEntry +*/ +package mapdefaults + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMapTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapTestMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapEntryMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapEntryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FakeMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FakeMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FakeMapEntry{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FakeMapEntry{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapDescription(t *testing.T) { + MapDescription() +} +func TestMapTestVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapEntryVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapTestGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapEntryGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapEntrySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestMapTestStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapEntryStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map.proto b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map.proto new file mode 100644 index 000000000..fe9912313 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map.proto @@ -0,0 +1,70 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package mapdefaults; + + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + + +message MapTest { + map str_str = 1; +} + +message FakeMap { + repeated FakeMapEntry entries = 1; +} + +message FakeMapEntry { + string key = 1; + string value = 2; + string other = 3; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map_test.go b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map_test.go new file mode 100644 index 000000000..9998ead10 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/map_test.go @@ -0,0 +1,180 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package mapdefaults + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestUnmarshalImplicitDefaultKeyValue1(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "foo", + Value: "", + }, + { + Key: "", + Value: "bar", + }, + { + Key: "as", + Value: "df", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 3 { + t.Fatal("StrStr map should have 3 key/value pairs") + } + + val, ok := strStr["foo"] + if !ok { + t.Fatal("\"foo\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"foo\": %s", val) + } + + val, ok = strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "bar" { + t.Fatalf("Unexpected value for \"\": %s", val) + } + + val, ok = strStr["as"] + if !ok { + t.Fatal("\"as\" not found in StrStr map.") + } + if val != "df" { + t.Fatalf("Unexpected value for \"as\": %s", val) + } +} + +func TestUnmarshalImplicitDefaultKeyValue2(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "", + Value: "", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + // Sanity check + if string(serializedMsg) != "\n\x00" { + t.Fatal("Serialized bytes mismatched") + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"\": %s", val) + } +} + +func TestUnmarshalIgnoreUnknownField(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "key", + Value: "value", + Other: "other", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := &MapTest{} + err = proto.Unmarshal(serializedMsg, msg) + + if err != nil { + var pb proto.Message = msg + _, ok := pb.(proto.Unmarshaler) + if !ok { + // non-codegen implementation returns error when extra tags are + // present. + return + } + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr["key"] + if !ok { + t.Fatal("\"key\" not found in StrStr map.") + } + if val != "value" { + t.Fatalf("Unexpected value for \"value\": %s", val) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/mappb_test.go b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/mappb_test.go new file mode 100644 index 000000000..41e962a9c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/marshaler/mappb_test.go @@ -0,0 +1,564 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/map.proto + +/* +Package mapdefaults is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/map.proto + +It has these top-level messages: + MapTest + FakeMap + FakeMapEntry +*/ +package mapdefaults + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMapTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapTestMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapEntryMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapEntryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FakeMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FakeMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FakeMapEntry{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FakeMapEntry{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapDescription(t *testing.T) { + MapDescription() +} +func TestMapTestVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapEntryVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapTestGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapEntryGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapEntrySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestMapTestStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapEntryStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map.proto b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map.proto new file mode 100644 index 000000000..43d5c0dab --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map.proto @@ -0,0 +1,70 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package mapdefaults; + + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + + +message MapTest { + map str_str = 1; +} + +message FakeMap { + repeated FakeMapEntry entries = 1; +} + +message FakeMapEntry { + string key = 1; + string value = 2; + string other = 3; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map_test.go b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map_test.go new file mode 100644 index 000000000..9998ead10 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/map_test.go @@ -0,0 +1,180 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package mapdefaults + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestUnmarshalImplicitDefaultKeyValue1(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "foo", + Value: "", + }, + { + Key: "", + Value: "bar", + }, + { + Key: "as", + Value: "df", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 3 { + t.Fatal("StrStr map should have 3 key/value pairs") + } + + val, ok := strStr["foo"] + if !ok { + t.Fatal("\"foo\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"foo\": %s", val) + } + + val, ok = strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "bar" { + t.Fatalf("Unexpected value for \"\": %s", val) + } + + val, ok = strStr["as"] + if !ok { + t.Fatal("\"as\" not found in StrStr map.") + } + if val != "df" { + t.Fatalf("Unexpected value for \"as\": %s", val) + } +} + +func TestUnmarshalImplicitDefaultKeyValue2(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "", + Value: "", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + // Sanity check + if string(serializedMsg) != "\n\x00" { + t.Fatal("Serialized bytes mismatched") + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"\": %s", val) + } +} + +func TestUnmarshalIgnoreUnknownField(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "key", + Value: "value", + Other: "other", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := &MapTest{} + err = proto.Unmarshal(serializedMsg, msg) + + if err != nil { + var pb proto.Message = msg + _, ok := pb.(proto.Unmarshaler) + if !ok { + // non-codegen implementation returns error when extra tags are + // present. + return + } + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr["key"] + if !ok { + t.Fatal("\"key\" not found in StrStr map.") + } + if val != "value" { + t.Fatalf("Unexpected value for \"value\": %s", val) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/mappb_test.go b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/mappb_test.go new file mode 100644 index 000000000..e9a2716e2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/neither/mappb_test.go @@ -0,0 +1,480 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/map.proto + +/* +Package mapdefaults is a generated protocol buffer package. + +It is generated from these files: + combos/neither/map.proto + +It has these top-level messages: + MapTest + FakeMap + FakeMapEntry +*/ +package mapdefaults + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMapTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapEntryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapEntryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FakeMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FakeMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FakeMapEntry{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FakeMapEntry{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapDescription(t *testing.T) { + MapDescription() +} +func TestMapTestVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapEntryVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapTestGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapEntryGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapEntrySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestMapTestStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapEntryStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map.proto b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map.proto new file mode 100644 index 000000000..75a379ce4 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map.proto @@ -0,0 +1,70 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package mapdefaults; + + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + + +message MapTest { + map str_str = 1; +} + +message FakeMap { + repeated FakeMapEntry entries = 1; +} + +message FakeMapEntry { + string key = 1; + string value = 2; + string other = 3; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map_test.go b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map_test.go new file mode 100644 index 000000000..9998ead10 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/map_test.go @@ -0,0 +1,180 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package mapdefaults + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestUnmarshalImplicitDefaultKeyValue1(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "foo", + Value: "", + }, + { + Key: "", + Value: "bar", + }, + { + Key: "as", + Value: "df", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 3 { + t.Fatal("StrStr map should have 3 key/value pairs") + } + + val, ok := strStr["foo"] + if !ok { + t.Fatal("\"foo\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"foo\": %s", val) + } + + val, ok = strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "bar" { + t.Fatalf("Unexpected value for \"\": %s", val) + } + + val, ok = strStr["as"] + if !ok { + t.Fatal("\"as\" not found in StrStr map.") + } + if val != "df" { + t.Fatalf("Unexpected value for \"as\": %s", val) + } +} + +func TestUnmarshalImplicitDefaultKeyValue2(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "", + Value: "", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + // Sanity check + if string(serializedMsg) != "\n\x00" { + t.Fatal("Serialized bytes mismatched") + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"\": %s", val) + } +} + +func TestUnmarshalIgnoreUnknownField(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + { + Key: "key", + Value: "value", + Other: "other", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := &MapTest{} + err = proto.Unmarshal(serializedMsg, msg) + + if err != nil { + var pb proto.Message = msg + _, ok := pb.(proto.Unmarshaler) + if !ok { + // non-codegen implementation returns error when extra tags are + // present. + return + } + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr["key"] + if !ok { + t.Fatal("\"key\" not found in StrStr map.") + } + if val != "value" { + t.Fatalf("Unexpected value for \"value\": %s", val) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/mappb_test.go b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/mappb_test.go new file mode 100644 index 000000000..d79882b3e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/combos/unmarshaler/mappb_test.go @@ -0,0 +1,480 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/map.proto + +/* +Package mapdefaults is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/map.proto + +It has these top-level messages: + MapTest + FakeMap + FakeMapEntry +*/ +package mapdefaults + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMapTestProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFakeMapEntryProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapTestJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapTest{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFakeMapEntryJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FakeMapEntry{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapTestProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapTestProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapTest{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FakeMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FakeMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FakeMapEntry{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFakeMapEntryProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FakeMapEntry{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapDescription(t *testing.T) { + MapDescription() +} +func TestMapTestVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapTest{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFakeMapEntryVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FakeMapEntry{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapTestGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFakeMapEntryGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapTestSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapTest(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestFakeMapEntrySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFakeMapEntry(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestMapTestStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapTest(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFakeMapEntryStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFakeMapEntry(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/map.proto b/vendor/github.com/gogo/protobuf/test/mapdefaults/map.proto new file mode 100644 index 000000000..43d5c0dab --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/map.proto @@ -0,0 +1,70 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package mapdefaults; + + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + + +message MapTest { + map str_str = 1; +} + +message FakeMap { + repeated FakeMapEntry entries = 1; +} + +message FakeMapEntry { + string key = 1; + string value = 2; + string other = 3; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapdefaults/map_test.go.in b/vendor/github.com/gogo/protobuf/test/mapdefaults/map_test.go.in new file mode 100644 index 000000000..51e1260c3 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapdefaults/map_test.go.in @@ -0,0 +1,180 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package mapdefaults + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestUnmarshalImplicitDefaultKeyValue1(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + &FakeMapEntry{ + Key: "foo", + Value: "", + }, + &FakeMapEntry{ + Key: "", + Value: "bar", + }, + &FakeMapEntry{ + Key: "as", + Value: "df", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 3 { + t.Fatal("StrStr map should have 3 key/value pairs") + } + + val, ok := strStr["foo"] + if !ok { + t.Fatal("\"foo\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"foo\": %s", val) + } + + val, ok = strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "bar" { + t.Fatalf("Unexpected value for \"\": %s", val) + } + + val, ok = strStr["as"] + if !ok { + t.Fatal("\"as\" not found in StrStr map.") + } + if val != "df" { + t.Fatalf("Unexpected value for \"as\": %s", val) + } +} + +func TestUnmarshalImplicitDefaultKeyValue2(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + &FakeMapEntry{ + Key: "", + Value: "", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + // Sanity check + if string(serializedMsg) != "\n\x00" { + t.Fatal("Serialized bytes mismatched") + } + + msg := MapTest{} + err = proto.Unmarshal(serializedMsg, &msg) + + if err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr[""] + if !ok { + t.Fatal("\"\" not found in StrStr map.") + } + if val != "" { + t.Fatalf("Unexpected value for \"\": %s", val) + } +} + +func TestUnmarshalIgnoreUnknownField(t *testing.T) { + fm := &FakeMap{ + Entries: []*FakeMapEntry{ + &FakeMapEntry{ + Key: "key", + Value: "value", + Other: "other", + }, + }, + } + + serializedMsg, err := proto.Marshal(fm) + if err != nil { + t.Fatalf("Failed to serialize msg: %s", err) + } + + msg := &MapTest{} + err = proto.Unmarshal(serializedMsg, msg) + + if err != nil { + var pb proto.Message = msg + _, ok := pb.(proto.Unmarshaler) + if !ok { + // non-codegen implementation returns error when extra tags are + // present. + return + } + t.Fatalf("Unexpected error: %s", err) + } + + strStr := msg.StrStr + if len(strStr) != 1 { + t.Fatal("StrStr map should have 1 key/value pairs") + } + + val, ok := strStr["key"] + if !ok { + t.Fatal("\"key\" not found in StrStr map.") + } + if val != "value" { + t.Fatalf("Unexpected value for \"value\": %s", val) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/Makefile b/vendor/github.com/gogo/protobuf/test/mapsproto2/Makefile new file mode 100644 index 000000000..6a43fe506 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/Makefile @@ -0,0 +1,35 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-combo + go install github.com/gogo/protobuf/protoc-gen-gogo + cp header.proto mapsproto2.proto + cat ../theproto3/maps.proto >> mapsproto2.proto + find combos -type d -not -name combos -exec cp mapsproto2_test.go.in {}/mapsproto2_test.go \; + protoc-gen-combo --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. mapsproto2.proto diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2.proto b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2.proto new file mode 100644 index 000000000..4f8e4ab91 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2.proto @@ -0,0 +1,124 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package proto2.maps; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message FloatingPoint { + optional double f = 1; +} + +message CustomMap { + map Nullable128s = 1 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128"]; + map Uint128s = 2 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable)=false]; + map NullableIds = 3 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid"]; + map Ids = 4 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid", (gogoproto.nullable)=false]; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2_test.go b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2_test.go new file mode 100644 index 000000000..488bc86bf --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2_test.go @@ -0,0 +1,104 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto2_maps + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2pb_test.go b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2pb_test.go new file mode 100644 index 000000000..9dddf5971 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/both/mapsproto2pb_test.go @@ -0,0 +1,989 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/mapsproto2.proto + +/* +Package proto2_maps is a generated protocol buffer package. + +It is generated from these files: + combos/both/mapsproto2.proto + +It has these top-level messages: + FloatingPoint + CustomMap + AllMaps + AllMapsOrdered +*/ +package proto2_maps + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFloatingPointMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsOrderedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapsproto2Description(t *testing.T) { + Mapsproto2Description() +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2.proto b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2.proto new file mode 100644 index 000000000..dc972a908 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2.proto @@ -0,0 +1,124 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package proto2.maps; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message FloatingPoint { + optional double f = 1; +} + +message CustomMap { + map Nullable128s = 1 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128"]; + map Uint128s = 2 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable)=false]; + map NullableIds = 3 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid"]; + map Ids = 4 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid", (gogoproto.nullable)=false]; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2_test.go b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2_test.go new file mode 100644 index 000000000..488bc86bf --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2_test.go @@ -0,0 +1,104 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto2_maps + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2pb_test.go b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2pb_test.go new file mode 100644 index 000000000..e302f3f97 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/marshaler/mapsproto2pb_test.go @@ -0,0 +1,989 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/mapsproto2.proto + +/* +Package proto2_maps is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/mapsproto2.proto + +It has these top-level messages: + FloatingPoint + CustomMap + AllMaps + AllMapsOrdered +*/ +package proto2_maps + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFloatingPointMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkCustomMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsOrderedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapsproto2Description(t *testing.T) { + Mapsproto2Description() +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2.proto b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2.proto new file mode 100644 index 000000000..39de58312 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2.proto @@ -0,0 +1,124 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package proto2.maps; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message FloatingPoint { + optional double f = 1; +} + +message CustomMap { + map Nullable128s = 1 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128"]; + map Uint128s = 2 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable)=false]; + map NullableIds = 3 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid"]; + map Ids = 4 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid", (gogoproto.nullable)=false]; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2_test.go b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2_test.go new file mode 100644 index 000000000..488bc86bf --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2_test.go @@ -0,0 +1,104 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto2_maps + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2pb_test.go b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2pb_test.go new file mode 100644 index 000000000..fc7b78285 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/neither/mapsproto2pb_test.go @@ -0,0 +1,877 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/mapsproto2.proto + +/* +Package proto2_maps is a generated protocol buffer package. + +It is generated from these files: + combos/neither/mapsproto2.proto + +It has these top-level messages: + FloatingPoint + CustomMap + AllMaps + AllMapsOrdered +*/ +package proto2_maps + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapsproto2Description(t *testing.T) { + Mapsproto2Description() +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2.proto b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2.proto new file mode 100644 index 000000000..27a47d6af --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2.proto @@ -0,0 +1,124 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package proto2.maps; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message FloatingPoint { + optional double f = 1; +} + +message CustomMap { + map Nullable128s = 1 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128"]; + map Uint128s = 2 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable)=false]; + map NullableIds = 3 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid"]; + map Ids = 4 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid", (gogoproto.nullable)=false]; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2_test.go b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2_test.go new file mode 100644 index 000000000..488bc86bf --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2_test.go @@ -0,0 +1,104 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto2_maps + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2pb_test.go b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2pb_test.go new file mode 100644 index 000000000..8e770c030 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/combos/unmarshaler/mapsproto2pb_test.go @@ -0,0 +1,877 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/mapsproto2.proto + +/* +Package proto2_maps is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/mapsproto2.proto + +It has these top-level messages: + FloatingPoint + CustomMap + AllMaps + AllMapsOrdered +*/ +package proto2_maps + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapsproto2Description(t *testing.T) { + Mapsproto2Description() +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/header.proto b/vendor/github.com/gogo/protobuf/test/mapsproto2/header.proto new file mode 100644 index 000000000..5d87649a6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/header.proto @@ -0,0 +1,76 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package proto2.maps; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message FloatingPoint { + optional double f = 1; +} + +message CustomMap { + map Nullable128s = 1 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128"]; + map Uint128s = 2 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable)=false]; + map NullableIds = 3 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid"]; + map Ids = 4 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid", (gogoproto.nullable)=false]; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/mapsproto2.proto b/vendor/github.com/gogo/protobuf/test/mapsproto2/mapsproto2.proto new file mode 100644 index 000000000..39de58312 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/mapsproto2.proto @@ -0,0 +1,124 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package proto2.maps; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message FloatingPoint { + optional double f = 1; +} + +message CustomMap { + map Nullable128s = 1 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128"]; + map Uint128s = 2 [(gogoproto.customtype)="github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable)=false]; + map NullableIds = 3 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid"]; + map Ids = 4 [(gogoproto.customtype)="github.com/gogo/protobuf/test.Uuid", (gogoproto.nullable)=false]; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} diff --git a/vendor/github.com/gogo/protobuf/test/mapsproto2/mapsproto2_test.go.in b/vendor/github.com/gogo/protobuf/test/mapsproto2/mapsproto2_test.go.in new file mode 100644 index 000000000..5ccc86602 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mapsproto2/mapsproto2_test.go.in @@ -0,0 +1,104 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package proto2_maps + +import ( + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": []byte{}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/mixbench/.gitignore b/vendor/github.com/gogo/protobuf/test/mixbench/.gitignore new file mode 100644 index 000000000..95341f35b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mixbench/.gitignore @@ -0,0 +1 @@ +mixbench \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/mixbench/marshal.txt b/vendor/github.com/gogo/protobuf/test/mixbench/marshal.txt new file mode 100644 index 000000000..58efdca46 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mixbench/marshal.txt @@ -0,0 +1,73 @@ +goos: darwin +goarch: amd64 +pkg: github.com/gogo/protobuf/test +BenchmarkNidOptNativeProtoMarshal-8 2000000 831 ns/op 276.72 MB/s +BenchmarkNinOptNativeProtoMarshal-8 2000000 931 ns/op 224.49 MB/s +BenchmarkNidRepNativeProtoMarshal-8 500000 2341 ns/op 349.71 MB/s +BenchmarkNinRepNativeProtoMarshal-8 500000 2500 ns/op 327.56 MB/s +BenchmarkNidRepPackedNativeProtoMarshal-8 500000 3542 ns/op 105.30 MB/s +BenchmarkNinRepPackedNativeProtoMarshal-8 500000 3571 ns/op 104.44 MB/s +BenchmarkNidOptStructProtoMarshal-8 500000 2386 ns/op 354.44 MB/s +BenchmarkNinOptStructProtoMarshal-8 500000 2361 ns/op 324.30 MB/s +BenchmarkNidRepStructProtoMarshal-8 200000 5585 ns/op 317.40 MB/s +BenchmarkNinRepStructProtoMarshal-8 200000 5608 ns/op 316.16 MB/s +BenchmarkNidEmbeddedStructProtoMarshal-8 1000000 1475 ns/op 327.39 MB/s +BenchmarkNinEmbeddedStructProtoMarshal-8 1000000 1465 ns/op 312.60 MB/s +BenchmarkNidNestedStructProtoMarshal-8 100000 14816 ns/op 278.74 MB/s +BenchmarkNinNestedStructProtoMarshal-8 100000 13744 ns/op 283.03 MB/s +BenchmarkNidOptCustomProtoMarshal-8 3000000 539 ns/op 131.63 MB/s +BenchmarkCustomDashProtoMarshal-8 3000000 474 ns/op 172.86 MB/s +BenchmarkNinOptCustomProtoMarshal-8 3000000 578 ns/op 115.81 MB/s +BenchmarkNidRepCustomProtoMarshal-8 1000000 1700 ns/op 107.04 MB/s +BenchmarkNinRepCustomProtoMarshal-8 1000000 1715 ns/op 106.07 MB/s +BenchmarkNinOptNativeUnionProtoMarshal-8 5000000 346 ns/op 46.17 MB/s +BenchmarkNinOptStructUnionProtoMarshal-8 3000000 518 ns/op 121.60 MB/s +BenchmarkNinEmbeddedStructUnionProtoMarshal-8 2000000 785 ns/op 189.70 MB/s +BenchmarkNinNestedStructUnionProtoMarshal-8 2000000 657 ns/op 118.58 MB/s +BenchmarkTreeProtoMarshal-8 3000000 584 ns/op 176.32 MB/s +BenchmarkOrBranchProtoMarshal-8 2000000 997 ns/op 245.52 MB/s +BenchmarkAndBranchProtoMarshal-8 2000000 982 ns/op 249.36 MB/s +BenchmarkLeafProtoMarshal-8 3000000 453 ns/op 213.86 MB/s +BenchmarkDeepTreeProtoMarshal-8 2000000 822 ns/op 176.28 MB/s +BenchmarkADeepBranchProtoMarshal-8 2000000 931 ns/op 196.52 MB/s +BenchmarkAndDeepBranchProtoMarshal-8 1000000 1515 ns/op 219.09 MB/s +BenchmarkDeepLeafProtoMarshal-8 2000000 696 ns/op 200.89 MB/s +BenchmarkNilProtoMarshal-8 10000000 219 ns/op 159.54 MB/s +BenchmarkNidOptEnumProtoMarshal-8 5000000 275 ns/op 134.49 MB/s +BenchmarkNinOptEnumProtoMarshal-8 5000000 314 ns/op 130.50 MB/s +BenchmarkNidRepEnumProtoMarshal-8 3000000 516 ns/op 114.31 MB/s +BenchmarkNinRepEnumProtoMarshal-8 3000000 516 ns/op 114.21 MB/s +BenchmarkNinOptEnumDefaultProtoMarshal-8 5000000 308 ns/op 132.80 MB/s +BenchmarkAnotherNinOptEnumProtoMarshal-8 5000000 311 ns/op 131.65 MB/s +BenchmarkAnotherNinOptEnumDefaultProtoMarshal-8 5000000 312 ns/op 131.11 MB/s +BenchmarkTimerProtoMarshal-8 3000000 503 ns/op 208.34 MB/s +BenchmarkMyExtendableProtoMarshal-8 2000000 689 ns/op 117.49 MB/s +BenchmarkOtherExtenableProtoMarshal-8 1000000 1356 ns/op 116.48 MB/s +BenchmarkNestedDefinitionProtoMarshal-8 2000000 919 ns/op 252.30 MB/s +BenchmarkNestedDefinition_NestedMessageProtoMarshal-8 3000000 566 ns/op 210.03 MB/s +BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal-8 5000000 395 ns/op 207.58 MB/s +BenchmarkNestedScopeProtoMarshal-8 2000000 840 ns/op 265.32 MB/s +BenchmarkNinOptNativeDefaultProtoMarshal-8 2000000 932 ns/op 224.11 MB/s +BenchmarkCustomContainerProtoMarshal-8 2000000 680 ns/op 160.07 MB/s +BenchmarkCustomNameNidOptNativeProtoMarshal-8 2000000 844 ns/op 272.51 MB/s +BenchmarkCustomNameNinOptNativeProtoMarshal-8 2000000 915 ns/op 228.30 MB/s +BenchmarkCustomNameNinRepNativeProtoMarshal-8 500000 2346 ns/op 348.99 MB/s +BenchmarkCustomNameNinStructProtoMarshal-8 500000 3010 ns/op 318.50 MB/s +BenchmarkCustomNameCustomTypeProtoMarshal-8 1000000 2003 ns/op 106.79 MB/s +BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal-8 2000000 757 ns/op 196.79 MB/s +BenchmarkCustomNameEnumProtoMarshal-8 5000000 375 ns/op 119.68 MB/s +BenchmarkNoExtensionsMapProtoMarshal-8 3000000 423 ns/op 191.12 MB/s +BenchmarkUnrecognizedProtoMarshal-8 5000000 279 ns/op 160.80 MB/s +BenchmarkUnrecognizedWithInnerProtoMarshal-8 3000000 582 ns/op 161.34 MB/s +BenchmarkUnrecognizedWithInner_InnerProtoMarshal-8 10000000 209 ns/op 23.87 MB/s +BenchmarkUnrecognizedWithEmbedProtoMarshal-8 3000000 497 ns/op 178.98 MB/s +BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal-8 10000000 216 ns/op 23.12 MB/s +BenchmarkNodeProtoMarshal-8 3000000 436 ns/op 231.46 MB/s +BenchmarkNonByteCustomTypeProtoMarshal-8 2000000 843 ns/op 93.69 MB/s +BenchmarkNidOptNonByteCustomTypeProtoMarshal-8 2000000 851 ns/op 97.47 MB/s +BenchmarkNinOptNonByteCustomTypeProtoMarshal-8 2000000 857 ns/op 92.15 MB/s +BenchmarkNidRepNonByteCustomTypeProtoMarshal-8 500000 2748 ns/op 83.67 MB/s +BenchmarkNinRepNonByteCustomTypeProtoMarshal-8 500000 2750 ns/op 83.62 MB/s +BenchmarkProtoTypeProtoMarshal-8 5000000 395 ns/op 207.07 MB/s +PASS +ok github.com/gogo/protobuf/test 159.241s diff --git a/vendor/github.com/gogo/protobuf/test/mixbench/marshaler.txt b/vendor/github.com/gogo/protobuf/test/mixbench/marshaler.txt new file mode 100644 index 000000000..e9674c43e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mixbench/marshaler.txt @@ -0,0 +1,73 @@ +goos: darwin +goarch: amd64 +pkg: github.com/gogo/protobuf/test/combos/both +BenchmarkNidOptNativeProtoMarshal-8 5000000 240 ns/op 955.07 MB/s +BenchmarkNinOptNativeProtoMarshal-8 5000000 277 ns/op 752.54 MB/s +BenchmarkNidRepNativeProtoMarshal-8 1000000 1074 ns/op 762.27 MB/s +BenchmarkNinRepNativeProtoMarshal-8 1000000 1065 ns/op 768.51 MB/s +BenchmarkNidRepPackedNativeProtoMarshal-8 1000000 1033 ns/op 361.05 MB/s +BenchmarkNinRepPackedNativeProtoMarshal-8 1000000 1018 ns/op 366.08 MB/s +BenchmarkNidOptStructProtoMarshal-8 1000000 1024 ns/op 825.83 MB/s +BenchmarkNinOptStructProtoMarshal-8 2000000 974 ns/op 785.66 MB/s +BenchmarkNidRepStructProtoMarshal-8 500000 2593 ns/op 683.64 MB/s +BenchmarkNinRepStructProtoMarshal-8 500000 2443 ns/op 725.73 MB/s +BenchmarkNidEmbeddedStructProtoMarshal-8 3000000 582 ns/op 829.86 MB/s +BenchmarkNinEmbeddedStructProtoMarshal-8 3000000 557 ns/op 821.40 MB/s +BenchmarkNidNestedStructProtoMarshal-8 200000 7862 ns/op 525.28 MB/s +BenchmarkNinNestedStructProtoMarshal-8 200000 6228 ns/op 624.58 MB/s +BenchmarkNidOptCustomProtoMarshal-8 20000000 95.1 ns/op 746.84 MB/s +BenchmarkCustomDashProtoMarshal-8 20000000 92.5 ns/op 886.08 MB/s +BenchmarkNinOptCustomProtoMarshal-8 20000000 96.2 ns/op 696.51 MB/s +BenchmarkNidRepCustomProtoMarshal-8 5000000 258 ns/op 703.59 MB/s +BenchmarkNinRepCustomProtoMarshal-8 5000000 267 ns/op 679.91 MB/s +BenchmarkNinOptNativeUnionProtoMarshal-8 20000000 68.8 ns/op 232.44 MB/s +BenchmarkNinOptStructUnionProtoMarshal-8 10000000 137 ns/op 457.92 MB/s +BenchmarkNinEmbeddedStructUnionProtoMarshal-8 5000000 259 ns/op 573.18 MB/s +BenchmarkNinNestedStructUnionProtoMarshal-8 10000000 212 ns/op 366.72 MB/s +BenchmarkTreeProtoMarshal-8 10000000 154 ns/op 666.39 MB/s +BenchmarkOrBranchProtoMarshal-8 5000000 353 ns/op 692.18 MB/s +BenchmarkAndBranchProtoMarshal-8 5000000 348 ns/op 703.45 MB/s +BenchmarkLeafProtoMarshal-8 20000000 118 ns/op 820.16 MB/s +BenchmarkDeepTreeProtoMarshal-8 5000000 251 ns/op 576.84 MB/s +BenchmarkADeepBranchProtoMarshal-8 5000000 308 ns/op 594.07 MB/s +BenchmarkAndDeepBranchProtoMarshal-8 2000000 604 ns/op 549.21 MB/s +BenchmarkDeepLeafProtoMarshal-8 10000000 213 ns/op 654.76 MB/s +BenchmarkNilProtoMarshal-8 30000000 50.1 ns/op 698.93 MB/s +BenchmarkNidOptEnumProtoMarshal-8 20000000 61.7 ns/op 599.27 MB/s +BenchmarkNinOptEnumProtoMarshal-8 20000000 77.8 ns/op 527.05 MB/s +BenchmarkNidRepEnumProtoMarshal-8 10000000 186 ns/op 316.64 MB/s +BenchmarkNinRepEnumProtoMarshal-8 10000000 183 ns/op 321.59 MB/s +BenchmarkNinOptEnumDefaultProtoMarshal-8 20000000 77.9 ns/op 526.44 MB/s +BenchmarkAnotherNinOptEnumProtoMarshal-8 20000000 78.9 ns/op 519.95 MB/s +BenchmarkAnotherNinOptEnumDefaultProtoMarshal-8 20000000 78.6 ns/op 521.58 MB/s +BenchmarkTimerProtoMarshal-8 20000000 103 ns/op 1011.39 MB/s +BenchmarkMyExtendableProtoMarshal-8 3000000 515 ns/op 157.02 MB/s +BenchmarkOtherExtenableProtoMarshal-8 2000000 1000 ns/op 157.91 MB/s +BenchmarkNestedDefinitionProtoMarshal-8 5000000 285 ns/op 811.76 MB/s +BenchmarkNestedDefinition_NestedMessageProtoMarshal-8 10000000 142 ns/op 837.36 MB/s +BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal-8 20000000 93.3 ns/op 878.69 MB/s +BenchmarkNestedScopeProtoMarshal-8 5000000 260 ns/op 854.95 MB/s +BenchmarkNinOptNativeDefaultProtoMarshal-8 5000000 277 ns/op 752.14 MB/s +BenchmarkCustomContainerProtoMarshal-8 10000000 141 ns/op 772.49 MB/s +BenchmarkCustomNameNidOptNativeProtoMarshal-8 5000000 242 ns/op 947.27 MB/s +BenchmarkCustomNameNinOptNativeProtoMarshal-8 5000000 276 ns/op 754.67 MB/s +BenchmarkCustomNameNinRepNativeProtoMarshal-8 1000000 1043 ns/op 785.18 MB/s +BenchmarkCustomNameNinStructProtoMarshal-8 1000000 1294 ns/op 740.75 MB/s +BenchmarkCustomNameCustomTypeProtoMarshal-8 5000000 298 ns/op 715.82 MB/s +BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal-8 5000000 255 ns/op 583.23 MB/s +BenchmarkCustomNameEnumProtoMarshal-8 20000000 102 ns/op 441.00 MB/s +BenchmarkNoExtensionsMapProtoMarshal-8 20000000 118 ns/op 684.15 MB/s +BenchmarkUnrecognizedProtoMarshal-8 20000000 66.4 ns/op 677.96 MB/s +BenchmarkUnrecognizedWithInnerProtoMarshal-8 10000000 168 ns/op 557.06 MB/s +BenchmarkUnrecognizedWithInner_InnerProtoMarshal-8 30000000 43.4 ns/op 115.08 MB/s +BenchmarkUnrecognizedWithEmbedProtoMarshal-8 10000000 126 ns/op 704.09 MB/s +BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal-8 30000000 43.7 ns/op 114.32 MB/s +BenchmarkNodeProtoMarshal-8 10000000 121 ns/op 833.02 MB/s +BenchmarkNonByteCustomTypeProtoMarshal-8 10000000 123 ns/op 641.79 MB/s +BenchmarkNidOptNonByteCustomTypeProtoMarshal-8 10000000 130 ns/op 633.95 MB/s +BenchmarkNinOptNonByteCustomTypeProtoMarshal-8 10000000 124 ns/op 636.74 MB/s +BenchmarkNidRepNonByteCustomTypeProtoMarshal-8 5000000 387 ns/op 592.85 MB/s +BenchmarkNinRepNonByteCustomTypeProtoMarshal-8 5000000 390 ns/op 589.05 MB/s +BenchmarkProtoTypeProtoMarshal-8 20000000 94.1 ns/op 871.54 MB/s +PASS +ok github.com/gogo/protobuf/test/combos/both 139.443s diff --git a/vendor/github.com/gogo/protobuf/test/mixbench/oldmarshaler.txt b/vendor/github.com/gogo/protobuf/test/mixbench/oldmarshaler.txt new file mode 100644 index 000000000..a0cd56a7b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mixbench/oldmarshaler.txt @@ -0,0 +1,73 @@ +goos: darwin +goarch: amd64 +pkg: github.com/gogo/protobuf/test/combos/both +BenchmarkNidOptNativeProtoMarshal-8 5000000 255 ns/op 898.51 MB/s +BenchmarkNinOptNativeProtoMarshal-8 5000000 292 ns/op 714.19 MB/s +BenchmarkNidRepNativeProtoMarshal-8 1000000 1215 ns/op 673.78 MB/s +BenchmarkNinRepNativeProtoMarshal-8 1000000 1129 ns/op 724.87 MB/s +BenchmarkNidRepPackedNativeProtoMarshal-8 1000000 1070 ns/op 348.30 MB/s +BenchmarkNinRepPackedNativeProtoMarshal-8 1000000 1126 ns/op 331.05 MB/s +BenchmarkNidOptStructProtoMarshal-8 1000000 1090 ns/op 775.47 MB/s +BenchmarkNinOptStructProtoMarshal-8 1000000 1077 ns/op 711.02 MB/s +BenchmarkNidRepStructProtoMarshal-8 500000 2826 ns/op 627.36 MB/s +BenchmarkNinRepStructProtoMarshal-8 500000 2585 ns/op 685.69 MB/s +BenchmarkNidEmbeddedStructProtoMarshal-8 2000000 661 ns/op 729.67 MB/s +BenchmarkNinEmbeddedStructProtoMarshal-8 2000000 612 ns/op 747.51 MB/s +BenchmarkNidNestedStructProtoMarshal-8 200000 8685 ns/op 475.50 MB/s +BenchmarkNinNestedStructProtoMarshal-8 200000 7278 ns/op 534.43 MB/s +BenchmarkNidOptCustomProtoMarshal-8 20000000 99.3 ns/op 715.23 MB/s +BenchmarkCustomDashProtoMarshal-8 20000000 94.7 ns/op 866.23 MB/s +BenchmarkNinOptCustomProtoMarshal-8 20000000 100 ns/op 663.46 MB/s +BenchmarkNidRepCustomProtoMarshal-8 5000000 275 ns/op 661.13 MB/s +BenchmarkNinRepCustomProtoMarshal-8 5000000 274 ns/op 662.53 MB/s +BenchmarkNinOptNativeUnionProtoMarshal-8 20000000 74.9 ns/op 213.63 MB/s +BenchmarkNinOptStructUnionProtoMarshal-8 10000000 150 ns/op 417.38 MB/s +BenchmarkNinEmbeddedStructUnionProtoMarshal-8 5000000 273 ns/op 545.04 MB/s +BenchmarkNinNestedStructUnionProtoMarshal-8 10000000 239 ns/op 325.57 MB/s +BenchmarkTreeProtoMarshal-8 10000000 164 ns/op 627.52 MB/s +BenchmarkOrBranchProtoMarshal-8 5000000 384 ns/op 637.63 MB/s +BenchmarkAndBranchProtoMarshal-8 5000000 386 ns/op 633.51 MB/s +BenchmarkLeafProtoMarshal-8 10000000 123 ns/op 786.11 MB/s +BenchmarkDeepTreeProtoMarshal-8 5000000 258 ns/op 561.33 MB/s +BenchmarkADeepBranchProtoMarshal-8 5000000 327 ns/op 559.19 MB/s +BenchmarkAndDeepBranchProtoMarshal-8 2000000 650 ns/op 510.35 MB/s +BenchmarkDeepLeafProtoMarshal-8 10000000 219 ns/op 638.44 MB/s +BenchmarkNilProtoMarshal-8 30000000 51.0 ns/op 686.29 MB/s +BenchmarkNidOptEnumProtoMarshal-8 20000000 62.5 ns/op 591.74 MB/s +BenchmarkNinOptEnumProtoMarshal-8 20000000 78.7 ns/op 521.09 MB/s +BenchmarkNidRepEnumProtoMarshal-8 10000000 186 ns/op 316.21 MB/s +BenchmarkNinRepEnumProtoMarshal-8 10000000 179 ns/op 328.20 MB/s +BenchmarkNinOptEnumDefaultProtoMarshal-8 20000000 81.4 ns/op 503.41 MB/s +BenchmarkAnotherNinOptEnumProtoMarshal-8 20000000 85.7 ns/op 478.31 MB/s +BenchmarkAnotherNinOptEnumDefaultProtoMarshal-8 20000000 83.6 ns/op 490.49 MB/s +BenchmarkTimerProtoMarshal-8 20000000 110 ns/op 952.31 MB/s +BenchmarkMyExtendableProtoMarshal-8 3000000 508 ns/op 159.38 MB/s +BenchmarkOtherExtenableProtoMarshal-8 1000000 1090 ns/op 144.83 MB/s +BenchmarkNestedDefinitionProtoMarshal-8 5000000 302 ns/op 765.71 MB/s +BenchmarkNestedDefinition_NestedMessageProtoMarshal-8 10000000 147 ns/op 805.16 MB/s +BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal-8 20000000 94.4 ns/op 868.83 MB/s +BenchmarkNestedScopeProtoMarshal-8 5000000 275 ns/op 809.77 MB/s +BenchmarkNinOptNativeDefaultProtoMarshal-8 5000000 283 ns/op 737.12 MB/s +BenchmarkCustomContainerProtoMarshal-8 10000000 142 ns/op 765.46 MB/s +BenchmarkCustomNameNidOptNativeProtoMarshal-8 5000000 255 ns/op 900.47 MB/s +BenchmarkCustomNameNinOptNativeProtoMarshal-8 5000000 284 ns/op 735.53 MB/s +BenchmarkCustomNameNinRepNativeProtoMarshal-8 1000000 1056 ns/op 775.01 MB/s +BenchmarkCustomNameNinStructProtoMarshal-8 1000000 1471 ns/op 651.55 MB/s +BenchmarkCustomNameCustomTypeProtoMarshal-8 5000000 304 ns/op 703.60 MB/s +BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal-8 5000000 268 ns/op 554.35 MB/s +BenchmarkCustomNameEnumProtoMarshal-8 20000000 103 ns/op 435.03 MB/s +BenchmarkNoExtensionsMapProtoMarshal-8 20000000 115 ns/op 702.08 MB/s +BenchmarkUnrecognizedProtoMarshal-8 20000000 67.0 ns/op 671.64 MB/s +BenchmarkUnrecognizedWithInnerProtoMarshal-8 10000000 175 ns/op 536.86 MB/s +BenchmarkUnrecognizedWithInner_InnerProtoMarshal-8 30000000 47.6 ns/op 105.15 MB/s +BenchmarkUnrecognizedWithEmbedProtoMarshal-8 10000000 134 ns/op 659.48 MB/s +BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal-8 30000000 47.1 ns/op 106.07 MB/s +BenchmarkNodeProtoMarshal-8 10000000 125 ns/op 804.09 MB/s +BenchmarkNonByteCustomTypeProtoMarshal-8 10000000 131 ns/op 602.08 MB/s +BenchmarkNidOptNonByteCustomTypeProtoMarshal-8 10000000 133 ns/op 623.02 MB/s +BenchmarkNinOptNonByteCustomTypeProtoMarshal-8 10000000 134 ns/op 588.03 MB/s +BenchmarkNidRepNonByteCustomTypeProtoMarshal-8 3000000 402 ns/op 570.96 MB/s +BenchmarkNinRepNonByteCustomTypeProtoMarshal-8 3000000 394 ns/op 583.29 MB/s +BenchmarkProtoTypeProtoMarshal-8 20000000 94.3 ns/op 869.83 MB/s +PASS +ok github.com/gogo/protobuf/test/combos/both 140.308s diff --git a/vendor/github.com/gogo/protobuf/test/mixbench/oldunmarshaler.txt b/vendor/github.com/gogo/protobuf/test/mixbench/oldunmarshaler.txt new file mode 100644 index 000000000..9ad44dce5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mixbench/oldunmarshaler.txt @@ -0,0 +1,73 @@ +goos: darwin +goarch: amd64 +pkg: github.com/gogo/protobuf/test/combos/both +BenchmarkNidOptNativeProtoUnmarshal-8 3000000 441 ns/op 520.98 MB/s +BenchmarkNinOptNativeProtoUnmarshal-8 2000000 638 ns/op 327.14 MB/s +BenchmarkNidRepNativeProtoUnmarshal-8 500000 2830 ns/op 289.36 MB/s +BenchmarkNinRepNativeProtoUnmarshal-8 500000 2859 ns/op 286.37 MB/s +BenchmarkNidRepPackedNativeProtoUnmarshal-8 1000000 1813 ns/op 205.67 MB/s +BenchmarkNinRepPackedNativeProtoUnmarshal-8 1000000 1793 ns/op 207.96 MB/s +BenchmarkNidOptStructProtoUnmarshal-8 1000000 1876 ns/op 450.92 MB/s +BenchmarkNinOptStructProtoUnmarshal-8 1000000 1992 ns/op 384.38 MB/s +BenchmarkNidRepStructProtoUnmarshal-8 300000 5234 ns/op 338.72 MB/s +BenchmarkNinRepStructProtoUnmarshal-8 300000 5097 ns/op 347.79 MB/s +BenchmarkNidEmbeddedStructProtoUnmarshal-8 1000000 1077 ns/op 448.06 MB/s +BenchmarkNinEmbeddedStructProtoUnmarshal-8 1000000 1088 ns/op 420.67 MB/s +BenchmarkNidNestedStructProtoUnmarshal-8 100000 11850 ns/op 348.52 MB/s +BenchmarkNinNestedStructProtoUnmarshal-8 200000 11242 ns/op 346.02 MB/s +BenchmarkNidOptCustomProtoUnmarshal-8 10000000 196 ns/op 361.07 MB/s +BenchmarkCustomDashProtoUnmarshal-8 10000000 228 ns/op 359.22 MB/s +BenchmarkNinOptCustomProtoUnmarshal-8 5000000 243 ns/op 275.11 MB/s +BenchmarkNidRepCustomProtoUnmarshal-8 2000000 811 ns/op 224.17 MB/s +BenchmarkNinRepCustomProtoUnmarshal-8 2000000 812 ns/op 223.94 MB/s +BenchmarkNinOptNativeUnionProtoUnmarshal-8 20000000 78.0 ns/op 205.18 MB/s +BenchmarkNinOptStructUnionProtoUnmarshal-8 10000000 198 ns/op 318.01 MB/s +BenchmarkNinEmbeddedStructUnionProtoUnmarshal-8 3000000 465 ns/op 320.00 MB/s +BenchmarkNinNestedStructUnionProtoUnmarshal-8 5000000 329 ns/op 236.72 MB/s +BenchmarkTreeProtoUnmarshal-8 5000000 301 ns/op 341.52 MB/s +BenchmarkOrBranchProtoUnmarshal-8 2000000 788 ns/op 310.72 MB/s +BenchmarkAndBranchProtoUnmarshal-8 2000000 809 ns/op 302.61 MB/s +BenchmarkLeafProtoUnmarshal-8 10000000 226 ns/op 428.13 MB/s +BenchmarkDeepTreeProtoUnmarshal-8 3000000 564 ns/op 256.96 MB/s +BenchmarkADeepBranchProtoUnmarshal-8 2000000 746 ns/op 244.98 MB/s +BenchmarkAndDeepBranchProtoUnmarshal-8 1000000 1262 ns/op 263.05 MB/s +BenchmarkDeepLeafProtoUnmarshal-8 3000000 474 ns/op 294.99 MB/s +BenchmarkNilProtoUnmarshal-8 10000000 139 ns/op 251.16 MB/s +BenchmarkNidOptEnumProtoUnmarshal-8 10000000 145 ns/op 254.37 MB/s +BenchmarkNinOptEnumProtoUnmarshal-8 10000000 204 ns/op 200.49 MB/s +BenchmarkNidRepEnumProtoUnmarshal-8 3000000 453 ns/op 130.01 MB/s +BenchmarkNinRepEnumProtoUnmarshal-8 3000000 444 ns/op 132.65 MB/s +BenchmarkNinOptEnumDefaultProtoUnmarshal-8 10000000 199 ns/op 205.24 MB/s +BenchmarkAnotherNinOptEnumProtoUnmarshal-8 10000000 208 ns/op 196.86 MB/s +BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal-8 10000000 201 ns/op 203.57 MB/s +BenchmarkTimerProtoUnmarshal-8 10000000 235 ns/op 444.92 MB/s +BenchmarkMyExtendableProtoUnmarshal-8 2000000 649 ns/op 124.62 MB/s +BenchmarkOtherExtenableProtoUnmarshal-8 1000000 1348 ns/op 117.15 MB/s +BenchmarkNestedDefinitionProtoUnmarshal-8 2000000 932 ns/op 248.80 MB/s +BenchmarkNestedDefinition_NestedMessageProtoUnmarshal-8 3000000 431 ns/op 275.75 MB/s +BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal-8 10000000 219 ns/op 373.17 MB/s +BenchmarkNestedScopeProtoUnmarshal-8 2000000 907 ns/op 245.63 MB/s +BenchmarkNinOptNativeDefaultProtoUnmarshal-8 2000000 663 ns/op 315.15 MB/s +BenchmarkCustomContainerProtoUnmarshal-8 5000000 350 ns/op 310.78 MB/s +BenchmarkCustomNameNidOptNativeProtoUnmarshal-8 3000000 483 ns/op 475.48 MB/s +BenchmarkCustomNameNinOptNativeProtoUnmarshal-8 2000000 689 ns/op 303.07 MB/s +BenchmarkCustomNameNinRepNativeProtoUnmarshal-8 500000 2845 ns/op 287.79 MB/s +BenchmarkCustomNameNinStructProtoUnmarshal-8 500000 2730 ns/op 351.21 MB/s +BenchmarkCustomNameCustomTypeProtoUnmarshal-8 2000000 934 ns/op 229.08 MB/s +BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal-8 3000000 475 ns/op 313.63 MB/s +BenchmarkCustomNameEnumProtoUnmarshal-8 5000000 271 ns/op 166.03 MB/s +BenchmarkNoExtensionsMapProtoUnmarshal-8 5000000 344 ns/op 234.94 MB/s +BenchmarkUnrecognizedProtoUnmarshal-8 20000000 86.3 ns/op 521.53 MB/s +BenchmarkUnrecognizedWithInnerProtoUnmarshal-8 3000000 411 ns/op 228.40 MB/s +BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal-8 30000000 43.9 ns/op 113.80 MB/s +BenchmarkUnrecognizedWithEmbedProtoUnmarshal-8 5000000 261 ns/op 340.84 MB/s +BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal-8 30000000 43.9 ns/op 113.92 MB/s +BenchmarkNodeProtoUnmarshal-8 5000000 312 ns/op 323.19 MB/s +BenchmarkNonByteCustomTypeProtoUnmarshal-8 5000000 306 ns/op 257.52 MB/s +BenchmarkNidOptNonByteCustomTypeProtoUnmarshal-8 5000000 292 ns/op 283.61 MB/s +BenchmarkNinOptNonByteCustomTypeProtoUnmarshal-8 5000000 307 ns/op 257.00 MB/s +BenchmarkNidRepNonByteCustomTypeProtoUnmarshal-8 1000000 1057 ns/op 217.49 MB/s +BenchmarkNinRepNonByteCustomTypeProtoUnmarshal-8 1000000 1043 ns/op 220.36 MB/s +BenchmarkProtoTypeProtoUnmarshal-8 10000000 221 ns/op 369.64 MB/s +PASS +ok github.com/gogo/protobuf/test/combos/both 152.331s diff --git a/vendor/github.com/gogo/protobuf/test/mixbench/unmarshal.txt b/vendor/github.com/gogo/protobuf/test/mixbench/unmarshal.txt new file mode 100644 index 000000000..00f352180 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mixbench/unmarshal.txt @@ -0,0 +1,73 @@ +goos: darwin +goarch: amd64 +pkg: github.com/gogo/protobuf/test +BenchmarkNidOptNativeProtoUnmarshal-8 2000000 742 ns/op 309.65 MB/s +BenchmarkNinOptNativeProtoUnmarshal-8 2000000 892 ns/op 234.06 MB/s +BenchmarkNidRepNativeProtoUnmarshal-8 300000 3762 ns/op 217.69 MB/s +BenchmarkNinRepNativeProtoUnmarshal-8 500000 3750 ns/op 218.40 MB/s +BenchmarkNidRepPackedNativeProtoUnmarshal-8 1000000 2423 ns/op 153.89 MB/s +BenchmarkNinRepPackedNativeProtoUnmarshal-8 1000000 2356 ns/op 158.30 MB/s +BenchmarkNidOptStructProtoUnmarshal-8 500000 2595 ns/op 326.01 MB/s +BenchmarkNinOptStructProtoUnmarshal-8 500000 2679 ns/op 285.91 MB/s +BenchmarkNidRepStructProtoUnmarshal-8 200000 7477 ns/op 237.11 MB/s +BenchmarkNinRepStructProtoUnmarshal-8 200000 6672 ns/op 265.70 MB/s +BenchmarkNidEmbeddedStructProtoUnmarshal-8 1000000 1634 ns/op 295.59 MB/s +BenchmarkNinEmbeddedStructProtoUnmarshal-8 1000000 1655 ns/op 276.61 MB/s +BenchmarkNidNestedStructProtoUnmarshal-8 100000 16742 ns/op 246.68 MB/s +BenchmarkNinNestedStructProtoUnmarshal-8 100000 14573 ns/op 266.92 MB/s +BenchmarkNidOptCustomProtoUnmarshal-8 2000000 840 ns/op 84.48 MB/s +BenchmarkCustomDashProtoUnmarshal-8 3000000 573 ns/op 142.95 MB/s +BenchmarkNinOptCustomProtoUnmarshal-8 2000000 668 ns/op 100.17 MB/s +BenchmarkNidRepCustomProtoUnmarshal-8 500000 3945 ns/op 46.12 MB/s +BenchmarkNinRepCustomProtoUnmarshal-8 500000 3939 ns/op 46.20 MB/s +BenchmarkNinOptNativeUnionProtoUnmarshal-8 5000000 248 ns/op 64.30 MB/s +BenchmarkNinOptStructUnionProtoUnmarshal-8 3000000 432 ns/op 145.55 MB/s +BenchmarkNinEmbeddedStructUnionProtoUnmarshal-8 2000000 767 ns/op 194.07 MB/s +BenchmarkNinNestedStructUnionProtoUnmarshal-8 2000000 636 ns/op 122.51 MB/s +BenchmarkTreeProtoUnmarshal-8 2000000 649 ns/op 158.50 MB/s +BenchmarkOrBranchProtoUnmarshal-8 1000000 1312 ns/op 186.65 MB/s +BenchmarkAndBranchProtoUnmarshal-8 1000000 1301 ns/op 188.29 MB/s +BenchmarkLeafProtoUnmarshal-8 3000000 490 ns/op 197.62 MB/s +BenchmarkDeepTreeProtoUnmarshal-8 1000000 1059 ns/op 136.83 MB/s +BenchmarkADeepBranchProtoUnmarshal-8 1000000 1253 ns/op 145.96 MB/s +BenchmarkAndDeepBranchProtoUnmarshal-8 1000000 2041 ns/op 162.62 MB/s +BenchmarkDeepLeafProtoUnmarshal-8 2000000 894 ns/op 156.51 MB/s +BenchmarkNilProtoUnmarshal-8 5000000 362 ns/op 96.48 MB/s +BenchmarkNidOptEnumProtoUnmarshal-8 5000000 382 ns/op 96.84 MB/s +BenchmarkNinOptEnumProtoUnmarshal-8 3000000 448 ns/op 91.37 MB/s +BenchmarkNidRepEnumProtoUnmarshal-8 2000000 796 ns/op 74.10 MB/s +BenchmarkNinRepEnumProtoUnmarshal-8 2000000 799 ns/op 73.79 MB/s +BenchmarkNinOptEnumDefaultProtoUnmarshal-8 3000000 452 ns/op 90.59 MB/s +BenchmarkAnotherNinOptEnumProtoUnmarshal-8 3000000 446 ns/op 91.74 MB/s +BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal-8 3000000 451 ns/op 90.73 MB/s +BenchmarkTimerProtoUnmarshal-8 3000000 528 ns/op 198.78 MB/s +BenchmarkMyExtendableProtoUnmarshal-8 1000000 1295 ns/op 62.54 MB/s +BenchmarkOtherExtenableProtoUnmarshal-8 1000000 2420 ns/op 65.28 MB/s +BenchmarkNestedDefinitionProtoUnmarshal-8 1000000 1501 ns/op 154.48 MB/s +BenchmarkNestedDefinition_NestedMessageProtoUnmarshal-8 2000000 861 ns/op 138.09 MB/s +BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal-8 3000000 490 ns/op 167.26 MB/s +BenchmarkNestedScopeProtoUnmarshal-8 1000000 1469 ns/op 151.78 MB/s +BenchmarkNinOptNativeDefaultProtoUnmarshal-8 2000000 933 ns/op 223.93 MB/s +BenchmarkCustomContainerProtoUnmarshal-8 1000000 1141 ns/op 95.48 MB/s +BenchmarkCustomNameNidOptNativeProtoUnmarshal-8 2000000 771 ns/op 298.02 MB/s +BenchmarkCustomNameNinOptNativeProtoUnmarshal-8 2000000 938 ns/op 222.66 MB/s +BenchmarkCustomNameNinRepNativeProtoUnmarshal-8 500000 3820 ns/op 214.37 MB/s +BenchmarkCustomNameNinStructProtoUnmarshal-8 500000 3613 ns/op 265.38 MB/s +BenchmarkCustomNameCustomTypeProtoUnmarshal-8 300000 4301 ns/op 49.76 MB/s +BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal-8 2000000 772 ns/op 192.86 MB/s +BenchmarkCustomNameEnumProtoUnmarshal-8 3000000 569 ns/op 79.04 MB/s +BenchmarkNoExtensionsMapProtoUnmarshal-8 2000000 850 ns/op 95.19 MB/s +BenchmarkUnrecognizedProtoUnmarshal-8 5000000 269 ns/op 166.93 MB/s +BenchmarkUnrecognizedWithInnerProtoUnmarshal-8 2000000 858 ns/op 109.44 MB/s +BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal-8 10000000 221 ns/op 22.56 MB/s +BenchmarkUnrecognizedWithEmbedProtoUnmarshal-8 2000000 605 ns/op 146.89 MB/s +BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal-8 10000000 222 ns/op 22.45 MB/s +BenchmarkNodeProtoUnmarshal-8 2000000 664 ns/op 152.10 MB/s +BenchmarkNonByteCustomTypeProtoUnmarshal-8 2000000 880 ns/op 89.67 MB/s +BenchmarkNidOptNonByteCustomTypeProtoUnmarshal-8 2000000 953 ns/op 87.07 MB/s +BenchmarkNinOptNonByteCustomTypeProtoUnmarshal-8 2000000 893 ns/op 88.46 MB/s +BenchmarkNidRepNonByteCustomTypeProtoUnmarshal-8 500000 3460 ns/op 66.47 MB/s +BenchmarkNinRepNonByteCustomTypeProtoUnmarshal-8 500000 3452 ns/op 66.63 MB/s +BenchmarkProtoTypeProtoUnmarshal-8 3000000 510 ns/op 160.64 MB/s +PASS +ok github.com/gogo/protobuf/test 160.971s diff --git a/vendor/github.com/gogo/protobuf/test/mixbench/unmarshaler.txt b/vendor/github.com/gogo/protobuf/test/mixbench/unmarshaler.txt new file mode 100644 index 000000000..69ca32d62 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mixbench/unmarshaler.txt @@ -0,0 +1,73 @@ +goos: darwin +goarch: amd64 +pkg: github.com/gogo/protobuf/test/combos/both +BenchmarkNidOptNativeProtoUnmarshal-8 3000000 437 ns/op 525.94 MB/s +BenchmarkNinOptNativeProtoUnmarshal-8 2000000 648 ns/op 322.37 MB/s +BenchmarkNidRepNativeProtoUnmarshal-8 500000 2864 ns/op 285.90 MB/s +BenchmarkNinRepNativeProtoUnmarshal-8 500000 2820 ns/op 290.41 MB/s +BenchmarkNidRepPackedNativeProtoUnmarshal-8 1000000 1801 ns/op 207.09 MB/s +BenchmarkNinRepPackedNativeProtoUnmarshal-8 1000000 1813 ns/op 205.70 MB/s +BenchmarkNidOptStructProtoUnmarshal-8 1000000 1839 ns/op 459.88 MB/s +BenchmarkNinOptStructProtoUnmarshal-8 1000000 2018 ns/op 379.50 MB/s +BenchmarkNidRepStructProtoUnmarshal-8 300000 5149 ns/op 344.29 MB/s +BenchmarkNinRepStructProtoUnmarshal-8 300000 5018 ns/op 353.26 MB/s +BenchmarkNidEmbeddedStructProtoUnmarshal-8 1000000 1065 ns/op 453.50 MB/s +BenchmarkNinEmbeddedStructProtoUnmarshal-8 1000000 1079 ns/op 424.46 MB/s +BenchmarkNidNestedStructProtoUnmarshal-8 100000 11788 ns/op 350.34 MB/s +BenchmarkNinNestedStructProtoUnmarshal-8 200000 11113 ns/op 350.03 MB/s +BenchmarkNidOptCustomProtoUnmarshal-8 10000000 199 ns/op 355.77 MB/s +BenchmarkCustomDashProtoUnmarshal-8 10000000 228 ns/op 359.40 MB/s +BenchmarkNinOptCustomProtoUnmarshal-8 5000000 246 ns/op 271.79 MB/s +BenchmarkNidRepCustomProtoUnmarshal-8 2000000 801 ns/op 227.02 MB/s +BenchmarkNinRepCustomProtoUnmarshal-8 2000000 810 ns/op 224.64 MB/s +BenchmarkNinOptNativeUnionProtoUnmarshal-8 20000000 80.9 ns/op 197.77 MB/s +BenchmarkNinOptStructUnionProtoUnmarshal-8 10000000 201 ns/op 311.92 MB/s +BenchmarkNinEmbeddedStructUnionProtoUnmarshal-8 3000000 460 ns/op 323.74 MB/s +BenchmarkNinNestedStructUnionProtoUnmarshal-8 5000000 318 ns/op 245.16 MB/s +BenchmarkTreeProtoUnmarshal-8 5000000 308 ns/op 333.66 MB/s +BenchmarkOrBranchProtoUnmarshal-8 2000000 801 ns/op 305.77 MB/s +BenchmarkAndBranchProtoUnmarshal-8 2000000 786 ns/op 311.55 MB/s +BenchmarkLeafProtoUnmarshal-8 10000000 221 ns/op 437.02 MB/s +BenchmarkDeepTreeProtoUnmarshal-8 3000000 564 ns/op 256.77 MB/s +BenchmarkADeepBranchProtoUnmarshal-8 2000000 734 ns/op 249.07 MB/s +BenchmarkAndDeepBranchProtoUnmarshal-8 1000000 1259 ns/op 263.56 MB/s +BenchmarkDeepLeafProtoUnmarshal-8 3000000 473 ns/op 295.86 MB/s +BenchmarkNilProtoUnmarshal-8 10000000 138 ns/op 252.17 MB/s +BenchmarkNidOptEnumProtoUnmarshal-8 10000000 143 ns/op 258.45 MB/s +BenchmarkNinOptEnumProtoUnmarshal-8 10000000 203 ns/op 201.75 MB/s +BenchmarkNidRepEnumProtoUnmarshal-8 3000000 461 ns/op 127.85 MB/s +BenchmarkNinRepEnumProtoUnmarshal-8 3000000 445 ns/op 132.38 MB/s +BenchmarkNinOptEnumDefaultProtoUnmarshal-8 10000000 199 ns/op 205.22 MB/s +BenchmarkAnotherNinOptEnumProtoUnmarshal-8 10000000 199 ns/op 205.47 MB/s +BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal-8 10000000 203 ns/op 201.78 MB/s +BenchmarkTimerProtoUnmarshal-8 10000000 224 ns/op 468.19 MB/s +BenchmarkMyExtendableProtoUnmarshal-8 2000000 653 ns/op 123.97 MB/s +BenchmarkOtherExtenableProtoUnmarshal-8 1000000 1349 ns/op 117.08 MB/s +BenchmarkNestedDefinitionProtoUnmarshal-8 2000000 936 ns/op 247.70 MB/s +BenchmarkNestedDefinition_NestedMessageProtoUnmarshal-8 3000000 421 ns/op 282.31 MB/s +BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal-8 10000000 224 ns/op 364.55 MB/s +BenchmarkNestedScopeProtoUnmarshal-8 2000000 918 ns/op 242.79 MB/s +BenchmarkNinOptNativeDefaultProtoUnmarshal-8 2000000 663 ns/op 315.02 MB/s +BenchmarkCustomContainerProtoUnmarshal-8 5000000 360 ns/op 302.50 MB/s +BenchmarkCustomNameNidOptNativeProtoUnmarshal-8 3000000 455 ns/op 504.73 MB/s +BenchmarkCustomNameNinOptNativeProtoUnmarshal-8 2000000 667 ns/op 313.20 MB/s +BenchmarkCustomNameNinRepNativeProtoUnmarshal-8 500000 2908 ns/op 281.59 MB/s +BenchmarkCustomNameNinStructProtoUnmarshal-8 500000 2668 ns/op 359.44 MB/s +BenchmarkCustomNameCustomTypeProtoUnmarshal-8 2000000 926 ns/op 231.07 MB/s +BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal-8 3000000 471 ns/op 316.30 MB/s +BenchmarkCustomNameEnumProtoUnmarshal-8 5000000 267 ns/op 168.48 MB/s +BenchmarkNoExtensionsMapProtoUnmarshal-8 5000000 341 ns/op 237.47 MB/s +BenchmarkUnrecognizedProtoUnmarshal-8 20000000 85.0 ns/op 529.53 MB/s +BenchmarkUnrecognizedWithInnerProtoUnmarshal-8 3000000 408 ns/op 230.38 MB/s +BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal-8 30000000 45.5 ns/op 109.87 MB/s +BenchmarkUnrecognizedWithEmbedProtoUnmarshal-8 5000000 261 ns/op 340.78 MB/s +BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal-8 30000000 43.2 ns/op 115.70 MB/s +BenchmarkNodeProtoUnmarshal-8 5000000 310 ns/op 325.74 MB/s +BenchmarkNonByteCustomTypeProtoUnmarshal-8 5000000 310 ns/op 254.37 MB/s +BenchmarkNidOptNonByteCustomTypeProtoUnmarshal-8 5000000 294 ns/op 281.53 MB/s +BenchmarkNinOptNonByteCustomTypeProtoUnmarshal-8 5000000 308 ns/op 256.49 MB/s +BenchmarkNidRepNonByteCustomTypeProtoUnmarshal-8 1000000 1040 ns/op 221.03 MB/s +BenchmarkNinRepNonByteCustomTypeProtoUnmarshal-8 1000000 1039 ns/op 221.20 MB/s +BenchmarkProtoTypeProtoUnmarshal-8 10000000 220 ns/op 372.18 MB/s +PASS +ok github.com/gogo/protobuf/test/combos/both 153.117s diff --git a/vendor/github.com/gogo/protobuf/test/mixbench/unsafe_marshaler.txt b/vendor/github.com/gogo/protobuf/test/mixbench/unsafe_marshaler.txt new file mode 100644 index 000000000..424080a83 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mixbench/unsafe_marshaler.txt @@ -0,0 +1,73 @@ +goos: darwin +goarch: amd64 +pkg: github.com/gogo/protobuf/test/combos/unsafeboth +BenchmarkNidOptNativeProtoMarshal-8 10000000 235 ns/op 976.65 MB/s +BenchmarkNinOptNativeProtoMarshal-8 5000000 265 ns/op 788.37 MB/s +BenchmarkNidRepNativeProtoMarshal-8 1000000 1011 ns/op 810.06 MB/s +BenchmarkNinRepNativeProtoMarshal-8 1000000 1004 ns/op 815.63 MB/s +BenchmarkNidRepPackedNativeProtoMarshal-8 2000000 958 ns/op 389.24 MB/s +BenchmarkNinRepPackedNativeProtoMarshal-8 2000000 968 ns/op 385.16 MB/s +BenchmarkNidOptStructProtoMarshal-8 2000000 979 ns/op 863.95 MB/s +BenchmarkNinOptStructProtoMarshal-8 2000000 946 ns/op 808.91 MB/s +BenchmarkNidRepStructProtoMarshal-8 500000 2495 ns/op 710.38 MB/s +BenchmarkNinRepStructProtoMarshal-8 500000 2265 ns/op 782.62 MB/s +BenchmarkNidEmbeddedStructProtoMarshal-8 3000000 561 ns/op 860.52 MB/s +BenchmarkNinEmbeddedStructProtoMarshal-8 3000000 538 ns/op 849.81 MB/s +BenchmarkNidNestedStructProtoMarshal-8 200000 7308 ns/op 565.10 MB/s +BenchmarkNinNestedStructProtoMarshal-8 200000 6016 ns/op 646.61 MB/s +BenchmarkNidOptCustomProtoMarshal-8 20000000 97.3 ns/op 729.87 MB/s +BenchmarkCustomDashProtoMarshal-8 20000000 92.5 ns/op 886.05 MB/s +BenchmarkNinOptCustomProtoMarshal-8 20000000 97.4 ns/op 687.82 MB/s +BenchmarkNidRepCustomProtoMarshal-8 5000000 258 ns/op 705.25 MB/s +BenchmarkNinRepCustomProtoMarshal-8 5000000 258 ns/op 704.21 MB/s +BenchmarkNinOptNativeUnionProtoMarshal-8 20000000 69.0 ns/op 231.80 MB/s +BenchmarkNinOptStructUnionProtoMarshal-8 10000000 138 ns/op 453.62 MB/s +BenchmarkNinEmbeddedStructUnionProtoMarshal-8 5000000 251 ns/op 591.44 MB/s +BenchmarkNinNestedStructUnionProtoMarshal-8 10000000 208 ns/op 373.73 MB/s +BenchmarkTreeProtoMarshal-8 10000000 154 ns/op 664.72 MB/s +BenchmarkOrBranchProtoMarshal-8 5000000 343 ns/op 712.72 MB/s +BenchmarkAndBranchProtoMarshal-8 5000000 344 ns/op 710.24 MB/s +BenchmarkLeafProtoMarshal-8 20000000 117 ns/op 824.42 MB/s +BenchmarkDeepTreeProtoMarshal-8 5000000 247 ns/op 585.23 MB/s +BenchmarkADeepBranchProtoMarshal-8 5000000 301 ns/op 606.06 MB/s +BenchmarkAndDeepBranchProtoMarshal-8 3000000 595 ns/op 557.97 MB/s +BenchmarkDeepLeafProtoMarshal-8 10000000 206 ns/op 676.59 MB/s +BenchmarkNilProtoMarshal-8 30000000 51.2 ns/op 682.93 MB/s +BenchmarkNidOptEnumProtoMarshal-8 20000000 62.0 ns/op 596.44 MB/s +BenchmarkNinOptEnumProtoMarshal-8 20000000 78.6 ns/op 521.93 MB/s +BenchmarkNidRepEnumProtoMarshal-8 10000000 184 ns/op 320.25 MB/s +BenchmarkNinRepEnumProtoMarshal-8 10000000 184 ns/op 319.78 MB/s +BenchmarkNinOptEnumDefaultProtoMarshal-8 20000000 78.1 ns/op 525.05 MB/s +BenchmarkAnotherNinOptEnumProtoMarshal-8 20000000 77.6 ns/op 528.30 MB/s +BenchmarkAnotherNinOptEnumDefaultProtoMarshal-8 20000000 79.1 ns/op 518.59 MB/s +BenchmarkTimerProtoMarshal-8 20000000 103 ns/op 1011.16 MB/s +BenchmarkMyExtendableProtoMarshal-8 3000000 465 ns/op 174.04 MB/s +BenchmarkOtherExtenableProtoMarshal-8 2000000 1028 ns/op 153.66 MB/s +BenchmarkNestedDefinitionProtoMarshal-8 5000000 283 ns/op 818.76 MB/s +BenchmarkNestedDefinition_NestedMessageProtoMarshal-8 10000000 141 ns/op 838.57 MB/s +BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal-8 20000000 94.1 ns/op 871.31 MB/s +BenchmarkNestedScopeProtoMarshal-8 5000000 259 ns/op 857.99 MB/s +BenchmarkNinOptNativeDefaultProtoMarshal-8 5000000 272 ns/op 768.10 MB/s +BenchmarkCustomContainerProtoMarshal-8 10000000 141 ns/op 769.72 MB/s +BenchmarkCustomNameNidOptNativeProtoMarshal-8 10000000 237 ns/op 968.65 MB/s +BenchmarkCustomNameNinOptNativeProtoMarshal-8 5000000 290 ns/op 719.58 MB/s +BenchmarkCustomNameNinRepNativeProtoMarshal-8 1000000 1006 ns/op 813.87 MB/s +BenchmarkCustomNameNinStructProtoMarshal-8 1000000 1296 ns/op 739.54 MB/s +BenchmarkCustomNameCustomTypeProtoMarshal-8 5000000 300 ns/op 712.96 MB/s +BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal-8 5000000 247 ns/op 601.55 MB/s +BenchmarkCustomNameEnumProtoMarshal-8 20000000 107 ns/op 417.49 MB/s +BenchmarkNoExtensionsMapProtoMarshal-8 20000000 116 ns/op 695.54 MB/s +BenchmarkUnrecognizedProtoMarshal-8 20000000 66.8 ns/op 673.51 MB/s +BenchmarkUnrecognizedWithInnerProtoMarshal-8 10000000 171 ns/op 548.84 MB/s +BenchmarkUnrecognizedWithInner_InnerProtoMarshal-8 30000000 46.7 ns/op 107.10 MB/s +BenchmarkUnrecognizedWithEmbedProtoMarshal-8 10000000 126 ns/op 700.99 MB/s +BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal-8 30000000 43.8 ns/op 114.23 MB/s +BenchmarkNodeProtoMarshal-8 10000000 119 ns/op 844.78 MB/s +BenchmarkNonByteCustomTypeProtoMarshal-8 10000000 123 ns/op 639.73 MB/s +BenchmarkNidOptNonByteCustomTypeProtoMarshal-8 10000000 126 ns/op 657.86 MB/s +BenchmarkNinOptNonByteCustomTypeProtoMarshal-8 10000000 123 ns/op 641.02 MB/s +BenchmarkNidRepNonByteCustomTypeProtoMarshal-8 5000000 386 ns/op 595.49 MB/s +BenchmarkNinRepNonByteCustomTypeProtoMarshal-8 5000000 382 ns/op 601.83 MB/s +BenchmarkProtoTypeProtoMarshal-8 20000000 94.3 ns/op 869.89 MB/s +PASS +ok github.com/gogo/protobuf/test/combos/unsafeboth 147.234s diff --git a/vendor/github.com/gogo/protobuf/test/mixbench/unsafe_unmarshaler.txt b/vendor/github.com/gogo/protobuf/test/mixbench/unsafe_unmarshaler.txt new file mode 100644 index 000000000..751009e50 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/mixbench/unsafe_unmarshaler.txt @@ -0,0 +1,73 @@ +goos: darwin +goarch: amd64 +pkg: github.com/gogo/protobuf/test/combos/unsafeboth +BenchmarkNidOptNativeProtoUnmarshal-8 3000000 425 ns/op 540.14 MB/s +BenchmarkNinOptNativeProtoUnmarshal-8 2000000 612 ns/op 341.01 MB/s +BenchmarkNidRepNativeProtoUnmarshal-8 500000 2884 ns/op 283.98 MB/s +BenchmarkNinRepNativeProtoUnmarshal-8 500000 2809 ns/op 291.49 MB/s +BenchmarkNidRepPackedNativeProtoUnmarshal-8 1000000 1806 ns/op 206.53 MB/s +BenchmarkNinRepPackedNativeProtoUnmarshal-8 1000000 1769 ns/op 210.78 MB/s +BenchmarkNidOptStructProtoUnmarshal-8 1000000 1820 ns/op 464.71 MB/s +BenchmarkNinOptStructProtoUnmarshal-8 1000000 1932 ns/op 396.30 MB/s +BenchmarkNidRepStructProtoUnmarshal-8 300000 5074 ns/op 349.42 MB/s +BenchmarkNinRepStructProtoUnmarshal-8 300000 4891 ns/op 362.49 MB/s +BenchmarkNidEmbeddedStructProtoUnmarshal-8 1000000 1034 ns/op 466.75 MB/s +BenchmarkNinEmbeddedStructProtoUnmarshal-8 1000000 1061 ns/op 431.37 MB/s +BenchmarkNidNestedStructProtoUnmarshal-8 200000 11579 ns/op 356.66 MB/s +BenchmarkNinNestedStructProtoUnmarshal-8 200000 10862 ns/op 358.12 MB/s +BenchmarkNidOptCustomProtoUnmarshal-8 10000000 202 ns/op 350.76 MB/s +BenchmarkCustomDashProtoUnmarshal-8 10000000 228 ns/op 358.70 MB/s +BenchmarkNinOptCustomProtoUnmarshal-8 5000000 245 ns/op 272.41 MB/s +BenchmarkNidRepCustomProtoUnmarshal-8 2000000 810 ns/op 224.66 MB/s +BenchmarkNinRepCustomProtoUnmarshal-8 2000000 812 ns/op 224.11 MB/s +BenchmarkNinOptNativeUnionProtoUnmarshal-8 20000000 73.2 ns/op 218.58 MB/s +BenchmarkNinOptStructUnionProtoUnmarshal-8 10000000 194 ns/op 323.57 MB/s +BenchmarkNinEmbeddedStructUnionProtoUnmarshal-8 3000000 459 ns/op 324.42 MB/s +BenchmarkNinNestedStructUnionProtoUnmarshal-8 5000000 315 ns/op 247.13 MB/s +BenchmarkTreeProtoUnmarshal-8 5000000 307 ns/op 335.37 MB/s +BenchmarkOrBranchProtoUnmarshal-8 2000000 782 ns/op 313.01 MB/s +BenchmarkAndBranchProtoUnmarshal-8 2000000 776 ns/op 315.38 MB/s +BenchmarkLeafProtoUnmarshal-8 10000000 218 ns/op 443.71 MB/s +BenchmarkDeepTreeProtoUnmarshal-8 3000000 565 ns/op 256.61 MB/s +BenchmarkADeepBranchProtoUnmarshal-8 2000000 734 ns/op 249.27 MB/s +BenchmarkAndDeepBranchProtoUnmarshal-8 1000000 1263 ns/op 262.80 MB/s +BenchmarkDeepLeafProtoUnmarshal-8 3000000 476 ns/op 294.03 MB/s +BenchmarkNilProtoUnmarshal-8 10000000 137 ns/op 254.01 MB/s +BenchmarkNidOptEnumProtoUnmarshal-8 10000000 141 ns/op 260.58 MB/s +BenchmarkNinOptEnumProtoUnmarshal-8 10000000 200 ns/op 204.30 MB/s +BenchmarkNidRepEnumProtoUnmarshal-8 3000000 449 ns/op 131.35 MB/s +BenchmarkNinRepEnumProtoUnmarshal-8 3000000 459 ns/op 128.30 MB/s +BenchmarkNinOptEnumDefaultProtoUnmarshal-8 10000000 203 ns/op 201.59 MB/s +BenchmarkAnotherNinOptEnumProtoUnmarshal-8 10000000 201 ns/op 203.75 MB/s +BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal-8 10000000 205 ns/op 199.16 MB/s +BenchmarkTimerProtoUnmarshal-8 10000000 223 ns/op 469.62 MB/s +BenchmarkMyExtendableProtoUnmarshal-8 2000000 654 ns/op 123.72 MB/s +BenchmarkOtherExtenableProtoUnmarshal-8 1000000 1353 ns/op 116.72 MB/s +BenchmarkNestedDefinitionProtoUnmarshal-8 2000000 919 ns/op 252.43 MB/s +BenchmarkNestedDefinition_NestedMessageProtoUnmarshal-8 3000000 427 ns/op 278.50 MB/s +BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal-8 10000000 216 ns/op 378.01 MB/s +BenchmarkNestedScopeProtoUnmarshal-8 2000000 893 ns/op 249.72 MB/s +BenchmarkNinOptNativeDefaultProtoUnmarshal-8 2000000 671 ns/op 311.36 MB/s +BenchmarkCustomContainerProtoUnmarshal-8 5000000 351 ns/op 310.13 MB/s +BenchmarkCustomNameNidOptNativeProtoUnmarshal-8 3000000 446 ns/op 514.92 MB/s +BenchmarkCustomNameNinOptNativeProtoUnmarshal-8 2000000 652 ns/op 320.55 MB/s +BenchmarkCustomNameNinRepNativeProtoUnmarshal-8 500000 2841 ns/op 288.23 MB/s +BenchmarkCustomNameNinStructProtoUnmarshal-8 500000 2639 ns/op 363.30 MB/s +BenchmarkCustomNameCustomTypeProtoUnmarshal-8 2000000 919 ns/op 232.73 MB/s +BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal-8 3000000 461 ns/op 322.60 MB/s +BenchmarkCustomNameEnumProtoUnmarshal-8 5000000 270 ns/op 166.20 MB/s +BenchmarkNoExtensionsMapProtoUnmarshal-8 5000000 353 ns/op 228.99 MB/s +BenchmarkUnrecognizedProtoUnmarshal-8 20000000 85.7 ns/op 525.21 MB/s +BenchmarkUnrecognizedWithInnerProtoUnmarshal-8 3000000 415 ns/op 226.40 MB/s +BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal-8 30000000 42.6 ns/op 117.47 MB/s +BenchmarkUnrecognizedWithEmbedProtoUnmarshal-8 5000000 259 ns/op 343.44 MB/s +BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal-8 30000000 43.2 ns/op 115.84 MB/s +BenchmarkNodeProtoUnmarshal-8 5000000 306 ns/op 329.03 MB/s +BenchmarkNonByteCustomTypeProtoUnmarshal-8 5000000 308 ns/op 256.11 MB/s +BenchmarkNidOptNonByteCustomTypeProtoUnmarshal-8 5000000 292 ns/op 284.10 MB/s +BenchmarkNinOptNonByteCustomTypeProtoUnmarshal-8 5000000 306 ns/op 258.01 MB/s +BenchmarkNidRepNonByteCustomTypeProtoUnmarshal-8 1000000 1049 ns/op 219.19 MB/s +BenchmarkNinRepNonByteCustomTypeProtoUnmarshal-8 1000000 1046 ns/op 219.68 MB/s +BenchmarkProtoTypeProtoUnmarshal-8 10000000 221 ns/op 370.99 MB/s +PASS +ok github.com/gogo/protobuf/test/combos/unsafeboth 151.728s diff --git a/vendor/github.com/gogo/protobuf/test/moredefaults/Makefile b/vendor/github.com/gogo/protobuf/test/moredefaults/Makefile new file mode 100644 index 000000000..0d4f698dd --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/moredefaults/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. md.proto) diff --git a/vendor/github.com/gogo/protobuf/test/moredefaults/md.proto b/vendor/github.com/gogo/protobuf/test/moredefaults/md.proto new file mode 100644 index 000000000..7f5b2190c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/moredefaults/md.proto @@ -0,0 +1,53 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package moredefaults; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/gogo/protobuf/test/example/example.proto"; + +option (gogoproto.goproto_getters_all) = true; +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; + +message MoreDefaultsB { + optional string Field1 = 1; +} + +message MoreDefaultsA { + optional int64 Field1 = 1 [default=1234]; + optional int64 Field2 = 2 [(gogoproto.nullable) = false]; + optional MoreDefaultsB B1 = 3; + optional MoreDefaultsB B2 = 4 [(gogoproto.nullable) = false]; + optional test.A A1 = 5; + optional test.A A2 = 6 [(gogoproto.nullable) = false]; +} + diff --git a/vendor/github.com/gogo/protobuf/test/moredefaults/md_test.go b/vendor/github.com/gogo/protobuf/test/moredefaults/md_test.go new file mode 100644 index 000000000..45a8eac56 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/moredefaults/md_test.go @@ -0,0 +1,61 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package moredefaults + +import ( + "testing" + + test "github.com/gogo/protobuf/test/example" +) + +func TestDefaults(t *testing.T) { + b := MoreDefaultsB{} + aa := test.A{} + a := &MoreDefaultsA{} + b2 := a.GetB2() + a2 := a.GetA2() + if a.GetField1() != 1234 { + t.Fatalf("Field1 wrong") + } + if a.GetField2() != 0 { + t.Fatalf("Field2 wrong") + } + if a.GetB1() != nil { + t.Fatalf("B1 wrong") + } + if b2.GetField1() != b.GetField1() { + t.Fatalf("B2 wrong") + } + if a.GetA1() != nil { + t.Fatalf("A1 wrong") + } + if a2.GetNumber() != aa.GetNumber() { + t.Fatalf("A2 wrong") + } +} diff --git a/vendor/github.com/gogo/protobuf/test/moredefaults/mdpb_test.go b/vendor/github.com/gogo/protobuf/test/moredefaults/mdpb_test.go new file mode 100644 index 000000000..4ca8445d7 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/moredefaults/mdpb_test.go @@ -0,0 +1,185 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: md.proto + +/* +Package moredefaults is a generated protocol buffer package. + +It is generated from these files: + md.proto + +It has these top-level messages: + MoreDefaultsB + MoreDefaultsA +*/ +package moredefaults + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/example" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMoreDefaultsBProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsB(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MoreDefaultsB{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMoreDefaultsAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsA(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MoreDefaultsA{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMoreDefaultsBJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsB(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MoreDefaultsB{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMoreDefaultsAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsA(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MoreDefaultsA{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMoreDefaultsBProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsB(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MoreDefaultsB{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMoreDefaultsBProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsB(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MoreDefaultsB{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMoreDefaultsAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsA(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MoreDefaultsA{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMoreDefaultsAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMoreDefaultsA(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MoreDefaultsA{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/nopackage/Makefile b/vendor/github.com/gogo/protobuf/test/nopackage/Makefile new file mode 100644 index 000000000..0aa49e25b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/nopackage/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc-min-version --version="3.0.0" --proto_path=../../../../../:../../protobuf/:. --gogofast_out=. nopackage.proto) diff --git a/vendor/github.com/gogo/protobuf/test/nopackage/nopackage.proto b/vendor/github.com/gogo/protobuf/test/nopackage/nopackage.proto new file mode 100644 index 000000000..cfaed76ba --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/nopackage/nopackage.proto @@ -0,0 +1,33 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +message M { + map f = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/nopackage/nopackage_test.go b/vendor/github.com/gogo/protobuf/test/nopackage/nopackage_test.go new file mode 100644 index 000000000..3318a29cd --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/nopackage/nopackage_test.go @@ -0,0 +1,38 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package nopackage + +import ( + "testing" +) + +func TestNoPackage(t *testing.T) { + //should compile + _ = (&M{}).Marshal +} diff --git a/vendor/github.com/gogo/protobuf/test/oneof/Makefile b/vendor/github.com/gogo/protobuf/test/oneof/Makefile new file mode 100644 index 000000000..d9c0c4c36 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/Makefile @@ -0,0 +1,32 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-combo + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-gen-combo --version="2.6.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. one.proto diff --git a/vendor/github.com/gogo/protobuf/test/oneof/combos/both/one.proto b/vendor/github.com/gogo/protobuf/test/oneof/combos/both/one.proto new file mode 100644 index 000000000..a72dde02f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/combos/both/one.proto @@ -0,0 +1,103 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + optional string sub = 1; +} + +message AllTypesOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + +message TwoOneofs { + oneof one { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + } + + oneof two { + string Field34 = 34; + bytes Field35 = 35; + Subby sub_message2 = 36; + } +} + +message CustomOneof { + oneof custom { + string Stringy = 34; + bytes CustomType = 35 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + uint64 CastType = 36 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + int64 CustomName = 37 [(gogoproto.customname) = "MyCustomName"]; + } +} diff --git a/vendor/github.com/gogo/protobuf/test/oneof/combos/both/onepb_test.go b/vendor/github.com/gogo/protobuf/test/oneof/combos/both/onepb_test.go new file mode 100644 index 000000000..82925d0cf --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/combos/both/onepb_test.go @@ -0,0 +1,741 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/both/one.proto + +It has these top-level messages: + Subby + AllTypesOneOf + TwoOneofs + CustomOneof +*/ +package one + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllTypesOneOfMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTwoOneofsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomOneofMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllTypesOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTwoOneofsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomOneofJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllTypesOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllTypesOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &TwoOneofs{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := proto.CompactTextString(p) + msg := &TwoOneofs{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomOneof{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomOneof{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllTypesOneOfVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTwoOneofsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomOneofVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllTypesOneOfGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTwoOneofsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomOneofGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAllTypesOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestTwoOneofsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCustomOneofSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllTypesOneOfStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTwoOneofsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomOneofStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/one.proto b/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/one.proto new file mode 100644 index 000000000..d9a8204e2 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/one.proto @@ -0,0 +1,103 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + optional string sub = 1; +} + +message AllTypesOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + +message TwoOneofs { + oneof one { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + } + + oneof two { + string Field34 = 34; + bytes Field35 = 35; + Subby sub_message2 = 36; + } +} + +message CustomOneof { + oneof custom { + string Stringy = 34; + bytes CustomType = 35 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + uint64 CastType = 36 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + int64 CustomName = 37 [(gogoproto.customname) = "MyCustomName"]; + } +} diff --git a/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/onepb_test.go b/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/onepb_test.go new file mode 100644 index 000000000..4e8b9e773 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/combos/marshaler/onepb_test.go @@ -0,0 +1,741 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/one.proto + +It has these top-level messages: + Subby + AllTypesOneOf + TwoOneofs + CustomOneof +*/ +package one + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllTypesOneOfMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTwoOneofsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomOneofMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllTypesOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTwoOneofsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomOneofJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllTypesOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllTypesOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &TwoOneofs{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := proto.CompactTextString(p) + msg := &TwoOneofs{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomOneof{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomOneof{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllTypesOneOfVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTwoOneofsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomOneofVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllTypesOneOfGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTwoOneofsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomOneofGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAllTypesOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestTwoOneofsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCustomOneofSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllTypesOneOfStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTwoOneofsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomOneofStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/one.proto b/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/one.proto new file mode 100644 index 000000000..66d4b4496 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/one.proto @@ -0,0 +1,103 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + optional string sub = 1; +} + +message AllTypesOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + +message TwoOneofs { + oneof one { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + } + + oneof two { + string Field34 = 34; + bytes Field35 = 35; + Subby sub_message2 = 36; + } +} + +message CustomOneof { + oneof custom { + string Stringy = 34; + bytes CustomType = 35 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + uint64 CastType = 36 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + int64 CustomName = 37 [(gogoproto.customname) = "MyCustomName"]; + } +} diff --git a/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/onepb_test.go b/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/onepb_test.go new file mode 100644 index 000000000..14b202521 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/combos/neither/onepb_test.go @@ -0,0 +1,629 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/neither/one.proto + +It has these top-level messages: + Subby + AllTypesOneOf + TwoOneofs + CustomOneof +*/ +package one + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllTypesOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTwoOneofsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomOneofProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllTypesOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTwoOneofsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomOneofJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllTypesOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllTypesOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &TwoOneofs{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := proto.CompactTextString(p) + msg := &TwoOneofs{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomOneof{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomOneof{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllTypesOneOfVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTwoOneofsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomOneofVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllTypesOneOfGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTwoOneofsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomOneofGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAllTypesOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestTwoOneofsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCustomOneofSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllTypesOneOfStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTwoOneofsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomOneofStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/one.proto b/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/one.proto new file mode 100644 index 000000000..633f01224 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/one.proto @@ -0,0 +1,103 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + optional string sub = 1; +} + +message AllTypesOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + +message TwoOneofs { + oneof one { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + } + + oneof two { + string Field34 = 34; + bytes Field35 = 35; + Subby sub_message2 = 36; + } +} + +message CustomOneof { + oneof custom { + string Stringy = 34; + bytes CustomType = 35 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + uint64 CastType = 36 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + int64 CustomName = 37 [(gogoproto.customname) = "MyCustomName"]; + } +} diff --git a/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/onepb_test.go b/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/onepb_test.go new file mode 100644 index 000000000..fa343d463 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/combos/unmarshaler/onepb_test.go @@ -0,0 +1,629 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/one.proto + +It has these top-level messages: + Subby + AllTypesOneOf + TwoOneofs + CustomOneof +*/ +package one + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllTypesOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestTwoOneofsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCustomOneofProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllTypesOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllTypesOneOf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTwoOneofsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &TwoOneofs{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomOneofJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomOneof{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllTypesOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllTypesOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllTypesOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &TwoOneofs{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTwoOneofsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + dAtA := proto.CompactTextString(p) + msg := &TwoOneofs{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomOneof{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomOneofProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomOneof{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllTypesOneOfVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllTypesOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTwoOneofsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &TwoOneofs{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomOneofVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomOneof{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllTypesOneOfGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTwoOneofsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomOneofGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAllTypesOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllTypesOneOf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestTwoOneofsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTwoOneofs(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCustomOneofSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomOneof(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllTypesOneOfStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllTypesOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTwoOneofsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTwoOneofs(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomOneofStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomOneof(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/oneof/one.proto b/vendor/github.com/gogo/protobuf/test/oneof/one.proto new file mode 100644 index 000000000..66d4b4496 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof/one.proto @@ -0,0 +1,103 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + optional string sub = 1; +} + +message AllTypesOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + +message TwoOneofs { + oneof one { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + } + + oneof two { + string Field34 = 34; + bytes Field35 = 35; + Subby sub_message2 = 36; + } +} + +message CustomOneof { + oneof custom { + string Stringy = 34; + bytes CustomType = 35 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + uint64 CastType = 36 [(gogoproto.casttype) = "github.com/gogo/protobuf/test/casttype.MyUint64Type"]; + int64 CustomName = 37 [(gogoproto.customname) = "MyCustomName"]; + } +} diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/Makefile b/vendor/github.com/gogo/protobuf/test/oneof3/Makefile new file mode 100644 index 000000000..b42ef60ee --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/Makefile @@ -0,0 +1,32 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-combo + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-gen-combo --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. one.proto diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/one.proto b/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/one.proto new file mode 100644 index 000000000..51876e235 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/one.proto @@ -0,0 +1,82 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + string sub = 1; +} + +message SampleOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + + diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/onepb_test.go b/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/onepb_test.go new file mode 100644 index 000000000..663f7c9d8 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/combos/both/onepb_test.go @@ -0,0 +1,387 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/both/one.proto + +It has these top-level messages: + Subby + SampleOneOf +*/ +package one + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSampleOneOfMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSampleOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &SampleOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &SampleOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSampleOneOfVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSampleOneOfGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSampleOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSampleOneOfStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/one.proto b/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/one.proto new file mode 100644 index 000000000..32ea8482c --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/one.proto @@ -0,0 +1,82 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + string sub = 1; +} + +message SampleOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + + diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/onepb_test.go b/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/onepb_test.go new file mode 100644 index 000000000..db9c7982f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/combos/marshaler/onepb_test.go @@ -0,0 +1,387 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/one.proto + +It has these top-level messages: + Subby + SampleOneOf +*/ +package one + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSampleOneOfMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSampleOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &SampleOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &SampleOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSampleOneOfVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSampleOneOfGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSampleOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSampleOneOfStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/one.proto b/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/one.proto new file mode 100644 index 000000000..2eca9a07f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/one.proto @@ -0,0 +1,82 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + string sub = 1; +} + +message SampleOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + + diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/onepb_test.go b/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/onepb_test.go new file mode 100644 index 000000000..b846e9222 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/combos/neither/onepb_test.go @@ -0,0 +1,331 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/neither/one.proto + +It has these top-level messages: + Subby + SampleOneOf +*/ +package one + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSampleOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSampleOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &SampleOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &SampleOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSampleOneOfVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSampleOneOfGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSampleOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSampleOneOfStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/one.proto b/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/one.proto new file mode 100644 index 000000000..d8b550438 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/one.proto @@ -0,0 +1,82 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + string sub = 1; +} + +message SampleOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + + diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/onepb_test.go b/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/onepb_test.go new file mode 100644 index 000000000..876e08161 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/onepb_test.go @@ -0,0 +1,331 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/one.proto + +/* +Package one is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/one.proto + +It has these top-level messages: + Subby + SampleOneOf +*/ +package one + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSubbyProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSampleOneOfProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSubbyJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Subby{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSampleOneOfJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SampleOneOf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubbyProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubbyProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Subby{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &SampleOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSampleOneOfProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &SampleOneOf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneDescription(t *testing.T) { + OneDescription() +} +func TestSubbyVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Subby{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSampleOneOfVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &SampleOneOf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubbyGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSampleOneOfGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubbySize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSubby(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSampleOneOfSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSampleOneOf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestSubbyStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSubby(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSampleOneOfStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSampleOneOf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/oneof3/one.proto b/vendor/github.com/gogo/protobuf/test/oneof3/one.proto new file mode 100644 index 000000000..2eca9a07f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneof3/one.proto @@ -0,0 +1,82 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package one; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Subby { + string sub = 1; +} + +message SampleOneOf { + oneof test_oneof { + double Field1 = 1; + float Field2 = 2; + int32 Field3 = 3; + int64 Field4 = 4; + uint32 Field5 = 5; + uint64 Field6 = 6; + sint32 Field7 = 7; + sint64 Field8 = 8; + fixed32 Field9 = 9; + sfixed32 Field10 = 10; + fixed64 Field11 = 11; + sfixed64 Field12 = 12; + bool Field13 = 13; + string Field14 = 14; + bytes Field15 = 15; + Subby sub_message = 16; + } +} + + diff --git a/vendor/github.com/gogo/protobuf/test/oneofembed/Makefile b/vendor/github.com/gogo/protobuf/test/oneofembed/Makefile new file mode 100644 index 000000000..c68629fad --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneofembed/Makefile @@ -0,0 +1,31 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + protoc-min-version --proto_path=../../../../../:../../protobuf/:. --version="3.0.0" --gogo_out=. *.proto + diff --git a/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembed.proto b/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembed.proto new file mode 100644 index 000000000..8c1ee3835 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembed.proto @@ -0,0 +1,46 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package proto; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.testgen_all) = true; + +message Foo { + Bar bar = 1 [(gogoproto.embed) = true]; +} + +message Bar { + oneof pick { + bool a = 11; + bool b = 12; + } +} diff --git a/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembedpb_test.go b/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembedpb_test.go new file mode 100644 index 000000000..e5af25de8 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/oneofembed/oneofembedpb_test.go @@ -0,0 +1,184 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: oneofembed.proto + +/* +Package proto is a generated protocol buffer package. + +It is generated from these files: + oneofembed.proto + +It has these top-level messages: + Foo + Bar +*/ +package proto + +import testing "testing" +import rand "math/rand" +import time "time" +import proto1 "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto1.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestFooProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFoo(popr, false) + dAtA, err := proto1.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Foo{} + if err := proto1.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto1.Unmarshal(littlefuzz, msg) + } +} + +func TestBarProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBar(popr, false) + dAtA, err := proto1.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Bar{} + if err := proto1.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto1.Unmarshal(littlefuzz, msg) + } +} + +func TestFooJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Foo{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBarJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBar(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Bar{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFooProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + dAtA := proto1.MarshalTextString(p) + msg := &Foo{} + if err := proto1.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFooProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFoo(popr, true) + dAtA := proto1.CompactTextString(p) + msg := &Foo{} + if err := proto1.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBarProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBar(popr, true) + dAtA := proto1.MarshalTextString(p) + msg := &Bar{} + if err := proto1.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBarProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBar(popr, true) + dAtA := proto1.CompactTextString(p) + msg := &Bar{} + if err := proto1.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/packed/Makefile b/vendor/github.com/gogo/protobuf/test/packed/Makefile new file mode 100644 index 000000000..9d195810f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/packed/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. packed.proto) diff --git a/vendor/github.com/gogo/protobuf/test/packed/packed.proto b/vendor/github.com/gogo/protobuf/test/packed/packed.proto new file mode 100644 index 000000000..f37df6e3d --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/packed/packed.proto @@ -0,0 +1,103 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package packed; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.populate_all) = true; + +message NinRepNative { + option (gogoproto.unmarshaler) = true; + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated int32 Field3 = 3; + repeated int64 Field4 = 4; + repeated uint32 Field5 = 5; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated sint64 Field8 = 8; + repeated fixed32 Field9 = 9; + repeated sfixed32 Field10 = 10; + repeated fixed64 Field11 = 11; + repeated sfixed64 Field12 = 12; + repeated bool Field13 = 13; +} + +message NinRepPackedNative { + option (gogoproto.unmarshaler) = true; + repeated double Field1 = 1 [packed = true]; + repeated float Field2 = 2 [packed = true]; + repeated int32 Field3 = 3 [packed = true]; + repeated int64 Field4 = 4 [packed = true]; + repeated uint32 Field5 = 5 [packed = true]; + repeated uint64 Field6 = 6 [packed = true]; + repeated sint32 Field7 = 7 [packed = true]; + repeated sint64 Field8 = 8 [packed = true]; + repeated fixed32 Field9 = 9 [packed = true]; + repeated sfixed32 Field10 = 10 [packed = true]; + repeated fixed64 Field11 = 11 [packed = true]; + repeated sfixed64 Field12 = 12 [packed = true]; + repeated bool Field13 = 13 [packed = true]; +} + +message NinRepNativeUnsafe { + option (gogoproto.unsafe_unmarshaler) = true; + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated int32 Field3 = 3; + repeated int64 Field4 = 4; + repeated uint32 Field5 = 5; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated sint64 Field8 = 8; + repeated fixed32 Field9 = 9; + repeated sfixed32 Field10 = 10; + repeated fixed64 Field11 = 11; + repeated sfixed64 Field12 = 12; + repeated bool Field13 = 13; +} + +message NinRepPackedNativeUnsafe { + option (gogoproto.unsafe_unmarshaler) = true; + repeated double Field1 = 1 [packed = true]; + repeated float Field2 = 2 [packed = true]; + repeated int32 Field3 = 3 [packed = true]; + repeated int64 Field4 = 4 [packed = true]; + repeated uint32 Field5 = 5 [packed = true]; + repeated uint64 Field6 = 6 [packed = true]; + repeated sint32 Field7 = 7 [packed = true]; + repeated sint64 Field8 = 8 [packed = true]; + repeated fixed32 Field9 = 9 [packed = true]; + repeated sfixed32 Field10 = 10 [packed = true]; + repeated fixed64 Field11 = 11 [packed = true]; + repeated sfixed64 Field12 = 12 [packed = true]; + repeated bool Field13 = 13 [packed = true]; +} diff --git a/vendor/github.com/gogo/protobuf/test/packed/packed_test.go b/vendor/github.com/gogo/protobuf/test/packed/packed_test.go new file mode 100644 index 000000000..ea66292c6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/packed/packed_test.go @@ -0,0 +1,328 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package packed + +import ( + "bytes" + "fmt" + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + "time" + "unsafe" +) + +/* +https://github.com/gogo/protobuf/issues/detail?id=21 +https://developers.google.com/protocol-buffers/docs/proto#options +In 2.3.0 and later, this change is safe, as parsers for packable fields will always accept both formats, +*/ +func TestSafeIssue21(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + msg1 := NewPopulatedNinRepNative(popr, true) + data1, err := proto.Marshal(msg1) + if err != nil { + t.Fatal(err) + } + packedmsg := &NinRepPackedNative{} + err = proto.Unmarshal(data1, packedmsg) + if err != nil { + t.Fatal(err) + } + if len(packedmsg.XXX_unrecognized) != 0 { + t.Fatalf("packed msg unmarshaled unrecognized fields, even though there aren't any") + } + if err := VerboseEqual(msg1, packedmsg); err != nil { + t.Fatalf("%v", err) + } +} + +func TestUnsafeIssue21(t *testing.T) { + var bigendian uint32 = 0x01020304 + if *(*byte)(unsafe.Pointer(&bigendian)) == 1 { + t.Skip("unsafe does not work on big endian architectures") + } + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + msg1 := NewPopulatedNinRepNativeUnsafe(popr, true) + data1, err := proto.Marshal(msg1) + if err != nil { + t.Fatal(err) + } + packedmsg := &NinRepPackedNativeUnsafe{} + err = proto.Unmarshal(data1, packedmsg) + if err != nil { + t.Fatal(err) + } + if len(packedmsg.XXX_unrecognized) != 0 { + t.Fatalf("packed msg unmarshaled unrecognized fields, even though there aren't any") + } + if err := VerboseEqualUnsafe(msg1, packedmsg); err != nil { + t.Fatalf("%v", err) + } +} + +func VerboseEqual(this *NinRepNative, that *NinRepPackedNative) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } else if this == nil { + return fmt.Errorf("that != nil && this == nil") + } + + if len(this.Field1) != len(that.Field1) { + return fmt.Errorf("Field1 this(%v) Not Equal that(%v)", len(this.Field1), len(that.Field1)) + } + for i := range this.Field1 { + if this.Field1[i] != that.Field1[i] { + return fmt.Errorf("Field1 this[%v](%v) Not Equal that[%v](%v)", i, this.Field1[i], i, that.Field1[i]) + } + } + if len(this.Field2) != len(that.Field2) { + return fmt.Errorf("Field2 this(%v) Not Equal that(%v)", len(this.Field2), len(that.Field2)) + } + for i := range this.Field2 { + if this.Field2[i] != that.Field2[i] { + return fmt.Errorf("Field2 this[%v](%v) Not Equal that[%v](%v)", i, this.Field2[i], i, that.Field2[i]) + } + } + if len(this.Field3) != len(that.Field3) { + return fmt.Errorf("Field3 this(%v) Not Equal that(%v)", len(this.Field3), len(that.Field3)) + } + for i := range this.Field3 { + if this.Field3[i] != that.Field3[i] { + return fmt.Errorf("Field3 this[%v](%v) Not Equal that[%v](%v)", i, this.Field3[i], i, that.Field3[i]) + } + } + if len(this.Field4) != len(that.Field4) { + return fmt.Errorf("Field4 this(%v) Not Equal that(%v)", len(this.Field4), len(that.Field4)) + } + for i := range this.Field4 { + if this.Field4[i] != that.Field4[i] { + return fmt.Errorf("Field4 this[%v](%v) Not Equal that[%v](%v)", i, this.Field4[i], i, that.Field4[i]) + } + } + if len(this.Field5) != len(that.Field5) { + return fmt.Errorf("Field5 this(%v) Not Equal that(%v)", len(this.Field5), len(that.Field5)) + } + for i := range this.Field5 { + if this.Field5[i] != that.Field5[i] { + return fmt.Errorf("Field5 this[%v](%v) Not Equal that[%v](%v)", i, this.Field5[i], i, that.Field5[i]) + } + } + if len(this.Field6) != len(that.Field6) { + return fmt.Errorf("Field6 this(%v) Not Equal that(%v)", len(this.Field6), len(that.Field6)) + } + for i := range this.Field6 { + if this.Field6[i] != that.Field6[i] { + return fmt.Errorf("Field6 this[%v](%v) Not Equal that[%v](%v)", i, this.Field6[i], i, that.Field6[i]) + } + } + if len(this.Field7) != len(that.Field7) { + return fmt.Errorf("Field7 this(%v) Not Equal that(%v)", len(this.Field7), len(that.Field7)) + } + for i := range this.Field7 { + if this.Field7[i] != that.Field7[i] { + return fmt.Errorf("Field7 this[%v](%v) Not Equal that[%v](%v)", i, this.Field7[i], i, that.Field7[i]) + } + } + if len(this.Field8) != len(that.Field8) { + return fmt.Errorf("Field8 this(%v) Not Equal that(%v)", len(this.Field8), len(that.Field8)) + } + for i := range this.Field8 { + if this.Field8[i] != that.Field8[i] { + return fmt.Errorf("Field8 this[%v](%v) Not Equal that[%v](%v)", i, this.Field8[i], i, that.Field8[i]) + } + } + if len(this.Field9) != len(that.Field9) { + return fmt.Errorf("Field9 this(%v) Not Equal that(%v)", len(this.Field9), len(that.Field9)) + } + for i := range this.Field9 { + if this.Field9[i] != that.Field9[i] { + return fmt.Errorf("Field9 this[%v](%v) Not Equal that[%v](%v)", i, this.Field9[i], i, that.Field9[i]) + } + } + if len(this.Field10) != len(that.Field10) { + return fmt.Errorf("Field10 this(%v) Not Equal that(%v)", len(this.Field10), len(that.Field10)) + } + for i := range this.Field10 { + if this.Field10[i] != that.Field10[i] { + return fmt.Errorf("Field10 this[%v](%v) Not Equal that[%v](%v)", i, this.Field10[i], i, that.Field10[i]) + } + } + if len(this.Field11) != len(that.Field11) { + return fmt.Errorf("Field11 this(%v) Not Equal that(%v)", len(this.Field11), len(that.Field11)) + } + for i := range this.Field11 { + if this.Field11[i] != that.Field11[i] { + return fmt.Errorf("Field11 this[%v](%v) Not Equal that[%v](%v)", i, this.Field11[i], i, that.Field11[i]) + } + } + if len(this.Field12) != len(that.Field12) { + return fmt.Errorf("Field12 this(%v) Not Equal that(%v)", len(this.Field12), len(that.Field12)) + } + for i := range this.Field12 { + if this.Field12[i] != that.Field12[i] { + return fmt.Errorf("Field12 this[%v](%v) Not Equal that[%v](%v)", i, this.Field12[i], i, that.Field12[i]) + } + } + if len(this.Field13) != len(that.Field13) { + return fmt.Errorf("Field13 this(%v) Not Equal that(%v)", len(this.Field13), len(that.Field13)) + } + for i := range this.Field13 { + if this.Field13[i] != that.Field13[i] { + return fmt.Errorf("Field13 this[%v](%v) Not Equal that[%v](%v)", i, this.Field13[i], i, that.Field13[i]) + } + } + if !bytes.Equal(this.XXX_unrecognized, that.XXX_unrecognized) { + return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that.XXX_unrecognized) + } + return nil +} + +func VerboseEqualUnsafe(this *NinRepNativeUnsafe, that *NinRepPackedNativeUnsafe) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } else if this == nil { + return fmt.Errorf("that != nil && this == nil") + } + + if len(this.Field1) != len(that.Field1) { + return fmt.Errorf("Field1 this(%v) Not Equal that(%v)", len(this.Field1), len(that.Field1)) + } + for i := range this.Field1 { + if this.Field1[i] != that.Field1[i] { + return fmt.Errorf("Field1 this[%v](%v) Not Equal that[%v](%v)", i, this.Field1[i], i, that.Field1[i]) + } + } + if len(this.Field2) != len(that.Field2) { + return fmt.Errorf("Field2 this(%v) Not Equal that(%v)", len(this.Field2), len(that.Field2)) + } + for i := range this.Field2 { + if this.Field2[i] != that.Field2[i] { + return fmt.Errorf("Field2 this[%v](%v) Not Equal that[%v](%v)", i, this.Field2[i], i, that.Field2[i]) + } + } + if len(this.Field3) != len(that.Field3) { + return fmt.Errorf("Field3 this(%v) Not Equal that(%v)", len(this.Field3), len(that.Field3)) + } + for i := range this.Field3 { + if this.Field3[i] != that.Field3[i] { + return fmt.Errorf("Field3 this[%v](%v) Not Equal that[%v](%v)", i, this.Field3[i], i, that.Field3[i]) + } + } + if len(this.Field4) != len(that.Field4) { + return fmt.Errorf("Field4 this(%v) Not Equal that(%v)", len(this.Field4), len(that.Field4)) + } + for i := range this.Field4 { + if this.Field4[i] != that.Field4[i] { + return fmt.Errorf("Field4 this[%v](%v) Not Equal that[%v](%v)", i, this.Field4[i], i, that.Field4[i]) + } + } + if len(this.Field5) != len(that.Field5) { + return fmt.Errorf("Field5 this(%v) Not Equal that(%v)", len(this.Field5), len(that.Field5)) + } + for i := range this.Field5 { + if this.Field5[i] != that.Field5[i] { + return fmt.Errorf("Field5 this[%v](%v) Not Equal that[%v](%v)", i, this.Field5[i], i, that.Field5[i]) + } + } + if len(this.Field6) != len(that.Field6) { + return fmt.Errorf("Field6 this(%v) Not Equal that(%v)", len(this.Field6), len(that.Field6)) + } + for i := range this.Field6 { + if this.Field6[i] != that.Field6[i] { + return fmt.Errorf("Field6 this[%v](%v) Not Equal that[%v](%v)", i, this.Field6[i], i, that.Field6[i]) + } + } + if len(this.Field7) != len(that.Field7) { + return fmt.Errorf("Field7 this(%v) Not Equal that(%v)", len(this.Field7), len(that.Field7)) + } + for i := range this.Field7 { + if this.Field7[i] != that.Field7[i] { + return fmt.Errorf("Field7 this[%v](%v) Not Equal that[%v](%v)", i, this.Field7[i], i, that.Field7[i]) + } + } + if len(this.Field8) != len(that.Field8) { + return fmt.Errorf("Field8 this(%v) Not Equal that(%v)", len(this.Field8), len(that.Field8)) + } + for i := range this.Field8 { + if this.Field8[i] != that.Field8[i] { + return fmt.Errorf("Field8 this[%v](%v) Not Equal that[%v](%v)", i, this.Field8[i], i, that.Field8[i]) + } + } + if len(this.Field9) != len(that.Field9) { + return fmt.Errorf("Field9 this(%v) Not Equal that(%v)", len(this.Field9), len(that.Field9)) + } + for i := range this.Field9 { + if this.Field9[i] != that.Field9[i] { + return fmt.Errorf("Field9 this[%v](%v) Not Equal that[%v](%v)", i, this.Field9[i], i, that.Field9[i]) + } + } + if len(this.Field10) != len(that.Field10) { + return fmt.Errorf("Field10 this(%v) Not Equal that(%v)", len(this.Field10), len(that.Field10)) + } + for i := range this.Field10 { + if this.Field10[i] != that.Field10[i] { + return fmt.Errorf("Field10 this[%v](%v) Not Equal that[%v](%v)", i, this.Field10[i], i, that.Field10[i]) + } + } + if len(this.Field11) != len(that.Field11) { + return fmt.Errorf("Field11 this(%v) Not Equal that(%v)", len(this.Field11), len(that.Field11)) + } + for i := range this.Field11 { + if this.Field11[i] != that.Field11[i] { + return fmt.Errorf("Field11 this[%v](%v) Not Equal that[%v](%v)", i, this.Field11[i], i, that.Field11[i]) + } + } + if len(this.Field12) != len(that.Field12) { + return fmt.Errorf("Field12 this(%v) Not Equal that(%v)", len(this.Field12), len(that.Field12)) + } + for i := range this.Field12 { + if this.Field12[i] != that.Field12[i] { + return fmt.Errorf("Field12 this[%v](%v) Not Equal that[%v](%v)", i, this.Field12[i], i, that.Field12[i]) + } + } + if len(this.Field13) != len(that.Field13) { + return fmt.Errorf("Field13 this(%v) Not Equal that(%v)", len(this.Field13), len(that.Field13)) + } + for i := range this.Field13 { + if this.Field13[i] != that.Field13[i] { + return fmt.Errorf("Field13 this[%v](%v) Not Equal that[%v](%v)", i, this.Field13[i], i, that.Field13[i]) + } + } + if !bytes.Equal(this.XXX_unrecognized, that.XXX_unrecognized) { + return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that.XXX_unrecognized) + } + return nil +} diff --git a/vendor/github.com/gogo/protobuf/test/proto3extension/Makefile b/vendor/github.com/gogo/protobuf/test/proto3extension/Makefile new file mode 100644 index 000000000..4477b52d3 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/proto3extension/Makefile @@ -0,0 +1,32 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2016, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + go install github.com/gogo/protobuf/protoc-min-version + protoc-min-version --version="3.0.0" --gogo_out=Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor:. --proto_path=../../../../../:../../protobuf/:. *.proto \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/proto3extension/proto3ext.proto b/vendor/github.com/gogo/protobuf/test/proto3extension/proto3ext.proto new file mode 100644 index 000000000..8249f7a99 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/proto3extension/proto3ext.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package proto3extension; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + bool primary = 51234; + bool index = 51235; +} + diff --git a/vendor/github.com/gogo/protobuf/test/protosize/Makefile b/vendor/github.com/gogo/protobuf/test/protosize/Makefile new file mode 100644 index 000000000..dea154ae0 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/protosize/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. protosize.proto) diff --git a/vendor/github.com/gogo/protobuf/test/protosize/protosize.proto b/vendor/github.com/gogo/protobuf/test/protosize/protosize.proto new file mode 100644 index 000000000..f2d10c1c8 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/protosize/protosize.proto @@ -0,0 +1,46 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package protosize; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.marshaler_all) = true; +option (gogoproto.protosizer_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.testgen_all) = true; +option (gogoproto.equal_all) = true; + +message SizeMessage { + optional int64 size = 1; + optional int64 proto_size = 2; + optional bool Equal = 3; + optional string String = 4; +} diff --git a/vendor/github.com/gogo/protobuf/test/protosize/protosize_test.go b/vendor/github.com/gogo/protobuf/test/protosize/protosize_test.go new file mode 100644 index 000000000..1a6d46768 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/protosize/protosize_test.go @@ -0,0 +1,37 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package protosize + +// We expect that Size field will have no suffix and ProtoSize will be present +var ( + _ = SizeMessage{}.Size + _ = (&SizeMessage{}).GetSize + + _ = (&SizeMessage{}).ProtoSize +) diff --git a/vendor/github.com/gogo/protobuf/test/protosize/protosizepb_test.go b/vendor/github.com/gogo/protobuf/test/protosize/protosizepb_test.go new file mode 100644 index 000000000..a242d3a91 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/protosize/protosizepb_test.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: protosize.proto + +/* +Package protosize is a generated protocol buffer package. + +It is generated from these files: + protosize.proto + +It has these top-level messages: + SizeMessage +*/ +package protosize + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSizeMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSizeMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, false) + size := p.ProtoSize() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSizeMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &SizeMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &SizeMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageProtoSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.ProtoSize() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/registration/.gitignore b/vendor/github.com/gogo/protobuf/test/registration/.gitignore new file mode 100644 index 000000000..c6064dff9 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/registration/.gitignore @@ -0,0 +1,2 @@ +*.pb.go +*_test.go diff --git a/vendor/github.com/gogo/protobuf/test/registration/Makefile b/vendor/github.com/gogo/protobuf/test/registration/Makefile new file mode 100644 index 000000000..03a096d89 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/registration/Makefile @@ -0,0 +1,33 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2017, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +test: + go install github.com/gogo/protobuf/protoc-gen-gogo + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. registration.proto) + cp registration_test.go.in registration_test.go + go test ./... diff --git a/vendor/github.com/gogo/protobuf/test/registration/registration.proto b/vendor/github.com/gogo/protobuf/test/registration/registration.proto new file mode 100644 index 000000000..d8543a18b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/registration/registration.proto @@ -0,0 +1,45 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package registration; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_registration) = true; + +enum AnEnum { + A_VALUE = 0; + ANOTHER_VALUE = 1; +} + +message AMessage { + string a_string = 1; + uint32 a_uint = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/registration/registration_test.go.in b/vendor/github.com/gogo/protobuf/test/registration/registration_test.go.in new file mode 100644 index 000000000..93c843c73 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/registration/registration_test.go.in @@ -0,0 +1,85 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package registration + +import ( + "testing" + + gogoproto "github.com/gogo/protobuf/proto" + golangproto "github.com/golang/protobuf/proto" +) + +func TestEnumRegistered(t *testing.T) { + wantMap := map[string]int32{ + "A_VALUE": 0, + "ANOTHER_VALUE": 1, + } + gotMap := golangproto.EnumValueMap("registration.AnEnum") + for k, want := range wantMap { + got, ok := gotMap[k] + if !ok { + t.Errorf("Enum value %q was not registered with golang/protobuf", k) + } + if got != want { + t.Errorf("Enum value %q was different with golang/protobuf: want %v, got %v", k, want, got) + } + } + gotMap = gogoproto.EnumValueMap("registration.AnEnum") + for k, want := range wantMap { + got, ok := gotMap[k] + if !ok { + t.Errorf("Enum value %q was not registered with gogo/protobuf", k) + } + if got != want { + t.Errorf("Enum value %q was different with gogo/protobuf: want %v, got %v", k, want, got) + } + } +} + +func TestMessageRegistered(t *testing.T) { + got := golangproto.MessageType("registration.AMessage") + if got == nil { + t.Error(`Message "AMessage" was not registered with golang/protobuf`) + } + got = gogoproto.MessageType("registration.AMessage") + if got == nil { + t.Error(`Message "AMessage" was not registered with gogo/protobuf`) + } +} + +func TestFileRegistered(t *testing.T) { + got := golangproto.FileDescriptor("registration.proto") + if got == nil { + t.Error(`File "registration.proto" was not registered with golang/protobuf`) + } + got = gogoproto.FileDescriptor("registration.proto") + if got == nil { + t.Error(`File "registration.proto" was not registered with gogo/protobuf`) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/required/Makefile b/vendor/github.com/gogo/protobuf/test/required/Makefile new file mode 100644 index 000000000..34e6f70c6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/required/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. requiredexample.proto) diff --git a/vendor/github.com/gogo/protobuf/test/required/requiredexample.proto b/vendor/github.com/gogo/protobuf/test/required/requiredexample.proto new file mode 100644 index 000000000..33215936e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/required/requiredexample.proto @@ -0,0 +1,83 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package required; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.populate_all) = true; + +message RequiredExample { + required string theRequiredString = 1; + optional string theOptionalString = 2; + repeated string theRepeatedStrings = 3; +} + +message NidOptNative { + required double Field1 = 1 [(gogoproto.nullable) = false]; + required float Field2 = 2 [(gogoproto.nullable) = false]; + required int32 Field3 = 3 [(gogoproto.nullable) = false]; + required int64 Field4 = 4 [(gogoproto.nullable) = false]; + required uint32 Field5 = 5 [(gogoproto.nullable) = false]; + required uint64 Field6 = 6 [(gogoproto.nullable) = false]; + required sint32 Field7 = 7 [(gogoproto.nullable) = false]; + required sint64 Field8 = 8 [(gogoproto.nullable) = false]; + required fixed32 Field9 = 9 [(gogoproto.nullable) = false]; + required sfixed32 Field10 = 10 [(gogoproto.nullable) = false]; + required fixed64 Field11 = 11 [(gogoproto.nullable) = false]; + required sfixed64 Field12 = 12 [(gogoproto.nullable) = false]; + required bool Field13 = 13 [(gogoproto.nullable) = false]; + required string Field14 = 14 [(gogoproto.nullable) = false]; + required bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinOptNative { + required double Field1 = 1; + required float Field2 = 2; + required int32 Field3 = 3; + required int64 Field4 = 4; + required uint32 Field5 = 5; + required uint64 Field6 = 6; + required sint32 Field7 = 7; + required sint64 Field8 = 8; + required fixed32 Field9 = 9; + required sfixed32 Field10 = 10; + required fixed64 Field11 = 11; + required sfixed64 Field12 = 12; + required bool Field13 = 13; + required string Field14 = 14; + required bytes Field15 = 15; +} + +message NestedNinOptNative { + repeated NinOptNative NestedNinOpts = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/required/requiredexamplepb_test.go b/vendor/github.com/gogo/protobuf/test/required/requiredexamplepb_test.go new file mode 100644 index 000000000..b9c26375e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/required/requiredexamplepb_test.go @@ -0,0 +1,181 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package required + +import ( + "github.com/gogo/protobuf/proto" + "github.com/gogo/protobuf/test" + "math/rand" + "reflect" + "strconv" + "testing" + "time" +) + +func TestMarshalToErrorsWhenRequiredFieldIsNotPresent(t *testing.T) { + data := RequiredExample{} + buf, err := proto.Marshal(&data) + if err == nil { + t.Fatalf("err == nil; was %v instead", err) + } + if err.Error() != `proto: required field "theRequiredString" not set` { + t.Fatalf(`err.Error() != "proto: required field "theRequiredString" not set"; was "%s" instead`, err.Error()) + } + if len(buf) != 0 { + t.Fatalf(`len(buf) != 0; was %d instead`, len(buf)) + } +} + +func TestMarshalToSucceedsWhenRequiredFieldIsPresent(t *testing.T) { + data := RequiredExample{ + TheRequiredString: proto.String("present"), + } + buf, err := proto.Marshal(&data) + if err != nil { + t.Fatalf("err != nil; was %v instead", err) + } + if len(buf) == 0 { + t.Fatalf(`len(buf) == 0; expected nonzero`) + } +} + +func TestUnmarshalErrorsWhenRequiredFieldIsNotPresent(t *testing.T) { + missingRequiredField := []byte{0x12, 0x8, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c} + data := RequiredExample{} + err := proto.Unmarshal(missingRequiredField, &data) + if err == nil { + t.Fatalf("err == nil; was %v instead", err) + } + if err.Error() != `proto: required field "theRequiredString" not set` { + t.Fatalf(`err.Error() != "proto: required field "theRequiredString" not set"; was "%s" instead`, err.Error()) + } +} + +func TestUnmarshalSucceedsWhenRequiredIsNotPresent(t *testing.T) { + dataOut := RequiredExample{ + TheRequiredString: proto.String("present"), + } + encodedMessage, err := proto.Marshal(&dataOut) + if err != nil { + t.Fatalf("Unexpected error when marshalling dataOut: %v", err) + } + dataIn := RequiredExample{} + err = proto.Unmarshal(encodedMessage, &dataIn) + if err != nil { + t.Fatalf("err != nil; was %v instead", err) + } +} + +func TestUnmarshalPopulatedOptionalFieldsAsRequiredSucceeds(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + dataOut := test.NewPopulatedNidOptNative(r, true) + encodedMessage, err := proto.Marshal(dataOut) + if err != nil { + t.Fatalf("Unexpected error when marshalling dataOut: %v", err) + } + dataIn := NidOptNative{} + err = proto.Unmarshal(encodedMessage, &dataIn) + if err != nil { + t.Fatalf("err != nil; was %v instead", err) + } +} + +func TestUnmarshalPartiallyPopulatedOptionalFieldsFails(t *testing.T) { + // Fill in all fields, then randomly remove one. + dataOut := &test.NinOptNative{ + Field1: proto.Float64(0), + Field2: proto.Float32(0), + Field3: proto.Int32(0), + Field4: proto.Int64(0), + Field5: proto.Uint32(0), + Field6: proto.Uint64(0), + Field7: proto.Int32(0), + Field8: proto.Int64(0), + Field9: proto.Uint32(0), + Field10: proto.Int32(0), + Field11: proto.Uint64(0), + Field12: proto.Int64(0), + Field13: proto.Bool(false), + Field14: proto.String("0"), + Field15: []byte("0"), + } + r := rand.New(rand.NewSource(time.Now().UnixNano())) + fieldName := "Field" + strconv.Itoa(r.Intn(15)+1) + field := reflect.ValueOf(dataOut).Elem().FieldByName(fieldName) + fieldType := field.Type() + field.Set(reflect.Zero(fieldType)) + encodedMessage, err := proto.Marshal(dataOut) + if err != nil { + t.Fatalf("Unexpected error when marshalling dataOut: %v", err) + } + dataIn := NidOptNative{} + err = proto.Unmarshal(encodedMessage, &dataIn) + if err.Error() != `proto: required field "`+fieldName+`" not set` { + t.Fatalf(`err.Error() != "proto: required field "`+fieldName+`" not set"; was "%s" instead`, err.Error()) + } +} + +func TestMarshalFailsWithoutAllFieldsSet(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + dataOut := NewPopulatedNinOptNative(r, true) + fieldName := "Field" + strconv.Itoa(r.Intn(15)+1) + field := reflect.ValueOf(dataOut).Elem().FieldByName(fieldName) + fieldType := field.Type() + field.Set(reflect.Zero(fieldType)) + encodedMessage, err := proto.Marshal(dataOut) + if err.Error() != `proto: required field "`+fieldName+`" not set` { + t.Fatalf(`err.Error() != "proto: required field "`+fieldName+`" not set"; was "%s" instead`, err.Error()) + } + if len(encodedMessage) > 0 { + t.Fatalf("Got some bytes from marshal, expected none.") + } +} + +func TestMissingFieldsOnRepeatedNestedTypes(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + dataOut := &NestedNinOptNative{ + NestedNinOpts: []*NinOptNative{ + NewPopulatedNinOptNative(r, true), + NewPopulatedNinOptNative(r, true), + NewPopulatedNinOptNative(r, true), + }, + } + middle := dataOut.GetNestedNinOpts()[1] + fieldName := "Field" + strconv.Itoa(r.Intn(15)+1) + field := reflect.ValueOf(middle).Elem().FieldByName(fieldName) + fieldType := field.Type() + field.Set(reflect.Zero(fieldType)) + encodedMessage, err := proto.Marshal(dataOut) + if err.Error() != `proto: required field "`+fieldName+`" not set` { + t.Fatalf(`err.Error() != "proto: required field "`+fieldName+`" not set"; was "%s" instead`, err.Error()) + } + if len(encodedMessage) > 0 { + t.Fatalf("Got some bytes from marshal, expected none.") + } +} diff --git a/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict.proto b/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict.proto new file mode 100644 index 000000000..66345af80 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict.proto @@ -0,0 +1,43 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; +package sizerconflict; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.sizer_all) = true; +option (gogoproto.protosizer_all) = true; + +message Value { + oneof type { + int64 type_one = 1; + uint64 type_two = 2; + } +} + diff --git a/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict_test.go b/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict_test.go new file mode 100644 index 000000000..907b923f7 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/sizerconflict/sizerconflict_test.go @@ -0,0 +1,48 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2017, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package sizerconflict + +import ( + "os" + "os/exec" + "strings" + "testing" +) + +func TestSizerConflict(t *testing.T) { + cmd := exec.Command("protoc", "--gogo_out=.", "-I=../../../../../:../../protobuf/:./", "sizerconflict.proto") + data, err := cmd.CombinedOutput() + if err == nil && !strings.Contains(string(data), "Plugin failed with status code 1") { + t.Errorf("Expected error, got: %s", data) + if err = os.Remove("sizerconflict.pb.go"); err != nil { + t.Error(err) + } + } + t.Logf("received expected error = %v and output = %v", err, string(data)) +} diff --git a/vendor/github.com/gogo/protobuf/test/sizeunderscore/Makefile b/vendor/github.com/gogo/protobuf/test/sizeunderscore/Makefile new file mode 100644 index 000000000..fca7b2afa --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/sizeunderscore/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. sizeunderscore.proto) diff --git a/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscore.proto b/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscore.proto new file mode 100644 index 000000000..922f53229 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscore.proto @@ -0,0 +1,45 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package sizeunderscore; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.testgen_all) = true; +option (gogoproto.equal_all) = true; + +message SizeMessage { + optional int64 size = 1; + optional bool Equal = 2; + optional string String = 3; +} diff --git a/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscorepb_test.go b/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscorepb_test.go new file mode 100644 index 000000000..c499477d8 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/sizeunderscore/sizeunderscorepb_test.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sizeunderscore.proto + +/* +Package sizeunderscore is a generated protocol buffer package. + +It is generated from these files: + sizeunderscore.proto + +It has these top-level messages: + SizeMessage +*/ +package sizeunderscore + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestSizeMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestSizeMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &SizeMessage{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSizeMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &SizeMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &SizeMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSizeMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSizeMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/stdtypes/Makefile b/vendor/github.com/gogo/protobuf/test/stdtypes/Makefile new file mode 100644 index 000000000..82c4c8c0b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/stdtypes/Makefile @@ -0,0 +1,39 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2016, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-min-version + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=\ + Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types\ + :. \ + --proto_path=../../../../../:../../protobuf/:. stdtypes.proto + +test: + go test -race -run=TestConcurrentTextMarshal . \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/stdtypes/concurrency_test.go b/vendor/github.com/gogo/protobuf/test/stdtypes/concurrency_test.go new file mode 100644 index 000000000..fd1181fff --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/stdtypes/concurrency_test.go @@ -0,0 +1,31 @@ +package stdtypes + +import ( + "io/ioutil" + "sync" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestConcurrentTextMarshal(t *testing.T) { + // Verify that there are no race conditions when calling + // TextMarshaler.Marshal on a protobuf message that contains a StdDuration + + std := StdTypes{} + var wg sync.WaitGroup + + tm := proto.TextMarshaler{} + + for i := 0; i < 2; i++ { + wg.Add(1) + go func() { + defer wg.Done() + err := tm.Marshal(ioutil.Discard, &std) + if err != nil { + t.Fatal(err) + } + }() + } + wg.Wait() +} diff --git a/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypes.proto b/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypes.proto new file mode 100644 index 000000000..fb69b7327 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypes.proto @@ -0,0 +1,78 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package stdtypes; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message StdTypes { + google.protobuf.Timestamp nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration nullableDuration = 2 [(gogoproto.stdduration) = true]; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message RepStdTypes { + repeated google.protobuf.Timestamp nullableTimestamps = 1 [(gogoproto.stdtime) = true]; + repeated google.protobuf.Duration nullableDurations = 2 [(gogoproto.stdduration) = true]; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message MapStdTypes { + map nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + map timestamp = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + + map nullableDuration = 3 [(gogoproto.stdduration) = true]; + map duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message OneofStdTypes { + oneof OneOfStdTimes { + google.protobuf.Timestamp timestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration duration = 2 [(gogoproto.stdduration) = true]; + } +} + diff --git a/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypespb_test.go b/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypespb_test.go new file mode 100644 index 000000000..86885c929 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/stdtypes/stdtypespb_test.go @@ -0,0 +1,807 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stdtypes.proto + +/* +Package stdtypes is a generated protocol buffer package. + +It is generated from these files: + stdtypes.proto + +It has these top-level messages: + StdTypes + RepStdTypes + MapStdTypes + OneofStdTypes +*/ +package stdtypes + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestRepStdTypesGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMapStdTypesGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOneofStdTypesGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/tags/Makefile b/vendor/github.com/gogo/protobuf/test/tags/Makefile new file mode 100644 index 000000000..e1105dc5e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/tags/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. tags.proto) diff --git a/vendor/github.com/gogo/protobuf/test/tags/tags.proto b/vendor/github.com/gogo/protobuf/test/tags/tags.proto new file mode 100644 index 000000000..f4ef2a68d --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/tags/tags.proto @@ -0,0 +1,44 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package tags; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.populate_all) = true; + +message Outside { + optional Inside Inside = 1 [(gogoproto.embed) = true, (gogoproto.jsontag) = ""]; + optional string Field2 = 2 [(gogoproto.jsontag) = "MyField2", (gogoproto.moretags) = "xml:\",comment\""]; +} + +message Inside { + optional string Field1 = 1 [(gogoproto.jsontag) = "MyField1", (gogoproto.moretags) = "xml:\",chardata\""]; +} diff --git a/vendor/github.com/gogo/protobuf/test/tags/tags_test.go b/vendor/github.com/gogo/protobuf/test/tags/tags_test.go new file mode 100644 index 000000000..460273e42 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/tags/tags_test.go @@ -0,0 +1,119 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package tags + +import ( + "bytes" + "encoding/json" + "encoding/xml" + math_rand "math/rand" + "testing" + "time" +) + +type MyJson struct { + MyField1 string + MyField2 string +} + +func NewPopulatedMyJson(r randyTags) *MyJson { + this := &MyJson{} + if r.Intn(10) != 0 { + this.MyField1 = randStringTags(r) + } + if r.Intn(10) != 0 { + this.MyField2 = randStringTags(r) + } + return this +} + +func TestJson(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + msg1 := NewPopulatedMyJson(popr) + data, err := json.Marshal(msg1) + if err != nil { + panic(err) + } + outside := &Outside{} + err = json.Unmarshal(data, outside) + if err != nil { + panic(err) + } + if outside.GetField1() != msg1.MyField1 { + t.Fatalf("proto field1 %s != %s", outside.GetField1(), msg1.MyField1) + } + if outside.GetField2() != msg1.MyField2 { + t.Fatalf("proto field2 %s != %s", outside.GetField2(), msg1.MyField2) + } + data2, err := json.Marshal(outside) + if err != nil { + panic(err) + } + msg2 := &MyJson{} + err = json.Unmarshal(data2, msg2) + if err != nil { + panic(err) + } + if msg2.MyField1 != msg1.MyField1 { + t.Fatalf("proto field1 %s != %s", msg2.MyField1, msg1.MyField1) + } + if msg2.MyField2 != msg1.MyField2 { + t.Fatalf("proto field2 %s != %s", msg2.MyField2, msg1.MyField2) + } +} + +func TestXml(t *testing.T) { + s := "Field1Value" + field1 := "Field1Value" + field2 := "Field2Value" + msg1 := &Outside{} + err := xml.Unmarshal([]byte(s), msg1) + if err != nil { + panic(err) + } + msg2 := &Outside{ + Inside: &Inside{ + Field1: &field1, + }, + Field2: &field2, + } + if msg1.GetField1() != msg2.GetField1() { + t.Fatalf("field1 expected %s got %s", msg2.GetField1(), msg1.GetField1()) + } + if err != nil { + panic(err) + } + data, err := xml.Marshal(msg2) + if err != nil { + panic(err) + } + if !bytes.Equal(data, []byte(s)) { + t.Fatalf("expected %s got %s", s, string(data)) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/Makefile b/vendor/github.com/gogo/protobuf/test/theproto3/Makefile new file mode 100644 index 000000000..fe1b67619 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/Makefile @@ -0,0 +1,36 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-combo + go install github.com/gogo/protobuf/protoc-gen-gogo + cp header.proto theproto3.proto + cat maps.proto >> theproto3.proto + cat footer.proto >> theproto3.proto + protoc-gen-combo --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. theproto3.proto + find combos -type d -not -name combos -exec cp proto3_test.go.in {}/proto3_test.go \; diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/proto3_test.go b/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/proto3_test.go new file mode 100644 index 000000000..bb7eb6bb9 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/proto3_test.go @@ -0,0 +1,159 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package theproto3 + +import ( + "reflect" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestCustomTypeSize(t *testing.T) { + m := &Uint128Pair{} + m.Size() // Should not panic. +} + +func TestCustomTypeMarshalUnmarshal(t *testing.T) { + m1 := &Uint128Pair{} + if b, err := proto.Marshal(m1); err != nil { + t.Fatal(err) + } else { + m2 := &Uint128Pair{} + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(m1, m2) { + t.Errorf("expected %+v, got %+v", m1, m2) + } + } +} + +func TestNotPackedToPacked(t *testing.T) { + input := []uint64{1, 10e9} + notpacked := &NotPacked{Key: input} + if data, err := proto.Marshal(notpacked); err != nil { + t.Fatal(err) + } else { + packed := &Message{} + if err := proto.Unmarshal(data, packed); err != nil { + t.Fatal(err) + } + output := packed.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} + +func TestPackedToNotPacked(t *testing.T) { + input := []uint64{1, 10e9} + packed := &Message{Key: input} + if data, err := proto.Marshal(packed); err != nil { + t.Fatal(err) + } else { + notpacked := &NotPacked{} + if err := proto.Unmarshal(data, notpacked); err != nil { + t.Fatal(err) + } + output := notpacked.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3.proto b/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3.proto new file mode 100644 index 000000000..d1f929884 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3.proto @@ -0,0 +1,168 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package theproto3; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "github.com/gogo/protobuf/test/combos/both/thetest.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Message { + enum Humour { + UNKNOWN = 0; + PUNS = 1; + SLAPSTICK = 2; + BILL_BAILEY = 3; + } + + string name = 1; + Humour hilarity = 2; + uint32 height_in_cm = 3; + bytes data = 4; + int64 result_count = 7; + bool true_scotsman = 8; + float score = 9; + + repeated uint64 key = 5; + Nested nested = 6; + + map terrain = 10; + test.NinOptNative proto2_field = 11; + map proto2_value = 13; +} + +message Nested { + string bunny = 1; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message MessageWithMap { + map name_mapping = 1; + map msg_mapping = 2; + map byte_mapping = 3; +} + +message FloatingPoint { + double f = 1; +} + +message Uint128Pair { + bytes left = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + bytes right = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message ContainsNestedMap { + message NestedMap { + map NestedMapField = 1; + } +} + +message NotPacked { + repeated uint64 key = 5 [packed=false]; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3pb_test.go b/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3pb_test.go new file mode 100644 index 000000000..ca8a80a5e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/both/theproto3pb_test.go @@ -0,0 +1,2423 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/theproto3.proto + +/* +Package theproto3 is a generated protocol buffer package. + +It is generated from these files: + combos/both/theproto3.proto + +It has these top-level messages: + Message + Nested + AllMaps + AllMapsOrdered + MessageWithMap + FloatingPoint + Uint128Pair + ContainsNestedMap + NotPacked +*/ +package theproto3 + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/combos/both" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNested(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nested{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsOrderedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageWithMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageWithMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageWithMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessageWithMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MessageWithMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFloatingPointMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUint128PairMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUint128PairProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUint128PairProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUint128Pair(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Uint128Pair{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestContainsNestedMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkContainsNestedMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedContainsNestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestContainsNestedMap_NestedMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkContainsNestedMap_NestedMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMap_NestedMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedContainsNestedMap_NestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap_NestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNotPackedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNotPackedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNotPackedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNotPacked(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NotPacked{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageWithMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUint128PairJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMap_NestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNotPackedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Nested{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Nested{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MessageWithMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MessageWithMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Uint128Pair{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Uint128Pair{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ContainsNestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ContainsNestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NotPacked{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NotPacked{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTheproto3Description(t *testing.T) { + Theproto3Description() +} +func TestMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageWithMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUint128PairVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMap_NestedMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNotPackedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageWithMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUint128PairFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMap_NestedMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNotPackedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageWithMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUint128PairGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMap_NestedMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNotPackedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageWithMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUint128PairSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMap_NestedMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNotPackedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMessageWithMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFloatingPointStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUint128PairStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMap_NestedMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNotPackedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/proto3_test.go b/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/proto3_test.go new file mode 100644 index 000000000..bb7eb6bb9 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/proto3_test.go @@ -0,0 +1,159 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package theproto3 + +import ( + "reflect" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestCustomTypeSize(t *testing.T) { + m := &Uint128Pair{} + m.Size() // Should not panic. +} + +func TestCustomTypeMarshalUnmarshal(t *testing.T) { + m1 := &Uint128Pair{} + if b, err := proto.Marshal(m1); err != nil { + t.Fatal(err) + } else { + m2 := &Uint128Pair{} + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(m1, m2) { + t.Errorf("expected %+v, got %+v", m1, m2) + } + } +} + +func TestNotPackedToPacked(t *testing.T) { + input := []uint64{1, 10e9} + notpacked := &NotPacked{Key: input} + if data, err := proto.Marshal(notpacked); err != nil { + t.Fatal(err) + } else { + packed := &Message{} + if err := proto.Unmarshal(data, packed); err != nil { + t.Fatal(err) + } + output := packed.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} + +func TestPackedToNotPacked(t *testing.T) { + input := []uint64{1, 10e9} + packed := &Message{Key: input} + if data, err := proto.Marshal(packed); err != nil { + t.Fatal(err) + } else { + notpacked := &NotPacked{} + if err := proto.Unmarshal(data, notpacked); err != nil { + t.Fatal(err) + } + output := notpacked.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3.proto b/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3.proto new file mode 100644 index 000000000..56f8584bd --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3.proto @@ -0,0 +1,168 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package theproto3; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "github.com/gogo/protobuf/test/combos/both/thetest.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Message { + enum Humour { + UNKNOWN = 0; + PUNS = 1; + SLAPSTICK = 2; + BILL_BAILEY = 3; + } + + string name = 1; + Humour hilarity = 2; + uint32 height_in_cm = 3; + bytes data = 4; + int64 result_count = 7; + bool true_scotsman = 8; + float score = 9; + + repeated uint64 key = 5; + Nested nested = 6; + + map terrain = 10; + test.NinOptNative proto2_field = 11; + map proto2_value = 13; +} + +message Nested { + string bunny = 1; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message MessageWithMap { + map name_mapping = 1; + map msg_mapping = 2; + map byte_mapping = 3; +} + +message FloatingPoint { + double f = 1; +} + +message Uint128Pair { + bytes left = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + bytes right = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message ContainsNestedMap { + message NestedMap { + map NestedMapField = 1; + } +} + +message NotPacked { + repeated uint64 key = 5 [packed=false]; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3pb_test.go b/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3pb_test.go new file mode 100644 index 000000000..d66aeb5bc --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/marshaler/theproto3pb_test.go @@ -0,0 +1,2423 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/theproto3.proto + +/* +Package theproto3 is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/theproto3.proto + +It has these top-level messages: + Message + Nested + AllMaps + AllMapsOrdered + MessageWithMap + FloatingPoint + Uint128Pair + ContainsNestedMap + NotPacked +*/ +package theproto3 + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/combos/both" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNestedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNested(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nested{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAllMapsOrderedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMessageWithMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMessageWithMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageWithMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessageWithMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MessageWithMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestFloatingPointMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUint128PairMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkUint128PairProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUint128PairProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUint128Pair(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Uint128Pair{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestContainsNestedMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkContainsNestedMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedContainsNestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestContainsNestedMap_NestedMapMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkContainsNestedMap_NestedMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMap_NestedMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedContainsNestedMap_NestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap_NestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNotPackedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkNotPackedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNotPackedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNotPacked(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NotPacked{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageWithMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUint128PairJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMap_NestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNotPackedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Nested{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Nested{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MessageWithMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MessageWithMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Uint128Pair{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Uint128Pair{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ContainsNestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ContainsNestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NotPacked{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NotPacked{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTheproto3Description(t *testing.T) { + Theproto3Description() +} +func TestMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageWithMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUint128PairVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMap_NestedMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNotPackedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageWithMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUint128PairFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMap_NestedMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNotPackedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageWithMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUint128PairGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMap_NestedMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNotPackedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageWithMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUint128PairSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMap_NestedMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNotPackedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMessageWithMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFloatingPointStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUint128PairStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMap_NestedMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNotPackedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/proto3_test.go b/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/proto3_test.go new file mode 100644 index 000000000..bb7eb6bb9 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/proto3_test.go @@ -0,0 +1,159 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package theproto3 + +import ( + "reflect" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestCustomTypeSize(t *testing.T) { + m := &Uint128Pair{} + m.Size() // Should not panic. +} + +func TestCustomTypeMarshalUnmarshal(t *testing.T) { + m1 := &Uint128Pair{} + if b, err := proto.Marshal(m1); err != nil { + t.Fatal(err) + } else { + m2 := &Uint128Pair{} + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(m1, m2) { + t.Errorf("expected %+v, got %+v", m1, m2) + } + } +} + +func TestNotPackedToPacked(t *testing.T) { + input := []uint64{1, 10e9} + notpacked := &NotPacked{Key: input} + if data, err := proto.Marshal(notpacked); err != nil { + t.Fatal(err) + } else { + packed := &Message{} + if err := proto.Unmarshal(data, packed); err != nil { + t.Fatal(err) + } + output := packed.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} + +func TestPackedToNotPacked(t *testing.T) { + input := []uint64{1, 10e9} + packed := &Message{Key: input} + if data, err := proto.Marshal(packed); err != nil { + t.Fatal(err) + } else { + notpacked := &NotPacked{} + if err := proto.Unmarshal(data, notpacked); err != nil { + t.Fatal(err) + } + output := notpacked.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3.proto b/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3.proto new file mode 100644 index 000000000..0f4525cdc --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3.proto @@ -0,0 +1,168 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package theproto3; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "github.com/gogo/protobuf/test/combos/both/thetest.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Message { + enum Humour { + UNKNOWN = 0; + PUNS = 1; + SLAPSTICK = 2; + BILL_BAILEY = 3; + } + + string name = 1; + Humour hilarity = 2; + uint32 height_in_cm = 3; + bytes data = 4; + int64 result_count = 7; + bool true_scotsman = 8; + float score = 9; + + repeated uint64 key = 5; + Nested nested = 6; + + map terrain = 10; + test.NinOptNative proto2_field = 11; + map proto2_value = 13; +} + +message Nested { + string bunny = 1; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message MessageWithMap { + map name_mapping = 1; + map msg_mapping = 2; + map byte_mapping = 3; +} + +message FloatingPoint { + double f = 1; +} + +message Uint128Pair { + bytes left = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + bytes right = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message ContainsNestedMap { + message NestedMap { + map NestedMapField = 1; + } +} + +message NotPacked { + repeated uint64 key = 5 [packed=false]; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3pb_test.go b/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3pb_test.go new file mode 100644 index 000000000..508713dc3 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/neither/theproto3pb_test.go @@ -0,0 +1,2143 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/theproto3.proto + +/* +Package theproto3 is a generated protocol buffer package. + +It is generated from these files: + combos/neither/theproto3.proto + +It has these top-level messages: + Message + Nested + AllMaps + AllMapsOrdered + MessageWithMap + FloatingPoint + Uint128Pair + ContainsNestedMap + NotPacked +*/ +package theproto3 + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/combos/both" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNested(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nested{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMessageWithMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageWithMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessageWithMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MessageWithMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUint128PairProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUint128PairProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUint128Pair(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Uint128Pair{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkContainsNestedMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedContainsNestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkContainsNestedMap_NestedMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMap_NestedMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedContainsNestedMap_NestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap_NestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNotPackedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNotPackedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNotPacked(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NotPacked{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageWithMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUint128PairJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMap_NestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNotPackedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Nested{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Nested{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MessageWithMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MessageWithMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Uint128Pair{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Uint128Pair{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ContainsNestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ContainsNestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NotPacked{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NotPacked{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTheproto3Description(t *testing.T) { + Theproto3Description() +} +func TestMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageWithMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUint128PairVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMap_NestedMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNotPackedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageWithMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUint128PairFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMap_NestedMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNotPackedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageWithMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUint128PairGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMap_NestedMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNotPackedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageWithMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUint128PairSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMap_NestedMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNotPackedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMessageWithMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFloatingPointStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUint128PairStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMap_NestedMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNotPackedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/proto3_test.go b/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/proto3_test.go new file mode 100644 index 000000000..bb7eb6bb9 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/proto3_test.go @@ -0,0 +1,159 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package theproto3 + +import ( + "reflect" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestCustomTypeSize(t *testing.T) { + m := &Uint128Pair{} + m.Size() // Should not panic. +} + +func TestCustomTypeMarshalUnmarshal(t *testing.T) { + m1 := &Uint128Pair{} + if b, err := proto.Marshal(m1); err != nil { + t.Fatal(err) + } else { + m2 := &Uint128Pair{} + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(m1, m2) { + t.Errorf("expected %+v, got %+v", m1, m2) + } + } +} + +func TestNotPackedToPacked(t *testing.T) { + input := []uint64{1, 10e9} + notpacked := &NotPacked{Key: input} + if data, err := proto.Marshal(notpacked); err != nil { + t.Fatal(err) + } else { + packed := &Message{} + if err := proto.Unmarshal(data, packed); err != nil { + t.Fatal(err) + } + output := packed.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} + +func TestPackedToNotPacked(t *testing.T) { + input := []uint64{1, 10e9} + packed := &Message{Key: input} + if data, err := proto.Marshal(packed); err != nil { + t.Fatal(err) + } else { + notpacked := &NotPacked{} + if err := proto.Unmarshal(data, notpacked); err != nil { + t.Fatal(err) + } + output := notpacked.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3.proto b/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3.proto new file mode 100644 index 000000000..0c130b73f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3.proto @@ -0,0 +1,168 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package theproto3; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "github.com/gogo/protobuf/test/combos/both/thetest.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Message { + enum Humour { + UNKNOWN = 0; + PUNS = 1; + SLAPSTICK = 2; + BILL_BAILEY = 3; + } + + string name = 1; + Humour hilarity = 2; + uint32 height_in_cm = 3; + bytes data = 4; + int64 result_count = 7; + bool true_scotsman = 8; + float score = 9; + + repeated uint64 key = 5; + Nested nested = 6; + + map terrain = 10; + test.NinOptNative proto2_field = 11; + map proto2_value = 13; +} + +message Nested { + string bunny = 1; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message MessageWithMap { + map name_mapping = 1; + map msg_mapping = 2; + map byte_mapping = 3; +} + +message FloatingPoint { + double f = 1; +} + +message Uint128Pair { + bytes left = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + bytes right = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message ContainsNestedMap { + message NestedMap { + map NestedMapField = 1; + } +} + +message NotPacked { + repeated uint64 key = 5 [packed=false]; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3pb_test.go b/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3pb_test.go new file mode 100644 index 000000000..e963ff2ae --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/combos/unmarshaler/theproto3pb_test.go @@ -0,0 +1,2143 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/theproto3.proto + +/* +Package theproto3 is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/theproto3.proto + +It has these top-level messages: + Message + Nested + AllMaps + AllMapsOrdered + MessageWithMap + FloatingPoint + Uint128Pair + ContainsNestedMap + NotPacked +*/ +package theproto3 + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/test/combos/both" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Message{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNested(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nested{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMaps(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMaps{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAllMapsOrderedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAllMapsOrderedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAllMapsOrdered(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AllMapsOrdered{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMessageWithMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMessageWithMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMessageWithMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MessageWithMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkFloatingPointProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkFloatingPointProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedFloatingPoint(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &FloatingPoint{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUint128PairProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUint128PairProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUint128Pair(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Uint128Pair{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkContainsNestedMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedContainsNestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkContainsNestedMap_NestedMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkContainsNestedMap_NestedMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedContainsNestedMap_NestedMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ContainsNestedMap_NestedMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNotPackedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNotPackedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNotPacked(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NotPacked{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Message{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nested{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMaps{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAllMapsOrderedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AllMapsOrdered{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageWithMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MessageWithMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestFloatingPointJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &FloatingPoint{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUint128PairJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Uint128Pair{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestContainsNestedMap_NestedMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ContainsNestedMap_NestedMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNotPackedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NotPacked{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Message{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Nested{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Nested{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMaps{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAllMapsOrderedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AllMapsOrdered{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MessageWithMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMessageWithMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MessageWithMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestFloatingPointProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + dAtA := proto.CompactTextString(p) + msg := &FloatingPoint{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Uint128Pair{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUint128PairProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Uint128Pair{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ContainsNestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ContainsNestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestContainsNestedMap_NestedMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ContainsNestedMap_NestedMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NotPacked{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNotPackedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NotPacked{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTheproto3Description(t *testing.T) { + Theproto3Description() +} +func TestMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Message{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nested{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMaps{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAllMapsOrderedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AllMapsOrdered{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageWithMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MessageWithMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestFloatingPointVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &FloatingPoint{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUint128PairVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Uint128Pair{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestContainsNestedMap_NestedMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ContainsNestedMap_NestedMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNotPackedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NotPacked{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMessageFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAllMapsOrderedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageWithMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestFloatingPointFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUint128PairFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestContainsNestedMap_NestedMapFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNotPackedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestMessageGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAllMapsOrderedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageWithMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestFloatingPointGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUint128PairGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestContainsNestedMap_NestedMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNotPackedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Message, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNested(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nested, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNested(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMaps(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMaps, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMaps(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAllMapsOrderedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAllMapsOrdered(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAllMapsOrderedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AllMapsOrdered, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAllMapsOrdered(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageWithMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMessageWithMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMessageWithMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MessageWithMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMessageWithMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestFloatingPointSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedFloatingPoint(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkFloatingPointSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*FloatingPoint, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedFloatingPoint(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUint128PairSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUint128Pair(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUint128PairSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Uint128Pair, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUint128Pair(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestContainsNestedMap_NestedMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedContainsNestedMap_NestedMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkContainsNestedMap_NestedMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ContainsNestedMap_NestedMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedContainsNestedMap_NestedMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNotPackedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNotPacked(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNotPackedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NotPacked, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNotPacked(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMessageStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNested(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMaps(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAllMapsOrderedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAllMapsOrdered(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMessageWithMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMessageWithMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestFloatingPointStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedFloatingPoint(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUint128PairStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUint128Pair(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestContainsNestedMap_NestedMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedContainsNestedMap_NestedMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNotPackedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNotPacked(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/footer.proto b/vendor/github.com/gogo/protobuf/test/theproto3/footer.proto new file mode 100644 index 000000000..abf45e72e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/footer.proto @@ -0,0 +1,25 @@ + +message MessageWithMap { + map name_mapping = 1; + map msg_mapping = 2; + map byte_mapping = 3; +} + +message FloatingPoint { + double f = 1; +} + +message Uint128Pair { + bytes left = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + bytes right = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message ContainsNestedMap { + message NestedMap { + map NestedMapField = 1; + } +} + +message NotPacked { + repeated uint64 key = 5 [packed=false]; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/header.proto b/vendor/github.com/gogo/protobuf/test/theproto3/header.proto new file mode 100644 index 000000000..314e48f29 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/header.proto @@ -0,0 +1,95 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package theproto3; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "github.com/gogo/protobuf/test/combos/both/thetest.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Message { + enum Humour { + UNKNOWN = 0; + PUNS = 1; + SLAPSTICK = 2; + BILL_BAILEY = 3; + } + + string name = 1; + Humour hilarity = 2; + uint32 height_in_cm = 3; + bytes data = 4; + int64 result_count = 7; + bool true_scotsman = 8; + float score = 9; + + repeated uint64 key = 5; + Nested nested = 6; + + map terrain = 10; + test.NinOptNative proto2_field = 11; + map proto2_value = 13; +} + +message Nested { + string bunny = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/maps.proto b/vendor/github.com/gogo/protobuf/test/theproto3/maps.proto new file mode 100644 index 000000000..18aff7ae7 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/maps.proto @@ -0,0 +1,48 @@ + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/proto3_test.go.in b/vendor/github.com/gogo/protobuf/test/theproto3/proto3_test.go.in new file mode 100644 index 000000000..bb7eb6bb9 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/proto3_test.go.in @@ -0,0 +1,159 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package theproto3 + +import ( + "reflect" + "testing" + + "github.com/gogo/protobuf/proto" +) + +func TestNilMaps(t *testing.T) { + m := &AllMaps{StringToMsgMap: map[string]*FloatingPoint{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToMsgMap["a"]; !ok { + t.Error("element not in map") + } else if v != nil { + t.Errorf("element should be nil, but its %v", v) + } +} + +func TestNilMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"a": nil}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["a"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestEmptyMapsBytes(t *testing.T) { + m := &AllMaps{StringToBytesMap: map[string][]byte{"b": {}}} + data, err := proto.Marshal(m) + if err != nil { + t.Fatal(err) + } + size := m.Size() + protoSize := proto.Size(m) + marshaledSize := len(data) + if size != protoSize || marshaledSize != protoSize { + t.Errorf("size %d != protoSize %d != marshaledSize %d", size, protoSize, marshaledSize) + } + m2 := &AllMaps{} + if err := proto.Unmarshal(data, m2); err != nil { + t.Fatal(err) + } + if v, ok := m2.StringToBytesMap["b"]; !ok { + t.Error("element not in map") + } else if len(v) != 0 { + t.Errorf("element should be empty, but its %v", v) + } +} + +func TestCustomTypeSize(t *testing.T) { + m := &Uint128Pair{} + m.Size() // Should not panic. +} + +func TestCustomTypeMarshalUnmarshal(t *testing.T) { + m1 := &Uint128Pair{} + if b, err := proto.Marshal(m1); err != nil { + t.Fatal(err) + } else { + m2 := &Uint128Pair{} + if err := proto.Unmarshal(b, m2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(m1, m2) { + t.Errorf("expected %+v, got %+v", m1, m2) + } + } +} + +func TestNotPackedToPacked(t *testing.T) { + input := []uint64{1, 10e9} + notpacked := &NotPacked{Key: input} + if data, err := proto.Marshal(notpacked); err != nil { + t.Fatal(err) + } else { + packed := &Message{} + if err := proto.Unmarshal(data, packed); err != nil { + t.Fatal(err) + } + output := packed.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} + +func TestPackedToNotPacked(t *testing.T) { + input := []uint64{1, 10e9} + packed := &Message{Key: input} + if data, err := proto.Marshal(packed); err != nil { + t.Fatal(err) + } else { + notpacked := &NotPacked{} + if err := proto.Unmarshal(data, notpacked); err != nil { + t.Fatal(err) + } + output := notpacked.Key + if !reflect.DeepEqual(input, output) { + t.Fatalf("expected %#v, got %#v", input, output) + } + } +} diff --git a/vendor/github.com/gogo/protobuf/test/theproto3/theproto3.proto b/vendor/github.com/gogo/protobuf/test/theproto3/theproto3.proto new file mode 100644 index 000000000..0f4525cdc --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/theproto3/theproto3.proto @@ -0,0 +1,168 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2014 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package theproto3; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "github.com/gogo/protobuf/test/combos/both/thetest.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Message { + enum Humour { + UNKNOWN = 0; + PUNS = 1; + SLAPSTICK = 2; + BILL_BAILEY = 3; + } + + string name = 1; + Humour hilarity = 2; + uint32 height_in_cm = 3; + bytes data = 4; + int64 result_count = 7; + bool true_scotsman = 8; + float score = 9; + + repeated uint64 key = 5; + Nested nested = 6; + + map terrain = 10; + test.NinOptNative proto2_field = 11; + map proto2_value = 13; +} + +message Nested { + string bunny = 1; +} + +enum MapEnum { + MA = 0; + MB = 1; + MC = 2; +} + +message AllMaps { + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message AllMapsOrdered { + option (gogoproto.stable_marshaler) = true; + + map StringToDoubleMap = 1; + map StringToFloatMap = 2; + map Int32Map = 3; + map Int64Map = 4; + map Uint32Map = 5; + map Uint64Map = 6; + map Sint32Map = 7; + map Sint64Map = 8; + map Fixed32Map = 9; + map Sfixed32Map = 10; + map Fixed64Map = 11; + map Sfixed64Map = 12; + map BoolMap = 13; + map StringMap = 14; + map StringToBytesMap = 15; + map StringToEnumMap = 16; + map StringToMsgMap = 17; +} + +message MessageWithMap { + map name_mapping = 1; + map msg_mapping = 2; + map byte_mapping = 3; +} + +message FloatingPoint { + double f = 1; +} + +message Uint128Pair { + bytes left = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + bytes right = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message ContainsNestedMap { + message NestedMap { + map NestedMapField = 1; + } +} + +message NotPacked { + repeated uint64 key = 5 [packed=false]; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/thetest.proto b/vendor/github.com/gogo/protobuf/test/thetest.proto new file mode 100644 index 000000000..4d25c0b4e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/thetest.proto @@ -0,0 +1,649 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; +package test; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.face_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; +option (gogoproto.protosizer_all) = false; + +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.enum_stringer_all) = true; + +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +option (gogoproto.compare_all) = true; + +message NidOptNative { + optional double Field1 = 1 [(gogoproto.nullable) = false]; + optional float Field2 = 2 [(gogoproto.nullable) = false]; + optional int32 Field3 = 3 [(gogoproto.nullable) = false]; + optional int64 Field4 = 4 [(gogoproto.nullable) = false]; + optional uint32 Field5 = 5 [(gogoproto.nullable) = false]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false]; + optional sint64 Field8 = 8 [(gogoproto.nullable) = false]; + optional fixed32 Field9 = 9 [(gogoproto.nullable) = false]; + optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false]; + optional fixed64 Field11 = 11 [(gogoproto.nullable) = false]; + optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false]; + optional bool Field13 = 13 [(gogoproto.nullable) = false]; + optional string Field14 = 14 [(gogoproto.nullable) = false]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinOptNative { + optional double Field1 = 1; + optional float Field2 = 2; + optional int32 Field3 = 3; + optional int64 Field4 = 4; + optional uint32 Field5 = 5; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional sint64 Field8 = 8; + optional fixed32 Field9 = 9; + optional sfixed32 Field10 = 10; + optional fixed64 Field11 = 11; + optional sfixed64 Field12 = 12; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NidRepNative { + repeated double Field1 = 1 [(gogoproto.nullable) = false]; + repeated float Field2 = 2 [(gogoproto.nullable) = false]; + repeated int32 Field3 = 3 [(gogoproto.nullable) = false]; + repeated int64 Field4 = 4 [(gogoproto.nullable) = false]; + repeated uint32 Field5 = 5 [(gogoproto.nullable) = false]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false]; + repeated sint64 Field8 = 8 [(gogoproto.nullable) = false]; + repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false]; + repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false]; + repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false]; + repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false]; + repeated string Field14 = 14 [(gogoproto.nullable) = false]; + repeated bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinRepNative { + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated int32 Field3 = 3; + repeated int64 Field4 = 4; + repeated uint32 Field5 = 5; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated sint64 Field8 = 8; + repeated fixed32 Field9 = 9; + repeated sfixed32 Field10 = 10; + repeated fixed64 Field11 = 11; + repeated sfixed64 Field12 = 12; + repeated bool Field13 = 13; + repeated string Field14 = 14; + repeated bytes Field15 = 15; +} + +message NidRepPackedNative { + repeated double Field1 = 1 [(gogoproto.nullable) = false, packed = true]; + repeated float Field2 = 2 [(gogoproto.nullable) = false, packed = true]; + repeated int32 Field3 = 3 [(gogoproto.nullable) = false, packed = true]; + repeated int64 Field4 = 4 [(gogoproto.nullable) = false, packed = true]; + repeated uint32 Field5 = 5 [(gogoproto.nullable) = false, packed = true]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false, packed = true]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false, packed = true]; + repeated sint64 Field8 = 8 [(gogoproto.nullable) = false, packed = true]; + repeated fixed32 Field9 = 9 [(gogoproto.nullable) = false, packed = true]; + repeated sfixed32 Field10 = 10 [(gogoproto.nullable) = false, packed = true]; + repeated fixed64 Field11 = 11 [(gogoproto.nullable) = false, packed = true]; + repeated sfixed64 Field12 = 12 [(gogoproto.nullable) = false, packed = true]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false, packed = true]; +} + +message NinRepPackedNative { + repeated double Field1 = 1 [packed = true]; + repeated float Field2 = 2 [packed = true]; + repeated int32 Field3 = 3 [packed = true]; + repeated int64 Field4 = 4 [packed = true]; + repeated uint32 Field5 = 5 [packed = true]; + repeated uint64 Field6 = 6 [packed = true]; + repeated sint32 Field7 = 7 [packed = true]; + repeated sint64 Field8 = 8 [packed = true]; + repeated fixed32 Field9 = 9 [packed = true]; + repeated sfixed32 Field10 = 10 [packed = true]; + repeated fixed64 Field11 = 11 [packed = true]; + repeated sfixed64 Field12 = 12 [packed = true]; + repeated bool Field13 = 13 [packed = true]; +} + +message NidOptStruct { + optional double Field1 = 1 [(gogoproto.nullable) = false]; + optional float Field2 = 2 [(gogoproto.nullable) = false]; + optional NidOptNative Field3 = 3 [(gogoproto.nullable) = false]; + optional NinOptNative Field4 = 4 [(gogoproto.nullable) = false]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false]; + optional NidOptNative Field8 = 8 [(gogoproto.nullable) = false]; + optional bool Field13 = 13 [(gogoproto.nullable) = false]; + optional string Field14 = 14 [(gogoproto.nullable) = false]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinOptStruct { + optional double Field1 = 1; + optional float Field2 = 2; + optional NidOptNative Field3 = 3; + optional NinOptNative Field4 = 4; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional NidOptNative Field8 = 8; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NidRepStruct { + repeated double Field1 = 1 [(gogoproto.nullable) = false]; + repeated float Field2 = 2 [(gogoproto.nullable) = false]; + repeated NidOptNative Field3 = 3 [(gogoproto.nullable) = false]; + repeated NinOptNative Field4 = 4 [(gogoproto.nullable) = false]; + repeated uint64 Field6 = 6 [(gogoproto.nullable) = false]; + repeated sint32 Field7 = 7 [(gogoproto.nullable) = false]; + repeated NidOptNative Field8 = 8 [(gogoproto.nullable) = false]; + repeated bool Field13 = 13 [(gogoproto.nullable) = false]; + repeated string Field14 = 14 [(gogoproto.nullable) = false]; + repeated bytes Field15 = 15 [(gogoproto.nullable) = false]; +} + +message NinRepStruct { + repeated double Field1 = 1; + repeated float Field2 = 2; + repeated NidOptNative Field3 = 3; + repeated NinOptNative Field4 = 4; + repeated uint64 Field6 = 6; + repeated sint32 Field7 = 7; + repeated NidOptNative Field8 = 8; + repeated bool Field13 = 13; + repeated string Field14 = 14; + repeated bytes Field15 = 15; +} + +message NidEmbeddedStruct { + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NidOptNative Field200 = 200 [(gogoproto.nullable) = false]; + optional bool Field210 = 210 [(gogoproto.nullable) = false]; +} + +message NinEmbeddedStruct { + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NidOptNative Field200 = 200; + optional bool Field210 = 210; +} + +message NidNestedStruct { + optional NidOptStruct Field1 = 1 [(gogoproto.nullable) = false]; + repeated NidRepStruct Field2 = 2 [(gogoproto.nullable) = false]; +} + +message NinNestedStruct { + optional NinOptStruct Field1 = 1; + repeated NinRepStruct Field2 = 2; +} + +message NidOptCustom { + optional bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false]; + optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; +} + +message CustomDash { + optional bytes Value = 1 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom-dash-type.Bytes"]; +} + +message NinOptCustom { + optional bytes Id = 1 [(gogoproto.customtype) = "Uuid"]; + optional bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message NidRepCustom { + repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false]; + repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; +} + +message NinRepCustom { + repeated bytes Id = 1 [(gogoproto.customtype) = "Uuid"]; + repeated bytes Value = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message NinOptNativeUnion { + option (gogoproto.onlyone) = true; + optional double Field1 = 1; + optional float Field2 = 2; + optional int32 Field3 = 3; + optional int64 Field4 = 4; + optional uint32 Field5 = 5; + optional uint64 Field6 = 6; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NinOptStructUnion { + option (gogoproto.onlyone) = true; + optional double Field1 = 1; + optional float Field2 = 2; + optional NidOptNative Field3 = 3; + optional NinOptNative Field4 = 4; + optional uint64 Field6 = 6; + optional sint32 Field7 = 7; + optional bool Field13 = 13; + optional string Field14 = 14; + optional bytes Field15 = 15; +} + +message NinEmbeddedStructUnion { + option (gogoproto.onlyone) = true; + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NinOptNative Field200 = 200; + optional bool Field210 = 210; +} + +message NinNestedStructUnion { + option (gogoproto.onlyone) = true; + optional NinOptNativeUnion Field1 = 1; + optional NinOptStructUnion Field2 = 2; + optional NinEmbeddedStructUnion Field3 = 3; +} + +message Tree { + option (gogoproto.onlyone) = true; + optional OrBranch Or = 1; + optional AndBranch And = 2; + optional Leaf Leaf = 3; +} + +message OrBranch { + optional Tree Left = 1 [(gogoproto.nullable) = false]; + optional Tree Right = 2 [(gogoproto.nullable) = false]; +} + +message AndBranch { + optional Tree Left = 1 [(gogoproto.nullable) = false]; + optional Tree Right = 2 [(gogoproto.nullable) = false]; +} + +message Leaf { + optional int64 Value = 1 [(gogoproto.nullable) = false]; + optional string StrValue = 2 [(gogoproto.nullable) = false]; +} + +message DeepTree { + option (gogoproto.onlyone) = true; + optional ADeepBranch Down = 1; + optional AndDeepBranch And = 2; + optional DeepLeaf Leaf = 3; +} + +message ADeepBranch { + optional DeepTree Down = 2 [(gogoproto.nullable) = false]; +} + +message AndDeepBranch { + optional DeepTree Left = 1 [(gogoproto.nullable) = false]; + optional DeepTree Right = 2 [(gogoproto.nullable) = false]; +} + +message DeepLeaf { + optional Tree Tree = 1 [(gogoproto.nullable) = false]; +} + +message Nil { + +} + +enum TheTestEnum { + A = 0; + B = 1; + C = 2; +} + +enum AnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = false; + D = 10; + E = 11; +} + +// YetAnotherTestEnum is used to test cross-package import of custom name +// fields and default resolution. +enum YetAnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = false; + AA = 0; + BB = 1 [(gogoproto.enumvalue_customname) = "BetterYetBB"]; +} + +// YetAnotherTestEnum is used to test cross-package import of custom name +// fields and default resolution. +enum YetYetAnotherTestEnum { + option (gogoproto.goproto_enum_prefix) = true; + CC = 0; + DD = 1 [(gogoproto.enumvalue_customname) = "BetterYetDD"]; +} + +message NidOptEnum { + optional TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; +} + +message NinOptEnum { + optional TheTestEnum Field1 = 1; + optional YetAnotherTestEnum Field2 = 2; + optional YetYetAnotherTestEnum Field3 = 3; +} + +message NidRepEnum { + repeated TheTestEnum Field1 = 1 [(gogoproto.nullable) = false]; + repeated YetAnotherTestEnum Field2 = 2 [(gogoproto.nullable) = false]; + repeated YetYetAnotherTestEnum Field3 = 3 [(gogoproto.nullable) = false]; +} + +message NinRepEnum { + repeated TheTestEnum Field1 = 1; + repeated YetAnotherTestEnum Field2 = 2; + repeated YetYetAnotherTestEnum Field3 = 3; +} + +message NinOptEnumDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional TheTestEnum Field1 = 1 [default=C]; + optional YetAnotherTestEnum Field2 = 2 [default=BB]; + optional YetYetAnotherTestEnum Field3 = 3 [default=CC]; +} + +message AnotherNinOptEnum { + optional AnotherTestEnum Field1 = 1; + optional YetAnotherTestEnum Field2 = 2; + optional YetYetAnotherTestEnum Field3 = 3; +} + +message AnotherNinOptEnumDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional AnotherTestEnum Field1 = 1 [default=E]; + optional YetAnotherTestEnum Field2 = 2 [default=BB]; + optional YetYetAnotherTestEnum Field3 = 3 [default=CC]; +} + + +message Timer { + optional sfixed64 Time1 = 1 [(gogoproto.nullable) = false]; + optional sfixed64 Time2 = 2 [(gogoproto.nullable) = false]; + optional bytes Data = 3 [(gogoproto.nullable) = false]; +} + +message MyExtendable { + option (gogoproto.face) = false; + optional int64 Field1 = 1; + extensions 100 to 199; +} + +extend MyExtendable { + optional double FieldA = 100; + optional NinOptNative FieldB = 101; + optional NinEmbeddedStruct FieldC = 102; + repeated int64 FieldD = 104; + repeated NinOptNative FieldE = 105; +} + +message OtherExtenable { + option (gogoproto.face) = false; + optional int64 Field2 = 2; + extensions 14 to 16; + optional int64 Field13 = 13; + extensions 10 to 12; + optional MyExtendable M = 1; +} + +message NestedDefinition { + optional int64 Field1 = 1; + message NestedMessage { + optional fixed64 NestedField1 = 1; + optional NestedNestedMsg NNM = 2; + message NestedNestedMsg { + optional string NestedNestedField1 = 10; + } + } + enum NestedEnum { + TYPE_NESTED = 1; + } + optional NestedEnum EnumField = 2; + optional NestedMessage.NestedNestedMsg NNM = 3; + optional NestedMessage NM = 4; +} + +message NestedScope { + optional NestedDefinition.NestedMessage.NestedNestedMsg A = 1; + optional NestedDefinition.NestedEnum B = 2; + optional NestedDefinition.NestedMessage C = 3; +} + +message NinOptNativeDefault { + option (gogoproto.goproto_getters) = true; + option (gogoproto.face) = false; + optional double Field1 = 1 [default = 1234.1234]; + optional float Field2 = 2 [default = 1234.1234]; + optional int32 Field3 = 3 [default = 1234]; + optional int64 Field4 = 4 [default = 1234]; + optional uint32 Field5 = 5 [default = 1234]; + optional uint64 Field6 = 6 [default = 1234]; + optional sint32 Field7 = 7 [default = 1234]; + optional sint64 Field8 = 8 [default = 1234]; + optional fixed32 Field9 = 9 [default = 1234]; + optional sfixed32 Field10 = 10 [default = 1234]; + optional fixed64 Field11 = 11 [default = 1234]; + optional sfixed64 Field12 = 12 [default = 1234]; + optional bool Field13 = 13 [default = true]; + optional string Field14 = 14 [default = "1234"]; + optional bytes Field15 = 15; +} + +message CustomContainer { + optional NidOptCustom CustomStruct = 1 [(gogoproto.nullable) = false]; +} + +message CustomNameNidOptNative { + optional double Field1 = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldB"]; + optional int32 Field3 = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldC"]; + optional int64 Field4 = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldD"]; + optional uint32 Field5 = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldE"]; + optional uint64 Field6 = 6 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldF"]; + optional sint32 Field7 = 7 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldG"]; + optional sint64 Field8 = 8 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldH"]; + optional fixed32 Field9 = 9 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldI"]; + optional sfixed32 Field10 = 10 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldJ"]; + optional fixed64 Field11 = 11 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldK"]; + optional sfixed64 Field12 = 12 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldL"]; + optional bool Field13 = 13 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldM"]; + optional string Field14 = 14 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldN"]; + optional bytes Field15 = 15 [(gogoproto.nullable) = false, (gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinOptNative { + optional double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + optional int32 Field3 = 3 [(gogoproto.customname) = "FieldC"]; + optional int64 Field4 = 4 [(gogoproto.customname) = "FieldD"]; + optional uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"]; + optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"]; + optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"]; + optional sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"]; + optional fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"]; + optional sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"]; + optional fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"]; + optional sfixed64 Field12 = 12 [(gogoproto.customname) = "FielL"]; + optional bool Field13 = 13 [(gogoproto.customname) = "FieldM"]; + optional string Field14 = 14 [(gogoproto.customname) = "FieldN"]; + optional bytes Field15 = 15 [(gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinRepNative { + repeated double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + repeated float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + repeated int32 Field3 = 3 [(gogoproto.customname) = "FieldC"]; + repeated int64 Field4 = 4 [(gogoproto.customname) = "FieldD"]; + repeated uint32 Field5 = 5 [(gogoproto.customname) = "FieldE"]; + repeated uint64 Field6 = 6 [(gogoproto.customname) = "FieldF"]; + repeated sint32 Field7 = 7 [(gogoproto.customname) = "FieldG"]; + repeated sint64 Field8 = 8 [(gogoproto.customname) = "FieldH"]; + repeated fixed32 Field9 = 9 [(gogoproto.customname) = "FieldI"]; + repeated sfixed32 Field10 = 10 [(gogoproto.customname) = "FieldJ"]; + repeated fixed64 Field11 = 11 [(gogoproto.customname) = "FieldK"]; + repeated sfixed64 Field12 = 12 [(gogoproto.customname) = "FieldL"]; + repeated bool Field13 = 13 [(gogoproto.customname) = "FieldM"]; + repeated string Field14 = 14 [(gogoproto.customname) = "FieldN"]; + repeated bytes Field15 = 15 [(gogoproto.customname) = "FieldO"]; +} + +message CustomNameNinStruct { + optional double Field1 = 1 [(gogoproto.customname) = "FieldA"]; + optional float Field2 = 2 [(gogoproto.customname) = "FieldB"]; + optional NidOptNative Field3 = 3 [(gogoproto.customname) = "FieldC"]; + repeated NinOptNative Field4 = 4 [(gogoproto.customname) = "FieldD"]; + optional uint64 Field6 = 6 [(gogoproto.customname) = "FieldE"]; + optional sint32 Field7 = 7 [(gogoproto.customname) = "FieldF"]; + optional NidOptNative Field8 = 8 [(gogoproto.customname) = "FieldG"]; + optional bool Field13 = 13 [(gogoproto.customname) = "FieldH"]; + optional string Field14 = 14 [(gogoproto.customname) = "FieldI"]; + optional bytes Field15 = 15 [(gogoproto.customname) = "FieldJ"]; +} + +message CustomNameCustomType { + optional bytes Id = 1 [(gogoproto.customname) = "FieldA", (gogoproto.customtype) = "Uuid"]; + optional bytes Value = 2 [(gogoproto.customname) = "FieldB", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; + repeated bytes Ids = 3 [(gogoproto.customname) = "FieldC", (gogoproto.customtype) = "Uuid"]; + repeated bytes Values = 4 [(gogoproto.customname) = "FieldD", (gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128"]; +} + +message CustomNameNinEmbeddedStructUnion { + option (gogoproto.onlyone) = true; + optional NidOptNative Field1 = 1 [(gogoproto.embed) = true]; + optional NinOptNative Field200 = 200 [(gogoproto.customname) = "FieldA"]; + optional bool Field210 = 210 [(gogoproto.customname) = "FieldB"]; +} + +message CustomNameEnum { + optional TheTestEnum Field1 = 1 [(gogoproto.customname) = "FieldA"]; + repeated TheTestEnum Field2 = 2 [(gogoproto.customname) = "FieldB"]; +} + +message NoExtensionsMap { + option (gogoproto.face) = false; + option (gogoproto.goproto_extensions_map) = false; + optional int64 Field1 = 1; + extensions 100 to 199; +} + +extend NoExtensionsMap { + optional double FieldA1 = 100; + optional NinOptNative FieldB1 = 101; + optional NinEmbeddedStruct FieldC1 = 102; +} + +message Unrecognized { + option (gogoproto.goproto_unrecognized) = false; + optional string Field1 = 1; +} + +message UnrecognizedWithInner { + message Inner { + option (gogoproto.goproto_unrecognized) = false; + optional uint32 Field1 = 1; + } + + repeated Inner embedded = 1; + optional string Field2 = 2; +} + +message UnrecognizedWithEmbed { + message Embedded { + option (gogoproto.goproto_unrecognized) = false; + optional uint32 Field1 = 1; + } + + optional Embedded embedded = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; + optional string Field2 = 2; +} + +message Node { + optional string Label = 1; + repeated Node Children = 2; +} + +message NonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message NidOptNonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false]; +} + +message NinOptNonByteCustomType { + optional ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message NidRepNonByteCustomType { + repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T", (gogoproto.nullable) = false]; +} + +message NinRepNonByteCustomType { + repeated ProtoType Field1 = 1 [(gogoproto.customtype) = "T"]; +} + +message ProtoType { + optional string Field2 = 1; +} diff --git a/vendor/github.com/gogo/protobuf/test/thetestpb_test.go b/vendor/github.com/gogo/protobuf/test/thetestpb_test.go new file mode 100644 index 000000000..6bd5195c6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/thetestpb_test.go @@ -0,0 +1,16045 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: thetest.proto + +/* +Package test is a generated protocol buffer package. + +It is generated from these files: + thetest.proto + +It has these top-level messages: + NidOptNative + NinOptNative + NidRepNative + NinRepNative + NidRepPackedNative + NinRepPackedNative + NidOptStruct + NinOptStruct + NidRepStruct + NinRepStruct + NidEmbeddedStruct + NinEmbeddedStruct + NidNestedStruct + NinNestedStruct + NidOptCustom + CustomDash + NinOptCustom + NidRepCustom + NinRepCustom + NinOptNativeUnion + NinOptStructUnion + NinEmbeddedStructUnion + NinNestedStructUnion + Tree + OrBranch + AndBranch + Leaf + DeepTree + ADeepBranch + AndDeepBranch + DeepLeaf + Nil + NidOptEnum + NinOptEnum + NidRepEnum + NinRepEnum + NinOptEnumDefault + AnotherNinOptEnum + AnotherNinOptEnumDefault + Timer + MyExtendable + OtherExtenable + NestedDefinition + NestedScope + NinOptNativeDefault + CustomContainer + CustomNameNidOptNative + CustomNameNinOptNative + CustomNameNinRepNative + CustomNameNinStruct + CustomNameCustomType + CustomNameNinEmbeddedStructUnion + CustomNameEnum + NoExtensionsMap + Unrecognized + UnrecognizedWithInner + UnrecognizedWithEmbed + Node + NonByteCustomType + NidOptNonByteCustomType + NinOptNonByteCustomType + NidRepNonByteCustomType + NinRepNonByteCustomType + ProtoType +*/ +package test + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepPackedNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepPackedNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepPackedNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepPackedNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepPackedNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidEmbeddedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinEmbeddedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinEmbeddedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidNestedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidNestedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinNestedStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinNestedStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomDashProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomDashProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomDash(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomDash{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepCustomProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepCustomProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepCustom(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepCustom{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNativeUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinNestedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinNestedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinNestedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinNestedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkTreeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTreeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Tree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOrBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOrBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOrBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OrBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAndBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAndBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkLeafProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkLeafProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Leaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkDeepTreeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepTreeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDeepTree(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepTree{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkADeepBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkADeepBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedADeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ADeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAndDeepBranchProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAndDeepBranchProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAndDeepBranch(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AndDeepBranch{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkDeepLeafProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDeepLeafProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDeepLeaf(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DeepLeaf{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNilProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNilProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNil(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Nil{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAnotherNinOptEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAnotherNinOptEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkAnotherNinOptEnumDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkAnotherNinOptEnumDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedAnotherNinOptEnumDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &AnotherNinOptEnumDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkTimerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkTimerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedTimer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Timer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMyExtendableProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMyExtendableProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMyExtendable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MyExtendable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOtherExtenableProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOtherExtenableProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOtherExtenable(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OtherExtenable{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinitionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinitionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinition_NestedMessageProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessageProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition_NestedMessage(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNestedScopeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNestedScopeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNestedScope(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NestedScope{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNativeDefaultProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNativeDefaultProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNativeDefault(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNativeDefault{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomContainerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomContainerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomContainer(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomContainer{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNidOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNidOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNidOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNidOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinOptNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinOptNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinOptNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinOptNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinRepNativeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinRepNativeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinRepNative(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinRepNative{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinStructProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinStructProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinStruct(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinStruct{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameNinEmbeddedStructUnionProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameNinEmbeddedStructUnion{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkCustomNameEnumProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkCustomNameEnumProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedCustomNameEnum(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &CustomNameEnum{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNoExtensionsMapProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNoExtensionsMapProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNoExtensionsMap(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NoExtensionsMap{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognized(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Unrecognized{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithInnerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInnerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithInner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithInner_InnerProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithInner_InnerProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithInner_Inner(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithInner_Inner{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithEmbedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithEmbed(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &UnrecognizedWithEmbed_Embedded{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNodeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Node, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNodeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNode(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Node{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinOptNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinOptNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinOptNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinOptNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNidRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNidRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNidRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NidRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkNinRepNonByteCustomTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkNinRepNonByteCustomTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedNinRepNonByteCustomType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &NinRepNonByteCustomType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkProtoTypeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedProtoType(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoType{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepPackedNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepPackedNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepPackedNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidEmbeddedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidNestedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomDashJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomDash{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepCustomJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepCustom{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinEmbeddedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinNestedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinNestedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Tree{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOrBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OrBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Leaf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepTreeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepTree{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestADeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ADeepBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAndDeepBranchJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AndDeepBranch{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDeepLeafJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DeepLeaf{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNilJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Nil{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptEnumDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAnotherNinOptEnumDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &AnotherNinOptEnumDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestTimerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Timer{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMyExtendableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MyExtendable{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOtherExtenableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OtherExtenable{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinitionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedScopeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedScope{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNativeDefaultJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNativeDefault{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomContainerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomContainer{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNidOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNidOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinOptNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinOptNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinRepNativeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinRepNative{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinStructJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinStruct{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCustomNameEnumJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &CustomNameEnum{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNoExtensionsMapJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NoExtensionsMap{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Unrecognized{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithInner_InnerJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithInner_Inner{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNodeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Node{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidOptNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinOptNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinOptNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NidRepNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNinRepNonByteCustomTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NinRepNonByteCustomType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoType{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepPackedNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepPackedNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinEmbeddedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinNestedStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomDash{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomDashProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomDash{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepCustomProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepCustom{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNativeUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNativeUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinNestedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinNestedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinNestedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Tree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Tree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OrBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOrBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OrBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AndBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AndBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Leaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Leaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DeepTree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepTreeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DeepTree{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ADeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestADeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ADeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AndDeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAndDeepBranchProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AndDeepBranch{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DeepLeaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDeepLeafProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DeepLeaf{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Nil{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNilProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Nil{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AnotherNinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AnotherNinOptEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAnotherNinOptEnumDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &AnotherNinOptEnumDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Timer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestTimerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Timer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MyExtendable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMyExtendableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MyExtendable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OtherExtenable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOtherExtenableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OtherExtenable{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NestedScope{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedScopeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NestedScope{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNativeDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNativeDefaultProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNativeDefault{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomContainer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomContainerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomContainer{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNidOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNidOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinOptNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinOptNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinRepNativeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinRepNative{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinStructProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinStruct{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameNinEmbeddedStructUnionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &CustomNameEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCustomNameEnumProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + dAtA := proto.CompactTextString(p) + msg := &CustomNameEnum{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NoExtensionsMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNoExtensionsMapProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NoExtensionsMap{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Unrecognized{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Unrecognized{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithInner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithInner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithInner_InnerProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithInner_Inner{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedWithEmbed_EmbeddedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Node{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNodeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Node{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinOptNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinOptNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NidRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NidRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NinRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNinRepNonByteCustomTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NinRepNonByteCustomType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ProtoType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ProtoType{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNidOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepPackedNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepPackedNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepPackedNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidEmbeddedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidNestedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomDashCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomDash(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepCustomCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepCustom(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinEmbeddedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinNestedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinNestedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTreeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOrBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOrBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestLeafCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepTreeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepTree(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestADeepBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedADeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAndDeepBranchCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAndDeepBranch(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestDeepLeafCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedDeepLeaf(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNilCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNil(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptEnumDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestAnotherNinOptEnumDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedAnotherNinOptEnumDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestTimerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedTimer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestMyExtendableCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedMyExtendable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestOtherExtenableCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedOtherExtenable(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinitionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessageCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNestedScopeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNestedScope(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNativeDefaultCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNativeDefault(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomContainerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomContainer(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNidOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNidOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinOptNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinOptNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinRepNativeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinRepNative(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinStructCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinStruct(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameNinEmbeddedStructUnionCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestCustomNameEnumCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedCustomNameEnum(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNoExtensionsMapCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNoExtensionsMap(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognized(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInnerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithInner_InnerCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNodeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNode(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidOptNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinOptNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinOptNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNidRepNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNidRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestNinRepNonByteCustomTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedNinRepNonByteCustomType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypeCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoType(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestThetestDescription(t *testing.T) { + ThetestDescription() +} +func TestNidOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepPackedNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepPackedNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepPackedNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidEmbeddedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidNestedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomDashVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomDash{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepCustomVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepCustom{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinNestedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinNestedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTreeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Tree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOrBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OrBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestLeafVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Leaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepTreeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepTree{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestADeepBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ADeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAndDeepBranchVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AndDeepBranch{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDeepLeafVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DeepLeaf{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNilVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Nil{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAnotherNinOptEnumDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &AnotherNinOptEnumDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestTimerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Timer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMyExtendableVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MyExtendable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOtherExtenableVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OtherExtenable{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinitionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessageVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedDefinition_NestedMessage_NestedNestedMsg{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNestedScopeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NestedScope{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNativeDefaultVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNativeDefault{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomContainerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomContainer{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNidOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNidOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinOptNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinOptNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinRepNativeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinRepNative{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinStructVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinStruct{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameNinEmbeddedStructUnionVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameNinEmbeddedStructUnion{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCustomNameEnumVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &CustomNameEnum{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNoExtensionsMapVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NoExtensionsMap{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Unrecognized{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInnerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithInner_InnerVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithInner_Inner{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnrecognizedWithEmbed_Embedded{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNodeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Node{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinOptNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinOptNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NidRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNinRepNonByteCustomTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NinRepNonByteCustomType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoType{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNidOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepPackedNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepPackedNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidEmbeddedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidNestedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomDashFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepCustomFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNativeUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTreeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestOrBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestLeafFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepTreeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestADeepBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAndDeepBranchFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestDeepLeafFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNilFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestAnotherNinOptEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestTimerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinitionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessageFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNestedScopeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomContainerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNidOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinOptNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinRepNativeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinStructFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestCustomNameEnumFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInnerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithInner_InnerFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestUnrecognizedWithEmbed_EmbeddedFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNodeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinOptNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidRepNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNinRepNonByteCustomTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestProtoTypeFace(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, true) + msg := p.TestProto() + if !p.Equal(msg) { + t.Fatalf("%#v !Face Equal %#v", msg, p) + } +} +func TestNidOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepPackedNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepPackedNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidEmbeddedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidNestedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomDashGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepCustomGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinEmbeddedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinNestedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTreeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOrBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestLeafGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepTreeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestADeepBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAndDeepBranchGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDeepLeafGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNilGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptEnumDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAnotherNinOptEnumDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestTimerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestMyExtendableGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOtherExtenableGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinitionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessageGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedScopeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNativeDefaultGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomContainerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNidOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinOptNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinRepNativeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinStructGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameNinEmbeddedStructUnionGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCustomNameEnumGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNoExtensionsMapGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInnerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithInner_InnerGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnrecognizedWithEmbed_EmbeddedGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNodeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinOptNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidRepNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNinRepNonByteCustomTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestProtoTypeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepPackedNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepPackedNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepPackedNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepPackedNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepPackedNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepPackedNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepPackedNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidEmbeddedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidEmbeddedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidNestedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidNestedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomDashSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomDash(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomDashSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomDash, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomDash(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepCustomSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepCustom(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepCustomSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepCustom, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepCustom(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinEmbeddedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinNestedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinNestedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinNestedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinNestedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinNestedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTree(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTreeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Tree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOrBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOrBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOrBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OrBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOrBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedLeaf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkLeafSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Leaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepTreeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepTree(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepTreeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepTree, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepTree(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestADeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedADeepBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkADeepBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ADeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedADeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAndDeepBranchSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAndDeepBranch(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAndDeepBranchSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AndDeepBranch, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAndDeepBranch(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDeepLeafSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDeepLeaf(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDeepLeafSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DeepLeaf, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDeepLeaf(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNilSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNil(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNilSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Nil, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNil(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptEnumDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptEnumDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestAnotherNinOptEnumDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedAnotherNinOptEnumDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkAnotherNinOptEnumDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*AnotherNinOptEnumDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedAnotherNinOptEnumDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestTimerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedTimer(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkTimerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Timer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedTimer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMyExtendableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMyExtendable(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMyExtendableSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MyExtendable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMyExtendable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOtherExtenableSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOtherExtenable(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOtherExtenableSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OtherExtenable, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOtherExtenable(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinitionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinitionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessageSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessageSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedDefinition_NestedMessage_NestedNestedMsgSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedDefinition_NestedMessage_NestedNestedMsgSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedDefinition_NestedMessage_NestedNestedMsg, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNestedScopeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNestedScope(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNestedScopeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NestedScope, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNestedScope(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNativeDefaultSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNativeDefault(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNativeDefaultSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNativeDefault, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNativeDefault(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomContainerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomContainer(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomContainerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomContainer, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomContainer(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNidOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNidOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNidOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNidOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNidOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinOptNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinOptNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinOptNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinOptNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinOptNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinRepNativeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinRepNative(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinRepNativeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinRepNative, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinRepNative(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinStructSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinStruct(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinStructSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinStruct, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinStruct(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameNinEmbeddedStructUnionSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameNinEmbeddedStructUnionSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameNinEmbeddedStructUnion, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestCustomNameEnumSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedCustomNameEnum(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkCustomNameEnumSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*CustomNameEnum, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedCustomNameEnum(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNoExtensionsMapSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNoExtensionsMap(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNoExtensionsMapSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NoExtensionsMap, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNoExtensionsMap(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognized(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Unrecognized, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognized(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInnerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithInner_InnerSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithInner_InnerSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithInner_Inner, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithInner_Inner(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestUnrecognizedWithEmbed_EmbeddedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkUnrecognizedWithEmbed_EmbeddedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*UnrecognizedWithEmbed_Embedded, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNodeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNode(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNodeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Node, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNode(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidOptNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidOptNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinOptNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinOptNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinOptNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinOptNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinOptNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNidRepNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNidRepNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NidRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNidRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNinRepNonByteCustomTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNinRepNonByteCustomType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkNinRepNonByteCustomTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*NinRepNonByteCustomType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedNinRepNonByteCustomType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypeSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoType(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypeSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoType, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoType(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestNidOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepPackedNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepPackedNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepPackedNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidEmbeddedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidNestedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomDashStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomDash(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepCustomStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepCustom(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinEmbeddedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinNestedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTreeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOrBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOrBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestLeafStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepTreeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestADeepBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedADeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAndDeepBranchStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAndDeepBranch(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDeepLeafStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepLeaf(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNilStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNil(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptEnumDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAnotherNinOptEnumDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedAnotherNinOptEnumDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestTimerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTimer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestMyExtendableStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMyExtendable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOtherExtenableStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOtherExtenable(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinitionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessageStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedDefinition_NestedMessage_NestedNestedMsgStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition_NestedMessage_NestedNestedMsg(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNestedScopeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedScope(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeDefaultStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeDefault(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomContainerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomContainer(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNidOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNidOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinOptNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinOptNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinRepNativeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinRepNative(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinStructStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinStruct(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameNinEmbeddedStructUnionStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCustomNameEnumStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameEnum(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNoExtensionsMapStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNoExtensionsMap(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognized(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInnerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithInner_InnerStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithInner_Inner(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnrecognizedWithEmbed_EmbeddedStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnrecognizedWithEmbed_Embedded(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNodeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNode(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidOptNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNidRepNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNidRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinRepNonByteCustomTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinRepNonByteCustomType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestProtoTypeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoType(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestNinOptNativeUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptNativeUnion(popr, true) + v := p.GetValue() + msg := &NinOptNativeUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinOptStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinOptStructUnion(popr, true) + v := p.GetValue() + msg := &NinOptStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &NinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestNinNestedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNinNestedStructUnion(popr, true) + v := p.GetValue() + msg := &NinNestedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestTreeOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedTree(popr, true) + v := p.GetValue() + msg := &Tree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestDeepTreeOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDeepTree(popr, true) + v := p.GetValue() + msg := &DeepTree{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} +func TestCustomNameNinEmbeddedStructUnionOnlyOne(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedCustomNameNinEmbeddedStructUnion(popr, true) + v := p.GetValue() + msg := &CustomNameNinEmbeddedStructUnion{} + if !msg.SetValue(v) { + t.Fatalf("OnlyOne: Could not set Value") + } + if !p.Equal(msg) { + t.Fatalf("%#v !OnlyOne Equal %#v", msg, p) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/typedecl/Makefile b/vendor/github.com/gogo/protobuf/test/typedecl/Makefile new file mode 100644 index 000000000..5b924dfe7 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedecl/Makefile @@ -0,0 +1,3 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. typedecl.proto diff --git a/vendor/github.com/gogo/protobuf/test/typedecl/typedecl.proto b/vendor/github.com/gogo/protobuf/test/typedecl/typedecl.proto new file mode 100644 index 000000000..73f9178e8 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedecl/typedecl.proto @@ -0,0 +1,34 @@ +syntax = "proto3"; + +package typedecl; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message Dropped { + option (gogoproto.typedecl) = false; + string name = 1; + int32 age = 2; +} + +message DroppedWithoutGetters { + option (gogoproto.typedecl) = false; + option (gogoproto.goproto_getters) = false; + int64 height = 1; + int64 width = 2; +} + +message Kept { + string name = 1; + int32 age = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/typedecl/typedeclpb_test.go b/vendor/github.com/gogo/protobuf/test/typedecl/typedeclpb_test.go new file mode 100644 index 000000000..7a686559e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedecl/typedeclpb_test.go @@ -0,0 +1,655 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: typedecl.proto + +/* +Package typedecl is a generated protocol buffer package. + +It is generated from these files: + typedecl.proto + +It has these top-level messages: + Dropped + DroppedWithoutGetters + Kept +*/ +package typedecl + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestDroppedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDropped(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Dropped{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedWithoutGettersMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedWithoutGettersProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedWithoutGettersProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDroppedWithoutGetters(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DroppedWithoutGetters{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKeptMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKeptProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKeptProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedKept(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Kept{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedWithoutGettersJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKeptJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Dropped{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Dropped{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DroppedWithoutGetters{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DroppedWithoutGetters{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Kept{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Kept{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDropped(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Dropped{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedWithoutGettersVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DroppedWithoutGetters{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKeptVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKept(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Kept{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedWithoutGettersSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKeptSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/typedecl_all/Makefile b/vendor/github.com/gogo/protobuf/test/typedecl_all/Makefile new file mode 100644 index 000000000..994417461 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedecl_all/Makefile @@ -0,0 +1,3 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. typedeclall.proto diff --git a/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclall.proto b/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclall.proto new file mode 100644 index 000000000..76636e474 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclall.proto @@ -0,0 +1,34 @@ +syntax = "proto3"; + +package typedeclall; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; +option (gogoproto.typedecl_all) = false; + +message Dropped { + string name = 1; + int32 age = 2; +} + +message DroppedWithoutGetters { + option (gogoproto.goproto_getters) = false; + int64 height = 1; + int64 width = 2; +} + +message Kept { + option (gogoproto.typedecl) = true; + string name = 1; + int32 age = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclallpb_test.go b/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclallpb_test.go new file mode 100644 index 000000000..5693f580f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedecl_all/typedeclallpb_test.go @@ -0,0 +1,655 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: typedeclall.proto + +/* +Package typedeclall is a generated protocol buffer package. + +It is generated from these files: + typedeclall.proto + +It has these top-level messages: + Dropped + DroppedWithoutGetters + Kept +*/ +package typedeclall + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestDroppedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDropped(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Dropped{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDroppedWithoutGettersMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkDroppedWithoutGettersProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkDroppedWithoutGettersProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedDroppedWithoutGetters(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &DroppedWithoutGetters{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKeptMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKeptProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKeptProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedKept(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Kept{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Dropped{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedWithoutGettersJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &DroppedWithoutGetters{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKeptJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Kept{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDroppedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Dropped{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Dropped{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &DroppedWithoutGetters{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedWithoutGettersProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + dAtA := proto.CompactTextString(p) + msg := &DroppedWithoutGetters{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Kept{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKeptProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Kept{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDroppedVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDropped(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Dropped{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedWithoutGettersVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedDroppedWithoutGetters(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &DroppedWithoutGetters{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKeptVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKept(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Kept{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDroppedSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDropped(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Dropped, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDropped(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestDroppedWithoutGettersSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedDroppedWithoutGetters(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkDroppedWithoutGettersSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*DroppedWithoutGetters, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedDroppedWithoutGetters(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestKeptSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKept(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKeptSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Kept, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKept(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/typedeclimport/Makefile b/vendor/github.com/gogo/protobuf/test/typedeclimport/Makefile new file mode 100644 index 000000000..d8a8e1f3f --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedeclimport/Makefile @@ -0,0 +1,4 @@ +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. typedeclimport.proto + protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. ./subpkg/subpkg.proto \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/typedeclimport/subpkg/subpkg.proto b/vendor/github.com/gogo/protobuf/test/typedeclimport/subpkg/subpkg.proto new file mode 100644 index 000000000..2e20c9e7b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedeclimport/subpkg/subpkg.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package subpkg; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.marshaler_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; + +message AnotherMessage { + string foo = 1; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport.proto b/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport.proto new file mode 100644 index 000000000..8ab8dbf24 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package typedeclimport; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +import "github.com/gogo/protobuf/test/typedeclimport/subpkg/subpkg.proto"; + +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; + +message SomeMessage { + option (gogoproto.typedecl) = false; + subpkg.AnotherMessage imported = 1 [(gogoproto.nullable) = false]; +} \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport_test.go b/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport_test.go new file mode 100644 index 000000000..bea4cae73 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/typedeclimport/typedeclimport_test.go @@ -0,0 +1,7 @@ +package typedeclimport + +import "testing" + +func Test(t *testing.T) { + // No need to do anything, if this test runs, it means it works +} diff --git a/vendor/github.com/gogo/protobuf/test/types/Makefile b/vendor/github.com/gogo/protobuf/test/types/Makefile new file mode 100644 index 000000000..7f489b367 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/Makefile @@ -0,0 +1,39 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2016, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-combo + go install github.com/gogo/protobuf/protoc-gen-gogo + protoc-gen-combo --version="3.0.0" --gogo_out=\ + Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:. \ + --proto_path=../../../../../:../../protobuf/:. types.proto + find combos -type d -not -name combos -exec cp types_test.go.in {}/types_test.go \; diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/both/types.proto b/vendor/github.com/gogo/protobuf/test/types/combos/both/types.proto new file mode 100644 index 000000000..6c0377763 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/both/types.proto @@ -0,0 +1,131 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package types; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +//import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +//import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message KnownTypes { + option (gogoproto.compare) = true; + google.protobuf.Duration dur = 1; + google.protobuf.Timestamp ts = 2; + google.protobuf.DoubleValue dbl = 3; + google.protobuf.FloatValue flt = 4; + google.protobuf.Int64Value i64 = 5; + google.protobuf.UInt64Value u64 = 6; + google.protobuf.Int32Value i32 = 7; + google.protobuf.UInt32Value u32 = 8; + google.protobuf.BoolValue bool = 9; + google.protobuf.StringValue str = 10; + google.protobuf.BytesValue bytes = 11; + + // TODO uncomment this once https://github.com/gogo/protobuf/issues/197 is fixed + // google.protobuf.Struct st = 12; + // google.protobuf.Any an = 14; +} + +message ProtoTypes { + // TODO this should be a compare_all at the top of the file once time.Time, time.Duration, oneof and map is supported by compare + option (gogoproto.compare) = true; + google.protobuf.Timestamp nullableTimestamp = 1; + google.protobuf.Duration nullableDuration = 2; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.nullable) = false]; +} + +message StdTypes { + google.protobuf.Timestamp nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration nullableDuration = 2 [(gogoproto.stdduration) = true]; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message RepProtoTypes { + option (gogoproto.compare) = true; + repeated google.protobuf.Timestamp nullableTimestamps = 1; + repeated google.protobuf.Duration nullableDurations = 2; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.nullable) = false]; +} + +message RepStdTypes { + repeated google.protobuf.Timestamp nullableTimestamps = 1 [(gogoproto.stdtime) = true]; + repeated google.protobuf.Duration nullableDurations = 2 [(gogoproto.stdduration) = true]; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message MapProtoTypes { + map nullableTimestamp = 1; + map timestamp = 2 [(gogoproto.nullable) = false]; + + map nullableDuration = 3; + map duration = 4 [(gogoproto.nullable) = false]; +} + +message MapStdTypes { + map nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + map timestamp = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + + map nullableDuration = 3 [(gogoproto.stdduration) = true]; + map duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message OneofProtoTypes { + oneof OneOfProtoTimes { + google.protobuf.Timestamp timestamp = 1; + google.protobuf.Duration duration = 2; + } +} + +message OneofStdTypes { + oneof OneOfStdTimes { + google.protobuf.Timestamp timestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration duration = 2 [(gogoproto.stdduration) = true]; + } +} + diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/both/types_test.go b/vendor/github.com/gogo/protobuf/test/types/combos/both/types_test.go new file mode 100644 index 000000000..7d24f58e6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/both/types_test.go @@ -0,0 +1,242 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + math_rand "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" +) + +func TestFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/both/typespb_test.go b/vendor/github.com/gogo/protobuf/test/types/combos/both/typespb_test.go new file mode 100644 index 000000000..5b1fb2b45 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/both/typespb_test.go @@ -0,0 +1,1984 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/both/types.proto + +/* +Package types is a generated protocol buffer package. + +It is generated from these files: + combos/both/types.proto + +It has these top-level messages: + KnownTypes + ProtoTypes + StdTypes + RepProtoTypes + RepStdTypes + MapProtoTypes + MapStdTypes + OneofProtoTypes + OneofStdTypes +*/ +package types + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestKnownTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKnownTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKnownTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKnownTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedKnownTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &KnownTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRepProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRepProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedRepProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRepStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMapProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMapProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOneofProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOneofProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKnownTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKnownTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &KnownTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &KnownTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &RepProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &RepProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedKnownTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestRepProtoTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedRepProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestKnownTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKnownTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKnownTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types.proto b/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types.proto new file mode 100644 index 000000000..05cb95567 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types.proto @@ -0,0 +1,131 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package types; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +//import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +//import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message KnownTypes { + option (gogoproto.compare) = true; + google.protobuf.Duration dur = 1; + google.protobuf.Timestamp ts = 2; + google.protobuf.DoubleValue dbl = 3; + google.protobuf.FloatValue flt = 4; + google.protobuf.Int64Value i64 = 5; + google.protobuf.UInt64Value u64 = 6; + google.protobuf.Int32Value i32 = 7; + google.protobuf.UInt32Value u32 = 8; + google.protobuf.BoolValue bool = 9; + google.protobuf.StringValue str = 10; + google.protobuf.BytesValue bytes = 11; + + // TODO uncomment this once https://github.com/gogo/protobuf/issues/197 is fixed + // google.protobuf.Struct st = 12; + // google.protobuf.Any an = 14; +} + +message ProtoTypes { + // TODO this should be a compare_all at the top of the file once time.Time, time.Duration, oneof and map is supported by compare + option (gogoproto.compare) = true; + google.protobuf.Timestamp nullableTimestamp = 1; + google.protobuf.Duration nullableDuration = 2; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.nullable) = false]; +} + +message StdTypes { + google.protobuf.Timestamp nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration nullableDuration = 2 [(gogoproto.stdduration) = true]; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message RepProtoTypes { + option (gogoproto.compare) = true; + repeated google.protobuf.Timestamp nullableTimestamps = 1; + repeated google.protobuf.Duration nullableDurations = 2; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.nullable) = false]; +} + +message RepStdTypes { + repeated google.protobuf.Timestamp nullableTimestamps = 1 [(gogoproto.stdtime) = true]; + repeated google.protobuf.Duration nullableDurations = 2 [(gogoproto.stdduration) = true]; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message MapProtoTypes { + map nullableTimestamp = 1; + map timestamp = 2 [(gogoproto.nullable) = false]; + + map nullableDuration = 3; + map duration = 4 [(gogoproto.nullable) = false]; +} + +message MapStdTypes { + map nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + map timestamp = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + + map nullableDuration = 3 [(gogoproto.stdduration) = true]; + map duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message OneofProtoTypes { + oneof OneOfProtoTimes { + google.protobuf.Timestamp timestamp = 1; + google.protobuf.Duration duration = 2; + } +} + +message OneofStdTypes { + oneof OneOfStdTimes { + google.protobuf.Timestamp timestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration duration = 2 [(gogoproto.stdduration) = true]; + } +} + diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types_test.go b/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types_test.go new file mode 100644 index 000000000..7d24f58e6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/types_test.go @@ -0,0 +1,242 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + math_rand "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" +) + +func TestFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/typespb_test.go b/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/typespb_test.go new file mode 100644 index 000000000..5a2bac94a --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/marshaler/typespb_test.go @@ -0,0 +1,1984 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/marshaler/types.proto + +/* +Package types is a generated protocol buffer package. + +It is generated from these files: + combos/marshaler/types.proto + +It has these top-level messages: + KnownTypes + ProtoTypes + StdTypes + RepProtoTypes + RepStdTypes + MapProtoTypes + MapStdTypes + OneofProtoTypes + OneofStdTypes +*/ +package types + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestKnownTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestKnownTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkKnownTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKnownTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedKnownTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &KnownTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRepProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRepProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedRepProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestRepStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMapProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMapProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestMapStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofProtoTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOneofProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOneofProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOneofStdTypesMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKnownTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKnownTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &KnownTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &KnownTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &RepProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &RepProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedKnownTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestRepProtoTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedRepProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestKnownTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKnownTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKnownTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/neither/types.proto b/vendor/github.com/gogo/protobuf/test/types/combos/neither/types.proto new file mode 100644 index 000000000..3c26fae20 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/neither/types.proto @@ -0,0 +1,131 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package types; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +//import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +//import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message KnownTypes { + option (gogoproto.compare) = true; + google.protobuf.Duration dur = 1; + google.protobuf.Timestamp ts = 2; + google.protobuf.DoubleValue dbl = 3; + google.protobuf.FloatValue flt = 4; + google.protobuf.Int64Value i64 = 5; + google.protobuf.UInt64Value u64 = 6; + google.protobuf.Int32Value i32 = 7; + google.protobuf.UInt32Value u32 = 8; + google.protobuf.BoolValue bool = 9; + google.protobuf.StringValue str = 10; + google.protobuf.BytesValue bytes = 11; + + // TODO uncomment this once https://github.com/gogo/protobuf/issues/197 is fixed + // google.protobuf.Struct st = 12; + // google.protobuf.Any an = 14; +} + +message ProtoTypes { + // TODO this should be a compare_all at the top of the file once time.Time, time.Duration, oneof and map is supported by compare + option (gogoproto.compare) = true; + google.protobuf.Timestamp nullableTimestamp = 1; + google.protobuf.Duration nullableDuration = 2; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.nullable) = false]; +} + +message StdTypes { + google.protobuf.Timestamp nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration nullableDuration = 2 [(gogoproto.stdduration) = true]; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message RepProtoTypes { + option (gogoproto.compare) = true; + repeated google.protobuf.Timestamp nullableTimestamps = 1; + repeated google.protobuf.Duration nullableDurations = 2; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.nullable) = false]; +} + +message RepStdTypes { + repeated google.protobuf.Timestamp nullableTimestamps = 1 [(gogoproto.stdtime) = true]; + repeated google.protobuf.Duration nullableDurations = 2 [(gogoproto.stdduration) = true]; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message MapProtoTypes { + map nullableTimestamp = 1; + map timestamp = 2 [(gogoproto.nullable) = false]; + + map nullableDuration = 3; + map duration = 4 [(gogoproto.nullable) = false]; +} + +message MapStdTypes { + map nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + map timestamp = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + + map nullableDuration = 3 [(gogoproto.stdduration) = true]; + map duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message OneofProtoTypes { + oneof OneOfProtoTimes { + google.protobuf.Timestamp timestamp = 1; + google.protobuf.Duration duration = 2; + } +} + +message OneofStdTypes { + oneof OneOfStdTimes { + google.protobuf.Timestamp timestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration duration = 2 [(gogoproto.stdduration) = true]; + } +} + diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/neither/types_test.go b/vendor/github.com/gogo/protobuf/test/types/combos/neither/types_test.go new file mode 100644 index 000000000..7d24f58e6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/neither/types_test.go @@ -0,0 +1,242 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + math_rand "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" +) + +func TestFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/neither/typespb_test.go b/vendor/github.com/gogo/protobuf/test/types/combos/neither/typespb_test.go new file mode 100644 index 000000000..5b1edbb28 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/neither/typespb_test.go @@ -0,0 +1,1732 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/neither/types.proto + +/* +Package types is a generated protocol buffer package. + +It is generated from these files: + combos/neither/types.proto + +It has these top-level messages: + KnownTypes + ProtoTypes + StdTypes + RepProtoTypes + RepStdTypes + MapProtoTypes + MapStdTypes + OneofProtoTypes + OneofStdTypes +*/ +package types + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestKnownTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkKnownTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKnownTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedKnownTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &KnownTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedRepProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMapProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOneofProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKnownTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKnownTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &KnownTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &KnownTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &RepProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &RepProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedKnownTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestRepProtoTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedRepProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestKnownTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKnownTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKnownTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types.proto b/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types.proto new file mode 100644 index 000000000..0fd0bb6a8 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types.proto @@ -0,0 +1,131 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package types; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +//import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +//import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message KnownTypes { + option (gogoproto.compare) = true; + google.protobuf.Duration dur = 1; + google.protobuf.Timestamp ts = 2; + google.protobuf.DoubleValue dbl = 3; + google.protobuf.FloatValue flt = 4; + google.protobuf.Int64Value i64 = 5; + google.protobuf.UInt64Value u64 = 6; + google.protobuf.Int32Value i32 = 7; + google.protobuf.UInt32Value u32 = 8; + google.protobuf.BoolValue bool = 9; + google.protobuf.StringValue str = 10; + google.protobuf.BytesValue bytes = 11; + + // TODO uncomment this once https://github.com/gogo/protobuf/issues/197 is fixed + // google.protobuf.Struct st = 12; + // google.protobuf.Any an = 14; +} + +message ProtoTypes { + // TODO this should be a compare_all at the top of the file once time.Time, time.Duration, oneof and map is supported by compare + option (gogoproto.compare) = true; + google.protobuf.Timestamp nullableTimestamp = 1; + google.protobuf.Duration nullableDuration = 2; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.nullable) = false]; +} + +message StdTypes { + google.protobuf.Timestamp nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration nullableDuration = 2 [(gogoproto.stdduration) = true]; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message RepProtoTypes { + option (gogoproto.compare) = true; + repeated google.protobuf.Timestamp nullableTimestamps = 1; + repeated google.protobuf.Duration nullableDurations = 2; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.nullable) = false]; +} + +message RepStdTypes { + repeated google.protobuf.Timestamp nullableTimestamps = 1 [(gogoproto.stdtime) = true]; + repeated google.protobuf.Duration nullableDurations = 2 [(gogoproto.stdduration) = true]; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message MapProtoTypes { + map nullableTimestamp = 1; + map timestamp = 2 [(gogoproto.nullable) = false]; + + map nullableDuration = 3; + map duration = 4 [(gogoproto.nullable) = false]; +} + +message MapStdTypes { + map nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + map timestamp = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + + map nullableDuration = 3 [(gogoproto.stdduration) = true]; + map duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message OneofProtoTypes { + oneof OneOfProtoTimes { + google.protobuf.Timestamp timestamp = 1; + google.protobuf.Duration duration = 2; + } +} + +message OneofStdTypes { + oneof OneOfStdTimes { + google.protobuf.Timestamp timestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration duration = 2 [(gogoproto.stdduration) = true]; + } +} + diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types_test.go b/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types_test.go new file mode 100644 index 000000000..7d24f58e6 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/types_test.go @@ -0,0 +1,242 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + math_rand "math/rand" + "testing" + "time" + + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" +) + +func TestFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/typespb_test.go b/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/typespb_test.go new file mode 100644 index 000000000..98aaeda4b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/combos/unmarshaler/typespb_test.go @@ -0,0 +1,1732 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: combos/unmarshaler/types.proto + +/* +Package types is a generated protocol buffer package. + +It is generated from these files: + combos/unmarshaler/types.proto + +It has these top-level messages: + KnownTypes + ProtoTypes + StdTypes + RepProtoTypes + RepStdTypes + MapProtoTypes + MapStdTypes + OneofProtoTypes + OneofStdTypes +*/ +package types + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" +import _ "github.com/gogo/protobuf/types" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestKnownTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkKnownTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkKnownTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedKnownTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &KnownTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &ProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &StdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedRepProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkRepStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkRepStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedRepStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &RepStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMapProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkMapStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkMapStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedMapStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &MapStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofProtoTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofProtoTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOneofProtoTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofProtoTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkOneofStdTypesProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkOneofStdTypesProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedOneofStdTypes(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &OneofStdTypes{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestKnownTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &KnownTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &ProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestRepStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &RepStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestMapStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &MapStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofProtoTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofProtoTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOneofStdTypesJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OneofStdTypes{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestKnownTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &KnownTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &KnownTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &ProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &ProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &StdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &RepProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &RepProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestRepStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &RepStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestMapStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &MapStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofProtoTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofProtoTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOneofStdTypesProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OneofStdTypes{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestKnownTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedKnownTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestProtoTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestRepProtoTypesCompare(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if c := p.Compare(msg); c != 0 { + t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) + } + p2 := NewPopulatedRepProtoTypes(popr, false) + c := p.Compare(p2) + c2 := p2.Compare(p) + if c != (-1 * c2) { + t.Errorf("p.Compare(p2) = %d", c) + t.Errorf("p2.Compare(p) = %d", c2) + t.Errorf("p = %#v", p) + t.Errorf("p2 = %#v", p2) + } +} +func TestKnownTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedKnownTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &KnownTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &ProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &StdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestRepStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedRepStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &RepStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestMapStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedMapStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &MapStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofProtoTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofProtoTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofProtoTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOneofStdTypesVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOneofStdTypes(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OneofStdTypes{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestKnownTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedKnownTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkKnownTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*KnownTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedKnownTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*ProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*StdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestRepStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedRepStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkRepStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*RepStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedRepStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestMapStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedMapStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkMapStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*MapStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedMapStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofProtoTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofProtoTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofProtoTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofProtoTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofProtoTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +func TestOneofStdTypesSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOneofStdTypes(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func BenchmarkOneofStdTypesSize(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*OneofStdTypes, 1000) + for i := 0; i < 1000; i++ { + pops[i] = NewPopulatedOneofStdTypes(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += pops[i%1000].Size() + } + b.SetBytes(int64(total / b.N)) +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/types/types.proto b/vendor/github.com/gogo/protobuf/test/types/types.proto new file mode 100644 index 000000000..3c26fae20 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/types.proto @@ -0,0 +1,131 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package types; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +//import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +//import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; +option (gogoproto.unmarshaler_all) = false; +option (gogoproto.marshaler_all) = false; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.unsafe_marshaler_all) = false; +option (gogoproto.unsafe_unmarshaler_all) = false; + +message KnownTypes { + option (gogoproto.compare) = true; + google.protobuf.Duration dur = 1; + google.protobuf.Timestamp ts = 2; + google.protobuf.DoubleValue dbl = 3; + google.protobuf.FloatValue flt = 4; + google.protobuf.Int64Value i64 = 5; + google.protobuf.UInt64Value u64 = 6; + google.protobuf.Int32Value i32 = 7; + google.protobuf.UInt32Value u32 = 8; + google.protobuf.BoolValue bool = 9; + google.protobuf.StringValue str = 10; + google.protobuf.BytesValue bytes = 11; + + // TODO uncomment this once https://github.com/gogo/protobuf/issues/197 is fixed + // google.protobuf.Struct st = 12; + // google.protobuf.Any an = 14; +} + +message ProtoTypes { + // TODO this should be a compare_all at the top of the file once time.Time, time.Duration, oneof and map is supported by compare + option (gogoproto.compare) = true; + google.protobuf.Timestamp nullableTimestamp = 1; + google.protobuf.Duration nullableDuration = 2; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.nullable) = false]; +} + +message StdTypes { + google.protobuf.Timestamp nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration nullableDuration = 2 [(gogoproto.stdduration) = true]; + google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + google.protobuf.Duration duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message RepProtoTypes { + option (gogoproto.compare) = true; + repeated google.protobuf.Timestamp nullableTimestamps = 1; + repeated google.protobuf.Duration nullableDurations = 2; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.nullable) = false]; +} + +message RepStdTypes { + repeated google.protobuf.Timestamp nullableTimestamps = 1 [(gogoproto.stdtime) = true]; + repeated google.protobuf.Duration nullableDurations = 2 [(gogoproto.stdduration) = true]; + repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + repeated google.protobuf.Duration durations = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message MapProtoTypes { + map nullableTimestamp = 1; + map timestamp = 2 [(gogoproto.nullable) = false]; + + map nullableDuration = 3; + map duration = 4 [(gogoproto.nullable) = false]; +} + +message MapStdTypes { + map nullableTimestamp = 1 [(gogoproto.stdtime) = true]; + map timestamp = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + + map nullableDuration = 3 [(gogoproto.stdduration) = true]; + map duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; +} + +message OneofProtoTypes { + oneof OneOfProtoTimes { + google.protobuf.Timestamp timestamp = 1; + google.protobuf.Duration duration = 2; + } +} + +message OneofStdTypes { + oneof OneOfStdTimes { + google.protobuf.Timestamp timestamp = 1 [(gogoproto.stdtime) = true]; + google.protobuf.Duration duration = 2 [(gogoproto.stdduration) = true]; + } +} + diff --git a/vendor/github.com/gogo/protobuf/test/types/types_test.go.in b/vendor/github.com/gogo/protobuf/test/types/types_test.go.in new file mode 100644 index 000000000..fcb0974e0 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/types/types_test.go.in @@ -0,0 +1,243 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2016, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + "testing" + "time" + math_rand "math/rand" + + "github.com/gogo/protobuf/proto" + "github.com/gogo/protobuf/jsonpb" +) + +func TestFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &StdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &ProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleRepProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedRepProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &RepStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &RepProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + + +func TestFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleMapProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedMapProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &MapStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &MapProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + protoData, err := proto.Marshal(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := proto.Unmarshal(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := proto.Marshal(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := proto.Unmarshal(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} + +func TestJsonFullCircleOneofProtoToStd(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + protoMsg := NewPopulatedOneofProtoTypes(popr, true) + j := &jsonpb.Marshaler{} + protoData, err := j.MarshalToString(protoMsg) + if err != nil { + t.Fatal(err) + } + stdMsg := &OneofStdTypes{} + if err2 := jsonpb.UnmarshalString(protoData, stdMsg); err2 != nil { + t.Fatal(err) + } + stdData, err := j.MarshalToString(stdMsg) + if err != nil { + t.Fatal(err) + } + protoMsgOut := &OneofProtoTypes{} + if err3 := jsonpb.UnmarshalString(stdData, protoMsgOut); err3 != nil { + t.Fatal(err) + } + if !protoMsg.Equal(protoMsgOut) { + t.Fatalf("want %#v got %#v", protoMsg, protoMsgOut) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/unmarshalmerge/Makefile b/vendor/github.com/gogo/protobuf/test/unmarshalmerge/Makefile new file mode 100644 index 000000000..e9fa8934d --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unmarshalmerge/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. unmarshalmerge.proto) diff --git a/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge.proto b/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge.proto new file mode 100644 index 000000000..1fdbceaf5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge.proto @@ -0,0 +1,75 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package unmarshalmerge; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.goproto_stringer_all) = false; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.benchgen_all) = true; + +message Big { + option (gogoproto.unmarshaler) = true; + optional Sub Sub = 1; + optional int64 Number = 2; +} + +message BigUnsafe { + option (gogoproto.unsafe_unmarshaler) = true; + optional Sub Sub = 1; + optional int64 Number = 2; +} + +message Sub { + option (gogoproto.unmarshaler) = true; + optional int64 SubNumber = 1; +} + +message IntMerge { + option (gogoproto.unmarshaler) = true; + required int64 Int64 = 1 [(gogoproto.nullable) = false]; + optional int32 Int32 = 2 [(gogoproto.nullable) = false]; + required sint32 Sint32 = 3 [(gogoproto.nullable) = false]; + optional sint64 Sint64 = 4 [(gogoproto.nullable) = false]; + optional uint64 Uint64 = 5 [(gogoproto.nullable) = false]; + required uint32 Uint32 = 6 [(gogoproto.nullable) = false]; + optional fixed64 Fixed64 = 7 [(gogoproto.nullable) = false]; + optional fixed32 Fixed32 = 8 [(gogoproto.nullable) = false]; + required sfixed32 Sfixed32 = 9 [(gogoproto.nullable) = false]; + optional sfixed64 Sfixed64 = 10 [(gogoproto.nullable) = false]; + optional bool Bool = 11 [(gogoproto.nullable) = false]; +} diff --git a/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge_test.go b/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge_test.go new file mode 100644 index 000000000..b842ef9bf --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmerge_test.go @@ -0,0 +1,99 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package unmarshalmerge + +import ( + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + "time" +) + +func TestUnmarshalMerge(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBig(popr, true) + if p.GetSub() == nil { + p.Sub = &Sub{SubNumber: proto.Int64(12345)} + } + data, err := proto.Marshal(p) + if err != nil { + t.Fatal(err) + } + s := &Sub{} + b := &Big{ + Sub: s, + } + err = proto.UnmarshalMerge(data, b) + if err != nil { + t.Fatal(err) + } + if s.GetSubNumber() != p.GetSub().GetSubNumber() { + t.Fatalf("should have unmarshaled subnumber into sub") + } +} + +func TestUnsafeUnmarshalMerge(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBigUnsafe(popr, true) + if p.GetSub() == nil { + p.Sub = &Sub{SubNumber: proto.Int64(12345)} + } + data, err := proto.Marshal(p) + if err != nil { + t.Fatal(err) + } + s := &Sub{} + b := &BigUnsafe{ + Sub: s, + } + err = proto.UnmarshalMerge(data, b) + if err != nil { + t.Fatal(err) + } + + if s.GetSubNumber() != p.GetSub().GetSubNumber() { + t.Fatalf("should have unmarshaled subnumber into sub") + } +} + +func TestInt64Merge(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedIntMerge(popr, true) + p2 := NewPopulatedIntMerge(popr, true) + data, err := proto.Marshal(p2) + if err != nil { + t.Fatal(err) + } + if err := proto.UnmarshalMerge(data, p); err != nil { + t.Fatal(err) + } + if !p.Equal(p2) { + t.Fatalf("exptected %#v but got %#v", p2, p) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmergepb_test.go b/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmergepb_test.go new file mode 100644 index 000000000..1a34a8395 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmergepb_test.go @@ -0,0 +1,703 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: unmarshalmerge.proto + +/* +Package unmarshalmerge is a generated protocol buffer package. + +It is generated from these files: + unmarshalmerge.proto + +It has these top-level messages: + Big + BigUnsafe + Sub + IntMerge +*/ +package unmarshalmerge + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import unsafe "unsafe" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestBigProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBig(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Big{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkBigProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Big, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedBig(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkBigProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedBig(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Big{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestBigUnsafeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBigUnsafe(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &BigUnsafe{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkBigUnsafeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*BigUnsafe, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedBigUnsafe(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkBigUnsafeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedBigUnsafe(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &BigUnsafe{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestSubProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSub(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Sub{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkSubProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*Sub, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedSub(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkSubProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedSub(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &Sub{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestIntMergeProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIntMerge(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IntMerge{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func BenchmarkIntMergeProtoMarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + pops := make([]*IntMerge, 10000) + for i := 0; i < 10000; i++ { + pops[i] = NewPopulatedIntMerge(popr, false) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + dAtA, err := proto.Marshal(pops[i%10000]) + if err != nil { + panic(err) + } + total += len(dAtA) + } + b.SetBytes(int64(total / b.N)) +} + +func BenchmarkIntMergeProtoUnmarshal(b *testing.B) { + popr := rand.New(rand.NewSource(616)) + total := 0 + datas := make([][]byte, 10000) + for i := 0; i < 10000; i++ { + dAtA, err := proto.Marshal(NewPopulatedIntMerge(popr, false)) + if err != nil { + panic(err) + } + datas[i] = dAtA + } + msg := &IntMerge{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + total += len(datas[i%10000]) + if err := proto.Unmarshal(datas[i%10000], msg); err != nil { + panic(err) + } + } + b.SetBytes(int64(total / b.N)) +} + +func TestBigJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBig(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Big{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBigUnsafeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBigUnsafe(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &BigUnsafe{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestSubJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSub(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &Sub{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestIntMergeJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIntMerge(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &IntMerge{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBigProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBig(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Big{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBigProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBig(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Big{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBigUnsafeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBigUnsafe(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &BigUnsafe{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBigUnsafeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedBigUnsafe(popr, true) + dAtA := proto.CompactTextString(p) + msg := &BigUnsafe{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSub(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &Sub{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestSubProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedSub(popr, true) + dAtA := proto.CompactTextString(p) + msg := &Sub{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIntMergeProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIntMerge(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &IntMerge{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestIntMergeProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedIntMerge(popr, true) + dAtA := proto.CompactTextString(p) + msg := &IntMerge{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBigVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBig(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Big{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestBigUnsafeVerboseEqual(t *testing.T) { + var bigendian uint32 = 0x01020304 + if *(*byte)(unsafe.Pointer(&bigendian)) == 1 { + t.Skip("unsafe does not work on big endian architectures") + } + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBigUnsafe(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &BigUnsafe{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestSubVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSub(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &Sub{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestIntMergeVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedIntMerge(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &IntMerge{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestBigGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBig(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestBigUnsafeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBigUnsafe(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestSubGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSub(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestIntMergeGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedIntMerge(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestBigStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBig(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestBigUnsafeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedBigUnsafe(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestSubStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedSub(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestIntMergeStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedIntMerge(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/unrecognized/Makefile b/vendor/github.com/gogo/protobuf/test/unrecognized/Makefile new file mode 100644 index 000000000..f09551ae7 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unrecognized/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. unrecognized.proto) diff --git a/vendor/github.com/gogo/protobuf/test/unrecognized/oldnew_test.go b/vendor/github.com/gogo/protobuf/test/unrecognized/oldnew_test.go new file mode 100644 index 000000000..16751014b --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unrecognized/oldnew_test.go @@ -0,0 +1,200 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package unrecognized + +import ( + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + time "time" +) + +func TestNewOld(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + newer := NewPopulatedA(popr, true) + data1, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + older := &OldA{} + if err = proto.Unmarshal(data1, older); err != nil { + panic(err) + } + data2, err := proto.Marshal(older) + if err != nil { + panic(err) + } + bluer := &A{} + if err := proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err := newer.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", newer, bluer, err) + } +} + +func TestOldNew(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldA(popr, true) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + newer := &A{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + bluer := &OldA{} + if err := proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err := older.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err) + } +} + +func TestOldNewOldNew(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldA(popr, true) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + newer := &A{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + bluer := &OldA{} + if err = proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err = older.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err) + } + + data3, err := proto.Marshal(bluer) + if err != nil { + panic(err) + } + purple := &A{} + if err = proto.Unmarshal(data3, purple); err != nil { + panic(err) + } + data4, err := proto.Marshal(purple) + if err != nil { + panic(err) + } + magenta := &OldA{} + if err := proto.Unmarshal(data4, magenta); err != nil { + panic(err) + } + if err := older.VerboseEqual(magenta); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, magenta, err) + } +} + +func TestOldUToU(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldU(popr, true) + // need optional field to be always initialized, to check it's lost in this test + older.Field1 = proto.String(randStringUnrecognized(popr)) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + + newer := &U{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + + older2 := &OldU{} + if err := proto.Unmarshal(data2, older2); err != nil { + panic(err) + } + + // check that Field1 is lost + if older2.Field1 != nil { + t.Fatalf("field must be lost, but it's not, older: %#v, older2: %#v", older, older2) + } + + // now restore Field1 and messages should be equal now + older2.Field1 = older.Field1 + if err := older.VerboseEqual(older2); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, older2, err) + } +} + +func TestOldUnoM(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldUnoM(popr, true) + // need optional field to be always initialized, to check it's lost in this test + older.Field1 = proto.String(randStringUnrecognized(popr)) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + + newer := &UnoM{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + + older2 := &OldUnoM{} + if err := proto.Unmarshal(data2, older2); err != nil { + panic(err) + } + + // check that Field1 is lost + if older2.Field1 != nil { + t.Fatalf("field must be lost, but it's not, older: %#v, older2: %#v", older, older2) + } + + // now restore Field1 and messages should be equal now + older2.Field1 = older.Field1 + if err := older.VerboseEqual(older2); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, older2, err) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognized.proto b/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognized.proto new file mode 100644 index 000000000..483227a33 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognized.proto @@ -0,0 +1,131 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package unrecognized; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; + +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; + +message A { + option (gogoproto.goproto_unrecognized) = false; + optional int64 Field1 = 2; + repeated B B = 1; +} + +message B { + optional C C = 1; + optional D D = 2; + optional OldC F = 5; +} + +message D { + optional int64 Field1 = 1; +} + +message C { + optional double Field2 = 2; + optional string Field3 = 3; + optional double Field4 = 4; + repeated bytes Field5 = 5; + optional int64 Field6 = 6; + repeated float Field7 = 7; +} + +message U { + // unserializing U as OldU must leave Field1 unset + option (gogoproto.goproto_unrecognized) = false; + repeated double Field2 = 2; + optional uint32 Field3 = 3; +} + +message UnoM { + // disable marshal/unmarshal generation here + // to check that reflection based code handles missing XXX_unrecognized field coorectly + option (gogoproto.sizer) = false; + option (gogoproto.marshaler) = false; + option (gogoproto.unmarshaler) = false; + // unserializing U as OldU must leave Field1 unset + option (gogoproto.goproto_unrecognized) = false; + + repeated double Field2 = 2; + optional uint32 Field3 = 3; +} + +message OldA { + // OldA == A, so removing unrecognized should not affect anything, tests must pass + option (gogoproto.goproto_unrecognized) = false; + optional int64 Field1 = 2; + repeated OldB B = 1; +} + +message OldB { + optional OldC C = 1; + optional OldC F = 5; +} + +message OldC { + optional int64 Field1 = 1; + optional double Field2 = 2; + optional string Field3 = 3; + optional int64 Field6 = 6; + repeated float Field7 = 7; +} + +message OldU { + optional string Field1 = 1; + repeated double Field2 = 2; +} + +message OldUnoM { + // disable marshal/unmarshal generation here + // to check that reflection based code handles missing XXX_unrecognized field coorectly + option (gogoproto.sizer) = false; + option (gogoproto.marshaler) = false; + option (gogoproto.unmarshaler) = false; + + optional string Field1 = 1; + repeated double Field2 = 2; +} diff --git a/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognizedpb_test.go b/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognizedpb_test.go new file mode 100644 index 000000000..6a595b53a --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unrecognized/unrecognizedpb_test.go @@ -0,0 +1,1880 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: unrecognized.proto + +/* +Package unrecognized is a generated protocol buffer package. + +It is generated from these files: + unrecognized.proto + +It has these top-level messages: + A + B + D + C + U + UnoM + OldA + OldB + OldC + OldU + OldUnoM +*/ +package unrecognized + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestBMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedD(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &D{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestDMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedD(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &D{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestCMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestUMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnoMProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnoM(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnoM{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldA(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldA{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldAMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldA(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldA{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldBProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldB(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldB{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldBMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldB(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldB{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldCProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldC(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldC{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldCMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldC(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldC{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldU(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldU{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldUMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldU(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldU{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUnoMProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldUnoM(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldUnoM{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestBJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &B{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestDJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedD(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &D{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestCJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &C{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &U{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestUnoMJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnoM(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &UnoM{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldA(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldA{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldBJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldB(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldB{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldCJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldC(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldC{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldUJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldU(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldU{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldUnoMJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldUnoM(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldUnoM{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &A{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := proto.CompactTextString(p) + msg := &A{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &B{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestBProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + dAtA := proto.CompactTextString(p) + msg := &B{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedD(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &D{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestDProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedD(popr, true) + dAtA := proto.CompactTextString(p) + msg := &D{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &C{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestCProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + dAtA := proto.CompactTextString(p) + msg := &C{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &U{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + dAtA := proto.CompactTextString(p) + msg := &U{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnoMProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnoM(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &UnoM{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnoMProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedUnoM(popr, true) + dAtA := proto.CompactTextString(p) + msg := &UnoM{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldA(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OldA{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldA(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OldA{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldBProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldB(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OldB{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldBProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldB(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OldB{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldCProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldC(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OldC{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldCProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldC(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OldC{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldU(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OldU{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldU(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OldU{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUnoMProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldUnoM(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OldUnoM{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldUnoMProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldUnoM(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OldUnoM{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedDescription(t *testing.T) { + UnrecognizedDescription() +} +func TestAVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &A{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestBVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &B{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestDVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedD(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &D{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestCVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &C{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &U{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestUnoMVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnoM(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &UnoM{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldAVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldA(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldA{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldBVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldB(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldB{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldCVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldC(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldC{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldUVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldU(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldU{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldUnoMVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldUnoM(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldUnoM{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestBGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestDGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedD(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestCGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestUnoMGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnoM(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldAGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldA(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldBGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldB(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldCGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldC(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldUGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldU(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldUnoMGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldUnoM(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestASize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestBSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedB(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestDSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedD(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestCSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedC(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestUSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedU(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestOldASize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldA(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestOldBSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldB(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestOldCSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldC(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestOldUSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldU(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestAStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestBStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedB(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestDStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedD(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestCStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedC(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedU(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestUnoMStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedUnoM(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldAStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldA(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldBStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldB(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldCStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldC(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldUStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldU(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldUnoMStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldUnoM(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/Makefile b/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/Makefile new file mode 100644 index 000000000..5ea242c4d --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../../../../:../../protobuf/:. --gogo_out=. unrecognizedgroup.proto) diff --git a/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/oldnew_test.go b/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/oldnew_test.go new file mode 100644 index 000000000..893cb5dea --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/oldnew_test.go @@ -0,0 +1,128 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package unrecognizedgroup + +import ( + "github.com/gogo/protobuf/proto" + math_rand "math/rand" + "testing" + time "time" +) + +func TestNewOld(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + newer := NewPopulatedNewNoGroup(popr, true) + data1, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + older := &OldWithGroup{} + if err = proto.Unmarshal(data1, older); err != nil { + panic(err) + } + data2, err := proto.Marshal(older) + if err != nil { + panic(err) + } + bluer := &NewNoGroup{} + if err := proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err := newer.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", newer, bluer, err) + } +} + +func TestOldNew(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldWithGroup(popr, true) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + newer := &NewNoGroup{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + bluer := &OldWithGroup{} + if err := proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err := older.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err) + } +} + +func TestOldNewOldNew(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + older := NewPopulatedOldWithGroup(popr, true) + data1, err := proto.Marshal(older) + if err != nil { + panic(err) + } + newer := &NewNoGroup{} + if err = proto.Unmarshal(data1, newer); err != nil { + panic(err) + } + data2, err := proto.Marshal(newer) + if err != nil { + panic(err) + } + bluer := &OldWithGroup{} + if err = proto.Unmarshal(data2, bluer); err != nil { + panic(err) + } + if err = older.VerboseEqual(bluer); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err) + } + + data3, err := proto.Marshal(bluer) + if err != nil { + panic(err) + } + purple := &NewNoGroup{} + if err = proto.Unmarshal(data3, purple); err != nil { + panic(err) + } + data4, err := proto.Marshal(purple) + if err != nil { + panic(err) + } + magenta := &OldWithGroup{} + if err := proto.Unmarshal(data4, magenta); err != nil { + panic(err) + } + if err := older.VerboseEqual(magenta); err != nil { + t.Fatalf("%#v !VerboseProto %#v, since %v", older, magenta, err) + } +} diff --git a/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgroup.proto b/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgroup.proto new file mode 100644 index 000000000..2e5813658 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgroup.proto @@ -0,0 +1,77 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package unrecognizedgroup; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_getters_all) = false; + +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.gostring_all) = true; +option (gogoproto.description_all) = true; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; + +message NewNoGroup { + option (gogoproto.unmarshaler) = true; + option (gogoproto.marshaler) = true; + option (gogoproto.sizer) = true; + optional int64 Field1 = 1; + repeated double Field3 = 3; + optional A A = 5; +} + +message A { + option (gogoproto.unmarshaler) = true; + option (gogoproto.marshaler) = true; + option (gogoproto.sizer) = true; + optional int64 AField = 1; +} + +message OldWithGroup { + optional int64 Field1 = 1; + optional group Group1 = 2 { + optional int64 Field1 = 1; + optional int32 Field2 = 2; + repeated double Field3 = 3; + } + repeated double Field3 = 3; + optional group Group2 = 4 { + optional int64 Field1 = 1; + repeated double Field2 = 2; + } +} + diff --git a/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgrouppb_test.go b/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgrouppb_test.go new file mode 100644 index 000000000..ea8ce4f1a --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/unrecognizedgroup/unrecognizedgrouppb_test.go @@ -0,0 +1,766 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: unrecognizedgroup.proto + +/* +Package unrecognizedgroup is a generated protocol buffer package. + +It is generated from these files: + unrecognizedgroup.proto + +It has these top-level messages: + NewNoGroup + A + OldWithGroup +*/ +package unrecognizedgroup + +import testing "testing" +import rand "math/rand" +import time "time" +import proto "github.com/gogo/protobuf/proto" +import jsonpb "github.com/gogo/protobuf/jsonpb" +import fmt "fmt" +import parser "go/parser" +import math "math" +import _ "github.com/gogo/protobuf/gogoproto" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestNewNoGroupProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NewNoGroup{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNewNoGroupMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NewNoGroup{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestAMarshalTo(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, false) + size := p.Size() + dAtA := make([]byte, size) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + _, err := p.MarshalTo(dAtA) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroupProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldWithGroup_Group1Proto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group1(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup_Group1{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestOldWithGroup_Group2Proto(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group2(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup_Group2{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNewNoGroupJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NewNoGroup{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestAJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &A{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldWithGroupJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldWithGroup_Group1JSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group1(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup_Group1{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestOldWithGroup_Group2JSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group2(popr, true) + marshaler := jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &OldWithGroup_Group2{} + err = jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNewNoGroupProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &NewNoGroup{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNewNoGroupProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, true) + dAtA := proto.CompactTextString(p) + msg := &NewNoGroup{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &A{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestAProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + dAtA := proto.CompactTextString(p) + msg := &A{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroupProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OldWithGroup{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroupProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OldWithGroup{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroup_Group1ProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group1(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OldWithGroup_Group1{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroup_Group1ProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group1(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OldWithGroup_Group1{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroup_Group2ProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group2(popr, true) + dAtA := proto.MarshalTextString(p) + msg := &OldWithGroup_Group2{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestOldWithGroup_Group2ProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedOldWithGroup_Group2(popr, true) + dAtA := proto.CompactTextString(p) + msg := &OldWithGroup_Group2{} + if err := proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestUnrecognizedgroupDescription(t *testing.T) { + UnrecognizedgroupDescription() +} +func TestNewNoGroupVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNewNoGroup(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &NewNoGroup{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestAVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &A{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldWithGroupVerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldWithGroup{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldWithGroup_Group1VerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group1(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldWithGroup_Group1{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestOldWithGroup_Group2VerboseEqual(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group2(popr, false) + dAtA, err := proto.Marshal(p) + if err != nil { + panic(err) + } + msg := &OldWithGroup_Group2{} + if err := proto.Unmarshal(dAtA, msg); err != nil { + panic(err) + } + if err := p.VerboseEqual(msg); err != nil { + t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) + } +} +func TestNewNoGroupGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNewNoGroup(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestAGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldWithGroupGoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldWithGroup_Group1GoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group1(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestOldWithGroup_Group2GoString(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group2(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNewNoGroupSize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedNewNoGroup(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestASize(t *testing.T) { + seed := time.Now().UnixNano() + popr := rand.New(rand.NewSource(seed)) + p := NewPopulatedA(popr, true) + size2 := proto.Size(p) + dAtA, err := proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + size := p.Size() + if len(dAtA) != size { + t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) + } + if size2 != size { + t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) + } + size3 := proto.Size(p) + if size3 != size { + t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) + } +} + +func TestNewNoGroupStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNewNoGroup(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestAStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedA(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldWithGroupStringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldWithGroup_Group1Stringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group1(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} +func TestOldWithGroup_Group2Stringer(t *testing.T) { + popr := rand.New(rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedOldWithGroup_Group2(popr, false) + s1 := p.String() + s2 := fmt.Sprintf("%v", p) + if s1 != s2 { + t.Fatalf("String want %v got %v", s1, s2) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/vendor/github.com/gogo/protobuf/test/uuid_test.go b/vendor/github.com/gogo/protobuf/test/uuid_test.go new file mode 100644 index 000000000..5f3b72801 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/test/uuid_test.go @@ -0,0 +1,51 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + "github.com/gogo/protobuf/proto" + "testing" +) + +func TestBugUuid(t *testing.T) { + u := &CustomContainer{CustomStruct: NidOptCustom{Id: Uuid{}}} + data, err := proto.Marshal(u) + if err != nil { + panic(err) + } + u2 := &CustomContainer{} + err = proto.Unmarshal(data, u2) + if err != nil { + panic(err) + } + t.Logf("%+v", u2) + if u2.CustomStruct.Id != nil { + t.Fatalf("should be nil") + } +} diff --git a/vendor/github.com/gogo/protobuf/types/Makefile b/vendor/github.com/gogo/protobuf/types/Makefile new file mode 100644 index 000000000..c326d2578 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/types/Makefile @@ -0,0 +1,39 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2016, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogotypes + go install github.com/gogo/protobuf/protoc-min-version + + protoc-min-version --version="3.0.0" --gogotypes_out=. -I=../protobuf/google/protobuf ../protobuf/google/protobuf/any.proto + protoc-min-version --version="3.0.0" --gogotypes_out=. -I=../protobuf/google/protobuf ../protobuf/google/protobuf/empty.proto + protoc-min-version --version="3.0.0" --gogotypes_out=. -I=../protobuf/google/protobuf ../protobuf/google/protobuf/timestamp.proto + protoc-min-version --version="3.0.0" --gogotypes_out=. -I=../protobuf/google/protobuf ../protobuf/google/protobuf/duration.proto + protoc-min-version --version="3.0.0" --gogotypes_out=. -I=../protobuf/google/protobuf ../protobuf/google/protobuf/struct.proto + protoc-min-version --version="3.0.0" --gogotypes_out=. -I=../protobuf/google/protobuf ../protobuf/google/protobuf/wrappers.proto + protoc-min-version --version="3.0.0" --gogotypes_out=. -I=../protobuf/google/protobuf ../protobuf/google/protobuf/field_mask.proto diff --git a/vendor/github.com/gogo/protobuf/types/any_test.go b/vendor/github.com/gogo/protobuf/types/any_test.go new file mode 100644 index 000000000..14679a244 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/types/any_test.go @@ -0,0 +1,112 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + "testing" + + "github.com/gogo/protobuf/proto" + pb "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" +) + +func TestMarshalUnmarshal(t *testing.T) { + orig := &Any{Value: []byte("test")} + + packed, err := MarshalAny(orig) + if err != nil { + t.Errorf("MarshalAny(%+v): got: _, %v exp: _, nil", orig, err) + } + + unpacked := &Any{} + err = UnmarshalAny(packed, unpacked) + if err != nil || !proto.Equal(unpacked, orig) { + t.Errorf("got: %v, %+v; want nil, %+v", err, unpacked, orig) + } +} + +func TestIs(t *testing.T) { + a, err := MarshalAny(&pb.FileDescriptorProto{}) + if err != nil { + t.Fatal(err) + } + if Is(a, &pb.DescriptorProto{}) { + t.Error("FileDescriptorProto is not a DescriptorProto, but Is says it is") + } + if !Is(a, &pb.FileDescriptorProto{}) { + t.Error("FileDescriptorProto is indeed a FileDescriptorProto, but Is says it is not") + } +} + +func TestIsDifferentUrlPrefixes(t *testing.T) { + m := &pb.FileDescriptorProto{} + a := &Any{TypeUrl: "foo/bar/" + proto.MessageName(m)} + if !Is(a, m) { + t.Errorf("message with type url %q didn't satisfy Is for type %q", a.TypeUrl, proto.MessageName(m)) + } +} + +func TestUnmarshalDynamic(t *testing.T) { + want := &pb.FileDescriptorProto{Name: proto.String("foo")} + a, err := MarshalAny(want) + if err != nil { + t.Fatal(err) + } + var got DynamicAny + if err := UnmarshalAny(a, &got); err != nil { + t.Fatal(err) + } + if !proto.Equal(got.Message, want) { + t.Errorf("invalid result from UnmarshalAny, got %q want %q", got.Message, want) + } +} + +func TestEmpty(t *testing.T) { + want := &pb.FileDescriptorProto{} + a, err := MarshalAny(want) + if err != nil { + t.Fatal(err) + } + got, err := EmptyAny(a) + if err != nil { + t.Fatal(err) + } + if !proto.Equal(got, want) { + t.Errorf("unequal empty message, got %q, want %q", got, want) + } + + // that's a valid type_url for a message which shouldn't be linked into this + // test binary. We want an error. + a.TypeUrl = "type.googleapis.com/google.protobuf.TestAny" + if _, err := EmptyAny(a); err == nil { + t.Errorf("got no error for an attempt to create a message of type %q, which shouldn't be linked in", a.TypeUrl) + } +} diff --git a/vendor/github.com/gogo/protobuf/types/duration_test.go b/vendor/github.com/gogo/protobuf/types/duration_test.go new file mode 100644 index 000000000..7f2bcb429 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/types/duration_test.go @@ -0,0 +1,120 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + "math" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +const ( + minGoSeconds = math.MinInt64 / int64(1e9) + maxGoSeconds = math.MaxInt64 / int64(1e9) +) + +var durationTests = []struct { + proto *Duration + isValid bool + inRange bool + dur time.Duration +}{ + // The zero duration. + {&Duration{Seconds: 0, Nanos: 0}, true, true, 0}, + // Some ordinary non-zero durations. + {&Duration{Seconds: 100, Nanos: 0}, true, true, 100 * time.Second}, + {&Duration{Seconds: -100, Nanos: 0}, true, true, -100 * time.Second}, + {&Duration{Seconds: 100, Nanos: 987}, true, true, 100*time.Second + 987}, + {&Duration{Seconds: -100, Nanos: -987}, true, true, -(100*time.Second + 987)}, + // The largest duration representable in Go. + {&Duration{Seconds: maxGoSeconds, Nanos: int32(math.MaxInt64 - 1e9*maxGoSeconds)}, true, true, math.MaxInt64}, + // The smallest duration representable in Go. + {&Duration{Seconds: minGoSeconds, Nanos: int32(math.MinInt64 - 1e9*minGoSeconds)}, true, true, math.MinInt64}, + {nil, false, false, 0}, + {&Duration{Seconds: -100, Nanos: 987}, false, false, 0}, + {&Duration{Seconds: 100, Nanos: -987}, false, false, 0}, + {&Duration{Seconds: math.MinInt64, Nanos: 0}, false, false, 0}, + {&Duration{Seconds: math.MaxInt64, Nanos: 0}, false, false, 0}, + // The largest valid duration. + {&Duration{Seconds: maxSeconds, Nanos: 1e9 - 1}, true, false, 0}, + // The smallest valid duration. + {&Duration{Seconds: minSeconds, Nanos: -(1e9 - 1)}, true, false, 0}, + // The smallest invalid duration above the valid range. + {&Duration{Seconds: maxSeconds + 1, Nanos: 0}, false, false, 0}, + // The largest invalid duration below the valid range. + {&Duration{Seconds: minSeconds - 1, Nanos: -(1e9 - 1)}, false, false, 0}, + // One nanosecond past the largest duration representable in Go. + {&Duration{Seconds: maxGoSeconds, Nanos: int32(math.MaxInt64-1e9*maxGoSeconds) + 1}, true, false, 0}, + // One nanosecond past the smallest duration representable in Go. + {&Duration{Seconds: minGoSeconds, Nanos: int32(math.MinInt64-1e9*minGoSeconds) - 1}, true, false, 0}, + // One second past the largest duration representable in Go. + {&Duration{Seconds: maxGoSeconds + 1, Nanos: int32(math.MaxInt64 - 1e9*maxGoSeconds)}, true, false, 0}, + // One second past the smallest duration representable in Go. + {&Duration{Seconds: minGoSeconds - 1, Nanos: int32(math.MinInt64 - 1e9*minGoSeconds)}, true, false, 0}, +} + +func TestValidateDuration(t *testing.T) { + for _, test := range durationTests { + err := validateDuration(test.proto) + gotValid := (err == nil) + if gotValid != test.isValid { + t.Errorf("validateDuration(%v) = %t, want %t", test.proto, gotValid, test.isValid) + } + } +} + +func TestDurationFromProto(t *testing.T) { + for _, test := range durationTests { + got, err := DurationFromProto(test.proto) + gotOK := (err == nil) + wantOK := test.isValid && test.inRange + if gotOK != wantOK { + t.Errorf("DurationFromProto(%v) ok = %t, want %t", test.proto, gotOK, wantOK) + } + if err == nil && got != test.dur { + t.Errorf("DurationFromProto(%v) = %v, want %v", test.proto, got, test.dur) + } + } +} + +func TestDurationProto(t *testing.T) { + for _, test := range durationTests { + if test.isValid && test.inRange { + got := DurationProto(test.dur) + if !proto.Equal(got, test.proto) { + t.Errorf("DurationProto(%v) = %v, want %v", test.dur, got, test.proto) + } + } + } +} diff --git a/vendor/github.com/gogo/protobuf/types/timestamp_test.go b/vendor/github.com/gogo/protobuf/types/timestamp_test.go new file mode 100644 index 000000000..6af8631e5 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/types/timestamp_test.go @@ -0,0 +1,152 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2016 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package types + +import ( + "math" + "testing" + "time" + + "github.com/gogo/protobuf/proto" +) + +var tests = []struct { + ts *Timestamp + valid bool + t time.Time +}{ + // The timestamp representing the Unix epoch date. + {&Timestamp{Seconds: 0, Nanos: 0}, true, utcDate(1970, 1, 1)}, + // The smallest representable timestamp. + {&Timestamp{Seconds: math.MinInt64, Nanos: math.MinInt32}, false, + time.Unix(math.MinInt64, math.MinInt32).UTC()}, + // The smallest representable timestamp with non-negative nanos. + {&Timestamp{Seconds: math.MinInt64, Nanos: 0}, false, time.Unix(math.MinInt64, 0).UTC()}, + // The earliest valid timestamp. + {&Timestamp{Seconds: minValidSeconds, Nanos: 0}, true, utcDate(1, 1, 1)}, + //"0001-01-01T00:00:00Z"}, + // The largest representable timestamp. + {&Timestamp{Seconds: math.MaxInt64, Nanos: math.MaxInt32}, false, + time.Unix(math.MaxInt64, math.MaxInt32).UTC()}, + // The largest representable timestamp with nanos in range. + {&Timestamp{Seconds: math.MaxInt64, Nanos: 1e9 - 1}, false, + time.Unix(math.MaxInt64, 1e9-1).UTC()}, + // The largest valid timestamp. + {&Timestamp{Seconds: maxValidSeconds - 1, Nanos: 1e9 - 1}, true, + time.Date(9999, 12, 31, 23, 59, 59, 1e9-1, time.UTC)}, + // The smallest invalid timestamp that is larger than the valid range. + {&Timestamp{Seconds: maxValidSeconds, Nanos: 0}, false, time.Unix(maxValidSeconds, 0).UTC()}, + // A date before the epoch. + {&Timestamp{Seconds: -281836800, Nanos: 0}, true, utcDate(1961, 1, 26)}, + // A date after the epoch. + {&Timestamp{Seconds: 1296000000, Nanos: 0}, true, utcDate(2011, 1, 26)}, + // A date after the epoch, in the middle of the day. + {&Timestamp{Seconds: 1296012345, Nanos: 940483}, true, + time.Date(2011, 1, 26, 3, 25, 45, 940483, time.UTC)}, +} + +func TestValidateTimestamp(t *testing.T) { + for _, s := range tests { + got := validateTimestamp(s.ts) + if (got == nil) != s.valid { + t.Errorf("validateTimestamp(%v) = %v, want %v", s.ts, got, s.valid) + } + } +} + +func TestTimestampFromProto(t *testing.T) { + for _, s := range tests { + got, err := TimestampFromProto(s.ts) + if (err == nil) != s.valid { + t.Errorf("TimestampFromProto(%v) error = %v, but valid = %t", s.ts, err, s.valid) + } else if s.valid && got != s.t { + t.Errorf("TimestampFromProto(%v) = %v, want %v", s.ts, got, s.t) + } + } + // Special case: a nil TimestampFromProto is an error, but returns the 0 Unix time. + got, err := TimestampFromProto(nil) + want := time.Unix(0, 0).UTC() + if got != want { + t.Errorf("TimestampFromProto(nil) = %v, want %v", got, want) + } + if err == nil { + t.Errorf("TimestampFromProto(nil) error = nil, expected error") + } +} + +func TestTimestampProto(t *testing.T) { + for _, s := range tests { + got, err := TimestampProto(s.t) + if (err == nil) != s.valid { + t.Errorf("TimestampProto(%v) error = %v, but valid = %t", s.t, err, s.valid) + } else if s.valid && !proto.Equal(got, s.ts) { + t.Errorf("TimestampProto(%v) = %v, want %v", s.t, got, s.ts) + } + } + // No corresponding special case here: no time.Time results in a nil Timestamp. +} + +func TestTimestampString(t *testing.T) { + for _, test := range []struct { + ts *Timestamp + want string + }{ + // Not much testing needed because presumably time.Format is + // well-tested. + {&Timestamp{Seconds: 0, Nanos: 0}, "1970-01-01T00:00:00Z"}, + {&Timestamp{Seconds: minValidSeconds - 1, Nanos: 0}, "(timestamp: &types.Timestamp{Seconds: -62135596801,\nNanos: 0,\n} before 0001-01-01)"}, + } { + got := TimestampString(test.ts) + if got != test.want { + t.Errorf("TimestampString(%v) = %q, want %q", test.ts, got, test.want) + } + } +} + +func utcDate(year, month, day int) time.Time { + return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC) +} + +func TestTimestampNow(t *testing.T) { + // Bracket the expected time. + before := time.Now() + ts := TimestampNow() + after := time.Now() + + tm, err := TimestampFromProto(ts) + if err != nil { + t.Errorf("between %v and %v\nTimestampNow() = %v\nwhich is invalid (%v)", before, after, ts, err) + } + if tm.Before(before) || tm.After(after) { + t.Errorf("between %v and %v\nTimestamp(TimestampNow()) = %v", before, after, tm) + } +} diff --git a/vendor/github.com/gogo/protobuf/vanity/test/Makefile b/vendor/github.com/gogo/protobuf/vanity/test/Makefile new file mode 100644 index 000000000..0958c4a9e --- /dev/null +++ b/vendor/github.com/gogo/protobuf/vanity/test/Makefile @@ -0,0 +1,46 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + go install github.com/gogo/protobuf/protoc-gen-gogofast + protoc --gogofast_out=./fast/ vanity.proto + protoc --proto_path=../../:../../../../../:../../protobuf/:. --gogofast_out=./fast/ gogovanity.proto + protoc-min-version -version="3.0.0" --proto_path=../../:../../../../../:../../protobuf/:. --gogofast_out=./fast/ proto3.proto + go install github.com/gogo/protobuf/protoc-gen-gogofaster + protoc --gogofaster_out=./faster/ vanity.proto + protoc --proto_path=../../:../../../../../:../../protobuf/:. --gogofaster_out=./faster/ gogovanity.proto + protoc-min-version -version="3.0.0" --proto_path=../../:../../../../../:../../protobuf/:. --gogofaster_out=./faster/ proto3.proto + go install github.com/gogo/protobuf/protoc-gen-gogoslick + protoc --gogoslick_out=./slick/ vanity.proto + protoc --proto_path=../../:../../../../../:../../protobuf/:. --gogoslick_out=./slick/ gogovanity.proto + protoc-min-version -version="3.0.0" --proto_path=../../:../../../../../:../../protobuf/:. --gogoslick_out=./slick/ proto3.proto + +test: + go install github.com/gogo/protobuf/protoc-gen-gofast + protoc --gofast_out=./gofast/ vanity.proto + go test ./... diff --git a/vendor/github.com/gogo/protobuf/vanity/test/gofast/.gitignore b/vendor/github.com/gogo/protobuf/vanity/test/gofast/.gitignore new file mode 100644 index 000000000..9b0b440dc --- /dev/null +++ b/vendor/github.com/gogo/protobuf/vanity/test/gofast/.gitignore @@ -0,0 +1 @@ +*.pb.go \ No newline at end of file diff --git a/vendor/github.com/gogo/protobuf/vanity/test/gogovanity.proto b/vendor/github.com/gogo/protobuf/vanity/test/gogovanity.proto new file mode 100644 index 000000000..b0f9279a1 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/vanity/test/gogovanity.proto @@ -0,0 +1,39 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package vanity; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message B { + optional string String = 1 [(gogoproto.nullable) = true]; + optional int64 Int64 = 2; + optional int32 Int32 = 3 [default = 1234]; +} diff --git a/vendor/github.com/gogo/protobuf/vanity/test/proto3.proto b/vendor/github.com/gogo/protobuf/vanity/test/proto3.proto new file mode 100644 index 000000000..aa2f4ac51 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/vanity/test/proto3.proto @@ -0,0 +1,35 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package vanity; + +message Aproto3 { + string B = 1; +} diff --git a/vendor/github.com/gogo/protobuf/vanity/test/vanity.proto b/vendor/github.com/gogo/protobuf/vanity/test/vanity.proto new file mode 100644 index 000000000..c21750bc0 --- /dev/null +++ b/vendor/github.com/gogo/protobuf/vanity/test/vanity.proto @@ -0,0 +1,36 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package vanity; + +message A { + optional string Strings = 1; + required int64 Int = 2; +} diff --git a/vendor/github.com/gogo/protobuf/vanity/test/vanity_test.go b/vendor/github.com/gogo/protobuf/vanity/test/vanity_test.go new file mode 100644 index 000000000..a0e5b824a --- /dev/null +++ b/vendor/github.com/gogo/protobuf/vanity/test/vanity_test.go @@ -0,0 +1,93 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package test + +import ( + fast "github.com/gogo/protobuf/vanity/test/fast" + faster "github.com/gogo/protobuf/vanity/test/faster" + slick "github.com/gogo/protobuf/vanity/test/slick" + "testing" +) + +func TestFast(t *testing.T) { + _ = (&fast.A{}).Marshal + _ = (&fast.A{}).MarshalTo + _ = (&fast.A{}).Unmarshal + _ = (&fast.A{}).Size + + _ = (&fast.B{}).Marshal + _ = (&fast.B{}).MarshalTo + _ = (&fast.B{}).Unmarshal + _ = (&fast.B{}).Size +} + +func TestFaster(t *testing.T) { + _ = (&faster.A{}).Marshal + _ = (&faster.A{}).MarshalTo + _ = (&faster.A{}).Unmarshal + _ = (&faster.A{}).Size + + _ = (&faster.A{}).Strings == "" + + _ = (&faster.B{}).Marshal + _ = (&faster.B{}).MarshalTo + _ = (&faster.B{}).Unmarshal + _ = (&faster.B{}).Size + + _ = (&faster.B{}).String_ == nil + _ = (&faster.B{}).Int64 == 0 + _ = (&faster.B{}).Int32 == nil + if (&faster.B{}).GetInt32() != 1234 { + t.Fatalf("expected default") + } +} + +func TestSlick(t *testing.T) { + _ = (&slick.A{}).Marshal + _ = (&slick.A{}).MarshalTo + _ = (&slick.A{}).Unmarshal + _ = (&slick.A{}).Size + + _ = (&slick.A{}).Strings == "" + + _ = (&slick.A{}).GoString + _ = (&slick.A{}).String + + _ = (&slick.B{}).Marshal + _ = (&slick.B{}).MarshalTo + _ = (&slick.B{}).Unmarshal + _ = (&slick.B{}).Size + + _ = (&slick.B{}).String_ == nil + _ = (&slick.B{}).Int64 == 0 + _ = (&slick.B{}).Int32 == nil + if (&slick.B{}).GetInt32() != 1234 { + t.Fatalf("expected default") + } +} diff --git a/vendor/github.com/lib/pq/array.go b/vendor/github.com/lib/pq/array.go deleted file mode 100644 index e4933e227..000000000 --- a/vendor/github.com/lib/pq/array.go +++ /dev/null @@ -1,756 +0,0 @@ -package pq - -import ( - "bytes" - "database/sql" - "database/sql/driver" - "encoding/hex" - "fmt" - "reflect" - "strconv" - "strings" -) - -var typeByteSlice = reflect.TypeOf([]byte{}) -var typeDriverValuer = reflect.TypeOf((*driver.Valuer)(nil)).Elem() -var typeSQLScanner = reflect.TypeOf((*sql.Scanner)(nil)).Elem() - -// Array returns the optimal driver.Valuer and sql.Scanner for an array or -// slice of any dimension. -// -// For example: -// db.Query(`SELECT * FROM t WHERE id = ANY($1)`, pq.Array([]int{235, 401})) -// -// var x []sql.NullInt64 -// db.QueryRow('SELECT ARRAY[235, 401]').Scan(pq.Array(&x)) -// -// Scanning multi-dimensional arrays is not supported. Arrays where the lower -// bound is not one (such as `[0:0]={1}') are not supported. -func Array(a interface{}) interface { - driver.Valuer - sql.Scanner -} { - switch a := a.(type) { - case []bool: - return (*BoolArray)(&a) - case []float64: - return (*Float64Array)(&a) - case []int64: - return (*Int64Array)(&a) - case []string: - return (*StringArray)(&a) - - case *[]bool: - return (*BoolArray)(a) - case *[]float64: - return (*Float64Array)(a) - case *[]int64: - return (*Int64Array)(a) - case *[]string: - return (*StringArray)(a) - } - - return GenericArray{a} -} - -// ArrayDelimiter may be optionally implemented by driver.Valuer or sql.Scanner -// to override the array delimiter used by GenericArray. -type ArrayDelimiter interface { - // ArrayDelimiter returns the delimiter character(s) for this element's type. - ArrayDelimiter() string -} - -// BoolArray represents a one-dimensional array of the PostgreSQL boolean type. -type BoolArray []bool - -// Scan implements the sql.Scanner interface. -func (a *BoolArray) Scan(src interface{}) error { - switch src := src.(type) { - case []byte: - return a.scanBytes(src) - case string: - return a.scanBytes([]byte(src)) - case nil: - *a = nil - return nil - } - - return fmt.Errorf("pq: cannot convert %T to BoolArray", src) -} - -func (a *BoolArray) scanBytes(src []byte) error { - elems, err := scanLinearArray(src, []byte{','}, "BoolArray") - if err != nil { - return err - } - if *a != nil && len(elems) == 0 { - *a = (*a)[:0] - } else { - b := make(BoolArray, len(elems)) - for i, v := range elems { - if len(v) != 1 { - return fmt.Errorf("pq: could not parse boolean array index %d: invalid boolean %q", i, v) - } - switch v[0] { - case 't': - b[i] = true - case 'f': - b[i] = false - default: - return fmt.Errorf("pq: could not parse boolean array index %d: invalid boolean %q", i, v) - } - } - *a = b - } - return nil -} - -// Value implements the driver.Valuer interface. -func (a BoolArray) Value() (driver.Value, error) { - if a == nil { - return nil, nil - } - - if n := len(a); n > 0 { - // There will be exactly two curly brackets, N bytes of values, - // and N-1 bytes of delimiters. - b := make([]byte, 1+2*n) - - for i := 0; i < n; i++ { - b[2*i] = ',' - if a[i] { - b[1+2*i] = 't' - } else { - b[1+2*i] = 'f' - } - } - - b[0] = '{' - b[2*n] = '}' - - return string(b), nil - } - - return "{}", nil -} - -// ByteaArray represents a one-dimensional array of the PostgreSQL bytea type. -type ByteaArray [][]byte - -// Scan implements the sql.Scanner interface. -func (a *ByteaArray) Scan(src interface{}) error { - switch src := src.(type) { - case []byte: - return a.scanBytes(src) - case string: - return a.scanBytes([]byte(src)) - case nil: - *a = nil - return nil - } - - return fmt.Errorf("pq: cannot convert %T to ByteaArray", src) -} - -func (a *ByteaArray) scanBytes(src []byte) error { - elems, err := scanLinearArray(src, []byte{','}, "ByteaArray") - if err != nil { - return err - } - if *a != nil && len(elems) == 0 { - *a = (*a)[:0] - } else { - b := make(ByteaArray, len(elems)) - for i, v := range elems { - b[i], err = parseBytea(v) - if err != nil { - return fmt.Errorf("could not parse bytea array index %d: %s", i, err.Error()) - } - } - *a = b - } - return nil -} - -// Value implements the driver.Valuer interface. It uses the "hex" format which -// is only supported on PostgreSQL 9.0 or newer. -func (a ByteaArray) Value() (driver.Value, error) { - if a == nil { - return nil, nil - } - - if n := len(a); n > 0 { - // There will be at least two curly brackets, 2*N bytes of quotes, - // 3*N bytes of hex formatting, and N-1 bytes of delimiters. - size := 1 + 6*n - for _, x := range a { - size += hex.EncodedLen(len(x)) - } - - b := make([]byte, size) - - for i, s := 0, b; i < n; i++ { - o := copy(s, `,"\\x`) - o += hex.Encode(s[o:], a[i]) - s[o] = '"' - s = s[o+1:] - } - - b[0] = '{' - b[size-1] = '}' - - return string(b), nil - } - - return "{}", nil -} - -// Float64Array represents a one-dimensional array of the PostgreSQL double -// precision type. -type Float64Array []float64 - -// Scan implements the sql.Scanner interface. -func (a *Float64Array) Scan(src interface{}) error { - switch src := src.(type) { - case []byte: - return a.scanBytes(src) - case string: - return a.scanBytes([]byte(src)) - case nil: - *a = nil - return nil - } - - return fmt.Errorf("pq: cannot convert %T to Float64Array", src) -} - -func (a *Float64Array) scanBytes(src []byte) error { - elems, err := scanLinearArray(src, []byte{','}, "Float64Array") - if err != nil { - return err - } - if *a != nil && len(elems) == 0 { - *a = (*a)[:0] - } else { - b := make(Float64Array, len(elems)) - for i, v := range elems { - if b[i], err = strconv.ParseFloat(string(v), 64); err != nil { - return fmt.Errorf("pq: parsing array element index %d: %v", i, err) - } - } - *a = b - } - return nil -} - -// Value implements the driver.Valuer interface. -func (a Float64Array) Value() (driver.Value, error) { - if a == nil { - return nil, nil - } - - if n := len(a); n > 0 { - // There will be at least two curly brackets, N bytes of values, - // and N-1 bytes of delimiters. - b := make([]byte, 1, 1+2*n) - b[0] = '{' - - b = strconv.AppendFloat(b, a[0], 'f', -1, 64) - for i := 1; i < n; i++ { - b = append(b, ',') - b = strconv.AppendFloat(b, a[i], 'f', -1, 64) - } - - return string(append(b, '}')), nil - } - - return "{}", nil -} - -// GenericArray implements the driver.Valuer and sql.Scanner interfaces for -// an array or slice of any dimension. -type GenericArray struct{ A interface{} } - -func (GenericArray) evaluateDestination(rt reflect.Type) (reflect.Type, func([]byte, reflect.Value) error, string) { - var assign func([]byte, reflect.Value) error - var del = "," - - // TODO calculate the assign function for other types - // TODO repeat this section on the element type of arrays or slices (multidimensional) - { - if reflect.PtrTo(rt).Implements(typeSQLScanner) { - // dest is always addressable because it is an element of a slice. - assign = func(src []byte, dest reflect.Value) (err error) { - ss := dest.Addr().Interface().(sql.Scanner) - if src == nil { - err = ss.Scan(nil) - } else { - err = ss.Scan(src) - } - return - } - goto FoundType - } - - assign = func([]byte, reflect.Value) error { - return fmt.Errorf("pq: scanning to %s is not implemented; only sql.Scanner", rt) - } - } - -FoundType: - - if ad, ok := reflect.Zero(rt).Interface().(ArrayDelimiter); ok { - del = ad.ArrayDelimiter() - } - - return rt, assign, del -} - -// Scan implements the sql.Scanner interface. -func (a GenericArray) Scan(src interface{}) error { - dpv := reflect.ValueOf(a.A) - switch { - case dpv.Kind() != reflect.Ptr: - return fmt.Errorf("pq: destination %T is not a pointer to array or slice", a.A) - case dpv.IsNil(): - return fmt.Errorf("pq: destination %T is nil", a.A) - } - - dv := dpv.Elem() - switch dv.Kind() { - case reflect.Slice: - case reflect.Array: - default: - return fmt.Errorf("pq: destination %T is not a pointer to array or slice", a.A) - } - - switch src := src.(type) { - case []byte: - return a.scanBytes(src, dv) - case string: - return a.scanBytes([]byte(src), dv) - case nil: - if dv.Kind() == reflect.Slice { - dv.Set(reflect.Zero(dv.Type())) - return nil - } - } - - return fmt.Errorf("pq: cannot convert %T to %s", src, dv.Type()) -} - -func (a GenericArray) scanBytes(src []byte, dv reflect.Value) error { - dtype, assign, del := a.evaluateDestination(dv.Type().Elem()) - dims, elems, err := parseArray(src, []byte(del)) - if err != nil { - return err - } - - // TODO allow multidimensional - - if len(dims) > 1 { - return fmt.Errorf("pq: scanning from multidimensional ARRAY%s is not implemented", - strings.Replace(fmt.Sprint(dims), " ", "][", -1)) - } - - // Treat a zero-dimensional array like an array with a single dimension of zero. - if len(dims) == 0 { - dims = append(dims, 0) - } - - for i, rt := 0, dv.Type(); i < len(dims); i, rt = i+1, rt.Elem() { - switch rt.Kind() { - case reflect.Slice: - case reflect.Array: - if rt.Len() != dims[i] { - return fmt.Errorf("pq: cannot convert ARRAY%s to %s", - strings.Replace(fmt.Sprint(dims), " ", "][", -1), dv.Type()) - } - default: - // TODO handle multidimensional - } - } - - values := reflect.MakeSlice(reflect.SliceOf(dtype), len(elems), len(elems)) - for i, e := range elems { - if err := assign(e, values.Index(i)); err != nil { - return fmt.Errorf("pq: parsing array element index %d: %v", i, err) - } - } - - // TODO handle multidimensional - - switch dv.Kind() { - case reflect.Slice: - dv.Set(values.Slice(0, dims[0])) - case reflect.Array: - for i := 0; i < dims[0]; i++ { - dv.Index(i).Set(values.Index(i)) - } - } - - return nil -} - -// Value implements the driver.Valuer interface. -func (a GenericArray) Value() (driver.Value, error) { - if a.A == nil { - return nil, nil - } - - rv := reflect.ValueOf(a.A) - - switch rv.Kind() { - case reflect.Slice: - if rv.IsNil() { - return nil, nil - } - case reflect.Array: - default: - return nil, fmt.Errorf("pq: Unable to convert %T to array", a.A) - } - - if n := rv.Len(); n > 0 { - // There will be at least two curly brackets, N bytes of values, - // and N-1 bytes of delimiters. - b := make([]byte, 0, 1+2*n) - - b, _, err := appendArray(b, rv, n) - return string(b), err - } - - return "{}", nil -} - -// Int64Array represents a one-dimensional array of the PostgreSQL integer types. -type Int64Array []int64 - -// Scan implements the sql.Scanner interface. -func (a *Int64Array) Scan(src interface{}) error { - switch src := src.(type) { - case []byte: - return a.scanBytes(src) - case string: - return a.scanBytes([]byte(src)) - case nil: - *a = nil - return nil - } - - return fmt.Errorf("pq: cannot convert %T to Int64Array", src) -} - -func (a *Int64Array) scanBytes(src []byte) error { - elems, err := scanLinearArray(src, []byte{','}, "Int64Array") - if err != nil { - return err - } - if *a != nil && len(elems) == 0 { - *a = (*a)[:0] - } else { - b := make(Int64Array, len(elems)) - for i, v := range elems { - if b[i], err = strconv.ParseInt(string(v), 10, 64); err != nil { - return fmt.Errorf("pq: parsing array element index %d: %v", i, err) - } - } - *a = b - } - return nil -} - -// Value implements the driver.Valuer interface. -func (a Int64Array) Value() (driver.Value, error) { - if a == nil { - return nil, nil - } - - if n := len(a); n > 0 { - // There will be at least two curly brackets, N bytes of values, - // and N-1 bytes of delimiters. - b := make([]byte, 1, 1+2*n) - b[0] = '{' - - b = strconv.AppendInt(b, a[0], 10) - for i := 1; i < n; i++ { - b = append(b, ',') - b = strconv.AppendInt(b, a[i], 10) - } - - return string(append(b, '}')), nil - } - - return "{}", nil -} - -// StringArray represents a one-dimensional array of the PostgreSQL character types. -type StringArray []string - -// Scan implements the sql.Scanner interface. -func (a *StringArray) Scan(src interface{}) error { - switch src := src.(type) { - case []byte: - return a.scanBytes(src) - case string: - return a.scanBytes([]byte(src)) - case nil: - *a = nil - return nil - } - - return fmt.Errorf("pq: cannot convert %T to StringArray", src) -} - -func (a *StringArray) scanBytes(src []byte) error { - elems, err := scanLinearArray(src, []byte{','}, "StringArray") - if err != nil { - return err - } - if *a != nil && len(elems) == 0 { - *a = (*a)[:0] - } else { - b := make(StringArray, len(elems)) - for i, v := range elems { - if b[i] = string(v); v == nil { - return fmt.Errorf("pq: parsing array element index %d: cannot convert nil to string", i) - } - } - *a = b - } - return nil -} - -// Value implements the driver.Valuer interface. -func (a StringArray) Value() (driver.Value, error) { - if a == nil { - return nil, nil - } - - if n := len(a); n > 0 { - // There will be at least two curly brackets, 2*N bytes of quotes, - // and N-1 bytes of delimiters. - b := make([]byte, 1, 1+3*n) - b[0] = '{' - - b = appendArrayQuotedBytes(b, []byte(a[0])) - for i := 1; i < n; i++ { - b = append(b, ',') - b = appendArrayQuotedBytes(b, []byte(a[i])) - } - - return string(append(b, '}')), nil - } - - return "{}", nil -} - -// appendArray appends rv to the buffer, returning the extended buffer and -// the delimiter used between elements. -// -// It panics when n <= 0 or rv's Kind is not reflect.Array nor reflect.Slice. -func appendArray(b []byte, rv reflect.Value, n int) ([]byte, string, error) { - var del string - var err error - - b = append(b, '{') - - if b, del, err = appendArrayElement(b, rv.Index(0)); err != nil { - return b, del, err - } - - for i := 1; i < n; i++ { - b = append(b, del...) - if b, del, err = appendArrayElement(b, rv.Index(i)); err != nil { - return b, del, err - } - } - - return append(b, '}'), del, nil -} - -// appendArrayElement appends rv to the buffer, returning the extended buffer -// and the delimiter to use before the next element. -// -// When rv's Kind is neither reflect.Array nor reflect.Slice, it is converted -// using driver.DefaultParameterConverter and the resulting []byte or string -// is double-quoted. -// -// See http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO -func appendArrayElement(b []byte, rv reflect.Value) ([]byte, string, error) { - if k := rv.Kind(); k == reflect.Array || k == reflect.Slice { - if t := rv.Type(); t != typeByteSlice && !t.Implements(typeDriverValuer) { - if n := rv.Len(); n > 0 { - return appendArray(b, rv, n) - } - - return b, "", nil - } - } - - var del = "," - var err error - var iv interface{} = rv.Interface() - - if ad, ok := iv.(ArrayDelimiter); ok { - del = ad.ArrayDelimiter() - } - - if iv, err = driver.DefaultParameterConverter.ConvertValue(iv); err != nil { - return b, del, err - } - - switch v := iv.(type) { - case nil: - return append(b, "NULL"...), del, nil - case []byte: - return appendArrayQuotedBytes(b, v), del, nil - case string: - return appendArrayQuotedBytes(b, []byte(v)), del, nil - } - - b, err = appendValue(b, iv) - return b, del, err -} - -func appendArrayQuotedBytes(b, v []byte) []byte { - b = append(b, '"') - for { - i := bytes.IndexAny(v, `"\`) - if i < 0 { - b = append(b, v...) - break - } - if i > 0 { - b = append(b, v[:i]...) - } - b = append(b, '\\', v[i]) - v = v[i+1:] - } - return append(b, '"') -} - -func appendValue(b []byte, v driver.Value) ([]byte, error) { - return append(b, encode(nil, v, 0)...), nil -} - -// parseArray extracts the dimensions and elements of an array represented in -// text format. Only representations emitted by the backend are supported. -// Notably, whitespace around brackets and delimiters is significant, and NULL -// is case-sensitive. -// -// See http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO -func parseArray(src, del []byte) (dims []int, elems [][]byte, err error) { - var depth, i int - - if len(src) < 1 || src[0] != '{' { - return nil, nil, fmt.Errorf("pq: unable to parse array; expected %q at offset %d", '{', 0) - } - -Open: - for i < len(src) { - switch src[i] { - case '{': - depth++ - i++ - case '}': - elems = make([][]byte, 0) - goto Close - default: - break Open - } - } - dims = make([]int, i) - -Element: - for i < len(src) { - switch src[i] { - case '{': - if depth == len(dims) { - break Element - } - depth++ - dims[depth-1] = 0 - i++ - case '"': - var elem = []byte{} - var escape bool - for i++; i < len(src); i++ { - if escape { - elem = append(elem, src[i]) - escape = false - } else { - switch src[i] { - default: - elem = append(elem, src[i]) - case '\\': - escape = true - case '"': - elems = append(elems, elem) - i++ - break Element - } - } - } - default: - for start := i; i < len(src); i++ { - if bytes.HasPrefix(src[i:], del) || src[i] == '}' { - elem := src[start:i] - if len(elem) == 0 { - return nil, nil, fmt.Errorf("pq: unable to parse array; unexpected %q at offset %d", src[i], i) - } - if bytes.Equal(elem, []byte("NULL")) { - elem = nil - } - elems = append(elems, elem) - break Element - } - } - } - } - - for i < len(src) { - if bytes.HasPrefix(src[i:], del) && depth > 0 { - dims[depth-1]++ - i += len(del) - goto Element - } else if src[i] == '}' && depth > 0 { - dims[depth-1]++ - depth-- - i++ - } else { - return nil, nil, fmt.Errorf("pq: unable to parse array; unexpected %q at offset %d", src[i], i) - } - } - -Close: - for i < len(src) { - if src[i] == '}' && depth > 0 { - depth-- - i++ - } else { - return nil, nil, fmt.Errorf("pq: unable to parse array; unexpected %q at offset %d", src[i], i) - } - } - if depth > 0 { - err = fmt.Errorf("pq: unable to parse array; expected %q at offset %d", '}', i) - } - if err == nil { - for _, d := range dims { - if (len(elems) % d) != 0 { - err = fmt.Errorf("pq: multidimensional arrays must have elements with matching dimensions") - } - } - } - return -} - -func scanLinearArray(src, del []byte, typ string) (elems [][]byte, err error) { - dims, elems, err := parseArray(src, del) - if err != nil { - return nil, err - } - if len(dims) > 1 { - return nil, fmt.Errorf("pq: cannot convert ARRAY%s to %s", strings.Replace(fmt.Sprint(dims), " ", "][", -1), typ) - } - return elems, err -} diff --git a/vendor/github.com/lib/pq/buf.go b/vendor/github.com/lib/pq/buf.go deleted file mode 100644 index 666b0012a..000000000 --- a/vendor/github.com/lib/pq/buf.go +++ /dev/null @@ -1,91 +0,0 @@ -package pq - -import ( - "bytes" - "encoding/binary" - - "github.com/lib/pq/oid" -) - -type readBuf []byte - -func (b *readBuf) int32() (n int) { - n = int(int32(binary.BigEndian.Uint32(*b))) - *b = (*b)[4:] - return -} - -func (b *readBuf) oid() (n oid.Oid) { - n = oid.Oid(binary.BigEndian.Uint32(*b)) - *b = (*b)[4:] - return -} - -// N.B: this is actually an unsigned 16-bit integer, unlike int32 -func (b *readBuf) int16() (n int) { - n = int(binary.BigEndian.Uint16(*b)) - *b = (*b)[2:] - return -} - -func (b *readBuf) string() string { - i := bytes.IndexByte(*b, 0) - if i < 0 { - errorf("invalid message format; expected string terminator") - } - s := (*b)[:i] - *b = (*b)[i+1:] - return string(s) -} - -func (b *readBuf) next(n int) (v []byte) { - v = (*b)[:n] - *b = (*b)[n:] - return -} - -func (b *readBuf) byte() byte { - return b.next(1)[0] -} - -type writeBuf struct { - buf []byte - pos int -} - -func (b *writeBuf) int32(n int) { - x := make([]byte, 4) - binary.BigEndian.PutUint32(x, uint32(n)) - b.buf = append(b.buf, x...) -} - -func (b *writeBuf) int16(n int) { - x := make([]byte, 2) - binary.BigEndian.PutUint16(x, uint16(n)) - b.buf = append(b.buf, x...) -} - -func (b *writeBuf) string(s string) { - b.buf = append(b.buf, (s + "\000")...) -} - -func (b *writeBuf) byte(c byte) { - b.buf = append(b.buf, c) -} - -func (b *writeBuf) bytes(v []byte) { - b.buf = append(b.buf, v...) -} - -func (b *writeBuf) wrap() []byte { - p := b.buf[b.pos:] - binary.BigEndian.PutUint32(p, uint32(len(p))) - return b.buf -} - -func (b *writeBuf) next(c byte) { - p := b.buf[b.pos:] - binary.BigEndian.PutUint32(p, uint32(len(p))) - b.pos = len(b.buf) + 1 - b.buf = append(b.buf, c, 0, 0, 0, 0) -} diff --git a/vendor/github.com/lib/pq/conn.go b/vendor/github.com/lib/pq/conn.go deleted file mode 100644 index fadb88e5e..000000000 --- a/vendor/github.com/lib/pq/conn.go +++ /dev/null @@ -1,1835 +0,0 @@ -package pq - -import ( - "bufio" - "crypto/md5" - "database/sql" - "database/sql/driver" - "encoding/binary" - "errors" - "fmt" - "io" - "net" - "os" - "os/user" - "path" - "path/filepath" - "strconv" - "strings" - "time" - "unicode" - - "github.com/lib/pq/oid" -) - -// Common error types -var ( - ErrNotSupported = errors.New("pq: Unsupported command") - ErrInFailedTransaction = errors.New("pq: Could not complete operation in a failed transaction") - ErrSSLNotSupported = errors.New("pq: SSL is not enabled on the server") - ErrSSLKeyHasWorldPermissions = errors.New("pq: Private key file has group or world access. Permissions should be u=rw (0600) or less") - ErrCouldNotDetectUsername = errors.New("pq: Could not detect default username. Please provide one explicitly") - - errUnexpectedReady = errors.New("unexpected ReadyForQuery") - errNoRowsAffected = errors.New("no RowsAffected available after the empty statement") - errNoLastInsertID = errors.New("no LastInsertId available after the empty statement") -) - -// Driver is the Postgres database driver. -type Driver struct{} - -// Open opens a new connection to the database. name is a connection string. -// Most users should only use it through database/sql package from the standard -// library. -func (d *Driver) Open(name string) (driver.Conn, error) { - return Open(name) -} - -func init() { - sql.Register("postgres", &Driver{}) -} - -type parameterStatus struct { - // server version in the same format as server_version_num, or 0 if - // unavailable - serverVersion int - - // the current location based on the TimeZone value of the session, if - // available - currentLocation *time.Location -} - -type transactionStatus byte - -const ( - txnStatusIdle transactionStatus = 'I' - txnStatusIdleInTransaction transactionStatus = 'T' - txnStatusInFailedTransaction transactionStatus = 'E' -) - -func (s transactionStatus) String() string { - switch s { - case txnStatusIdle: - return "idle" - case txnStatusIdleInTransaction: - return "idle in transaction" - case txnStatusInFailedTransaction: - return "in a failed transaction" - default: - errorf("unknown transactionStatus %d", s) - } - - panic("not reached") -} - -// Dialer is the dialer interface. It can be used to obtain more control over -// how pq creates network connections. -type Dialer interface { - Dial(network, address string) (net.Conn, error) - DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) -} - -type defaultDialer struct{} - -func (d defaultDialer) Dial(ntw, addr string) (net.Conn, error) { - return net.Dial(ntw, addr) -} -func (d defaultDialer) DialTimeout(ntw, addr string, timeout time.Duration) (net.Conn, error) { - return net.DialTimeout(ntw, addr, timeout) -} - -type conn struct { - c net.Conn - buf *bufio.Reader - namei int - scratch [512]byte - txnStatus transactionStatus - txnFinish func() - - // Save connection arguments to use during CancelRequest. - dialer Dialer - opts values - - // Cancellation key data for use with CancelRequest messages. - processID int - secretKey int - - parameterStatus parameterStatus - - saveMessageType byte - saveMessageBuffer []byte - - // If true, this connection is bad and all public-facing functions should - // return ErrBadConn. - bad bool - - // If set, this connection should never use the binary format when - // receiving query results from prepared statements. Only provided for - // debugging. - disablePreparedBinaryResult bool - - // Whether to always send []byte parameters over as binary. Enables single - // round-trip mode for non-prepared Query calls. - binaryParameters bool - - // If true this connection is in the middle of a COPY - inCopy bool -} - -// Handle driver-side settings in parsed connection string. -func (cn *conn) handleDriverSettings(o values) (err error) { - boolSetting := func(key string, val *bool) error { - if value, ok := o[key]; ok { - if value == "yes" { - *val = true - } else if value == "no" { - *val = false - } else { - return fmt.Errorf("unrecognized value %q for %s", value, key) - } - } - return nil - } - - err = boolSetting("disable_prepared_binary_result", &cn.disablePreparedBinaryResult) - if err != nil { - return err - } - return boolSetting("binary_parameters", &cn.binaryParameters) -} - -func (cn *conn) handlePgpass(o values) { - // if a password was supplied, do not process .pgpass - if _, ok := o["password"]; ok { - return - } - filename := os.Getenv("PGPASSFILE") - if filename == "" { - // XXX this code doesn't work on Windows where the default filename is - // XXX %APPDATA%\postgresql\pgpass.conf - // Prefer $HOME over user.Current due to glibc bug: golang.org/issue/13470 - userHome := os.Getenv("HOME") - if userHome == "" { - user, err := user.Current() - if err != nil { - return - } - userHome = user.HomeDir - } - filename = filepath.Join(userHome, ".pgpass") - } - fileinfo, err := os.Stat(filename) - if err != nil { - return - } - mode := fileinfo.Mode() - if mode&(0x77) != 0 { - // XXX should warn about incorrect .pgpass permissions as psql does - return - } - file, err := os.Open(filename) - if err != nil { - return - } - defer file.Close() - scanner := bufio.NewScanner(io.Reader(file)) - hostname := o["host"] - ntw, _ := network(o) - port := o["port"] - db := o["dbname"] - username := o["user"] - // From: https://github.com/tg/pgpass/blob/master/reader.go - getFields := func(s string) []string { - fs := make([]string, 0, 5) - f := make([]rune, 0, len(s)) - - var esc bool - for _, c := range s { - switch { - case esc: - f = append(f, c) - esc = false - case c == '\\': - esc = true - case c == ':': - fs = append(fs, string(f)) - f = f[:0] - default: - f = append(f, c) - } - } - return append(fs, string(f)) - } - for scanner.Scan() { - line := scanner.Text() - if len(line) == 0 || line[0] == '#' { - continue - } - split := getFields(line) - if len(split) != 5 { - continue - } - if (split[0] == "*" || split[0] == hostname || (split[0] == "localhost" && (hostname == "" || ntw == "unix"))) && (split[1] == "*" || split[1] == port) && (split[2] == "*" || split[2] == db) && (split[3] == "*" || split[3] == username) { - o["password"] = split[4] - return - } - } -} - -func (cn *conn) writeBuf(b byte) *writeBuf { - cn.scratch[0] = b - return &writeBuf{ - buf: cn.scratch[:5], - pos: 1, - } -} - -// Open opens a new connection to the database. name is a connection string. -// Most users should only use it through database/sql package from the standard -// library. -func Open(name string) (_ driver.Conn, err error) { - return DialOpen(defaultDialer{}, name) -} - -// DialOpen opens a new connection to the database using a dialer. -func DialOpen(d Dialer, name string) (_ driver.Conn, err error) { - // Handle any panics during connection initialization. Note that we - // specifically do *not* want to use errRecover(), as that would turn any - // connection errors into ErrBadConns, hiding the real error message from - // the user. - defer errRecoverNoErrBadConn(&err) - - o := make(values) - - // A number of defaults are applied here, in this order: - // - // * Very low precedence defaults applied in every situation - // * Environment variables - // * Explicitly passed connection information - o["host"] = "localhost" - o["port"] = "5432" - // N.B.: Extra float digits should be set to 3, but that breaks - // Postgres 8.4 and older, where the max is 2. - o["extra_float_digits"] = "2" - for k, v := range parseEnviron(os.Environ()) { - o[k] = v - } - - if strings.HasPrefix(name, "postgres://") || strings.HasPrefix(name, "postgresql://") { - name, err = ParseURL(name) - if err != nil { - return nil, err - } - } - - if err := parseOpts(name, o); err != nil { - return nil, err - } - - // Use the "fallback" application name if necessary - if fallback, ok := o["fallback_application_name"]; ok { - if _, ok := o["application_name"]; !ok { - o["application_name"] = fallback - } - } - - // We can't work with any client_encoding other than UTF-8 currently. - // However, we have historically allowed the user to set it to UTF-8 - // explicitly, and there's no reason to break such programs, so allow that. - // Note that the "options" setting could also set client_encoding, but - // parsing its value is not worth it. Instead, we always explicitly send - // client_encoding as a separate run-time parameter, which should override - // anything set in options. - if enc, ok := o["client_encoding"]; ok && !isUTF8(enc) { - return nil, errors.New("client_encoding must be absent or 'UTF8'") - } - o["client_encoding"] = "UTF8" - // DateStyle needs a similar treatment. - if datestyle, ok := o["datestyle"]; ok { - if datestyle != "ISO, MDY" { - panic(fmt.Sprintf("setting datestyle must be absent or %v; got %v", - "ISO, MDY", datestyle)) - } - } else { - o["datestyle"] = "ISO, MDY" - } - - // If a user is not provided by any other means, the last - // resort is to use the current operating system provided user - // name. - if _, ok := o["user"]; !ok { - u, err := userCurrent() - if err != nil { - return nil, err - } - o["user"] = u - } - - cn := &conn{ - opts: o, - dialer: d, - } - err = cn.handleDriverSettings(o) - if err != nil { - return nil, err - } - cn.handlePgpass(o) - - cn.c, err = dial(d, o) - if err != nil { - return nil, err - } - cn.ssl(o) - cn.buf = bufio.NewReader(cn.c) - cn.startup(o) - - // reset the deadline, in case one was set (see dial) - if timeout, ok := o["connect_timeout"]; ok && timeout != "0" { - err = cn.c.SetDeadline(time.Time{}) - } - return cn, err -} - -func dial(d Dialer, o values) (net.Conn, error) { - ntw, addr := network(o) - // SSL is not necessary or supported over UNIX domain sockets - if ntw == "unix" { - o["sslmode"] = "disable" - } - - // Zero or not specified means wait indefinitely. - if timeout, ok := o["connect_timeout"]; ok && timeout != "0" { - seconds, err := strconv.ParseInt(timeout, 10, 0) - if err != nil { - return nil, fmt.Errorf("invalid value for parameter connect_timeout: %s", err) - } - duration := time.Duration(seconds) * time.Second - // connect_timeout should apply to the entire connection establishment - // procedure, so we both use a timeout for the TCP connection - // establishment and set a deadline for doing the initial handshake. - // The deadline is then reset after startup() is done. - deadline := time.Now().Add(duration) - conn, err := d.DialTimeout(ntw, addr, duration) - if err != nil { - return nil, err - } - err = conn.SetDeadline(deadline) - return conn, err - } - return d.Dial(ntw, addr) -} - -func network(o values) (string, string) { - host := o["host"] - - if strings.HasPrefix(host, "/") { - sockPath := path.Join(host, ".s.PGSQL."+o["port"]) - return "unix", sockPath - } - - return "tcp", net.JoinHostPort(host, o["port"]) -} - -type values map[string]string - -// scanner implements a tokenizer for libpq-style option strings. -type scanner struct { - s []rune - i int -} - -// newScanner returns a new scanner initialized with the option string s. -func newScanner(s string) *scanner { - return &scanner{[]rune(s), 0} -} - -// Next returns the next rune. -// It returns 0, false if the end of the text has been reached. -func (s *scanner) Next() (rune, bool) { - if s.i >= len(s.s) { - return 0, false - } - r := s.s[s.i] - s.i++ - return r, true -} - -// SkipSpaces returns the next non-whitespace rune. -// It returns 0, false if the end of the text has been reached. -func (s *scanner) SkipSpaces() (rune, bool) { - r, ok := s.Next() - for unicode.IsSpace(r) && ok { - r, ok = s.Next() - } - return r, ok -} - -// parseOpts parses the options from name and adds them to the values. -// -// The parsing code is based on conninfo_parse from libpq's fe-connect.c -func parseOpts(name string, o values) error { - s := newScanner(name) - - for { - var ( - keyRunes, valRunes []rune - r rune - ok bool - ) - - if r, ok = s.SkipSpaces(); !ok { - break - } - - // Scan the key - for !unicode.IsSpace(r) && r != '=' { - keyRunes = append(keyRunes, r) - if r, ok = s.Next(); !ok { - break - } - } - - // Skip any whitespace if we're not at the = yet - if r != '=' { - r, ok = s.SkipSpaces() - } - - // The current character should be = - if r != '=' || !ok { - return fmt.Errorf(`missing "=" after %q in connection info string"`, string(keyRunes)) - } - - // Skip any whitespace after the = - if r, ok = s.SkipSpaces(); !ok { - // If we reach the end here, the last value is just an empty string as per libpq. - o[string(keyRunes)] = "" - break - } - - if r != '\'' { - for !unicode.IsSpace(r) { - if r == '\\' { - if r, ok = s.Next(); !ok { - return fmt.Errorf(`missing character after backslash`) - } - } - valRunes = append(valRunes, r) - - if r, ok = s.Next(); !ok { - break - } - } - } else { - quote: - for { - if r, ok = s.Next(); !ok { - return fmt.Errorf(`unterminated quoted string literal in connection string`) - } - switch r { - case '\'': - break quote - case '\\': - r, _ = s.Next() - fallthrough - default: - valRunes = append(valRunes, r) - } - } - } - - o[string(keyRunes)] = string(valRunes) - } - - return nil -} - -func (cn *conn) isInTransaction() bool { - return cn.txnStatus == txnStatusIdleInTransaction || - cn.txnStatus == txnStatusInFailedTransaction -} - -func (cn *conn) checkIsInTransaction(intxn bool) { - if cn.isInTransaction() != intxn { - cn.bad = true - errorf("unexpected transaction status %v", cn.txnStatus) - } -} - -func (cn *conn) Begin() (_ driver.Tx, err error) { - return cn.begin("") -} - -func (cn *conn) begin(mode string) (_ driver.Tx, err error) { - if cn.bad { - return nil, driver.ErrBadConn - } - defer cn.errRecover(&err) - - cn.checkIsInTransaction(false) - _, commandTag, err := cn.simpleExec("BEGIN" + mode) - if err != nil { - return nil, err - } - if commandTag != "BEGIN" { - cn.bad = true - return nil, fmt.Errorf("unexpected command tag %s", commandTag) - } - if cn.txnStatus != txnStatusIdleInTransaction { - cn.bad = true - return nil, fmt.Errorf("unexpected transaction status %v", cn.txnStatus) - } - return cn, nil -} - -func (cn *conn) closeTxn() { - if finish := cn.txnFinish; finish != nil { - finish() - } -} - -func (cn *conn) Commit() (err error) { - defer cn.closeTxn() - if cn.bad { - return driver.ErrBadConn - } - defer cn.errRecover(&err) - - cn.checkIsInTransaction(true) - // We don't want the client to think that everything is okay if it tries - // to commit a failed transaction. However, no matter what we return, - // database/sql will release this connection back into the free connection - // pool so we have to abort the current transaction here. Note that you - // would get the same behaviour if you issued a COMMIT in a failed - // transaction, so it's also the least surprising thing to do here. - if cn.txnStatus == txnStatusInFailedTransaction { - if err := cn.Rollback(); err != nil { - return err - } - return ErrInFailedTransaction - } - - _, commandTag, err := cn.simpleExec("COMMIT") - if err != nil { - if cn.isInTransaction() { - cn.bad = true - } - return err - } - if commandTag != "COMMIT" { - cn.bad = true - return fmt.Errorf("unexpected command tag %s", commandTag) - } - cn.checkIsInTransaction(false) - return nil -} - -func (cn *conn) Rollback() (err error) { - defer cn.closeTxn() - if cn.bad { - return driver.ErrBadConn - } - defer cn.errRecover(&err) - - cn.checkIsInTransaction(true) - _, commandTag, err := cn.simpleExec("ROLLBACK") - if err != nil { - if cn.isInTransaction() { - cn.bad = true - } - return err - } - if commandTag != "ROLLBACK" { - return fmt.Errorf("unexpected command tag %s", commandTag) - } - cn.checkIsInTransaction(false) - return nil -} - -func (cn *conn) gname() string { - cn.namei++ - return strconv.FormatInt(int64(cn.namei), 10) -} - -func (cn *conn) simpleExec(q string) (res driver.Result, commandTag string, err error) { - b := cn.writeBuf('Q') - b.string(q) - cn.send(b) - - for { - t, r := cn.recv1() - switch t { - case 'C': - res, commandTag = cn.parseComplete(r.string()) - case 'Z': - cn.processReadyForQuery(r) - if res == nil && err == nil { - err = errUnexpectedReady - } - // done - return - case 'E': - err = parseError(r) - case 'I': - res = emptyRows - case 'T', 'D': - // ignore any results - default: - cn.bad = true - errorf("unknown response for simple query: %q", t) - } - } -} - -func (cn *conn) simpleQuery(q string) (res *rows, err error) { - defer cn.errRecover(&err) - - b := cn.writeBuf('Q') - b.string(q) - cn.send(b) - - for { - t, r := cn.recv1() - switch t { - case 'C', 'I': - // We allow queries which don't return any results through Query as - // well as Exec. We still have to give database/sql a rows object - // the user can close, though, to avoid connections from being - // leaked. A "rows" with done=true works fine for that purpose. - if err != nil { - cn.bad = true - errorf("unexpected message %q in simple query execution", t) - } - if res == nil { - res = &rows{ - cn: cn, - } - } - // Set the result and tag to the last command complete if there wasn't a - // query already run. Although queries usually return from here and cede - // control to Next, a query with zero results does not. - if t == 'C' && res.colNames == nil { - res.result, res.tag = cn.parseComplete(r.string()) - } - res.done = true - case 'Z': - cn.processReadyForQuery(r) - // done - return - case 'E': - res = nil - err = parseError(r) - case 'D': - if res == nil { - cn.bad = true - errorf("unexpected DataRow in simple query execution") - } - // the query didn't fail; kick off to Next - cn.saveMessage(t, r) - return - case 'T': - // res might be non-nil here if we received a previous - // CommandComplete, but that's fine; just overwrite it - res = &rows{cn: cn} - res.colNames, res.colFmts, res.colTyps = parsePortalRowDescribe(r) - - // To work around a bug in QueryRow in Go 1.2 and earlier, wait - // until the first DataRow has been received. - default: - cn.bad = true - errorf("unknown response for simple query: %q", t) - } - } -} - -type noRows struct{} - -var emptyRows noRows - -var _ driver.Result = noRows{} - -func (noRows) LastInsertId() (int64, error) { - return 0, errNoLastInsertID -} - -func (noRows) RowsAffected() (int64, error) { - return 0, errNoRowsAffected -} - -// Decides which column formats to use for a prepared statement. The input is -// an array of type oids, one element per result column. -func decideColumnFormats(colTyps []fieldDesc, forceText bool) (colFmts []format, colFmtData []byte) { - if len(colTyps) == 0 { - return nil, colFmtDataAllText - } - - colFmts = make([]format, len(colTyps)) - if forceText { - return colFmts, colFmtDataAllText - } - - allBinary := true - allText := true - for i, t := range colTyps { - switch t.OID { - // This is the list of types to use binary mode for when receiving them - // through a prepared statement. If a type appears in this list, it - // must also be implemented in binaryDecode in encode.go. - case oid.T_bytea: - fallthrough - case oid.T_int8: - fallthrough - case oid.T_int4: - fallthrough - case oid.T_int2: - fallthrough - case oid.T_uuid: - colFmts[i] = formatBinary - allText = false - - default: - allBinary = false - } - } - - if allBinary { - return colFmts, colFmtDataAllBinary - } else if allText { - return colFmts, colFmtDataAllText - } else { - colFmtData = make([]byte, 2+len(colFmts)*2) - binary.BigEndian.PutUint16(colFmtData, uint16(len(colFmts))) - for i, v := range colFmts { - binary.BigEndian.PutUint16(colFmtData[2+i*2:], uint16(v)) - } - return colFmts, colFmtData - } -} - -func (cn *conn) prepareTo(q, stmtName string) *stmt { - st := &stmt{cn: cn, name: stmtName} - - b := cn.writeBuf('P') - b.string(st.name) - b.string(q) - b.int16(0) - - b.next('D') - b.byte('S') - b.string(st.name) - - b.next('S') - cn.send(b) - - cn.readParseResponse() - st.paramTyps, st.colNames, st.colTyps = cn.readStatementDescribeResponse() - st.colFmts, st.colFmtData = decideColumnFormats(st.colTyps, cn.disablePreparedBinaryResult) - cn.readReadyForQuery() - return st -} - -func (cn *conn) Prepare(q string) (_ driver.Stmt, err error) { - if cn.bad { - return nil, driver.ErrBadConn - } - defer cn.errRecover(&err) - - if len(q) >= 4 && strings.EqualFold(q[:4], "COPY") { - s, err := cn.prepareCopyIn(q) - if err == nil { - cn.inCopy = true - } - return s, err - } - return cn.prepareTo(q, cn.gname()), nil -} - -func (cn *conn) Close() (err error) { - // Skip cn.bad return here because we always want to close a connection. - defer cn.errRecover(&err) - - // Ensure that cn.c.Close is always run. Since error handling is done with - // panics and cn.errRecover, the Close must be in a defer. - defer func() { - cerr := cn.c.Close() - if err == nil { - err = cerr - } - }() - - // Don't go through send(); ListenerConn relies on us not scribbling on the - // scratch buffer of this connection. - return cn.sendSimpleMessage('X') -} - -// Implement the "Queryer" interface -func (cn *conn) Query(query string, args []driver.Value) (driver.Rows, error) { - return cn.query(query, args) -} - -func (cn *conn) query(query string, args []driver.Value) (_ *rows, err error) { - if cn.bad { - return nil, driver.ErrBadConn - } - if cn.inCopy { - return nil, errCopyInProgress - } - defer cn.errRecover(&err) - - // Check to see if we can use the "simpleQuery" interface, which is - // *much* faster than going through prepare/exec - if len(args) == 0 { - return cn.simpleQuery(query) - } - - if cn.binaryParameters { - cn.sendBinaryModeQuery(query, args) - - cn.readParseResponse() - cn.readBindResponse() - rows := &rows{cn: cn} - rows.colNames, rows.colFmts, rows.colTyps = cn.readPortalDescribeResponse() - cn.postExecuteWorkaround() - return rows, nil - } - st := cn.prepareTo(query, "") - st.exec(args) - return &rows{ - cn: cn, - colNames: st.colNames, - colTyps: st.colTyps, - colFmts: st.colFmts, - }, nil -} - -// Implement the optional "Execer" interface for one-shot queries -func (cn *conn) Exec(query string, args []driver.Value) (res driver.Result, err error) { - if cn.bad { - return nil, driver.ErrBadConn - } - defer cn.errRecover(&err) - - // Check to see if we can use the "simpleExec" interface, which is - // *much* faster than going through prepare/exec - if len(args) == 0 { - // ignore commandTag, our caller doesn't care - r, _, err := cn.simpleExec(query) - return r, err - } - - if cn.binaryParameters { - cn.sendBinaryModeQuery(query, args) - - cn.readParseResponse() - cn.readBindResponse() - cn.readPortalDescribeResponse() - cn.postExecuteWorkaround() - res, _, err = cn.readExecuteResponse("Execute") - return res, err - } - // Use the unnamed statement to defer planning until bind - // time, or else value-based selectivity estimates cannot be - // used. - st := cn.prepareTo(query, "") - r, err := st.Exec(args) - if err != nil { - panic(err) - } - return r, err -} - -func (cn *conn) send(m *writeBuf) { - _, err := cn.c.Write(m.wrap()) - if err != nil { - panic(err) - } -} - -func (cn *conn) sendStartupPacket(m *writeBuf) error { - _, err := cn.c.Write((m.wrap())[1:]) - return err -} - -// Send a message of type typ to the server on the other end of cn. The -// message should have no payload. This method does not use the scratch -// buffer. -func (cn *conn) sendSimpleMessage(typ byte) (err error) { - _, err = cn.c.Write([]byte{typ, '\x00', '\x00', '\x00', '\x04'}) - return err -} - -// saveMessage memorizes a message and its buffer in the conn struct. -// recvMessage will then return these values on the next call to it. This -// method is useful in cases where you have to see what the next message is -// going to be (e.g. to see whether it's an error or not) but you can't handle -// the message yourself. -func (cn *conn) saveMessage(typ byte, buf *readBuf) { - if cn.saveMessageType != 0 { - cn.bad = true - errorf("unexpected saveMessageType %d", cn.saveMessageType) - } - cn.saveMessageType = typ - cn.saveMessageBuffer = *buf -} - -// recvMessage receives any message from the backend, or returns an error if -// a problem occurred while reading the message. -func (cn *conn) recvMessage(r *readBuf) (byte, error) { - // workaround for a QueryRow bug, see exec - if cn.saveMessageType != 0 { - t := cn.saveMessageType - *r = cn.saveMessageBuffer - cn.saveMessageType = 0 - cn.saveMessageBuffer = nil - return t, nil - } - - x := cn.scratch[:5] - _, err := io.ReadFull(cn.buf, x) - if err != nil { - return 0, err - } - - // read the type and length of the message that follows - t := x[0] - n := int(binary.BigEndian.Uint32(x[1:])) - 4 - var y []byte - if n <= len(cn.scratch) { - y = cn.scratch[:n] - } else { - y = make([]byte, n) - } - _, err = io.ReadFull(cn.buf, y) - if err != nil { - return 0, err - } - *r = y - return t, nil -} - -// recv receives a message from the backend, but if an error happened while -// reading the message or the received message was an ErrorResponse, it panics. -// NoticeResponses are ignored. This function should generally be used only -// during the startup sequence. -func (cn *conn) recv() (t byte, r *readBuf) { - for { - var err error - r = &readBuf{} - t, err = cn.recvMessage(r) - if err != nil { - panic(err) - } - - switch t { - case 'E': - panic(parseError(r)) - case 'N': - // ignore - default: - return - } - } -} - -// recv1Buf is exactly equivalent to recv1, except it uses a buffer supplied by -// the caller to avoid an allocation. -func (cn *conn) recv1Buf(r *readBuf) byte { - for { - t, err := cn.recvMessage(r) - if err != nil { - panic(err) - } - - switch t { - case 'A', 'N': - // ignore - case 'S': - cn.processParameterStatus(r) - default: - return t - } - } -} - -// recv1 receives a message from the backend, panicking if an error occurs -// while attempting to read it. All asynchronous messages are ignored, with -// the exception of ErrorResponse. -func (cn *conn) recv1() (t byte, r *readBuf) { - r = &readBuf{} - t = cn.recv1Buf(r) - return t, r -} - -func (cn *conn) ssl(o values) { - upgrade := ssl(o) - if upgrade == nil { - // Nothing to do - return - } - - w := cn.writeBuf(0) - w.int32(80877103) - if err := cn.sendStartupPacket(w); err != nil { - panic(err) - } - - b := cn.scratch[:1] - _, err := io.ReadFull(cn.c, b) - if err != nil { - panic(err) - } - - if b[0] != 'S' { - panic(ErrSSLNotSupported) - } - - cn.c = upgrade(cn.c) -} - -// isDriverSetting returns true iff a setting is purely for configuring the -// driver's options and should not be sent to the server in the connection -// startup packet. -func isDriverSetting(key string) bool { - switch key { - case "host", "port": - return true - case "password": - return true - case "sslmode", "sslcert", "sslkey", "sslrootcert": - return true - case "fallback_application_name": - return true - case "connect_timeout": - return true - case "disable_prepared_binary_result": - return true - case "binary_parameters": - return true - - default: - return false - } -} - -func (cn *conn) startup(o values) { - w := cn.writeBuf(0) - w.int32(196608) - // Send the backend the name of the database we want to connect to, and the - // user we want to connect as. Additionally, we send over any run-time - // parameters potentially included in the connection string. If the server - // doesn't recognize any of them, it will reply with an error. - for k, v := range o { - if isDriverSetting(k) { - // skip options which can't be run-time parameters - continue - } - // The protocol requires us to supply the database name as "database" - // instead of "dbname". - if k == "dbname" { - k = "database" - } - w.string(k) - w.string(v) - } - w.string("") - if err := cn.sendStartupPacket(w); err != nil { - panic(err) - } - - for { - t, r := cn.recv() - switch t { - case 'K': - cn.processBackendKeyData(r) - case 'S': - cn.processParameterStatus(r) - case 'R': - cn.auth(r, o) - case 'Z': - cn.processReadyForQuery(r) - return - default: - errorf("unknown response for startup: %q", t) - } - } -} - -func (cn *conn) auth(r *readBuf, o values) { - switch code := r.int32(); code { - case 0: - // OK - case 3: - w := cn.writeBuf('p') - w.string(o["password"]) - cn.send(w) - - t, r := cn.recv() - if t != 'R' { - errorf("unexpected password response: %q", t) - } - - if r.int32() != 0 { - errorf("unexpected authentication response: %q", t) - } - case 5: - s := string(r.next(4)) - w := cn.writeBuf('p') - w.string("md5" + md5s(md5s(o["password"]+o["user"])+s)) - cn.send(w) - - t, r := cn.recv() - if t != 'R' { - errorf("unexpected password response: %q", t) - } - - if r.int32() != 0 { - errorf("unexpected authentication response: %q", t) - } - default: - errorf("unknown authentication response: %d", code) - } -} - -type format int - -const formatText format = 0 -const formatBinary format = 1 - -// One result-column format code with the value 1 (i.e. all binary). -var colFmtDataAllBinary = []byte{0, 1, 0, 1} - -// No result-column format codes (i.e. all text). -var colFmtDataAllText = []byte{0, 0} - -type stmt struct { - cn *conn - name string - colNames []string - colFmts []format - colFmtData []byte - colTyps []fieldDesc - paramTyps []oid.Oid - closed bool -} - -func (st *stmt) Close() (err error) { - if st.closed { - return nil - } - if st.cn.bad { - return driver.ErrBadConn - } - defer st.cn.errRecover(&err) - - w := st.cn.writeBuf('C') - w.byte('S') - w.string(st.name) - st.cn.send(w) - - st.cn.send(st.cn.writeBuf('S')) - - t, _ := st.cn.recv1() - if t != '3' { - st.cn.bad = true - errorf("unexpected close response: %q", t) - } - st.closed = true - - t, r := st.cn.recv1() - if t != 'Z' { - st.cn.bad = true - errorf("expected ready for query, but got: %q", t) - } - st.cn.processReadyForQuery(r) - - return nil -} - -func (st *stmt) Query(v []driver.Value) (r driver.Rows, err error) { - if st.cn.bad { - return nil, driver.ErrBadConn - } - defer st.cn.errRecover(&err) - - st.exec(v) - return &rows{ - cn: st.cn, - colNames: st.colNames, - colTyps: st.colTyps, - colFmts: st.colFmts, - }, nil -} - -func (st *stmt) Exec(v []driver.Value) (res driver.Result, err error) { - if st.cn.bad { - return nil, driver.ErrBadConn - } - defer st.cn.errRecover(&err) - - st.exec(v) - res, _, err = st.cn.readExecuteResponse("simple query") - return res, err -} - -func (st *stmt) exec(v []driver.Value) { - if len(v) >= 65536 { - errorf("got %d parameters but PostgreSQL only supports 65535 parameters", len(v)) - } - if len(v) != len(st.paramTyps) { - errorf("got %d parameters but the statement requires %d", len(v), len(st.paramTyps)) - } - - cn := st.cn - w := cn.writeBuf('B') - w.byte(0) // unnamed portal - w.string(st.name) - - if cn.binaryParameters { - cn.sendBinaryParameters(w, v) - } else { - w.int16(0) - w.int16(len(v)) - for i, x := range v { - if x == nil { - w.int32(-1) - } else { - b := encode(&cn.parameterStatus, x, st.paramTyps[i]) - w.int32(len(b)) - w.bytes(b) - } - } - } - w.bytes(st.colFmtData) - - w.next('E') - w.byte(0) - w.int32(0) - - w.next('S') - cn.send(w) - - cn.readBindResponse() - cn.postExecuteWorkaround() - -} - -func (st *stmt) NumInput() int { - return len(st.paramTyps) -} - -// parseComplete parses the "command tag" from a CommandComplete message, and -// returns the number of rows affected (if applicable) and a string -// identifying only the command that was executed, e.g. "ALTER TABLE". If the -// command tag could not be parsed, parseComplete panics. -func (cn *conn) parseComplete(commandTag string) (driver.Result, string) { - commandsWithAffectedRows := []string{ - "SELECT ", - // INSERT is handled below - "UPDATE ", - "DELETE ", - "FETCH ", - "MOVE ", - "COPY ", - } - - var affectedRows *string - for _, tag := range commandsWithAffectedRows { - if strings.HasPrefix(commandTag, tag) { - t := commandTag[len(tag):] - affectedRows = &t - commandTag = tag[:len(tag)-1] - break - } - } - // INSERT also includes the oid of the inserted row in its command tag. - // Oids in user tables are deprecated, and the oid is only returned when - // exactly one row is inserted, so it's unlikely to be of value to any - // real-world application and we can ignore it. - if affectedRows == nil && strings.HasPrefix(commandTag, "INSERT ") { - parts := strings.Split(commandTag, " ") - if len(parts) != 3 { - cn.bad = true - errorf("unexpected INSERT command tag %s", commandTag) - } - affectedRows = &parts[len(parts)-1] - commandTag = "INSERT" - } - // There should be no affected rows attached to the tag, just return it - if affectedRows == nil { - return driver.RowsAffected(0), commandTag - } - n, err := strconv.ParseInt(*affectedRows, 10, 64) - if err != nil { - cn.bad = true - errorf("could not parse commandTag: %s", err) - } - return driver.RowsAffected(n), commandTag -} - -type rows struct { - cn *conn - finish func() - colNames []string - colTyps []fieldDesc - colFmts []format - done bool - rb readBuf - result driver.Result - tag string -} - -func (rs *rows) Close() error { - if finish := rs.finish; finish != nil { - defer finish() - } - // no need to look at cn.bad as Next() will - for { - err := rs.Next(nil) - switch err { - case nil: - case io.EOF: - // rs.Next can return io.EOF on both 'Z' (ready for query) and 'T' (row - // description, used with HasNextResultSet). We need to fetch messages until - // we hit a 'Z', which is done by waiting for done to be set. - if rs.done { - return nil - } - default: - return err - } - } -} - -func (rs *rows) Columns() []string { - return rs.colNames -} - -func (rs *rows) Result() driver.Result { - if rs.result == nil { - return emptyRows - } - return rs.result -} - -func (rs *rows) Tag() string { - return rs.tag -} - -func (rs *rows) Next(dest []driver.Value) (err error) { - if rs.done { - return io.EOF - } - - conn := rs.cn - if conn.bad { - return driver.ErrBadConn - } - defer conn.errRecover(&err) - - for { - t := conn.recv1Buf(&rs.rb) - switch t { - case 'E': - err = parseError(&rs.rb) - case 'C', 'I': - if t == 'C' { - rs.result, rs.tag = conn.parseComplete(rs.rb.string()) - } - continue - case 'Z': - conn.processReadyForQuery(&rs.rb) - rs.done = true - if err != nil { - return err - } - return io.EOF - case 'D': - n := rs.rb.int16() - if err != nil { - conn.bad = true - errorf("unexpected DataRow after error %s", err) - } - if n < len(dest) { - dest = dest[:n] - } - for i := range dest { - l := rs.rb.int32() - if l == -1 { - dest[i] = nil - continue - } - dest[i] = decode(&conn.parameterStatus, rs.rb.next(l), rs.colTyps[i].OID, rs.colFmts[i]) - } - return - case 'T': - rs.colNames, rs.colFmts, rs.colTyps = parsePortalRowDescribe(&rs.rb) - return io.EOF - default: - errorf("unexpected message after execute: %q", t) - } - } -} - -func (rs *rows) HasNextResultSet() bool { - return !rs.done -} - -func (rs *rows) NextResultSet() error { - return nil -} - -// QuoteIdentifier quotes an "identifier" (e.g. a table or a column name) to be -// used as part of an SQL statement. For example: -// -// tblname := "my_table" -// data := "my_data" -// quoted := pq.QuoteIdentifier(tblname) -// err := db.Exec(fmt.Sprintf("INSERT INTO %s VALUES ($1)", quoted), data) -// -// Any double quotes in name will be escaped. The quoted identifier will be -// case sensitive when used in a query. If the input string contains a zero -// byte, the result will be truncated immediately before it. -func QuoteIdentifier(name string) string { - end := strings.IndexRune(name, 0) - if end > -1 { - name = name[:end] - } - return `"` + strings.Replace(name, `"`, `""`, -1) + `"` -} - -func md5s(s string) string { - h := md5.New() - h.Write([]byte(s)) - return fmt.Sprintf("%x", h.Sum(nil)) -} - -func (cn *conn) sendBinaryParameters(b *writeBuf, args []driver.Value) { - // Do one pass over the parameters to see if we're going to send any of - // them over in binary. If we are, create a paramFormats array at the - // same time. - var paramFormats []int - for i, x := range args { - _, ok := x.([]byte) - if ok { - if paramFormats == nil { - paramFormats = make([]int, len(args)) - } - paramFormats[i] = 1 - } - } - if paramFormats == nil { - b.int16(0) - } else { - b.int16(len(paramFormats)) - for _, x := range paramFormats { - b.int16(x) - } - } - - b.int16(len(args)) - for _, x := range args { - if x == nil { - b.int32(-1) - } else { - datum := binaryEncode(&cn.parameterStatus, x) - b.int32(len(datum)) - b.bytes(datum) - } - } -} - -func (cn *conn) sendBinaryModeQuery(query string, args []driver.Value) { - if len(args) >= 65536 { - errorf("got %d parameters but PostgreSQL only supports 65535 parameters", len(args)) - } - - b := cn.writeBuf('P') - b.byte(0) // unnamed statement - b.string(query) - b.int16(0) - - b.next('B') - b.int16(0) // unnamed portal and statement - cn.sendBinaryParameters(b, args) - b.bytes(colFmtDataAllText) - - b.next('D') - b.byte('P') - b.byte(0) // unnamed portal - - b.next('E') - b.byte(0) - b.int32(0) - - b.next('S') - cn.send(b) -} - -func (cn *conn) processParameterStatus(r *readBuf) { - var err error - - param := r.string() - switch param { - case "server_version": - var major1 int - var major2 int - var minor int - _, err = fmt.Sscanf(r.string(), "%d.%d.%d", &major1, &major2, &minor) - if err == nil { - cn.parameterStatus.serverVersion = major1*10000 + major2*100 + minor - } - - case "TimeZone": - cn.parameterStatus.currentLocation, err = time.LoadLocation(r.string()) - if err != nil { - cn.parameterStatus.currentLocation = nil - } - - default: - // ignore - } -} - -func (cn *conn) processReadyForQuery(r *readBuf) { - cn.txnStatus = transactionStatus(r.byte()) -} - -func (cn *conn) readReadyForQuery() { - t, r := cn.recv1() - switch t { - case 'Z': - cn.processReadyForQuery(r) - return - default: - cn.bad = true - errorf("unexpected message %q; expected ReadyForQuery", t) - } -} - -func (cn *conn) processBackendKeyData(r *readBuf) { - cn.processID = r.int32() - cn.secretKey = r.int32() -} - -func (cn *conn) readParseResponse() { - t, r := cn.recv1() - switch t { - case '1': - return - case 'E': - err := parseError(r) - cn.readReadyForQuery() - panic(err) - default: - cn.bad = true - errorf("unexpected Parse response %q", t) - } -} - -func (cn *conn) readStatementDescribeResponse() (paramTyps []oid.Oid, colNames []string, colTyps []fieldDesc) { - for { - t, r := cn.recv1() - switch t { - case 't': - nparams := r.int16() - paramTyps = make([]oid.Oid, nparams) - for i := range paramTyps { - paramTyps[i] = r.oid() - } - case 'n': - return paramTyps, nil, nil - case 'T': - colNames, colTyps = parseStatementRowDescribe(r) - return paramTyps, colNames, colTyps - case 'E': - err := parseError(r) - cn.readReadyForQuery() - panic(err) - default: - cn.bad = true - errorf("unexpected Describe statement response %q", t) - } - } -} - -func (cn *conn) readPortalDescribeResponse() (colNames []string, colFmts []format, colTyps []fieldDesc) { - t, r := cn.recv1() - switch t { - case 'T': - return parsePortalRowDescribe(r) - case 'n': - return nil, nil, nil - case 'E': - err := parseError(r) - cn.readReadyForQuery() - panic(err) - default: - cn.bad = true - errorf("unexpected Describe response %q", t) - } - panic("not reached") -} - -func (cn *conn) readBindResponse() { - t, r := cn.recv1() - switch t { - case '2': - return - case 'E': - err := parseError(r) - cn.readReadyForQuery() - panic(err) - default: - cn.bad = true - errorf("unexpected Bind response %q", t) - } -} - -func (cn *conn) postExecuteWorkaround() { - // Work around a bug in sql.DB.QueryRow: in Go 1.2 and earlier it ignores - // any errors from rows.Next, which masks errors that happened during the - // execution of the query. To avoid the problem in common cases, we wait - // here for one more message from the database. If it's not an error the - // query will likely succeed (or perhaps has already, if it's a - // CommandComplete), so we push the message into the conn struct; recv1 - // will return it as the next message for rows.Next or rows.Close. - // However, if it's an error, we wait until ReadyForQuery and then return - // the error to our caller. - for { - t, r := cn.recv1() - switch t { - case 'E': - err := parseError(r) - cn.readReadyForQuery() - panic(err) - case 'C', 'D', 'I': - // the query didn't fail, but we can't process this message - cn.saveMessage(t, r) - return - default: - cn.bad = true - errorf("unexpected message during extended query execution: %q", t) - } - } -} - -// Only for Exec(), since we ignore the returned data -func (cn *conn) readExecuteResponse(protocolState string) (res driver.Result, commandTag string, err error) { - for { - t, r := cn.recv1() - switch t { - case 'C': - if err != nil { - cn.bad = true - errorf("unexpected CommandComplete after error %s", err) - } - res, commandTag = cn.parseComplete(r.string()) - case 'Z': - cn.processReadyForQuery(r) - if res == nil && err == nil { - err = errUnexpectedReady - } - return res, commandTag, err - case 'E': - err = parseError(r) - case 'T', 'D', 'I': - if err != nil { - cn.bad = true - errorf("unexpected %q after error %s", t, err) - } - if t == 'I' { - res = emptyRows - } - // ignore any results - default: - cn.bad = true - errorf("unknown %s response: %q", protocolState, t) - } - } -} - -func parseStatementRowDescribe(r *readBuf) (colNames []string, colTyps []fieldDesc) { - n := r.int16() - colNames = make([]string, n) - colTyps = make([]fieldDesc, n) - for i := range colNames { - colNames[i] = r.string() - r.next(6) - colTyps[i].OID = r.oid() - colTyps[i].Len = r.int16() - colTyps[i].Mod = r.int32() - // format code not known when describing a statement; always 0 - r.next(2) - } - return -} - -func parsePortalRowDescribe(r *readBuf) (colNames []string, colFmts []format, colTyps []fieldDesc) { - n := r.int16() - colNames = make([]string, n) - colFmts = make([]format, n) - colTyps = make([]fieldDesc, n) - for i := range colNames { - colNames[i] = r.string() - r.next(6) - colTyps[i].OID = r.oid() - colTyps[i].Len = r.int16() - colTyps[i].Mod = r.int32() - colFmts[i] = format(r.int16()) - } - return -} - -// parseEnviron tries to mimic some of libpq's environment handling -// -// To ease testing, it does not directly reference os.Environ, but is -// designed to accept its output. -// -// Environment-set connection information is intended to have a higher -// precedence than a library default but lower than any explicitly -// passed information (such as in the URL or connection string). -func parseEnviron(env []string) (out map[string]string) { - out = make(map[string]string) - - for _, v := range env { - parts := strings.SplitN(v, "=", 2) - - accrue := func(keyname string) { - out[keyname] = parts[1] - } - unsupported := func() { - panic(fmt.Sprintf("setting %v not supported", parts[0])) - } - - // The order of these is the same as is seen in the - // PostgreSQL 9.1 manual. Unsupported but well-defined - // keys cause a panic; these should be unset prior to - // execution. Options which pq expects to be set to a - // certain value are allowed, but must be set to that - // value if present (they can, of course, be absent). - switch parts[0] { - case "PGHOST": - accrue("host") - case "PGHOSTADDR": - unsupported() - case "PGPORT": - accrue("port") - case "PGDATABASE": - accrue("dbname") - case "PGUSER": - accrue("user") - case "PGPASSWORD": - accrue("password") - case "PGSERVICE", "PGSERVICEFILE", "PGREALM": - unsupported() - case "PGOPTIONS": - accrue("options") - case "PGAPPNAME": - accrue("application_name") - case "PGSSLMODE": - accrue("sslmode") - case "PGSSLCERT": - accrue("sslcert") - case "PGSSLKEY": - accrue("sslkey") - case "PGSSLROOTCERT": - accrue("sslrootcert") - case "PGREQUIRESSL", "PGSSLCRL": - unsupported() - case "PGREQUIREPEER": - unsupported() - case "PGKRBSRVNAME", "PGGSSLIB": - unsupported() - case "PGCONNECT_TIMEOUT": - accrue("connect_timeout") - case "PGCLIENTENCODING": - accrue("client_encoding") - case "PGDATESTYLE": - accrue("datestyle") - case "PGTZ": - accrue("timezone") - case "PGGEQO": - accrue("geqo") - case "PGSYSCONFDIR", "PGLOCALEDIR": - unsupported() - } - } - - return out -} - -// isUTF8 returns whether name is a fuzzy variation of the string "UTF-8". -func isUTF8(name string) bool { - // Recognize all sorts of silly things as "UTF-8", like Postgres does - s := strings.Map(alnumLowerASCII, name) - return s == "utf8" || s == "unicode" -} - -func alnumLowerASCII(ch rune) rune { - if 'A' <= ch && ch <= 'Z' { - return ch + ('a' - 'A') - } - if 'a' <= ch && ch <= 'z' || '0' <= ch && ch <= '9' { - return ch - } - return -1 // discard -} diff --git a/vendor/github.com/lib/pq/conn_go18.go b/vendor/github.com/lib/pq/conn_go18.go deleted file mode 100644 index ab97a104d..000000000 --- a/vendor/github.com/lib/pq/conn_go18.go +++ /dev/null @@ -1,128 +0,0 @@ -// +build go1.8 - -package pq - -import ( - "context" - "database/sql" - "database/sql/driver" - "fmt" - "io" - "io/ioutil" -) - -// Implement the "QueryerContext" interface -func (cn *conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { - list := make([]driver.Value, len(args)) - for i, nv := range args { - list[i] = nv.Value - } - finish := cn.watchCancel(ctx) - r, err := cn.query(query, list) - if err != nil { - if finish != nil { - finish() - } - return nil, err - } - r.finish = finish - return r, nil -} - -// Implement the "ExecerContext" interface -func (cn *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) { - list := make([]driver.Value, len(args)) - for i, nv := range args { - list[i] = nv.Value - } - - if finish := cn.watchCancel(ctx); finish != nil { - defer finish() - } - - return cn.Exec(query, list) -} - -// Implement the "ConnBeginTx" interface -func (cn *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { - var mode string - - switch sql.IsolationLevel(opts.Isolation) { - case sql.LevelDefault: - // Don't touch mode: use the server's default - case sql.LevelReadUncommitted: - mode = " ISOLATION LEVEL READ UNCOMMITTED" - case sql.LevelReadCommitted: - mode = " ISOLATION LEVEL READ COMMITTED" - case sql.LevelRepeatableRead: - mode = " ISOLATION LEVEL REPEATABLE READ" - case sql.LevelSerializable: - mode = " ISOLATION LEVEL SERIALIZABLE" - default: - return nil, fmt.Errorf("pq: isolation level not supported: %d", opts.Isolation) - } - - if opts.ReadOnly { - mode += " READ ONLY" - } else { - mode += " READ WRITE" - } - - tx, err := cn.begin(mode) - if err != nil { - return nil, err - } - cn.txnFinish = cn.watchCancel(ctx) - return tx, nil -} - -func (cn *conn) watchCancel(ctx context.Context) func() { - if done := ctx.Done(); done != nil { - finished := make(chan struct{}) - go func() { - select { - case <-done: - _ = cn.cancel() - finished <- struct{}{} - case <-finished: - } - }() - return func() { - select { - case <-finished: - case finished <- struct{}{}: - } - } - } - return nil -} - -func (cn *conn) cancel() error { - c, err := dial(cn.dialer, cn.opts) - if err != nil { - return err - } - defer c.Close() - - { - can := conn{ - c: c, - } - can.ssl(cn.opts) - - w := can.writeBuf(0) - w.int32(80877102) // cancel request code - w.int32(cn.processID) - w.int32(cn.secretKey) - - if err := can.sendStartupPacket(w); err != nil { - return err - } - } - - // Read until EOF to ensure that the server received the cancel. - { - _, err := io.Copy(ioutil.Discard, c) - return err - } -} diff --git a/vendor/github.com/lib/pq/copy.go b/vendor/github.com/lib/pq/copy.go deleted file mode 100644 index 345c2398f..000000000 --- a/vendor/github.com/lib/pq/copy.go +++ /dev/null @@ -1,282 +0,0 @@ -package pq - -import ( - "database/sql/driver" - "encoding/binary" - "errors" - "fmt" - "sync" -) - -var ( - errCopyInClosed = errors.New("pq: copyin statement has already been closed") - errBinaryCopyNotSupported = errors.New("pq: only text format supported for COPY") - errCopyToNotSupported = errors.New("pq: COPY TO is not supported") - errCopyNotSupportedOutsideTxn = errors.New("pq: COPY is only allowed inside a transaction") - errCopyInProgress = errors.New("pq: COPY in progress") -) - -// CopyIn creates a COPY FROM statement which can be prepared with -// Tx.Prepare(). The target table should be visible in search_path. -func CopyIn(table string, columns ...string) string { - stmt := "COPY " + QuoteIdentifier(table) + " (" - for i, col := range columns { - if i != 0 { - stmt += ", " - } - stmt += QuoteIdentifier(col) - } - stmt += ") FROM STDIN" - return stmt -} - -// CopyInSchema creates a COPY FROM statement which can be prepared with -// Tx.Prepare(). -func CopyInSchema(schema, table string, columns ...string) string { - stmt := "COPY " + QuoteIdentifier(schema) + "." + QuoteIdentifier(table) + " (" - for i, col := range columns { - if i != 0 { - stmt += ", " - } - stmt += QuoteIdentifier(col) - } - stmt += ") FROM STDIN" - return stmt -} - -type copyin struct { - cn *conn - buffer []byte - rowData chan []byte - done chan bool - - closed bool - - sync.Mutex // guards err - err error -} - -const ciBufferSize = 64 * 1024 - -// flush buffer before the buffer is filled up and needs reallocation -const ciBufferFlushSize = 63 * 1024 - -func (cn *conn) prepareCopyIn(q string) (_ driver.Stmt, err error) { - if !cn.isInTransaction() { - return nil, errCopyNotSupportedOutsideTxn - } - - ci := ©in{ - cn: cn, - buffer: make([]byte, 0, ciBufferSize), - rowData: make(chan []byte), - done: make(chan bool, 1), - } - // add CopyData identifier + 4 bytes for message length - ci.buffer = append(ci.buffer, 'd', 0, 0, 0, 0) - - b := cn.writeBuf('Q') - b.string(q) - cn.send(b) - -awaitCopyInResponse: - for { - t, r := cn.recv1() - switch t { - case 'G': - if r.byte() != 0 { - err = errBinaryCopyNotSupported - break awaitCopyInResponse - } - go ci.resploop() - return ci, nil - case 'H': - err = errCopyToNotSupported - break awaitCopyInResponse - case 'E': - err = parseError(r) - case 'Z': - if err == nil { - ci.setBad() - errorf("unexpected ReadyForQuery in response to COPY") - } - cn.processReadyForQuery(r) - return nil, err - default: - ci.setBad() - errorf("unknown response for copy query: %q", t) - } - } - - // something went wrong, abort COPY before we return - b = cn.writeBuf('f') - b.string(err.Error()) - cn.send(b) - - for { - t, r := cn.recv1() - switch t { - case 'c', 'C', 'E': - case 'Z': - // correctly aborted, we're done - cn.processReadyForQuery(r) - return nil, err - default: - ci.setBad() - errorf("unknown response for CopyFail: %q", t) - } - } -} - -func (ci *copyin) flush(buf []byte) { - // set message length (without message identifier) - binary.BigEndian.PutUint32(buf[1:], uint32(len(buf)-1)) - - _, err := ci.cn.c.Write(buf) - if err != nil { - panic(err) - } -} - -func (ci *copyin) resploop() { - for { - var r readBuf - t, err := ci.cn.recvMessage(&r) - if err != nil { - ci.setBad() - ci.setError(err) - ci.done <- true - return - } - switch t { - case 'C': - // complete - case 'N': - // NoticeResponse - case 'Z': - ci.cn.processReadyForQuery(&r) - ci.done <- true - return - case 'E': - err := parseError(&r) - ci.setError(err) - default: - ci.setBad() - ci.setError(fmt.Errorf("unknown response during CopyIn: %q", t)) - ci.done <- true - return - } - } -} - -func (ci *copyin) setBad() { - ci.Lock() - ci.cn.bad = true - ci.Unlock() -} - -func (ci *copyin) isBad() bool { - ci.Lock() - b := ci.cn.bad - ci.Unlock() - return b -} - -func (ci *copyin) isErrorSet() bool { - ci.Lock() - isSet := (ci.err != nil) - ci.Unlock() - return isSet -} - -// setError() sets ci.err if one has not been set already. Caller must not be -// holding ci.Mutex. -func (ci *copyin) setError(err error) { - ci.Lock() - if ci.err == nil { - ci.err = err - } - ci.Unlock() -} - -func (ci *copyin) NumInput() int { - return -1 -} - -func (ci *copyin) Query(v []driver.Value) (r driver.Rows, err error) { - return nil, ErrNotSupported -} - -// Exec inserts values into the COPY stream. The insert is asynchronous -// and Exec can return errors from previous Exec calls to the same -// COPY stmt. -// -// You need to call Exec(nil) to sync the COPY stream and to get any -// errors from pending data, since Stmt.Close() doesn't return errors -// to the user. -func (ci *copyin) Exec(v []driver.Value) (r driver.Result, err error) { - if ci.closed { - return nil, errCopyInClosed - } - - if ci.isBad() { - return nil, driver.ErrBadConn - } - defer ci.cn.errRecover(&err) - - if ci.isErrorSet() { - return nil, ci.err - } - - if len(v) == 0 { - return nil, ci.Close() - } - - numValues := len(v) - for i, value := range v { - ci.buffer = appendEncodedText(&ci.cn.parameterStatus, ci.buffer, value) - if i < numValues-1 { - ci.buffer = append(ci.buffer, '\t') - } - } - - ci.buffer = append(ci.buffer, '\n') - - if len(ci.buffer) > ciBufferFlushSize { - ci.flush(ci.buffer) - // reset buffer, keep bytes for message identifier and length - ci.buffer = ci.buffer[:5] - } - - return driver.RowsAffected(0), nil -} - -func (ci *copyin) Close() (err error) { - if ci.closed { // Don't do anything, we're already closed - return nil - } - ci.closed = true - - if ci.isBad() { - return driver.ErrBadConn - } - defer ci.cn.errRecover(&err) - - if len(ci.buffer) > 0 { - ci.flush(ci.buffer) - } - // Avoid touching the scratch buffer as resploop could be using it. - err = ci.cn.sendSimpleMessage('c') - if err != nil { - return err - } - - <-ci.done - ci.cn.inCopy = false - - if ci.isErrorSet() { - err = ci.err - return err - } - return nil -} diff --git a/vendor/github.com/lib/pq/doc.go b/vendor/github.com/lib/pq/doc.go deleted file mode 100644 index a1b029713..000000000 --- a/vendor/github.com/lib/pq/doc.go +++ /dev/null @@ -1,245 +0,0 @@ -/* -Package pq is a pure Go Postgres driver for the database/sql package. - -In most cases clients will use the database/sql package instead of -using this package directly. For example: - - import ( - "database/sql" - - _ "github.com/lib/pq" - ) - - func main() { - connStr := "user=pqgotest dbname=pqgotest sslmode=verify-full" - db, err := sql.Open("postgres", connStr) - if err != nil { - log.Fatal(err) - } - - age := 21 - rows, err := db.Query("SELECT name FROM users WHERE age = $1", age) - … - } - -You can also connect to a database using a URL. For example: - - connStr := "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full" - db, err := sql.Open("postgres", connStr) - - -Connection String Parameters - - -Similarly to libpq, when establishing a connection using pq you are expected to -supply a connection string containing zero or more parameters. -A subset of the connection parameters supported by libpq are also supported by pq. -Additionally, pq also lets you specify run-time parameters (such as search_path or work_mem) -directly in the connection string. This is different from libpq, which does not allow -run-time parameters in the connection string, instead requiring you to supply -them in the options parameter. - -For compatibility with libpq, the following special connection parameters are -supported: - - * dbname - The name of the database to connect to - * user - The user to sign in as - * password - The user's password - * host - The host to connect to. Values that start with / are for unix - domain sockets. (default is localhost) - * port - The port to bind to. (default is 5432) - * sslmode - Whether or not to use SSL (default is require, this is not - the default for libpq) - * fallback_application_name - An application_name to fall back to if one isn't provided. - * connect_timeout - Maximum wait for connection, in seconds. Zero or - not specified means wait indefinitely. - * sslcert - Cert file location. The file must contain PEM encoded data. - * sslkey - Key file location. The file must contain PEM encoded data. - * sslrootcert - The location of the root certificate file. The file - must contain PEM encoded data. - -Valid values for sslmode are: - - * disable - No SSL - * require - Always SSL (skip verification) - * verify-ca - Always SSL (verify that the certificate presented by the - server was signed by a trusted CA) - * verify-full - Always SSL (verify that the certification presented by - the server was signed by a trusted CA and the server host name - matches the one in the certificate) - -See http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING -for more information about connection string parameters. - -Use single quotes for values that contain whitespace: - - "user=pqgotest password='with spaces'" - -A backslash will escape the next character in values: - - "user=space\ man password='it\'s valid'" - -Note that the connection parameter client_encoding (which sets the -text encoding for the connection) may be set but must be "UTF8", -matching with the same rules as Postgres. It is an error to provide -any other value. - -In addition to the parameters listed above, any run-time parameter that can be -set at backend start time can be set in the connection string. For more -information, see -http://www.postgresql.org/docs/current/static/runtime-config.html. - -Most environment variables as specified at http://www.postgresql.org/docs/current/static/libpq-envars.html -supported by libpq are also supported by pq. If any of the environment -variables not supported by pq are set, pq will panic during connection -establishment. Environment variables have a lower precedence than explicitly -provided connection parameters. - -The pgpass mechanism as described in http://www.postgresql.org/docs/current/static/libpq-pgpass.html -is supported, but on Windows PGPASSFILE must be specified explicitly. - - -Queries - - -database/sql does not dictate any specific format for parameter -markers in query strings, and pq uses the Postgres-native ordinal markers, -as shown above. The same marker can be reused for the same parameter: - - rows, err := db.Query(`SELECT name FROM users WHERE favorite_fruit = $1 - OR age BETWEEN $2 AND $2 + 3`, "orange", 64) - -pq does not support the LastInsertId() method of the Result type in database/sql. -To return the identifier of an INSERT (or UPDATE or DELETE), use the Postgres -RETURNING clause with a standard Query or QueryRow call: - - var userid int - err := db.QueryRow(`INSERT INTO users(name, favorite_fruit, age) - VALUES('beatrice', 'starfruit', 93) RETURNING id`).Scan(&userid) - -For more details on RETURNING, see the Postgres documentation: - - http://www.postgresql.org/docs/current/static/sql-insert.html - http://www.postgresql.org/docs/current/static/sql-update.html - http://www.postgresql.org/docs/current/static/sql-delete.html - -For additional instructions on querying see the documentation for the database/sql package. - - -Data Types - - -Parameters pass through driver.DefaultParameterConverter before they are handled -by this package. When the binary_parameters connection option is enabled, -[]byte values are sent directly to the backend as data in binary format. - -This package returns the following types for values from the PostgreSQL backend: - - - integer types smallint, integer, and bigint are returned as int64 - - floating-point types real and double precision are returned as float64 - - character types char, varchar, and text are returned as string - - temporal types date, time, timetz, timestamp, and timestamptz are - returned as time.Time - - the boolean type is returned as bool - - the bytea type is returned as []byte - -All other types are returned directly from the backend as []byte values in text format. - - -Errors - - -pq may return errors of type *pq.Error which can be interrogated for error details: - - if err, ok := err.(*pq.Error); ok { - fmt.Println("pq error:", err.Code.Name()) - } - -See the pq.Error type for details. - - -Bulk imports - -You can perform bulk imports by preparing a statement returned by pq.CopyIn (or -pq.CopyInSchema) in an explicit transaction (sql.Tx). The returned statement -handle can then be repeatedly "executed" to copy data into the target table. -After all data has been processed you should call Exec() once with no arguments -to flush all buffered data. Any call to Exec() might return an error which -should be handled appropriately, but because of the internal buffering an error -returned by Exec() might not be related to the data passed in the call that -failed. - -CopyIn uses COPY FROM internally. It is not possible to COPY outside of an -explicit transaction in pq. - -Usage example: - - txn, err := db.Begin() - if err != nil { - log.Fatal(err) - } - - stmt, err := txn.Prepare(pq.CopyIn("users", "name", "age")) - if err != nil { - log.Fatal(err) - } - - for _, user := range users { - _, err = stmt.Exec(user.Name, int64(user.Age)) - if err != nil { - log.Fatal(err) - } - } - - _, err = stmt.Exec() - if err != nil { - log.Fatal(err) - } - - err = stmt.Close() - if err != nil { - log.Fatal(err) - } - - err = txn.Commit() - if err != nil { - log.Fatal(err) - } - - -Notifications - - -PostgreSQL supports a simple publish/subscribe model over database -connections. See http://www.postgresql.org/docs/current/static/sql-notify.html -for more information about the general mechanism. - -To start listening for notifications, you first have to open a new connection -to the database by calling NewListener. This connection can not be used for -anything other than LISTEN / NOTIFY. Calling Listen will open a "notification -channel"; once a notification channel is open, a notification generated on that -channel will effect a send on the Listener.Notify channel. A notification -channel will remain open until Unlisten is called, though connection loss might -result in some notifications being lost. To solve this problem, Listener sends -a nil pointer over the Notify channel any time the connection is re-established -following a connection loss. The application can get information about the -state of the underlying connection by setting an event callback in the call to -NewListener. - -A single Listener can safely be used from concurrent goroutines, which means -that there is often no need to create more than one Listener in your -application. However, a Listener is always connected to a single database, so -you will need to create a new Listener instance for every database you want to -receive notifications in. - -The channel name in both Listen and Unlisten is case sensitive, and can contain -any characters legal in an identifier (see -http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS -for more information). Note that the channel name will be truncated to 63 -bytes by the PostgreSQL server. - -You can find a complete, working example of Listener usage at -http://godoc.org/github.com/lib/pq/example/listen. - -*/ -package pq diff --git a/vendor/github.com/lib/pq/encode.go b/vendor/github.com/lib/pq/encode.go deleted file mode 100644 index 3b0d365f2..000000000 --- a/vendor/github.com/lib/pq/encode.go +++ /dev/null @@ -1,603 +0,0 @@ -package pq - -import ( - "bytes" - "database/sql/driver" - "encoding/binary" - "encoding/hex" - "errors" - "fmt" - "math" - "strconv" - "strings" - "sync" - "time" - - "github.com/lib/pq/oid" -) - -func binaryEncode(parameterStatus *parameterStatus, x interface{}) []byte { - switch v := x.(type) { - case []byte: - return v - default: - return encode(parameterStatus, x, oid.T_unknown) - } -} - -func encode(parameterStatus *parameterStatus, x interface{}, pgtypOid oid.Oid) []byte { - switch v := x.(type) { - case int64: - return strconv.AppendInt(nil, v, 10) - case float64: - return strconv.AppendFloat(nil, v, 'f', -1, 64) - case []byte: - if pgtypOid == oid.T_bytea { - return encodeBytea(parameterStatus.serverVersion, v) - } - - return v - case string: - if pgtypOid == oid.T_bytea { - return encodeBytea(parameterStatus.serverVersion, []byte(v)) - } - - return []byte(v) - case bool: - return strconv.AppendBool(nil, v) - case time.Time: - return formatTs(v) - - default: - errorf("encode: unknown type for %T", v) - } - - panic("not reached") -} - -func decode(parameterStatus *parameterStatus, s []byte, typ oid.Oid, f format) interface{} { - switch f { - case formatBinary: - return binaryDecode(parameterStatus, s, typ) - case formatText: - return textDecode(parameterStatus, s, typ) - default: - panic("not reached") - } -} - -func binaryDecode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interface{} { - switch typ { - case oid.T_bytea: - return s - case oid.T_int8: - return int64(binary.BigEndian.Uint64(s)) - case oid.T_int4: - return int64(int32(binary.BigEndian.Uint32(s))) - case oid.T_int2: - return int64(int16(binary.BigEndian.Uint16(s))) - case oid.T_uuid: - b, err := decodeUUIDBinary(s) - if err != nil { - panic(err) - } - return b - - default: - errorf("don't know how to decode binary parameter of type %d", uint32(typ)) - } - - panic("not reached") -} - -func textDecode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interface{} { - switch typ { - case oid.T_char, oid.T_varchar, oid.T_text: - return string(s) - case oid.T_bytea: - b, err := parseBytea(s) - if err != nil { - errorf("%s", err) - } - return b - case oid.T_timestamptz: - return parseTs(parameterStatus.currentLocation, string(s)) - case oid.T_timestamp, oid.T_date: - return parseTs(nil, string(s)) - case oid.T_time: - return mustParse("15:04:05", typ, s) - case oid.T_timetz: - return mustParse("15:04:05-07", typ, s) - case oid.T_bool: - return s[0] == 't' - case oid.T_int8, oid.T_int4, oid.T_int2: - i, err := strconv.ParseInt(string(s), 10, 64) - if err != nil { - errorf("%s", err) - } - return i - case oid.T_float4, oid.T_float8: - bits := 64 - if typ == oid.T_float4 { - bits = 32 - } - f, err := strconv.ParseFloat(string(s), bits) - if err != nil { - errorf("%s", err) - } - return f - } - - return s -} - -// appendEncodedText encodes item in text format as required by COPY -// and appends to buf -func appendEncodedText(parameterStatus *parameterStatus, buf []byte, x interface{}) []byte { - switch v := x.(type) { - case int64: - return strconv.AppendInt(buf, v, 10) - case float64: - return strconv.AppendFloat(buf, v, 'f', -1, 64) - case []byte: - encodedBytea := encodeBytea(parameterStatus.serverVersion, v) - return appendEscapedText(buf, string(encodedBytea)) - case string: - return appendEscapedText(buf, v) - case bool: - return strconv.AppendBool(buf, v) - case time.Time: - return append(buf, formatTs(v)...) - case nil: - return append(buf, "\\N"...) - default: - errorf("encode: unknown type for %T", v) - } - - panic("not reached") -} - -func appendEscapedText(buf []byte, text string) []byte { - escapeNeeded := false - startPos := 0 - var c byte - - // check if we need to escape - for i := 0; i < len(text); i++ { - c = text[i] - if c == '\\' || c == '\n' || c == '\r' || c == '\t' { - escapeNeeded = true - startPos = i - break - } - } - if !escapeNeeded { - return append(buf, text...) - } - - // copy till first char to escape, iterate the rest - result := append(buf, text[:startPos]...) - for i := startPos; i < len(text); i++ { - c = text[i] - switch c { - case '\\': - result = append(result, '\\', '\\') - case '\n': - result = append(result, '\\', 'n') - case '\r': - result = append(result, '\\', 'r') - case '\t': - result = append(result, '\\', 't') - default: - result = append(result, c) - } - } - return result -} - -func mustParse(f string, typ oid.Oid, s []byte) time.Time { - str := string(s) - - // check for a 30-minute-offset timezone - if (typ == oid.T_timestamptz || typ == oid.T_timetz) && - str[len(str)-3] == ':' { - f += ":00" - } - t, err := time.Parse(f, str) - if err != nil { - errorf("decode: %s", err) - } - return t -} - -var errInvalidTimestamp = errors.New("invalid timestamp") - -type timestampParser struct { - err error -} - -func (p *timestampParser) expect(str string, char byte, pos int) { - if p.err != nil { - return - } - if pos+1 > len(str) { - p.err = errInvalidTimestamp - return - } - if c := str[pos]; c != char && p.err == nil { - p.err = fmt.Errorf("expected '%v' at position %v; got '%v'", char, pos, c) - } -} - -func (p *timestampParser) mustAtoi(str string, begin int, end int) int { - if p.err != nil { - return 0 - } - if begin < 0 || end < 0 || begin > end || end > len(str) { - p.err = errInvalidTimestamp - return 0 - } - result, err := strconv.Atoi(str[begin:end]) - if err != nil { - if p.err == nil { - p.err = fmt.Errorf("expected number; got '%v'", str) - } - return 0 - } - return result -} - -// The location cache caches the time zones typically used by the client. -type locationCache struct { - cache map[int]*time.Location - lock sync.Mutex -} - -// All connections share the same list of timezones. Benchmarking shows that -// about 5% speed could be gained by putting the cache in the connection and -// losing the mutex, at the cost of a small amount of memory and a somewhat -// significant increase in code complexity. -var globalLocationCache = newLocationCache() - -func newLocationCache() *locationCache { - return &locationCache{cache: make(map[int]*time.Location)} -} - -// Returns the cached timezone for the specified offset, creating and caching -// it if necessary. -func (c *locationCache) getLocation(offset int) *time.Location { - c.lock.Lock() - defer c.lock.Unlock() - - location, ok := c.cache[offset] - if !ok { - location = time.FixedZone("", offset) - c.cache[offset] = location - } - - return location -} - -var infinityTsEnabled = false -var infinityTsNegative time.Time -var infinityTsPositive time.Time - -const ( - infinityTsEnabledAlready = "pq: infinity timestamp enabled already" - infinityTsNegativeMustBeSmaller = "pq: infinity timestamp: negative value must be smaller (before) than positive" -) - -// EnableInfinityTs controls the handling of Postgres' "-infinity" and -// "infinity" "timestamp"s. -// -// If EnableInfinityTs is not called, "-infinity" and "infinity" will return -// []byte("-infinity") and []byte("infinity") respectively, and potentially -// cause error "sql: Scan error on column index 0: unsupported driver -> Scan -// pair: []uint8 -> *time.Time", when scanning into a time.Time value. -// -// Once EnableInfinityTs has been called, all connections created using this -// driver will decode Postgres' "-infinity" and "infinity" for "timestamp", -// "timestamp with time zone" and "date" types to the predefined minimum and -// maximum times, respectively. When encoding time.Time values, any time which -// equals or precedes the predefined minimum time will be encoded to -// "-infinity". Any values at or past the maximum time will similarly be -// encoded to "infinity". -// -// If EnableInfinityTs is called with negative >= positive, it will panic. -// Calling EnableInfinityTs after a connection has been established results in -// undefined behavior. If EnableInfinityTs is called more than once, it will -// panic. -func EnableInfinityTs(negative time.Time, positive time.Time) { - if infinityTsEnabled { - panic(infinityTsEnabledAlready) - } - if !negative.Before(positive) { - panic(infinityTsNegativeMustBeSmaller) - } - infinityTsEnabled = true - infinityTsNegative = negative - infinityTsPositive = positive -} - -/* - * Testing might want to toggle infinityTsEnabled - */ -func disableInfinityTs() { - infinityTsEnabled = false -} - -// This is a time function specific to the Postgres default DateStyle -// setting ("ISO, MDY"), the only one we currently support. This -// accounts for the discrepancies between the parsing available with -// time.Parse and the Postgres date formatting quirks. -func parseTs(currentLocation *time.Location, str string) interface{} { - switch str { - case "-infinity": - if infinityTsEnabled { - return infinityTsNegative - } - return []byte(str) - case "infinity": - if infinityTsEnabled { - return infinityTsPositive - } - return []byte(str) - } - t, err := ParseTimestamp(currentLocation, str) - if err != nil { - panic(err) - } - return t -} - -// ParseTimestamp parses Postgres' text format. It returns a time.Time in -// currentLocation iff that time's offset agrees with the offset sent from the -// Postgres server. Otherwise, ParseTimestamp returns a time.Time with the -// fixed offset offset provided by the Postgres server. -func ParseTimestamp(currentLocation *time.Location, str string) (time.Time, error) { - p := timestampParser{} - - monSep := strings.IndexRune(str, '-') - // this is Gregorian year, not ISO Year - // In Gregorian system, the year 1 BC is followed by AD 1 - year := p.mustAtoi(str, 0, monSep) - daySep := monSep + 3 - month := p.mustAtoi(str, monSep+1, daySep) - p.expect(str, '-', daySep) - timeSep := daySep + 3 - day := p.mustAtoi(str, daySep+1, timeSep) - - minLen := monSep + len("01-01") + 1 - - isBC := strings.HasSuffix(str, " BC") - if isBC { - minLen += 3 - } - - var hour, minute, second int - if len(str) > minLen { - p.expect(str, ' ', timeSep) - minSep := timeSep + 3 - p.expect(str, ':', minSep) - hour = p.mustAtoi(str, timeSep+1, minSep) - secSep := minSep + 3 - p.expect(str, ':', secSep) - minute = p.mustAtoi(str, minSep+1, secSep) - secEnd := secSep + 3 - second = p.mustAtoi(str, secSep+1, secEnd) - } - remainderIdx := monSep + len("01-01 00:00:00") + 1 - // Three optional (but ordered) sections follow: the - // fractional seconds, the time zone offset, and the BC - // designation. We set them up here and adjust the other - // offsets if the preceding sections exist. - - nanoSec := 0 - tzOff := 0 - - if remainderIdx < len(str) && str[remainderIdx] == '.' { - fracStart := remainderIdx + 1 - fracOff := strings.IndexAny(str[fracStart:], "-+ ") - if fracOff < 0 { - fracOff = len(str) - fracStart - } - fracSec := p.mustAtoi(str, fracStart, fracStart+fracOff) - nanoSec = fracSec * (1000000000 / int(math.Pow(10, float64(fracOff)))) - - remainderIdx += fracOff + 1 - } - if tzStart := remainderIdx; tzStart < len(str) && (str[tzStart] == '-' || str[tzStart] == '+') { - // time zone separator is always '-' or '+' (UTC is +00) - var tzSign int - switch c := str[tzStart]; c { - case '-': - tzSign = -1 - case '+': - tzSign = +1 - default: - return time.Time{}, fmt.Errorf("expected '-' or '+' at position %v; got %v", tzStart, c) - } - tzHours := p.mustAtoi(str, tzStart+1, tzStart+3) - remainderIdx += 3 - var tzMin, tzSec int - if remainderIdx < len(str) && str[remainderIdx] == ':' { - tzMin = p.mustAtoi(str, remainderIdx+1, remainderIdx+3) - remainderIdx += 3 - } - if remainderIdx < len(str) && str[remainderIdx] == ':' { - tzSec = p.mustAtoi(str, remainderIdx+1, remainderIdx+3) - remainderIdx += 3 - } - tzOff = tzSign * ((tzHours * 60 * 60) + (tzMin * 60) + tzSec) - } - var isoYear int - - if isBC { - isoYear = 1 - year - remainderIdx += 3 - } else { - isoYear = year - } - if remainderIdx < len(str) { - return time.Time{}, fmt.Errorf("expected end of input, got %v", str[remainderIdx:]) - } - t := time.Date(isoYear, time.Month(month), day, - hour, minute, second, nanoSec, - globalLocationCache.getLocation(tzOff)) - - if currentLocation != nil { - // Set the location of the returned Time based on the session's - // TimeZone value, but only if the local time zone database agrees with - // the remote database on the offset. - lt := t.In(currentLocation) - _, newOff := lt.Zone() - if newOff == tzOff { - t = lt - } - } - - return t, p.err -} - -// formatTs formats t into a format postgres understands. -func formatTs(t time.Time) []byte { - if infinityTsEnabled { - // t <= -infinity : ! (t > -infinity) - if !t.After(infinityTsNegative) { - return []byte("-infinity") - } - // t >= infinity : ! (!t < infinity) - if !t.Before(infinityTsPositive) { - return []byte("infinity") - } - } - return FormatTimestamp(t) -} - -// FormatTimestamp formats t into Postgres' text format for timestamps. -func FormatTimestamp(t time.Time) []byte { - // Need to send dates before 0001 A.D. with " BC" suffix, instead of the - // minus sign preferred by Go. - // Beware, "0000" in ISO is "1 BC", "-0001" is "2 BC" and so on - bc := false - if t.Year() <= 0 { - // flip year sign, and add 1, e.g: "0" will be "1", and "-10" will be "11" - t = t.AddDate((-t.Year())*2+1, 0, 0) - bc = true - } - b := []byte(t.Format("2006-01-02 15:04:05.999999999Z07:00")) - - _, offset := t.Zone() - offset = offset % 60 - if offset != 0 { - // RFC3339Nano already printed the minus sign - if offset < 0 { - offset = -offset - } - - b = append(b, ':') - if offset < 10 { - b = append(b, '0') - } - b = strconv.AppendInt(b, int64(offset), 10) - } - - if bc { - b = append(b, " BC"...) - } - return b -} - -// Parse a bytea value received from the server. Both "hex" and the legacy -// "escape" format are supported. -func parseBytea(s []byte) (result []byte, err error) { - if len(s) >= 2 && bytes.Equal(s[:2], []byte("\\x")) { - // bytea_output = hex - s = s[2:] // trim off leading "\\x" - result = make([]byte, hex.DecodedLen(len(s))) - _, err := hex.Decode(result, s) - if err != nil { - return nil, err - } - } else { - // bytea_output = escape - for len(s) > 0 { - if s[0] == '\\' { - // escaped '\\' - if len(s) >= 2 && s[1] == '\\' { - result = append(result, '\\') - s = s[2:] - continue - } - - // '\\' followed by an octal number - if len(s) < 4 { - return nil, fmt.Errorf("invalid bytea sequence %v", s) - } - r, err := strconv.ParseInt(string(s[1:4]), 8, 9) - if err != nil { - return nil, fmt.Errorf("could not parse bytea value: %s", err.Error()) - } - result = append(result, byte(r)) - s = s[4:] - } else { - // We hit an unescaped, raw byte. Try to read in as many as - // possible in one go. - i := bytes.IndexByte(s, '\\') - if i == -1 { - result = append(result, s...) - break - } - result = append(result, s[:i]...) - s = s[i:] - } - } - } - - return result, nil -} - -func encodeBytea(serverVersion int, v []byte) (result []byte) { - if serverVersion >= 90000 { - // Use the hex format if we know that the server supports it - result = make([]byte, 2+hex.EncodedLen(len(v))) - result[0] = '\\' - result[1] = 'x' - hex.Encode(result[2:], v) - } else { - // .. or resort to "escape" - for _, b := range v { - if b == '\\' { - result = append(result, '\\', '\\') - } else if b < 0x20 || b > 0x7e { - result = append(result, []byte(fmt.Sprintf("\\%03o", b))...) - } else { - result = append(result, b) - } - } - } - - return result -} - -// NullTime represents a time.Time that may be null. NullTime implements the -// sql.Scanner interface so it can be used as a scan destination, similar to -// sql.NullString. -type NullTime struct { - Time time.Time - Valid bool // Valid is true if Time is not NULL -} - -// Scan implements the Scanner interface. -func (nt *NullTime) Scan(value interface{}) error { - nt.Time, nt.Valid = value.(time.Time) - return nil -} - -// Value implements the driver Valuer interface. -func (nt NullTime) Value() (driver.Value, error) { - if !nt.Valid { - return nil, nil - } - return nt.Time, nil -} diff --git a/vendor/github.com/lib/pq/error.go b/vendor/github.com/lib/pq/error.go deleted file mode 100644 index b4bb44cee..000000000 --- a/vendor/github.com/lib/pq/error.go +++ /dev/null @@ -1,508 +0,0 @@ -package pq - -import ( - "database/sql/driver" - "fmt" - "io" - "net" - "runtime" -) - -// Error severities -const ( - Efatal = "FATAL" - Epanic = "PANIC" - Ewarning = "WARNING" - Enotice = "NOTICE" - Edebug = "DEBUG" - Einfo = "INFO" - Elog = "LOG" -) - -// Error represents an error communicating with the server. -// -// See http://www.postgresql.org/docs/current/static/protocol-error-fields.html for details of the fields -type Error struct { - Severity string - Code ErrorCode - Message string - Detail string - Hint string - Position string - InternalPosition string - InternalQuery string - Where string - Schema string - Table string - Column string - DataTypeName string - Constraint string - File string - Line string - Routine string -} - -// ErrorCode is a five-character error code. -type ErrorCode string - -// Name returns a more human friendly rendering of the error code, namely the -// "condition name". -// -// See http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html for -// details. -func (ec ErrorCode) Name() string { - return errorCodeNames[ec] -} - -// ErrorClass is only the class part of an error code. -type ErrorClass string - -// Name returns the condition name of an error class. It is equivalent to the -// condition name of the "standard" error code (i.e. the one having the last -// three characters "000"). -func (ec ErrorClass) Name() string { - return errorCodeNames[ErrorCode(ec+"000")] -} - -// Class returns the error class, e.g. "28". -// -// See http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html for -// details. -func (ec ErrorCode) Class() ErrorClass { - return ErrorClass(ec[0:2]) -} - -// errorCodeNames is a mapping between the five-character error codes and the -// human readable "condition names". It is derived from the list at -// http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html -var errorCodeNames = map[ErrorCode]string{ - // Class 00 - Successful Completion - "00000": "successful_completion", - // Class 01 - Warning - "01000": "warning", - "0100C": "dynamic_result_sets_returned", - "01008": "implicit_zero_bit_padding", - "01003": "null_value_eliminated_in_set_function", - "01007": "privilege_not_granted", - "01006": "privilege_not_revoked", - "01004": "string_data_right_truncation", - "01P01": "deprecated_feature", - // Class 02 - No Data (this is also a warning class per the SQL standard) - "02000": "no_data", - "02001": "no_additional_dynamic_result_sets_returned", - // Class 03 - SQL Statement Not Yet Complete - "03000": "sql_statement_not_yet_complete", - // Class 08 - Connection Exception - "08000": "connection_exception", - "08003": "connection_does_not_exist", - "08006": "connection_failure", - "08001": "sqlclient_unable_to_establish_sqlconnection", - "08004": "sqlserver_rejected_establishment_of_sqlconnection", - "08007": "transaction_resolution_unknown", - "08P01": "protocol_violation", - // Class 09 - Triggered Action Exception - "09000": "triggered_action_exception", - // Class 0A - Feature Not Supported - "0A000": "feature_not_supported", - // Class 0B - Invalid Transaction Initiation - "0B000": "invalid_transaction_initiation", - // Class 0F - Locator Exception - "0F000": "locator_exception", - "0F001": "invalid_locator_specification", - // Class 0L - Invalid Grantor - "0L000": "invalid_grantor", - "0LP01": "invalid_grant_operation", - // Class 0P - Invalid Role Specification - "0P000": "invalid_role_specification", - // Class 0Z - Diagnostics Exception - "0Z000": "diagnostics_exception", - "0Z002": "stacked_diagnostics_accessed_without_active_handler", - // Class 20 - Case Not Found - "20000": "case_not_found", - // Class 21 - Cardinality Violation - "21000": "cardinality_violation", - // Class 22 - Data Exception - "22000": "data_exception", - "2202E": "array_subscript_error", - "22021": "character_not_in_repertoire", - "22008": "datetime_field_overflow", - "22012": "division_by_zero", - "22005": "error_in_assignment", - "2200B": "escape_character_conflict", - "22022": "indicator_overflow", - "22015": "interval_field_overflow", - "2201E": "invalid_argument_for_logarithm", - "22014": "invalid_argument_for_ntile_function", - "22016": "invalid_argument_for_nth_value_function", - "2201F": "invalid_argument_for_power_function", - "2201G": "invalid_argument_for_width_bucket_function", - "22018": "invalid_character_value_for_cast", - "22007": "invalid_datetime_format", - "22019": "invalid_escape_character", - "2200D": "invalid_escape_octet", - "22025": "invalid_escape_sequence", - "22P06": "nonstandard_use_of_escape_character", - "22010": "invalid_indicator_parameter_value", - "22023": "invalid_parameter_value", - "2201B": "invalid_regular_expression", - "2201W": "invalid_row_count_in_limit_clause", - "2201X": "invalid_row_count_in_result_offset_clause", - "22009": "invalid_time_zone_displacement_value", - "2200C": "invalid_use_of_escape_character", - "2200G": "most_specific_type_mismatch", - "22004": "null_value_not_allowed", - "22002": "null_value_no_indicator_parameter", - "22003": "numeric_value_out_of_range", - "22026": "string_data_length_mismatch", - "22001": "string_data_right_truncation", - "22011": "substring_error", - "22027": "trim_error", - "22024": "unterminated_c_string", - "2200F": "zero_length_character_string", - "22P01": "floating_point_exception", - "22P02": "invalid_text_representation", - "22P03": "invalid_binary_representation", - "22P04": "bad_copy_file_format", - "22P05": "untranslatable_character", - "2200L": "not_an_xml_document", - "2200M": "invalid_xml_document", - "2200N": "invalid_xml_content", - "2200S": "invalid_xml_comment", - "2200T": "invalid_xml_processing_instruction", - // Class 23 - Integrity Constraint Violation - "23000": "integrity_constraint_violation", - "23001": "restrict_violation", - "23502": "not_null_violation", - "23503": "foreign_key_violation", - "23505": "unique_violation", - "23514": "check_violation", - "23P01": "exclusion_violation", - // Class 24 - Invalid Cursor State - "24000": "invalid_cursor_state", - // Class 25 - Invalid Transaction State - "25000": "invalid_transaction_state", - "25001": "active_sql_transaction", - "25002": "branch_transaction_already_active", - "25008": "held_cursor_requires_same_isolation_level", - "25003": "inappropriate_access_mode_for_branch_transaction", - "25004": "inappropriate_isolation_level_for_branch_transaction", - "25005": "no_active_sql_transaction_for_branch_transaction", - "25006": "read_only_sql_transaction", - "25007": "schema_and_data_statement_mixing_not_supported", - "25P01": "no_active_sql_transaction", - "25P02": "in_failed_sql_transaction", - // Class 26 - Invalid SQL Statement Name - "26000": "invalid_sql_statement_name", - // Class 27 - Triggered Data Change Violation - "27000": "triggered_data_change_violation", - // Class 28 - Invalid Authorization Specification - "28000": "invalid_authorization_specification", - "28P01": "invalid_password", - // Class 2B - Dependent Privilege Descriptors Still Exist - "2B000": "dependent_privilege_descriptors_still_exist", - "2BP01": "dependent_objects_still_exist", - // Class 2D - Invalid Transaction Termination - "2D000": "invalid_transaction_termination", - // Class 2F - SQL Routine Exception - "2F000": "sql_routine_exception", - "2F005": "function_executed_no_return_statement", - "2F002": "modifying_sql_data_not_permitted", - "2F003": "prohibited_sql_statement_attempted", - "2F004": "reading_sql_data_not_permitted", - // Class 34 - Invalid Cursor Name - "34000": "invalid_cursor_name", - // Class 38 - External Routine Exception - "38000": "external_routine_exception", - "38001": "containing_sql_not_permitted", - "38002": "modifying_sql_data_not_permitted", - "38003": "prohibited_sql_statement_attempted", - "38004": "reading_sql_data_not_permitted", - // Class 39 - External Routine Invocation Exception - "39000": "external_routine_invocation_exception", - "39001": "invalid_sqlstate_returned", - "39004": "null_value_not_allowed", - "39P01": "trigger_protocol_violated", - "39P02": "srf_protocol_violated", - // Class 3B - Savepoint Exception - "3B000": "savepoint_exception", - "3B001": "invalid_savepoint_specification", - // Class 3D - Invalid Catalog Name - "3D000": "invalid_catalog_name", - // Class 3F - Invalid Schema Name - "3F000": "invalid_schema_name", - // Class 40 - Transaction Rollback - "40000": "transaction_rollback", - "40002": "transaction_integrity_constraint_violation", - "40001": "serialization_failure", - "40003": "statement_completion_unknown", - "40P01": "deadlock_detected", - // Class 42 - Syntax Error or Access Rule Violation - "42000": "syntax_error_or_access_rule_violation", - "42601": "syntax_error", - "42501": "insufficient_privilege", - "42846": "cannot_coerce", - "42803": "grouping_error", - "42P20": "windowing_error", - "42P19": "invalid_recursion", - "42830": "invalid_foreign_key", - "42602": "invalid_name", - "42622": "name_too_long", - "42939": "reserved_name", - "42804": "datatype_mismatch", - "42P18": "indeterminate_datatype", - "42P21": "collation_mismatch", - "42P22": "indeterminate_collation", - "42809": "wrong_object_type", - "42703": "undefined_column", - "42883": "undefined_function", - "42P01": "undefined_table", - "42P02": "undefined_parameter", - "42704": "undefined_object", - "42701": "duplicate_column", - "42P03": "duplicate_cursor", - "42P04": "duplicate_database", - "42723": "duplicate_function", - "42P05": "duplicate_prepared_statement", - "42P06": "duplicate_schema", - "42P07": "duplicate_table", - "42712": "duplicate_alias", - "42710": "duplicate_object", - "42702": "ambiguous_column", - "42725": "ambiguous_function", - "42P08": "ambiguous_parameter", - "42P09": "ambiguous_alias", - "42P10": "invalid_column_reference", - "42611": "invalid_column_definition", - "42P11": "invalid_cursor_definition", - "42P12": "invalid_database_definition", - "42P13": "invalid_function_definition", - "42P14": "invalid_prepared_statement_definition", - "42P15": "invalid_schema_definition", - "42P16": "invalid_table_definition", - "42P17": "invalid_object_definition", - // Class 44 - WITH CHECK OPTION Violation - "44000": "with_check_option_violation", - // Class 53 - Insufficient Resources - "53000": "insufficient_resources", - "53100": "disk_full", - "53200": "out_of_memory", - "53300": "too_many_connections", - "53400": "configuration_limit_exceeded", - // Class 54 - Program Limit Exceeded - "54000": "program_limit_exceeded", - "54001": "statement_too_complex", - "54011": "too_many_columns", - "54023": "too_many_arguments", - // Class 55 - Object Not In Prerequisite State - "55000": "object_not_in_prerequisite_state", - "55006": "object_in_use", - "55P02": "cant_change_runtime_param", - "55P03": "lock_not_available", - // Class 57 - Operator Intervention - "57000": "operator_intervention", - "57014": "query_canceled", - "57P01": "admin_shutdown", - "57P02": "crash_shutdown", - "57P03": "cannot_connect_now", - "57P04": "database_dropped", - // Class 58 - System Error (errors external to PostgreSQL itself) - "58000": "system_error", - "58030": "io_error", - "58P01": "undefined_file", - "58P02": "duplicate_file", - // Class F0 - Configuration File Error - "F0000": "config_file_error", - "F0001": "lock_file_exists", - // Class HV - Foreign Data Wrapper Error (SQL/MED) - "HV000": "fdw_error", - "HV005": "fdw_column_name_not_found", - "HV002": "fdw_dynamic_parameter_value_needed", - "HV010": "fdw_function_sequence_error", - "HV021": "fdw_inconsistent_descriptor_information", - "HV024": "fdw_invalid_attribute_value", - "HV007": "fdw_invalid_column_name", - "HV008": "fdw_invalid_column_number", - "HV004": "fdw_invalid_data_type", - "HV006": "fdw_invalid_data_type_descriptors", - "HV091": "fdw_invalid_descriptor_field_identifier", - "HV00B": "fdw_invalid_handle", - "HV00C": "fdw_invalid_option_index", - "HV00D": "fdw_invalid_option_name", - "HV090": "fdw_invalid_string_length_or_buffer_length", - "HV00A": "fdw_invalid_string_format", - "HV009": "fdw_invalid_use_of_null_pointer", - "HV014": "fdw_too_many_handles", - "HV001": "fdw_out_of_memory", - "HV00P": "fdw_no_schemas", - "HV00J": "fdw_option_name_not_found", - "HV00K": "fdw_reply_handle", - "HV00Q": "fdw_schema_not_found", - "HV00R": "fdw_table_not_found", - "HV00L": "fdw_unable_to_create_execution", - "HV00M": "fdw_unable_to_create_reply", - "HV00N": "fdw_unable_to_establish_connection", - // Class P0 - PL/pgSQL Error - "P0000": "plpgsql_error", - "P0001": "raise_exception", - "P0002": "no_data_found", - "P0003": "too_many_rows", - // Class XX - Internal Error - "XX000": "internal_error", - "XX001": "data_corrupted", - "XX002": "index_corrupted", -} - -func parseError(r *readBuf) *Error { - err := new(Error) - for t := r.byte(); t != 0; t = r.byte() { - msg := r.string() - switch t { - case 'S': - err.Severity = msg - case 'C': - err.Code = ErrorCode(msg) - case 'M': - err.Message = msg - case 'D': - err.Detail = msg - case 'H': - err.Hint = msg - case 'P': - err.Position = msg - case 'p': - err.InternalPosition = msg - case 'q': - err.InternalQuery = msg - case 'W': - err.Where = msg - case 's': - err.Schema = msg - case 't': - err.Table = msg - case 'c': - err.Column = msg - case 'd': - err.DataTypeName = msg - case 'n': - err.Constraint = msg - case 'F': - err.File = msg - case 'L': - err.Line = msg - case 'R': - err.Routine = msg - } - } - return err -} - -// Fatal returns true if the Error Severity is fatal. -func (err *Error) Fatal() bool { - return err.Severity == Efatal -} - -// Get implements the legacy PGError interface. New code should use the fields -// of the Error struct directly. -func (err *Error) Get(k byte) (v string) { - switch k { - case 'S': - return err.Severity - case 'C': - return string(err.Code) - case 'M': - return err.Message - case 'D': - return err.Detail - case 'H': - return err.Hint - case 'P': - return err.Position - case 'p': - return err.InternalPosition - case 'q': - return err.InternalQuery - case 'W': - return err.Where - case 's': - return err.Schema - case 't': - return err.Table - case 'c': - return err.Column - case 'd': - return err.DataTypeName - case 'n': - return err.Constraint - case 'F': - return err.File - case 'L': - return err.Line - case 'R': - return err.Routine - } - return "" -} - -func (err Error) Error() string { - return "pq: " + err.Message -} - -// PGError is an interface used by previous versions of pq. It is provided -// only to support legacy code. New code should use the Error type. -type PGError interface { - Error() string - Fatal() bool - Get(k byte) (v string) -} - -func errorf(s string, args ...interface{}) { - panic(fmt.Errorf("pq: %s", fmt.Sprintf(s, args...))) -} - -func errRecoverNoErrBadConn(err *error) { - e := recover() - if e == nil { - // Do nothing - return - } - var ok bool - *err, ok = e.(error) - if !ok { - *err = fmt.Errorf("pq: unexpected error: %#v", e) - } -} - -func (c *conn) errRecover(err *error) { - e := recover() - switch v := e.(type) { - case nil: - // Do nothing - case runtime.Error: - c.bad = true - panic(v) - case *Error: - if v.Fatal() { - *err = driver.ErrBadConn - } else { - *err = v - } - case *net.OpError: - *err = driver.ErrBadConn - case error: - if v == io.EOF || v.(error).Error() == "remote error: handshake failure" { - *err = driver.ErrBadConn - } else { - *err = v - } - - default: - c.bad = true - panic(fmt.Sprintf("unknown error: %#v", e)) - } - - // Any time we return ErrBadConn, we need to remember it since *Tx doesn't - // mark the connection bad in database/sql. - if *err == driver.ErrBadConn { - c.bad = true - } -} diff --git a/vendor/github.com/lib/pq/example/listen/doc.go b/vendor/github.com/lib/pq/example/listen/doc.go deleted file mode 100644 index 91e2ddbad..000000000 --- a/vendor/github.com/lib/pq/example/listen/doc.go +++ /dev/null @@ -1,98 +0,0 @@ -/* - -Package listen is a self-contained Go program which uses the LISTEN / NOTIFY -mechanism to avoid polling the database while waiting for more work to arrive. - - // - // You can see the program in action by defining a function similar to - // the following: - // - // CREATE OR REPLACE FUNCTION public.get_work() - // RETURNS bigint - // LANGUAGE sql - // AS $$ - // SELECT CASE WHEN random() >= 0.2 THEN int8 '1' END - // $$ - // ; - - package main - - import ( - "database/sql" - "fmt" - "time" - - "github.com/lib/pq" - ) - - func doWork(db *sql.DB, work int64) { - // work here - } - - func getWork(db *sql.DB) { - for { - // get work from the database here - var work sql.NullInt64 - err := db.QueryRow("SELECT get_work()").Scan(&work) - if err != nil { - fmt.Println("call to get_work() failed: ", err) - time.Sleep(10 * time.Second) - continue - } - if !work.Valid { - // no more work to do - fmt.Println("ran out of work") - return - } - - fmt.Println("starting work on ", work.Int64) - go doWork(db, work.Int64) - } - } - - func waitForNotification(l *pq.Listener) { - select { - case <-l.Notify: - fmt.Println("received notification, new work available") - case <-time.After(90 * time.Second): - go l.Ping() - // Check if there's more work available, just in case it takes - // a while for the Listener to notice connection loss and - // reconnect. - fmt.Println("received no work for 90 seconds, checking for new work") - } - } - - func main() { - var conninfo string = "" - - db, err := sql.Open("postgres", conninfo) - if err != nil { - panic(err) - } - - reportProblem := func(ev pq.ListenerEventType, err error) { - if err != nil { - fmt.Println(err.Error()) - } - } - - minReconn := 10 * time.Second - maxReconn := time.Minute - listener := pq.NewListener(conninfo, minReconn, maxReconn, reportProblem) - err = listener.Listen("getwork") - if err != nil { - panic(err) - } - - fmt.Println("entering main loop") - for { - // process all available work before waiting for notifications - getWork(db) - waitForNotification(listener) - } - } - - -*/ -package listen diff --git a/vendor/github.com/lib/pq/hstore/hstore.go b/vendor/github.com/lib/pq/hstore/hstore.go deleted file mode 100644 index f1470db14..000000000 --- a/vendor/github.com/lib/pq/hstore/hstore.go +++ /dev/null @@ -1,118 +0,0 @@ -package hstore - -import ( - "database/sql" - "database/sql/driver" - "strings" -) - -// Hstore is a wrapper for transferring Hstore values back and forth easily. -type Hstore struct { - Map map[string]sql.NullString -} - -// escapes and quotes hstore keys/values -// s should be a sql.NullString or string -func hQuote(s interface{}) string { - var str string - switch v := s.(type) { - case sql.NullString: - if !v.Valid { - return "NULL" - } - str = v.String - case string: - str = v - default: - panic("not a string or sql.NullString") - } - - str = strings.Replace(str, "\\", "\\\\", -1) - return `"` + strings.Replace(str, "\"", "\\\"", -1) + `"` -} - -// Scan implements the Scanner interface. -// -// Note h.Map is reallocated before the scan to clear existing values. If the -// hstore column's database value is NULL, then h.Map is set to nil instead. -func (h *Hstore) Scan(value interface{}) error { - if value == nil { - h.Map = nil - return nil - } - h.Map = make(map[string]sql.NullString) - var b byte - pair := [][]byte{{}, {}} - pi := 0 - inQuote := false - didQuote := false - sawSlash := false - bindex := 0 - for bindex, b = range value.([]byte) { - if sawSlash { - pair[pi] = append(pair[pi], b) - sawSlash = false - continue - } - - switch b { - case '\\': - sawSlash = true - continue - case '"': - inQuote = !inQuote - if !didQuote { - didQuote = true - } - continue - default: - if !inQuote { - switch b { - case ' ', '\t', '\n', '\r': - continue - case '=': - continue - case '>': - pi = 1 - didQuote = false - continue - case ',': - s := string(pair[1]) - if !didQuote && len(s) == 4 && strings.ToLower(s) == "null" { - h.Map[string(pair[0])] = sql.NullString{String: "", Valid: false} - } else { - h.Map[string(pair[0])] = sql.NullString{String: string(pair[1]), Valid: true} - } - pair[0] = []byte{} - pair[1] = []byte{} - pi = 0 - continue - } - } - } - pair[pi] = append(pair[pi], b) - } - if bindex > 0 { - s := string(pair[1]) - if !didQuote && len(s) == 4 && strings.ToLower(s) == "null" { - h.Map[string(pair[0])] = sql.NullString{String: "", Valid: false} - } else { - h.Map[string(pair[0])] = sql.NullString{String: string(pair[1]), Valid: true} - } - } - return nil -} - -// Value implements the driver Valuer interface. Note if h.Map is nil, the -// database column value will be set to NULL. -func (h Hstore) Value() (driver.Value, error) { - if h.Map == nil { - return nil, nil - } - parts := []string{} - for key, val := range h.Map { - thispart := hQuote(key) + "=>" + hQuote(val) - parts = append(parts, thispart) - } - return []byte(strings.Join(parts, ",")), nil -} diff --git a/vendor/github.com/lib/pq/notify.go b/vendor/github.com/lib/pq/notify.go deleted file mode 100644 index 412c6ac1e..000000000 --- a/vendor/github.com/lib/pq/notify.go +++ /dev/null @@ -1,794 +0,0 @@ -package pq - -// Package pq is a pure Go Postgres driver for the database/sql package. -// This module contains support for Postgres LISTEN/NOTIFY. - -import ( - "errors" - "fmt" - "sync" - "sync/atomic" - "time" -) - -// Notification represents a single notification from the database. -type Notification struct { - // Process ID (PID) of the notifying postgres backend. - BePid int - // Name of the channel the notification was sent on. - Channel string - // Payload, or the empty string if unspecified. - Extra string -} - -func recvNotification(r *readBuf) *Notification { - bePid := r.int32() - channel := r.string() - extra := r.string() - - return &Notification{bePid, channel, extra} -} - -const ( - connStateIdle int32 = iota - connStateExpectResponse - connStateExpectReadyForQuery -) - -type message struct { - typ byte - err error -} - -var errListenerConnClosed = errors.New("pq: ListenerConn has been closed") - -// ListenerConn is a low-level interface for waiting for notifications. You -// should use Listener instead. -type ListenerConn struct { - // guards cn and err - connectionLock sync.Mutex - cn *conn - err error - - connState int32 - - // the sending goroutine will be holding this lock - senderLock sync.Mutex - - notificationChan chan<- *Notification - - replyChan chan message -} - -// NewListenerConn creates a new ListenerConn. Use NewListener instead. -func NewListenerConn(name string, notificationChan chan<- *Notification) (*ListenerConn, error) { - return newDialListenerConn(defaultDialer{}, name, notificationChan) -} - -func newDialListenerConn(d Dialer, name string, c chan<- *Notification) (*ListenerConn, error) { - cn, err := DialOpen(d, name) - if err != nil { - return nil, err - } - - l := &ListenerConn{ - cn: cn.(*conn), - notificationChan: c, - connState: connStateIdle, - replyChan: make(chan message, 2), - } - - go l.listenerConnMain() - - return l, nil -} - -// We can only allow one goroutine at a time to be running a query on the -// connection for various reasons, so the goroutine sending on the connection -// must be holding senderLock. -// -// Returns an error if an unrecoverable error has occurred and the ListenerConn -// should be abandoned. -func (l *ListenerConn) acquireSenderLock() error { - // we must acquire senderLock first to avoid deadlocks; see ExecSimpleQuery - l.senderLock.Lock() - - l.connectionLock.Lock() - err := l.err - l.connectionLock.Unlock() - if err != nil { - l.senderLock.Unlock() - return err - } - return nil -} - -func (l *ListenerConn) releaseSenderLock() { - l.senderLock.Unlock() -} - -// setState advances the protocol state to newState. Returns false if moving -// to that state from the current state is not allowed. -func (l *ListenerConn) setState(newState int32) bool { - var expectedState int32 - - switch newState { - case connStateIdle: - expectedState = connStateExpectReadyForQuery - case connStateExpectResponse: - expectedState = connStateIdle - case connStateExpectReadyForQuery: - expectedState = connStateExpectResponse - default: - panic(fmt.Sprintf("unexpected listenerConnState %d", newState)) - } - - return atomic.CompareAndSwapInt32(&l.connState, expectedState, newState) -} - -// Main logic is here: receive messages from the postgres backend, forward -// notifications and query replies and keep the internal state in sync with the -// protocol state. Returns when the connection has been lost, is about to go -// away or should be discarded because we couldn't agree on the state with the -// server backend. -func (l *ListenerConn) listenerConnLoop() (err error) { - defer errRecoverNoErrBadConn(&err) - - r := &readBuf{} - for { - t, err := l.cn.recvMessage(r) - if err != nil { - return err - } - - switch t { - case 'A': - // recvNotification copies all the data so we don't need to worry - // about the scratch buffer being overwritten. - l.notificationChan <- recvNotification(r) - - case 'T', 'D': - // only used by tests; ignore - - case 'E': - // We might receive an ErrorResponse even when not in a query; it - // is expected that the server will close the connection after - // that, but we should make sure that the error we display is the - // one from the stray ErrorResponse, not io.ErrUnexpectedEOF. - if !l.setState(connStateExpectReadyForQuery) { - return parseError(r) - } - l.replyChan <- message{t, parseError(r)} - - case 'C', 'I': - if !l.setState(connStateExpectReadyForQuery) { - // protocol out of sync - return fmt.Errorf("unexpected CommandComplete") - } - // ExecSimpleQuery doesn't need to know about this message - - case 'Z': - if !l.setState(connStateIdle) { - // protocol out of sync - return fmt.Errorf("unexpected ReadyForQuery") - } - l.replyChan <- message{t, nil} - - case 'N', 'S': - // ignore - default: - return fmt.Errorf("unexpected message %q from server in listenerConnLoop", t) - } - } -} - -// This is the main routine for the goroutine receiving on the database -// connection. Most of the main logic is in listenerConnLoop. -func (l *ListenerConn) listenerConnMain() { - err := l.listenerConnLoop() - - // listenerConnLoop terminated; we're done, but we still have to clean up. - // Make sure nobody tries to start any new queries by making sure the err - // pointer is set. It is important that we do not overwrite its value; a - // connection could be closed by either this goroutine or one sending on - // the connection -- whoever closes the connection is assumed to have the - // more meaningful error message (as the other one will probably get - // net.errClosed), so that goroutine sets the error we expose while the - // other error is discarded. If the connection is lost while two - // goroutines are operating on the socket, it probably doesn't matter which - // error we expose so we don't try to do anything more complex. - l.connectionLock.Lock() - if l.err == nil { - l.err = err - } - l.cn.Close() - l.connectionLock.Unlock() - - // There might be a query in-flight; make sure nobody's waiting for a - // response to it, since there's not going to be one. - close(l.replyChan) - - // let the listener know we're done - close(l.notificationChan) - - // this ListenerConn is done -} - -// Listen sends a LISTEN query to the server. See ExecSimpleQuery. -func (l *ListenerConn) Listen(channel string) (bool, error) { - return l.ExecSimpleQuery("LISTEN " + QuoteIdentifier(channel)) -} - -// Unlisten sends an UNLISTEN query to the server. See ExecSimpleQuery. -func (l *ListenerConn) Unlisten(channel string) (bool, error) { - return l.ExecSimpleQuery("UNLISTEN " + QuoteIdentifier(channel)) -} - -// UnlistenAll sends an `UNLISTEN *` query to the server. See ExecSimpleQuery. -func (l *ListenerConn) UnlistenAll() (bool, error) { - return l.ExecSimpleQuery("UNLISTEN *") -} - -// Ping the remote server to make sure it's alive. Non-nil error means the -// connection has failed and should be abandoned. -func (l *ListenerConn) Ping() error { - sent, err := l.ExecSimpleQuery("") - if !sent { - return err - } - if err != nil { - // shouldn't happen - panic(err) - } - return nil -} - -// Attempt to send a query on the connection. Returns an error if sending the -// query failed, and the caller should initiate closure of this connection. -// The caller must be holding senderLock (see acquireSenderLock and -// releaseSenderLock). -func (l *ListenerConn) sendSimpleQuery(q string) (err error) { - defer errRecoverNoErrBadConn(&err) - - // must set connection state before sending the query - if !l.setState(connStateExpectResponse) { - panic("two queries running at the same time") - } - - // Can't use l.cn.writeBuf here because it uses the scratch buffer which - // might get overwritten by listenerConnLoop. - b := &writeBuf{ - buf: []byte("Q\x00\x00\x00\x00"), - pos: 1, - } - b.string(q) - l.cn.send(b) - - return nil -} - -// ExecSimpleQuery executes a "simple query" (i.e. one with no bindable -// parameters) on the connection. The possible return values are: -// 1) "executed" is true; the query was executed to completion on the -// database server. If the query failed, err will be set to the error -// returned by the database, otherwise err will be nil. -// 2) If "executed" is false, the query could not be executed on the remote -// server. err will be non-nil. -// -// After a call to ExecSimpleQuery has returned an executed=false value, the -// connection has either been closed or will be closed shortly thereafter, and -// all subsequently executed queries will return an error. -func (l *ListenerConn) ExecSimpleQuery(q string) (executed bool, err error) { - if err = l.acquireSenderLock(); err != nil { - return false, err - } - defer l.releaseSenderLock() - - err = l.sendSimpleQuery(q) - if err != nil { - // We can't know what state the protocol is in, so we need to abandon - // this connection. - l.connectionLock.Lock() - // Set the error pointer if it hasn't been set already; see - // listenerConnMain. - if l.err == nil { - l.err = err - } - l.connectionLock.Unlock() - l.cn.c.Close() - return false, err - } - - // now we just wait for a reply.. - for { - m, ok := <-l.replyChan - if !ok { - // We lost the connection to server, don't bother waiting for a - // a response. err should have been set already. - l.connectionLock.Lock() - err := l.err - l.connectionLock.Unlock() - return false, err - } - switch m.typ { - case 'Z': - // sanity check - if m.err != nil { - panic("m.err != nil") - } - // done; err might or might not be set - return true, err - - case 'E': - // sanity check - if m.err == nil { - panic("m.err == nil") - } - // server responded with an error; ReadyForQuery to follow - err = m.err - - default: - return false, fmt.Errorf("unknown response for simple query: %q", m.typ) - } - } -} - -// Close closes the connection. -func (l *ListenerConn) Close() error { - l.connectionLock.Lock() - if l.err != nil { - l.connectionLock.Unlock() - return errListenerConnClosed - } - l.err = errListenerConnClosed - l.connectionLock.Unlock() - // We can't send anything on the connection without holding senderLock. - // Simply close the net.Conn to wake up everyone operating on it. - return l.cn.c.Close() -} - -// Err returns the reason the connection was closed. It is not safe to call -// this function until l.Notify has been closed. -func (l *ListenerConn) Err() error { - return l.err -} - -var errListenerClosed = errors.New("pq: Listener has been closed") - -// ErrChannelAlreadyOpen is returned from Listen when a channel is already -// open. -var ErrChannelAlreadyOpen = errors.New("pq: channel is already open") - -// ErrChannelNotOpen is returned from Unlisten when a channel is not open. -var ErrChannelNotOpen = errors.New("pq: channel is not open") - -// ListenerEventType is an enumeration of listener event types. -type ListenerEventType int - -const ( - // ListenerEventConnected is emitted only when the database connection - // has been initially initialized. The err argument of the callback - // will always be nil. - ListenerEventConnected ListenerEventType = iota - - // ListenerEventDisconnected is emitted after a database connection has - // been lost, either because of an error or because Close has been - // called. The err argument will be set to the reason the database - // connection was lost. - ListenerEventDisconnected - - // ListenerEventReconnected is emitted after a database connection has - // been re-established after connection loss. The err argument of the - // callback will always be nil. After this event has been emitted, a - // nil pq.Notification is sent on the Listener.Notify channel. - ListenerEventReconnected - - // ListenerEventConnectionAttemptFailed is emitted after a connection - // to the database was attempted, but failed. The err argument will be - // set to an error describing why the connection attempt did not - // succeed. - ListenerEventConnectionAttemptFailed -) - -// EventCallbackType is the event callback type. See also ListenerEventType -// constants' documentation. -type EventCallbackType func(event ListenerEventType, err error) - -// Listener provides an interface for listening to notifications from a -// PostgreSQL database. For general usage information, see section -// "Notifications". -// -// Listener can safely be used from concurrently running goroutines. -type Listener struct { - // Channel for receiving notifications from the database. In some cases a - // nil value will be sent. See section "Notifications" above. - Notify chan *Notification - - name string - minReconnectInterval time.Duration - maxReconnectInterval time.Duration - dialer Dialer - eventCallback EventCallbackType - - lock sync.Mutex - isClosed bool - reconnectCond *sync.Cond - cn *ListenerConn - connNotificationChan <-chan *Notification - channels map[string]struct{} -} - -// NewListener creates a new database connection dedicated to LISTEN / NOTIFY. -// -// name should be set to a connection string to be used to establish the -// database connection (see section "Connection String Parameters" above). -// -// minReconnectInterval controls the duration to wait before trying to -// re-establish the database connection after connection loss. After each -// consecutive failure this interval is doubled, until maxReconnectInterval is -// reached. Successfully completing the connection establishment procedure -// resets the interval back to minReconnectInterval. -// -// The last parameter eventCallback can be set to a function which will be -// called by the Listener when the state of the underlying database connection -// changes. This callback will be called by the goroutine which dispatches the -// notifications over the Notify channel, so you should try to avoid doing -// potentially time-consuming operations from the callback. -func NewListener(name string, - minReconnectInterval time.Duration, - maxReconnectInterval time.Duration, - eventCallback EventCallbackType) *Listener { - return NewDialListener(defaultDialer{}, name, minReconnectInterval, maxReconnectInterval, eventCallback) -} - -// NewDialListener is like NewListener but it takes a Dialer. -func NewDialListener(d Dialer, - name string, - minReconnectInterval time.Duration, - maxReconnectInterval time.Duration, - eventCallback EventCallbackType) *Listener { - - l := &Listener{ - name: name, - minReconnectInterval: minReconnectInterval, - maxReconnectInterval: maxReconnectInterval, - dialer: d, - eventCallback: eventCallback, - - channels: make(map[string]struct{}), - - Notify: make(chan *Notification, 32), - } - l.reconnectCond = sync.NewCond(&l.lock) - - go l.listenerMain() - - return l -} - -// NotificationChannel returns the notification channel for this listener. -// This is the same channel as Notify, and will not be recreated during the -// life time of the Listener. -func (l *Listener) NotificationChannel() <-chan *Notification { - return l.Notify -} - -// Listen starts listening for notifications on a channel. Calls to this -// function will block until an acknowledgement has been received from the -// server. Note that Listener automatically re-establishes the connection -// after connection loss, so this function may block indefinitely if the -// connection can not be re-established. -// -// Listen will only fail in three conditions: -// 1) The channel is already open. The returned error will be -// ErrChannelAlreadyOpen. -// 2) The query was executed on the remote server, but PostgreSQL returned an -// error message in response to the query. The returned error will be a -// pq.Error containing the information the server supplied. -// 3) Close is called on the Listener before the request could be completed. -// -// The channel name is case-sensitive. -func (l *Listener) Listen(channel string) error { - l.lock.Lock() - defer l.lock.Unlock() - - if l.isClosed { - return errListenerClosed - } - - // The server allows you to issue a LISTEN on a channel which is already - // open, but it seems useful to be able to detect this case to spot for - // mistakes in application logic. If the application genuinely does't - // care, it can check the exported error and ignore it. - _, exists := l.channels[channel] - if exists { - return ErrChannelAlreadyOpen - } - - if l.cn != nil { - // If gotResponse is true but error is set, the query was executed on - // the remote server, but resulted in an error. This should be - // relatively rare, so it's fine if we just pass the error to our - // caller. However, if gotResponse is false, we could not complete the - // query on the remote server and our underlying connection is about - // to go away, so we only add relname to l.channels, and wait for - // resync() to take care of the rest. - gotResponse, err := l.cn.Listen(channel) - if gotResponse && err != nil { - return err - } - } - - l.channels[channel] = struct{}{} - for l.cn == nil { - l.reconnectCond.Wait() - // we let go of the mutex for a while - if l.isClosed { - return errListenerClosed - } - } - - return nil -} - -// Unlisten removes a channel from the Listener's channel list. Returns -// ErrChannelNotOpen if the Listener is not listening on the specified channel. -// Returns immediately with no error if there is no connection. Note that you -// might still get notifications for this channel even after Unlisten has -// returned. -// -// The channel name is case-sensitive. -func (l *Listener) Unlisten(channel string) error { - l.lock.Lock() - defer l.lock.Unlock() - - if l.isClosed { - return errListenerClosed - } - - // Similarly to LISTEN, this is not an error in Postgres, but it seems - // useful to distinguish from the normal conditions. - _, exists := l.channels[channel] - if !exists { - return ErrChannelNotOpen - } - - if l.cn != nil { - // Similarly to Listen (see comment in that function), the caller - // should only be bothered with an error if it came from the backend as - // a response to our query. - gotResponse, err := l.cn.Unlisten(channel) - if gotResponse && err != nil { - return err - } - } - - // Don't bother waiting for resync if there's no connection. - delete(l.channels, channel) - return nil -} - -// UnlistenAll removes all channels from the Listener's channel list. Returns -// immediately with no error if there is no connection. Note that you might -// still get notifications for any of the deleted channels even after -// UnlistenAll has returned. -func (l *Listener) UnlistenAll() error { - l.lock.Lock() - defer l.lock.Unlock() - - if l.isClosed { - return errListenerClosed - } - - if l.cn != nil { - // Similarly to Listen (see comment in that function), the caller - // should only be bothered with an error if it came from the backend as - // a response to our query. - gotResponse, err := l.cn.UnlistenAll() - if gotResponse && err != nil { - return err - } - } - - // Don't bother waiting for resync if there's no connection. - l.channels = make(map[string]struct{}) - return nil -} - -// Ping the remote server to make sure it's alive. Non-nil return value means -// that there is no active connection. -func (l *Listener) Ping() error { - l.lock.Lock() - defer l.lock.Unlock() - - if l.isClosed { - return errListenerClosed - } - if l.cn == nil { - return errors.New("no connection") - } - - return l.cn.Ping() -} - -// Clean up after losing the server connection. Returns l.cn.Err(), which -// should have the reason the connection was lost. -func (l *Listener) disconnectCleanup() error { - l.lock.Lock() - defer l.lock.Unlock() - - // sanity check; can't look at Err() until the channel has been closed - select { - case _, ok := <-l.connNotificationChan: - if ok { - panic("connNotificationChan not closed") - } - default: - panic("connNotificationChan not closed") - } - - err := l.cn.Err() - l.cn.Close() - l.cn = nil - return err -} - -// Synchronize the list of channels we want to be listening on with the server -// after the connection has been established. -func (l *Listener) resync(cn *ListenerConn, notificationChan <-chan *Notification) error { - doneChan := make(chan error) - go func() { - for channel := range l.channels { - // If we got a response, return that error to our caller as it's - // going to be more descriptive than cn.Err(). - gotResponse, err := cn.Listen(channel) - if gotResponse && err != nil { - doneChan <- err - return - } - - // If we couldn't reach the server, wait for notificationChan to - // close and then return the error message from the connection, as - // per ListenerConn's interface. - if err != nil { - for range notificationChan { - } - doneChan <- cn.Err() - return - } - } - doneChan <- nil - }() - - // Ignore notifications while synchronization is going on to avoid - // deadlocks. We have to send a nil notification over Notify anyway as - // we can't possibly know which notifications (if any) were lost while - // the connection was down, so there's no reason to try and process - // these messages at all. - for { - select { - case _, ok := <-notificationChan: - if !ok { - notificationChan = nil - } - - case err := <-doneChan: - return err - } - } -} - -// caller should NOT be holding l.lock -func (l *Listener) closed() bool { - l.lock.Lock() - defer l.lock.Unlock() - - return l.isClosed -} - -func (l *Listener) connect() error { - notificationChan := make(chan *Notification, 32) - cn, err := newDialListenerConn(l.dialer, l.name, notificationChan) - if err != nil { - return err - } - - l.lock.Lock() - defer l.lock.Unlock() - - err = l.resync(cn, notificationChan) - if err != nil { - cn.Close() - return err - } - - l.cn = cn - l.connNotificationChan = notificationChan - l.reconnectCond.Broadcast() - - return nil -} - -// Close disconnects the Listener from the database and shuts it down. -// Subsequent calls to its methods will return an error. Close returns an -// error if the connection has already been closed. -func (l *Listener) Close() error { - l.lock.Lock() - defer l.lock.Unlock() - - if l.isClosed { - return errListenerClosed - } - - if l.cn != nil { - l.cn.Close() - } - l.isClosed = true - - return nil -} - -func (l *Listener) emitEvent(event ListenerEventType, err error) { - if l.eventCallback != nil { - l.eventCallback(event, err) - } -} - -// Main logic here: maintain a connection to the server when possible, wait -// for notifications and emit events. -func (l *Listener) listenerConnLoop() { - var nextReconnect time.Time - - reconnectInterval := l.minReconnectInterval - for { - for { - err := l.connect() - if err == nil { - break - } - - if l.closed() { - return - } - l.emitEvent(ListenerEventConnectionAttemptFailed, err) - - time.Sleep(reconnectInterval) - reconnectInterval *= 2 - if reconnectInterval > l.maxReconnectInterval { - reconnectInterval = l.maxReconnectInterval - } - } - - if nextReconnect.IsZero() { - l.emitEvent(ListenerEventConnected, nil) - } else { - l.emitEvent(ListenerEventReconnected, nil) - l.Notify <- nil - } - - reconnectInterval = l.minReconnectInterval - nextReconnect = time.Now().Add(reconnectInterval) - - for { - notification, ok := <-l.connNotificationChan - if !ok { - // lost connection, loop again - break - } - l.Notify <- notification - } - - err := l.disconnectCleanup() - if l.closed() { - return - } - l.emitEvent(ListenerEventDisconnected, err) - - time.Sleep(nextReconnect.Sub(time.Now())) - } -} - -func (l *Listener) listenerMain() { - l.listenerConnLoop() - close(l.Notify) -} diff --git a/vendor/github.com/lib/pq/oid/doc.go b/vendor/github.com/lib/pq/oid/doc.go deleted file mode 100644 index caaede248..000000000 --- a/vendor/github.com/lib/pq/oid/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// Package oid contains OID constants -// as defined by the Postgres server. -package oid - -// Oid is a Postgres Object ID. -type Oid uint32 diff --git a/vendor/github.com/lib/pq/oid/gen.go b/vendor/github.com/lib/pq/oid/gen.go deleted file mode 100644 index 7c634cdc5..000000000 --- a/vendor/github.com/lib/pq/oid/gen.go +++ /dev/null @@ -1,93 +0,0 @@ -// +build ignore - -// Generate the table of OID values -// Run with 'go run gen.go'. -package main - -import ( - "database/sql" - "fmt" - "log" - "os" - "os/exec" - "strings" - - _ "github.com/lib/pq" -) - -// OID represent a postgres Object Identifier Type. -type OID struct { - ID int - Type string -} - -// Name returns an upper case version of the oid type. -func (o OID) Name() string { - return strings.ToUpper(o.Type) -} - -func main() { - datname := os.Getenv("PGDATABASE") - sslmode := os.Getenv("PGSSLMODE") - - if datname == "" { - os.Setenv("PGDATABASE", "pqgotest") - } - - if sslmode == "" { - os.Setenv("PGSSLMODE", "disable") - } - - db, err := sql.Open("postgres", "") - if err != nil { - log.Fatal(err) - } - rows, err := db.Query(` - SELECT typname, oid - FROM pg_type WHERE oid < 10000 - ORDER BY oid; - `) - if err != nil { - log.Fatal(err) - } - oids := make([]*OID, 0) - for rows.Next() { - var oid OID - if err = rows.Scan(&oid.Type, &oid.ID); err != nil { - log.Fatal(err) - } - oids = append(oids, &oid) - } - if err = rows.Err(); err != nil { - log.Fatal(err) - } - cmd := exec.Command("gofmt") - cmd.Stderr = os.Stderr - w, err := cmd.StdinPipe() - if err != nil { - log.Fatal(err) - } - f, err := os.Create("types.go") - if err != nil { - log.Fatal(err) - } - cmd.Stdout = f - err = cmd.Start() - if err != nil { - log.Fatal(err) - } - fmt.Fprintln(w, "// Code generated by gen.go. DO NOT EDIT.") - fmt.Fprintln(w, "\npackage oid") - fmt.Fprintln(w, "const (") - for _, oid := range oids { - fmt.Fprintf(w, "T_%s Oid = %d\n", oid.Type, oid.ID) - } - fmt.Fprintln(w, ")") - fmt.Fprintln(w, "var TypeName = map[Oid]string{") - for _, oid := range oids { - fmt.Fprintf(w, "T_%s: \"%s\",\n", oid.Type, oid.Name()) - } - fmt.Fprintln(w, "}") - w.Close() - cmd.Wait() -} diff --git a/vendor/github.com/lib/pq/oid/types.go b/vendor/github.com/lib/pq/oid/types.go deleted file mode 100644 index ecc84c2c8..000000000 --- a/vendor/github.com/lib/pq/oid/types.go +++ /dev/null @@ -1,343 +0,0 @@ -// Code generated by gen.go. DO NOT EDIT. - -package oid - -const ( - T_bool Oid = 16 - T_bytea Oid = 17 - T_char Oid = 18 - T_name Oid = 19 - T_int8 Oid = 20 - T_int2 Oid = 21 - T_int2vector Oid = 22 - T_int4 Oid = 23 - T_regproc Oid = 24 - T_text Oid = 25 - T_oid Oid = 26 - T_tid Oid = 27 - T_xid Oid = 28 - T_cid Oid = 29 - T_oidvector Oid = 30 - T_pg_ddl_command Oid = 32 - T_pg_type Oid = 71 - T_pg_attribute Oid = 75 - T_pg_proc Oid = 81 - T_pg_class Oid = 83 - T_json Oid = 114 - T_xml Oid = 142 - T__xml Oid = 143 - T_pg_node_tree Oid = 194 - T__json Oid = 199 - T_smgr Oid = 210 - T_index_am_handler Oid = 325 - T_point Oid = 600 - T_lseg Oid = 601 - T_path Oid = 602 - T_box Oid = 603 - T_polygon Oid = 604 - T_line Oid = 628 - T__line Oid = 629 - T_cidr Oid = 650 - T__cidr Oid = 651 - T_float4 Oid = 700 - T_float8 Oid = 701 - T_abstime Oid = 702 - T_reltime Oid = 703 - T_tinterval Oid = 704 - T_unknown Oid = 705 - T_circle Oid = 718 - T__circle Oid = 719 - T_money Oid = 790 - T__money Oid = 791 - T_macaddr Oid = 829 - T_inet Oid = 869 - T__bool Oid = 1000 - T__bytea Oid = 1001 - T__char Oid = 1002 - T__name Oid = 1003 - T__int2 Oid = 1005 - T__int2vector Oid = 1006 - T__int4 Oid = 1007 - T__regproc Oid = 1008 - T__text Oid = 1009 - T__tid Oid = 1010 - T__xid Oid = 1011 - T__cid Oid = 1012 - T__oidvector Oid = 1013 - T__bpchar Oid = 1014 - T__varchar Oid = 1015 - T__int8 Oid = 1016 - T__point Oid = 1017 - T__lseg Oid = 1018 - T__path Oid = 1019 - T__box Oid = 1020 - T__float4 Oid = 1021 - T__float8 Oid = 1022 - T__abstime Oid = 1023 - T__reltime Oid = 1024 - T__tinterval Oid = 1025 - T__polygon Oid = 1027 - T__oid Oid = 1028 - T_aclitem Oid = 1033 - T__aclitem Oid = 1034 - T__macaddr Oid = 1040 - T__inet Oid = 1041 - T_bpchar Oid = 1042 - T_varchar Oid = 1043 - T_date Oid = 1082 - T_time Oid = 1083 - T_timestamp Oid = 1114 - T__timestamp Oid = 1115 - T__date Oid = 1182 - T__time Oid = 1183 - T_timestamptz Oid = 1184 - T__timestamptz Oid = 1185 - T_interval Oid = 1186 - T__interval Oid = 1187 - T__numeric Oid = 1231 - T_pg_database Oid = 1248 - T__cstring Oid = 1263 - T_timetz Oid = 1266 - T__timetz Oid = 1270 - T_bit Oid = 1560 - T__bit Oid = 1561 - T_varbit Oid = 1562 - T__varbit Oid = 1563 - T_numeric Oid = 1700 - T_refcursor Oid = 1790 - T__refcursor Oid = 2201 - T_regprocedure Oid = 2202 - T_regoper Oid = 2203 - T_regoperator Oid = 2204 - T_regclass Oid = 2205 - T_regtype Oid = 2206 - T__regprocedure Oid = 2207 - T__regoper Oid = 2208 - T__regoperator Oid = 2209 - T__regclass Oid = 2210 - T__regtype Oid = 2211 - T_record Oid = 2249 - T_cstring Oid = 2275 - T_any Oid = 2276 - T_anyarray Oid = 2277 - T_void Oid = 2278 - T_trigger Oid = 2279 - T_language_handler Oid = 2280 - T_internal Oid = 2281 - T_opaque Oid = 2282 - T_anyelement Oid = 2283 - T__record Oid = 2287 - T_anynonarray Oid = 2776 - T_pg_authid Oid = 2842 - T_pg_auth_members Oid = 2843 - T__txid_snapshot Oid = 2949 - T_uuid Oid = 2950 - T__uuid Oid = 2951 - T_txid_snapshot Oid = 2970 - T_fdw_handler Oid = 3115 - T_pg_lsn Oid = 3220 - T__pg_lsn Oid = 3221 - T_tsm_handler Oid = 3310 - T_anyenum Oid = 3500 - T_tsvector Oid = 3614 - T_tsquery Oid = 3615 - T_gtsvector Oid = 3642 - T__tsvector Oid = 3643 - T__gtsvector Oid = 3644 - T__tsquery Oid = 3645 - T_regconfig Oid = 3734 - T__regconfig Oid = 3735 - T_regdictionary Oid = 3769 - T__regdictionary Oid = 3770 - T_jsonb Oid = 3802 - T__jsonb Oid = 3807 - T_anyrange Oid = 3831 - T_event_trigger Oid = 3838 - T_int4range Oid = 3904 - T__int4range Oid = 3905 - T_numrange Oid = 3906 - T__numrange Oid = 3907 - T_tsrange Oid = 3908 - T__tsrange Oid = 3909 - T_tstzrange Oid = 3910 - T__tstzrange Oid = 3911 - T_daterange Oid = 3912 - T__daterange Oid = 3913 - T_int8range Oid = 3926 - T__int8range Oid = 3927 - T_pg_shseclabel Oid = 4066 - T_regnamespace Oid = 4089 - T__regnamespace Oid = 4090 - T_regrole Oid = 4096 - T__regrole Oid = 4097 -) - -var TypeName = map[Oid]string{ - T_bool: "BOOL", - T_bytea: "BYTEA", - T_char: "CHAR", - T_name: "NAME", - T_int8: "INT8", - T_int2: "INT2", - T_int2vector: "INT2VECTOR", - T_int4: "INT4", - T_regproc: "REGPROC", - T_text: "TEXT", - T_oid: "OID", - T_tid: "TID", - T_xid: "XID", - T_cid: "CID", - T_oidvector: "OIDVECTOR", - T_pg_ddl_command: "PG_DDL_COMMAND", - T_pg_type: "PG_TYPE", - T_pg_attribute: "PG_ATTRIBUTE", - T_pg_proc: "PG_PROC", - T_pg_class: "PG_CLASS", - T_json: "JSON", - T_xml: "XML", - T__xml: "_XML", - T_pg_node_tree: "PG_NODE_TREE", - T__json: "_JSON", - T_smgr: "SMGR", - T_index_am_handler: "INDEX_AM_HANDLER", - T_point: "POINT", - T_lseg: "LSEG", - T_path: "PATH", - T_box: "BOX", - T_polygon: "POLYGON", - T_line: "LINE", - T__line: "_LINE", - T_cidr: "CIDR", - T__cidr: "_CIDR", - T_float4: "FLOAT4", - T_float8: "FLOAT8", - T_abstime: "ABSTIME", - T_reltime: "RELTIME", - T_tinterval: "TINTERVAL", - T_unknown: "UNKNOWN", - T_circle: "CIRCLE", - T__circle: "_CIRCLE", - T_money: "MONEY", - T__money: "_MONEY", - T_macaddr: "MACADDR", - T_inet: "INET", - T__bool: "_BOOL", - T__bytea: "_BYTEA", - T__char: "_CHAR", - T__name: "_NAME", - T__int2: "_INT2", - T__int2vector: "_INT2VECTOR", - T__int4: "_INT4", - T__regproc: "_REGPROC", - T__text: "_TEXT", - T__tid: "_TID", - T__xid: "_XID", - T__cid: "_CID", - T__oidvector: "_OIDVECTOR", - T__bpchar: "_BPCHAR", - T__varchar: "_VARCHAR", - T__int8: "_INT8", - T__point: "_POINT", - T__lseg: "_LSEG", - T__path: "_PATH", - T__box: "_BOX", - T__float4: "_FLOAT4", - T__float8: "_FLOAT8", - T__abstime: "_ABSTIME", - T__reltime: "_RELTIME", - T__tinterval: "_TINTERVAL", - T__polygon: "_POLYGON", - T__oid: "_OID", - T_aclitem: "ACLITEM", - T__aclitem: "_ACLITEM", - T__macaddr: "_MACADDR", - T__inet: "_INET", - T_bpchar: "BPCHAR", - T_varchar: "VARCHAR", - T_date: "DATE", - T_time: "TIME", - T_timestamp: "TIMESTAMP", - T__timestamp: "_TIMESTAMP", - T__date: "_DATE", - T__time: "_TIME", - T_timestamptz: "TIMESTAMPTZ", - T__timestamptz: "_TIMESTAMPTZ", - T_interval: "INTERVAL", - T__interval: "_INTERVAL", - T__numeric: "_NUMERIC", - T_pg_database: "PG_DATABASE", - T__cstring: "_CSTRING", - T_timetz: "TIMETZ", - T__timetz: "_TIMETZ", - T_bit: "BIT", - T__bit: "_BIT", - T_varbit: "VARBIT", - T__varbit: "_VARBIT", - T_numeric: "NUMERIC", - T_refcursor: "REFCURSOR", - T__refcursor: "_REFCURSOR", - T_regprocedure: "REGPROCEDURE", - T_regoper: "REGOPER", - T_regoperator: "REGOPERATOR", - T_regclass: "REGCLASS", - T_regtype: "REGTYPE", - T__regprocedure: "_REGPROCEDURE", - T__regoper: "_REGOPER", - T__regoperator: "_REGOPERATOR", - T__regclass: "_REGCLASS", - T__regtype: "_REGTYPE", - T_record: "RECORD", - T_cstring: "CSTRING", - T_any: "ANY", - T_anyarray: "ANYARRAY", - T_void: "VOID", - T_trigger: "TRIGGER", - T_language_handler: "LANGUAGE_HANDLER", - T_internal: "INTERNAL", - T_opaque: "OPAQUE", - T_anyelement: "ANYELEMENT", - T__record: "_RECORD", - T_anynonarray: "ANYNONARRAY", - T_pg_authid: "PG_AUTHID", - T_pg_auth_members: "PG_AUTH_MEMBERS", - T__txid_snapshot: "_TXID_SNAPSHOT", - T_uuid: "UUID", - T__uuid: "_UUID", - T_txid_snapshot: "TXID_SNAPSHOT", - T_fdw_handler: "FDW_HANDLER", - T_pg_lsn: "PG_LSN", - T__pg_lsn: "_PG_LSN", - T_tsm_handler: "TSM_HANDLER", - T_anyenum: "ANYENUM", - T_tsvector: "TSVECTOR", - T_tsquery: "TSQUERY", - T_gtsvector: "GTSVECTOR", - T__tsvector: "_TSVECTOR", - T__gtsvector: "_GTSVECTOR", - T__tsquery: "_TSQUERY", - T_regconfig: "REGCONFIG", - T__regconfig: "_REGCONFIG", - T_regdictionary: "REGDICTIONARY", - T__regdictionary: "_REGDICTIONARY", - T_jsonb: "JSONB", - T__jsonb: "_JSONB", - T_anyrange: "ANYRANGE", - T_event_trigger: "EVENT_TRIGGER", - T_int4range: "INT4RANGE", - T__int4range: "_INT4RANGE", - T_numrange: "NUMRANGE", - T__numrange: "_NUMRANGE", - T_tsrange: "TSRANGE", - T__tsrange: "_TSRANGE", - T_tstzrange: "TSTZRANGE", - T__tstzrange: "_TSTZRANGE", - T_daterange: "DATERANGE", - T__daterange: "_DATERANGE", - T_int8range: "INT8RANGE", - T__int8range: "_INT8RANGE", - T_pg_shseclabel: "PG_SHSECLABEL", - T_regnamespace: "REGNAMESPACE", - T__regnamespace: "_REGNAMESPACE", - T_regrole: "REGROLE", - T__regrole: "_REGROLE", -} diff --git a/vendor/github.com/lib/pq/rows.go b/vendor/github.com/lib/pq/rows.go deleted file mode 100644 index c6aa5b9a3..000000000 --- a/vendor/github.com/lib/pq/rows.go +++ /dev/null @@ -1,93 +0,0 @@ -package pq - -import ( - "math" - "reflect" - "time" - - "github.com/lib/pq/oid" -) - -const headerSize = 4 - -type fieldDesc struct { - // The object ID of the data type. - OID oid.Oid - // The data type size (see pg_type.typlen). - // Note that negative values denote variable-width types. - Len int - // The type modifier (see pg_attribute.atttypmod). - // The meaning of the modifier is type-specific. - Mod int -} - -func (fd fieldDesc) Type() reflect.Type { - switch fd.OID { - case oid.T_int8: - return reflect.TypeOf(int64(0)) - case oid.T_int4: - return reflect.TypeOf(int32(0)) - case oid.T_int2: - return reflect.TypeOf(int16(0)) - case oid.T_varchar, oid.T_text: - return reflect.TypeOf("") - case oid.T_bool: - return reflect.TypeOf(false) - case oid.T_date, oid.T_time, oid.T_timetz, oid.T_timestamp, oid.T_timestamptz: - return reflect.TypeOf(time.Time{}) - case oid.T_bytea: - return reflect.TypeOf([]byte(nil)) - default: - return reflect.TypeOf(new(interface{})).Elem() - } -} - -func (fd fieldDesc) Name() string { - return oid.TypeName[fd.OID] -} - -func (fd fieldDesc) Length() (length int64, ok bool) { - switch fd.OID { - case oid.T_text, oid.T_bytea: - return math.MaxInt64, true - case oid.T_varchar, oid.T_bpchar: - return int64(fd.Mod - headerSize), true - default: - return 0, false - } -} - -func (fd fieldDesc) PrecisionScale() (precision, scale int64, ok bool) { - switch fd.OID { - case oid.T_numeric, oid.T__numeric: - mod := fd.Mod - headerSize - precision = int64((mod >> 16) & 0xffff) - scale = int64(mod & 0xffff) - return precision, scale, true - default: - return 0, 0, false - } -} - -// ColumnTypeScanType returns the value type that can be used to scan types into. -func (rs *rows) ColumnTypeScanType(index int) reflect.Type { - return rs.colTyps[index].Type() -} - -// ColumnTypeDatabaseTypeName return the database system type name. -func (rs *rows) ColumnTypeDatabaseTypeName(index int) string { - return rs.colTyps[index].Name() -} - -// ColumnTypeLength returns the length of the column type if the column is a -// variable length type. If the column is not a variable length type ok -// should return false. -func (rs *rows) ColumnTypeLength(index int) (length int64, ok bool) { - return rs.colTyps[index].Length() -} - -// ColumnTypePrecisionScale should return the precision and scale for decimal -// types. If not applicable, ok should be false. -func (rs *rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) { - return rs.colTyps[index].PrecisionScale() -} diff --git a/vendor/github.com/lib/pq/ssl.go b/vendor/github.com/lib/pq/ssl.go deleted file mode 100644 index 7deb30436..000000000 --- a/vendor/github.com/lib/pq/ssl.go +++ /dev/null @@ -1,158 +0,0 @@ -package pq - -import ( - "crypto/tls" - "crypto/x509" - "io/ioutil" - "net" - "os" - "os/user" - "path/filepath" -) - -// ssl generates a function to upgrade a net.Conn based on the "sslmode" and -// related settings. The function is nil when no upgrade should take place. -func ssl(o values) func(net.Conn) net.Conn { - verifyCaOnly := false - tlsConf := tls.Config{} - switch mode := o["sslmode"]; mode { - // "require" is the default. - case "", "require": - // We must skip TLS's own verification since it requires full - // verification since Go 1.3. - tlsConf.InsecureSkipVerify = true - - // From http://www.postgresql.org/docs/current/static/libpq-ssl.html: - // - // Note: For backwards compatibility with earlier versions of - // PostgreSQL, if a root CA file exists, the behavior of - // sslmode=require will be the same as that of verify-ca, meaning the - // server certificate is validated against the CA. Relying on this - // behavior is discouraged, and applications that need certificate - // validation should always use verify-ca or verify-full. - if sslrootcert, ok := o["sslrootcert"]; ok { - if _, err := os.Stat(sslrootcert); err == nil { - verifyCaOnly = true - } else { - delete(o, "sslrootcert") - } - } - case "verify-ca": - // We must skip TLS's own verification since it requires full - // verification since Go 1.3. - tlsConf.InsecureSkipVerify = true - verifyCaOnly = true - case "verify-full": - tlsConf.ServerName = o["host"] - case "disable": - return nil - default: - errorf(`unsupported sslmode %q; only "require" (default), "verify-full", "verify-ca", and "disable" supported`, mode) - } - - sslClientCertificates(&tlsConf, o) - sslCertificateAuthority(&tlsConf, o) - sslRenegotiation(&tlsConf) - - return func(conn net.Conn) net.Conn { - client := tls.Client(conn, &tlsConf) - if verifyCaOnly { - sslVerifyCertificateAuthority(client, &tlsConf) - } - return client - } -} - -// sslClientCertificates adds the certificate specified in the "sslcert" and -// "sslkey" settings, or if they aren't set, from the .postgresql directory -// in the user's home directory. The configured files must exist and have -// the correct permissions. -func sslClientCertificates(tlsConf *tls.Config, o values) { - // user.Current() might fail when cross-compiling. We have to ignore the - // error and continue without home directory defaults, since we wouldn't - // know from where to load them. - user, _ := user.Current() - - // In libpq, the client certificate is only loaded if the setting is not blank. - // - // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1036-L1037 - sslcert := o["sslcert"] - if len(sslcert) == 0 && user != nil { - sslcert = filepath.Join(user.HomeDir, ".postgresql", "postgresql.crt") - } - // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1045 - if len(sslcert) == 0 { - return - } - // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1050:L1054 - if _, err := os.Stat(sslcert); os.IsNotExist(err) { - return - } else if err != nil { - panic(err) - } - - // In libpq, the ssl key is only loaded if the setting is not blank. - // - // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1123-L1222 - sslkey := o["sslkey"] - if len(sslkey) == 0 && user != nil { - sslkey = filepath.Join(user.HomeDir, ".postgresql", "postgresql.key") - } - - if len(sslkey) > 0 { - if err := sslKeyPermissions(sslkey); err != nil { - panic(err) - } - } - - cert, err := tls.LoadX509KeyPair(sslcert, sslkey) - if err != nil { - panic(err) - } - tlsConf.Certificates = []tls.Certificate{cert} -} - -// sslCertificateAuthority adds the RootCA specified in the "sslrootcert" setting. -func sslCertificateAuthority(tlsConf *tls.Config, o values) { - // In libpq, the root certificate is only loaded if the setting is not blank. - // - // https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L950-L951 - if sslrootcert := o["sslrootcert"]; len(sslrootcert) > 0 { - tlsConf.RootCAs = x509.NewCertPool() - - cert, err := ioutil.ReadFile(sslrootcert) - if err != nil { - panic(err) - } - - if !tlsConf.RootCAs.AppendCertsFromPEM(cert) { - errorf("couldn't parse pem in sslrootcert") - } - } -} - -// sslVerifyCertificateAuthority carries out a TLS handshake to the server and -// verifies the presented certificate against the CA, i.e. the one specified in -// sslrootcert or the system CA if sslrootcert was not specified. -func sslVerifyCertificateAuthority(client *tls.Conn, tlsConf *tls.Config) { - err := client.Handshake() - if err != nil { - panic(err) - } - certs := client.ConnectionState().PeerCertificates - opts := x509.VerifyOptions{ - DNSName: client.ConnectionState().ServerName, - Intermediates: x509.NewCertPool(), - Roots: tlsConf.RootCAs, - } - for i, cert := range certs { - if i == 0 { - continue - } - opts.Intermediates.AddCert(cert) - } - _, err = certs[0].Verify(opts) - if err != nil { - panic(err) - } -} diff --git a/vendor/github.com/lib/pq/ssl_go1.7.go b/vendor/github.com/lib/pq/ssl_go1.7.go deleted file mode 100644 index d7ba43b32..000000000 --- a/vendor/github.com/lib/pq/ssl_go1.7.go +++ /dev/null @@ -1,14 +0,0 @@ -// +build go1.7 - -package pq - -import "crypto/tls" - -// Accept renegotiation requests initiated by the backend. -// -// Renegotiation was deprecated then removed from PostgreSQL 9.5, but -// the default configuration of older versions has it enabled. Redshift -// also initiates renegotiations and cannot be reconfigured. -func sslRenegotiation(conf *tls.Config) { - conf.Renegotiation = tls.RenegotiateFreelyAsClient -} diff --git a/vendor/github.com/lib/pq/ssl_permissions.go b/vendor/github.com/lib/pq/ssl_permissions.go deleted file mode 100644 index 3b7c3a2a3..000000000 --- a/vendor/github.com/lib/pq/ssl_permissions.go +++ /dev/null @@ -1,20 +0,0 @@ -// +build !windows - -package pq - -import "os" - -// sslKeyPermissions checks the permissions on user-supplied ssl key files. -// The key file should have very little access. -// -// libpq does not check key file permissions on Windows. -func sslKeyPermissions(sslkey string) error { - info, err := os.Stat(sslkey) - if err != nil { - return err - } - if info.Mode().Perm()&0077 != 0 { - return ErrSSLKeyHasWorldPermissions - } - return nil -} diff --git a/vendor/github.com/lib/pq/ssl_renegotiation.go b/vendor/github.com/lib/pq/ssl_renegotiation.go deleted file mode 100644 index 85ed5e437..000000000 --- a/vendor/github.com/lib/pq/ssl_renegotiation.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !go1.7 - -package pq - -import "crypto/tls" - -// Renegotiation is not supported by crypto/tls until Go 1.7. -func sslRenegotiation(*tls.Config) {} diff --git a/vendor/github.com/lib/pq/ssl_windows.go b/vendor/github.com/lib/pq/ssl_windows.go deleted file mode 100644 index 5d2c763ce..000000000 --- a/vendor/github.com/lib/pq/ssl_windows.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build windows - -package pq - -// sslKeyPermissions checks the permissions on user-supplied ssl key files. -// The key file should have very little access. -// -// libpq does not check key file permissions on Windows. -func sslKeyPermissions(string) error { return nil } diff --git a/vendor/github.com/lib/pq/url.go b/vendor/github.com/lib/pq/url.go deleted file mode 100644 index f4d8a7c20..000000000 --- a/vendor/github.com/lib/pq/url.go +++ /dev/null @@ -1,76 +0,0 @@ -package pq - -import ( - "fmt" - "net" - nurl "net/url" - "sort" - "strings" -) - -// ParseURL no longer needs to be used by clients of this library since supplying a URL as a -// connection string to sql.Open() is now supported: -// -// sql.Open("postgres", "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full") -// -// It remains exported here for backwards-compatibility. -// -// ParseURL converts a url to a connection string for driver.Open. -// Example: -// -// "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full" -// -// converts to: -// -// "user=bob password=secret host=1.2.3.4 port=5432 dbname=mydb sslmode=verify-full" -// -// A minimal example: -// -// "postgres://" -// -// This will be blank, causing driver.Open to use all of the defaults -func ParseURL(url string) (string, error) { - u, err := nurl.Parse(url) - if err != nil { - return "", err - } - - if u.Scheme != "postgres" && u.Scheme != "postgresql" { - return "", fmt.Errorf("invalid connection protocol: %s", u.Scheme) - } - - var kvs []string - escaper := strings.NewReplacer(` `, `\ `, `'`, `\'`, `\`, `\\`) - accrue := func(k, v string) { - if v != "" { - kvs = append(kvs, k+"="+escaper.Replace(v)) - } - } - - if u.User != nil { - v := u.User.Username() - accrue("user", v) - - v, _ = u.User.Password() - accrue("password", v) - } - - if host, port, err := net.SplitHostPort(u.Host); err != nil { - accrue("host", u.Host) - } else { - accrue("host", host) - accrue("port", port) - } - - if u.Path != "" { - accrue("dbname", u.Path[1:]) - } - - q := u.Query() - for k := range q { - accrue(k, q.Get(k)) - } - - sort.Strings(kvs) // Makes testing easier (not a performance concern) - return strings.Join(kvs, " "), nil -} diff --git a/vendor/github.com/lib/pq/user_posix.go b/vendor/github.com/lib/pq/user_posix.go deleted file mode 100644 index bf982524f..000000000 --- a/vendor/github.com/lib/pq/user_posix.go +++ /dev/null @@ -1,24 +0,0 @@ -// Package pq is a pure Go Postgres driver for the database/sql package. - -// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris rumprun - -package pq - -import ( - "os" - "os/user" -) - -func userCurrent() (string, error) { - u, err := user.Current() - if err == nil { - return u.Username, nil - } - - name := os.Getenv("USER") - if name != "" { - return name, nil - } - - return "", ErrCouldNotDetectUsername -} diff --git a/vendor/github.com/lib/pq/user_windows.go b/vendor/github.com/lib/pq/user_windows.go deleted file mode 100644 index 2b691267b..000000000 --- a/vendor/github.com/lib/pq/user_windows.go +++ /dev/null @@ -1,27 +0,0 @@ -// Package pq is a pure Go Postgres driver for the database/sql package. -package pq - -import ( - "path/filepath" - "syscall" -) - -// Perform Windows user name lookup identically to libpq. -// -// The PostgreSQL code makes use of the legacy Win32 function -// GetUserName, and that function has not been imported into stock Go. -// GetUserNameEx is available though, the difference being that a -// wider range of names are available. To get the output to be the -// same as GetUserName, only the base (or last) component of the -// result is returned. -func userCurrent() (string, error) { - pw_name := make([]uint16, 128) - pwname_size := uint32(len(pw_name)) - 1 - err := syscall.GetUserNameEx(syscall.NameSamCompatible, &pw_name[0], &pwname_size) - if err != nil { - return "", ErrCouldNotDetectUsername - } - s := syscall.UTF16ToString(pw_name) - u := filepath.Base(s) - return u, nil -} diff --git a/vendor/github.com/lib/pq/uuid.go b/vendor/github.com/lib/pq/uuid.go deleted file mode 100644 index 9a1b9e074..000000000 --- a/vendor/github.com/lib/pq/uuid.go +++ /dev/null @@ -1,23 +0,0 @@ -package pq - -import ( - "encoding/hex" - "fmt" -) - -// decodeUUIDBinary interprets the binary format of a uuid, returning it in text format. -func decodeUUIDBinary(src []byte) ([]byte, error) { - if len(src) != 16 { - return nil, fmt.Errorf("pq: unable to decode uuid; bad length: %d", len(src)) - } - - dst := make([]byte, 36) - dst[8], dst[13], dst[18], dst[23] = '-', '-', '-', '-' - hex.Encode(dst[0:], src[0:4]) - hex.Encode(dst[9:], src[4:6]) - hex.Encode(dst[14:], src[6:8]) - hex.Encode(dst[19:], src[8:10]) - hex.Encode(dst[24:], src[10:16]) - - return dst, nil -} diff --git a/vendor/github.com/magefile/mage/mg/LICENSE b/vendor/github.com/magefile/mage/mg/LICENSE new file mode 100644 index 000000000..8dada3eda --- /dev/null +++ b/vendor/github.com/magefile/mage/mg/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/magefile/mage/mg/deps.go b/vendor/github.com/magefile/mage/mg/deps.go new file mode 100644 index 000000000..30d6edc41 --- /dev/null +++ b/vendor/github.com/magefile/mage/mg/deps.go @@ -0,0 +1,166 @@ +package mg + +import ( + "context" + "fmt" + "reflect" + "runtime" + "strings" + "sync" + + "github.com/magefile/mage/types" +) + +type onceMap struct { + mu *sync.Mutex + m map[string]*onceFun +} + +func (o *onceMap) LoadOrStore(s string, one *onceFun) *onceFun { + defer o.mu.Unlock() + o.mu.Lock() + + existing, ok := o.m[s] + if ok { + return existing + } + o.m[s] = one + return one +} + +var onces = &onceMap{ + mu: &sync.Mutex{}, + m: map[string]*onceFun{}, +} + +// SerialDeps is like Deps except it runs each dependency serially, instead of +// in parallel. This can be useful for resource intensive dependencies that +// shouldn't be run at the same time. +func SerialDeps(fns ...interface{}) { + checkFns(fns) + ctx := context.Background() + for _, f := range fns { + runDeps(ctx, f) + } +} + +// SerialCtxDeps is like CtxDeps except it runs each dependency serially, +// instead of in parallel. This can be useful for resource intensive +// dependencies that shouldn't be run at the same time. +func SerialCtxDeps(ctx context.Context, fns ...interface{}) { + checkFns(fns) + for _, f := range fns { + runDeps(ctx, f) + } +} + +// CtxDeps runs the given functions as dependencies of the calling function. +// Dependencies must only be of type: github.com/magefile/mage/types.FuncType. +// The function calling Deps is guaranteed that all dependent functions will be +// run exactly once when Deps returns. Dependent functions may in turn declare +// their own dependencies using Deps. Each dependency is run in their own +// goroutines. Each function is given the context provided if the function +// prototype allows for it. +func CtxDeps(ctx context.Context, fns ...interface{}) { + checkFns(fns) + runDeps(ctx, fns...) +} + +// runDeps assumes you've already called checkFns. +func runDeps(ctx context.Context, fns ...interface{}) { + mu := &sync.Mutex{} + var errs []string + var exit int + wg := &sync.WaitGroup{} + for _, f := range fns { + fn := addDep(ctx, f) + wg.Add(1) + go func() { + defer func() { + if v := recover(); v != nil { + mu.Lock() + if err, ok := v.(error); ok { + exit = changeExit(exit, ExitStatus(err)) + } else { + exit = changeExit(exit, 1) + } + errs = append(errs, fmt.Sprint(v)) + mu.Unlock() + } + wg.Done() + }() + if err := fn.run(); err != nil { + mu.Lock() + errs = append(errs, fmt.Sprint(err)) + exit = changeExit(exit, ExitStatus(err)) + mu.Unlock() + } + }() + } + + wg.Wait() + if len(errs) > 0 { + panic(Fatal(exit, strings.Join(errs, "\n"))) + } +} + +func checkFns(fns []interface{}) { + for _, f := range fns { + if err := types.FuncCheck(f); err != nil { + panic(err) + } + } +} + +// Deps runs the given functions with the default runtime context +func Deps(fns ...interface{}) { + CtxDeps(context.Background(), fns...) +} + +func changeExit(old, new int) int { + if new == 0 { + return old + } + if old == 0 { + return new + } + if old == new { + return old + } + // both different and both non-zero, just set + // exit to 1. Nothing more we can do. + return 1 +} + +func addDep(ctx context.Context, f interface{}) *onceFun { + var fn func(context.Context) error + if fn = types.FuncTypeWrap(f); fn == nil { + // should be impossible, since we already checked this + panic("attempted to add a dep that did not match required type") + } + + n := name(f) + of := onces.LoadOrStore(n, &onceFun{ + fn: fn, + ctx: ctx, + }) + return of +} + +func name(i interface{}) string { + return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() +} + +type onceFun struct { + once sync.Once + fn func(context.Context) error + ctx context.Context +} + +func (o *onceFun) run() error { + var err error + o.once.Do(func() { + err = o.fn(o.ctx) + }) + return err +} diff --git a/vendor/github.com/magefile/mage/mg/errors.go b/vendor/github.com/magefile/mage/mg/errors.go new file mode 100644 index 000000000..06a869086 --- /dev/null +++ b/vendor/github.com/magefile/mage/mg/errors.go @@ -0,0 +1,51 @@ +package mg + +import ( + "errors" + "fmt" +) + +type fatalErr struct { + code int + error +} + +func (f fatalErr) ExitStatus() int { + return f.code +} + +type exitStatus interface { + ExitStatus() int +} + +// Fatal returns an error that will cause mage to print out the +// given args and exit with the given exit code. +func Fatal(code int, args ...interface{}) error { + return fatalErr{ + code: code, + error: errors.New(fmt.Sprint(args...)), + } +} + +// Fatalf returns an error that will cause mage to print out the +// given message and exit with an exit code of 1. +func Fatalf(code int, format string, args ...interface{}) error { + return fatalErr{ + code: code, + error: fmt.Errorf(format, args...), + } +} + +// ExitStatus queries the error for an exit status. If the error is nil, it +// returns 0. If the error does not implement ExitStatus() int, it returns 1. +// Otherwise it retiurns the value from ExitStatus(). +func ExitStatus(err error) int { + if err == nil { + return 0 + } + exit, ok := err.(exitStatus) + if !ok { + return 1 + } + return exit.ExitStatus() +} diff --git a/vendor/github.com/magefile/mage/mg/runtime.go b/vendor/github.com/magefile/mage/mg/runtime.go new file mode 100644 index 000000000..8b99613d6 --- /dev/null +++ b/vendor/github.com/magefile/mage/mg/runtime.go @@ -0,0 +1,36 @@ +package mg + +import ( + "os" + "path/filepath" + "runtime" +) + +// CacheEnv is the environment variable that users may set to change the +// location where mage stores its compiled binaries. +const CacheEnv = "MAGEFILE_CACHE" + +// verboseEnv is the environment variable that indicates the user requested +// verbose mode when running a magefile. +const verboseEnv = "MAGEFILE_VERBOSE" + +// Verbose reports whether a magefile was run with the verbose flag. +func Verbose() bool { + return os.Getenv(verboseEnv) != "" +} + +// CacheDir returns the directory where mage caches compiled binaries. It +// defaults to $HOME/.magefile, but may be overridden by the MAGEFILE_CACHE +// environment variable. +func CacheDir() string { + d := os.Getenv(CacheEnv) + if d != "" { + return d + } + switch runtime.GOOS { + case "windows": + return filepath.Join(os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"), "magefile") + default: + return filepath.Join(os.Getenv("HOME"), ".magefile") + } +} diff --git a/vendor/github.com/magefile/mage/sh/LICENSE b/vendor/github.com/magefile/mage/sh/LICENSE new file mode 100644 index 000000000..8dada3eda --- /dev/null +++ b/vendor/github.com/magefile/mage/sh/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/magefile/mage/sh/cmd.go b/vendor/github.com/magefile/mage/sh/cmd.go new file mode 100644 index 000000000..23fc37228 --- /dev/null +++ b/vendor/github.com/magefile/mage/sh/cmd.go @@ -0,0 +1,165 @@ +package sh + +import ( + "bytes" + "fmt" + "io" + "log" + "os" + "os/exec" + "strings" + + "github.com/magefile/mage/mg" +) + +// RunCmd returns a function that will call Run with the given command. This is +// useful for creating command aliases to make your scripts easier to read, like +// this: +// +// // in a helper file somewhere +// var g0 = sh.RunCmd("go") // go is a keyword :( +// +// // somewhere in your main code +// if err := g0("install", "github.com/gohugo/hugo"); err != nil { +// return err +// } +// +// Args passed to command get baked in as args to the command when you run it. +// Any args passed in when you run the returned function will be appended to the +// original args. For example, this is equivalent to the above: +// +// var goInstall = sh.RunCmd("go", "install") goInstall("github.com/gohugo/hugo") +// +// RunCmd uses Exec underneath, so see those docs for more details. +func RunCmd(cmd string, args ...string) func(args ...string) error { + return func(args2 ...string) error { + return Run(cmd, append(args, args2...)...) + } +} + +// OutCmd is like RunCmd except the command returns the output of the +// command. +func OutCmd(cmd string, args ...string) func(args ...string) (string, error) { + return func(args2 ...string) (string, error) { + return Output(cmd, append(args, args2...)...) + } +} + +// Run is like RunWith, but doesn't specify any environment variables. +func Run(cmd string, args ...string) error { + return RunWith(nil, cmd, args...) +} + +// RunV is like Run, but always sends the command's stdout to os.Stdout. +func RunV(cmd string, args ...string) error { + _, err := Exec(nil, os.Stdout, os.Stderr, cmd, args...) + return err +} + +// RunWith runs the given command, directing stderr to this program's stderr and +// printing stdout to stdout if mage was run with -v. It adds adds env to the +// environment variables for the command being run. Environment variables should +// be in the format name=value. +func RunWith(env map[string]string, cmd string, args ...string) error { + var output io.Writer + if mg.Verbose() { + output = os.Stdout + } + _, err := Exec(env, output, os.Stderr, cmd, args...) + return err +} + +// Output runs the command and returns the text from stdout. +func Output(cmd string, args ...string) (string, error) { + buf := &bytes.Buffer{} + _, err := Exec(nil, buf, os.Stderr, cmd, args...) + return strings.TrimSuffix(buf.String(), "\n"), err +} + +// OutputWith is like RunWith, ubt returns what is written to stdout. +func OutputWith(env map[string]string, cmd string, args ...string) (string, error) { + buf := &bytes.Buffer{} + _, err := Exec(env, buf, os.Stderr, cmd, args...) + return strings.TrimSuffix(buf.String(), "\n"), err +} + +// Exec executes the command, piping its stderr to mage's stderr and +// piping its stdout to the given writer. If the command fails, it will return +// an error that, if returned from a target or mg.Deps call, will cause mage to +// exit with the same code as the command failed with. Env is a list of +// environment variables to set when running the command, these override the +// current environment variables set (which are also passed to the command). cmd +// and args may include references to environment variables in $FOO format, in +// which case these will be expanded before the command is run. +// +// Ran reports if the command ran (rather than was not found or not executable). +// Code reports the exit code the command returned if it ran. If err == nil, ran +// is always true and code is always 0. +func Exec(env map[string]string, stdout, stderr io.Writer, cmd string, args ...string) (ran bool, err error) { + expand := func(s string) string { + s2, ok := env[s] + if ok { + return s2 + } + return os.Getenv(s) + } + cmd = os.Expand(cmd, expand) + for i := range args { + args[i] = os.Expand(args[i], expand) + } + ran, code, err := run(env, stdout, stderr, cmd, args...) + if err == nil { + return true, nil + } + if ran { + return ran, mg.Fatalf(code, `running "%s %s" failed with exit code %d`, cmd, strings.Join(args, " "), code) + } + return ran, fmt.Errorf(`failed to run "%s %s: %v"`, cmd, strings.Join(args, " "), err) +} + +func run(env map[string]string, stdout, stderr io.Writer, cmd string, args ...string) (ran bool, code int, err error) { + c := exec.Command(cmd, args...) + c.Env = os.Environ() + for k, v := range env { + c.Env = append(c.Env, k+"="+v) + } + c.Stderr = stderr + c.Stdout = stdout + c.Stdin = os.Stdin + log.Println("exec:", cmd, strings.Join(args, " ")) + err = c.Run() + return cmdRan(err), ExitStatus(err), err +} + +func cmdRan(err error) bool { + if err == nil { + return true + } + ee, ok := err.(*exec.ExitError) + if ok { + return ee.Exited() + } + return false +} + +type exitStatus interface { + ExitStatus() int +} + +// ExitStatus returns the exit status of the error if it is an exec.ExitError +// or if it implements ExitStatus() int. +// 0 if it is nil or 1 if it is a different error. +func ExitStatus(err error) int { + if err == nil { + return 0 + } + if e, ok := err.(exitStatus); ok { + return e.ExitStatus() + } + if e, ok := err.(*exec.ExitError); ok { + if ex, ok := e.Sys().(exitStatus); ok { + return ex.ExitStatus() + } + } + return 1 +} diff --git a/vendor/github.com/magefile/mage/sh/helpers.go b/vendor/github.com/magefile/mage/sh/helpers.go new file mode 100644 index 000000000..86b075ef2 --- /dev/null +++ b/vendor/github.com/magefile/mage/sh/helpers.go @@ -0,0 +1,16 @@ +package sh + +import ( + "fmt" + "os" +) + +// Rm removes the given file or directory even if non-empty. It will not return +// an error if the target doesn't exist, only if the target cannot be removed. +func Rm(path string) error { + err := os.RemoveAll(path) + if err == nil || os.IsNotExist(err) { + return nil + } + return fmt.Errorf(`failed to remove %s: %v`, path, err) +} diff --git a/vendor/github.com/magefile/mage/types/LICENSE b/vendor/github.com/magefile/mage/types/LICENSE new file mode 100644 index 000000000..8dada3eda --- /dev/null +++ b/vendor/github.com/magefile/mage/types/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/magefile/mage/types/funcs.go b/vendor/github.com/magefile/mage/types/funcs.go new file mode 100644 index 000000000..9e2e1331b --- /dev/null +++ b/vendor/github.com/magefile/mage/types/funcs.go @@ -0,0 +1,58 @@ +package types + +import ( + "context" + "fmt" +) + +// FuncType indicates a prototype of build job function +type FuncType int + +// FuncTypes +const ( + InvalidType FuncType = iota + VoidType + ErrorType + ContextVoidType + ContextErrorType +) + +// FuncCheck tests if a function is one of FuncType +func FuncCheck(fn interface{}) error { + switch fn.(type) { + case func(): + return nil + case func() error: + return nil + case func(context.Context): + return nil + case func(context.Context) error: + return nil + } + return fmt.Errorf("Invalid type for dependent function: %T. Dependencies must be func(), func() error, func(context.Context) or func(context.Context) error", fn) +} + +// FuncTypeWrap wraps a valid FuncType to FuncContextError +func FuncTypeWrap(fn interface{}) func(context.Context) error { + if FuncCheck(fn) == nil { + switch f := fn.(type) { + case func(): + return func(context.Context) error { + f() + return nil + } + case func() error: + return func(context.Context) error { + return f() + } + case func(context.Context): + return func(ctx context.Context) error { + f(ctx) + return nil + } + case func(context.Context) error: + return f + } + } + return nil +} diff --git a/vendor/github.com/mattn/go-runewidth/LICENSE b/vendor/github.com/mattn/go-runewidth/LICENSE new file mode 100644 index 000000000..91b5cef30 --- /dev/null +++ b/vendor/github.com/mattn/go-runewidth/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Yasuhiro Matsumoto + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/mattn/go-runewidth/runewidth.go b/vendor/github.com/mattn/go-runewidth/runewidth.go new file mode 100644 index 000000000..a16f1af0e --- /dev/null +++ b/vendor/github.com/mattn/go-runewidth/runewidth.go @@ -0,0 +1,1224 @@ +package runewidth + +var ( + // EastAsianWidth will be set true if the current locale is CJK + EastAsianWidth = IsEastAsian() + + // DefaultCondition is a condition in current locale + DefaultCondition = &Condition{EastAsianWidth} +) + +type interval struct { + first rune + last rune +} + +type table []interval + +func inTables(r rune, ts ...table) bool { + for _, t := range ts { + if inTable(r, t) { + return true + } + } + return false +} + +func inTable(r rune, t table) bool { + // func (t table) IncludesRune(r rune) bool { + if r < t[0].first { + return false + } + + bot := 0 + top := len(t) - 1 + for top >= bot { + mid := (bot + top) / 2 + + switch { + case t[mid].last < r: + bot = mid + 1 + case t[mid].first > r: + top = mid - 1 + default: + return true + } + } + + return false +} + +var private = table{ + {0x00E000, 0x00F8FF}, {0x0F0000, 0x0FFFFD}, {0x100000, 0x10FFFD}, +} + +var nonprint = table{ + {0x0000, 0x001F}, {0x007F, 0x009F}, {0x00AD, 0x00AD}, + {0x070F, 0x070F}, {0x180B, 0x180E}, {0x200B, 0x200F}, + {0x2028, 0x2029}, + {0x202A, 0x202E}, {0x206A, 0x206F}, {0xD800, 0xDFFF}, + {0xFEFF, 0xFEFF}, {0xFFF9, 0xFFFB}, {0xFFFE, 0xFFFF}, +} + +var combining = table{ + {0x0300, 0x036F}, {0x0483, 0x0489}, {0x0591, 0x05BD}, + {0x05BF, 0x05BF}, {0x05C1, 0x05C2}, {0x05C4, 0x05C5}, + {0x05C7, 0x05C7}, {0x0610, 0x061A}, {0x064B, 0x065F}, + {0x0670, 0x0670}, {0x06D6, 0x06DC}, {0x06DF, 0x06E4}, + {0x06E7, 0x06E8}, {0x06EA, 0x06ED}, {0x0711, 0x0711}, + {0x0730, 0x074A}, {0x07A6, 0x07B0}, {0x07EB, 0x07F3}, + {0x0816, 0x0819}, {0x081B, 0x0823}, {0x0825, 0x0827}, + {0x0829, 0x082D}, {0x0859, 0x085B}, {0x08D4, 0x08E1}, + {0x08E3, 0x0903}, {0x093A, 0x093C}, {0x093E, 0x094F}, + {0x0951, 0x0957}, {0x0962, 0x0963}, {0x0981, 0x0983}, + {0x09BC, 0x09BC}, {0x09BE, 0x09C4}, {0x09C7, 0x09C8}, + {0x09CB, 0x09CD}, {0x09D7, 0x09D7}, {0x09E2, 0x09E3}, + {0x0A01, 0x0A03}, {0x0A3C, 0x0A3C}, {0x0A3E, 0x0A42}, + {0x0A47, 0x0A48}, {0x0A4B, 0x0A4D}, {0x0A51, 0x0A51}, + {0x0A70, 0x0A71}, {0x0A75, 0x0A75}, {0x0A81, 0x0A83}, + {0x0ABC, 0x0ABC}, {0x0ABE, 0x0AC5}, {0x0AC7, 0x0AC9}, + {0x0ACB, 0x0ACD}, {0x0AE2, 0x0AE3}, {0x0B01, 0x0B03}, + {0x0B3C, 0x0B3C}, {0x0B3E, 0x0B44}, {0x0B47, 0x0B48}, + {0x0B4B, 0x0B4D}, {0x0B56, 0x0B57}, {0x0B62, 0x0B63}, + {0x0B82, 0x0B82}, {0x0BBE, 0x0BC2}, {0x0BC6, 0x0BC8}, + {0x0BCA, 0x0BCD}, {0x0BD7, 0x0BD7}, {0x0C00, 0x0C03}, + {0x0C3E, 0x0C44}, {0x0C46, 0x0C48}, {0x0C4A, 0x0C4D}, + {0x0C55, 0x0C56}, {0x0C62, 0x0C63}, {0x0C81, 0x0C83}, + {0x0CBC, 0x0CBC}, {0x0CBE, 0x0CC4}, {0x0CC6, 0x0CC8}, + {0x0CCA, 0x0CCD}, {0x0CD5, 0x0CD6}, {0x0CE2, 0x0CE3}, + {0x0D01, 0x0D03}, {0x0D3E, 0x0D44}, {0x0D46, 0x0D48}, + {0x0D4A, 0x0D4D}, {0x0D57, 0x0D57}, {0x0D62, 0x0D63}, + {0x0D82, 0x0D83}, {0x0DCA, 0x0DCA}, {0x0DCF, 0x0DD4}, + {0x0DD6, 0x0DD6}, {0x0DD8, 0x0DDF}, {0x0DF2, 0x0DF3}, + {0x0E31, 0x0E31}, {0x0E34, 0x0E3A}, {0x0E47, 0x0E4E}, + {0x0EB1, 0x0EB1}, {0x0EB4, 0x0EB9}, {0x0EBB, 0x0EBC}, + {0x0EC8, 0x0ECD}, {0x0F18, 0x0F19}, {0x0F35, 0x0F35}, + {0x0F37, 0x0F37}, {0x0F39, 0x0F39}, {0x0F3E, 0x0F3F}, + {0x0F71, 0x0F84}, {0x0F86, 0x0F87}, {0x0F8D, 0x0F97}, + {0x0F99, 0x0FBC}, {0x0FC6, 0x0FC6}, {0x102B, 0x103E}, + {0x1056, 0x1059}, {0x105E, 0x1060}, {0x1062, 0x1064}, + {0x1067, 0x106D}, {0x1071, 0x1074}, {0x1082, 0x108D}, + {0x108F, 0x108F}, {0x109A, 0x109D}, {0x135D, 0x135F}, + {0x1712, 0x1714}, {0x1732, 0x1734}, {0x1752, 0x1753}, + {0x1772, 0x1773}, {0x17B4, 0x17D3}, {0x17DD, 0x17DD}, + {0x180B, 0x180D}, {0x1885, 0x1886}, {0x18A9, 0x18A9}, + {0x1920, 0x192B}, {0x1930, 0x193B}, {0x1A17, 0x1A1B}, + {0x1A55, 0x1A5E}, {0x1A60, 0x1A7C}, {0x1A7F, 0x1A7F}, + {0x1AB0, 0x1ABE}, {0x1B00, 0x1B04}, {0x1B34, 0x1B44}, + {0x1B6B, 0x1B73}, {0x1B80, 0x1B82}, {0x1BA1, 0x1BAD}, + {0x1BE6, 0x1BF3}, {0x1C24, 0x1C37}, {0x1CD0, 0x1CD2}, + {0x1CD4, 0x1CE8}, {0x1CED, 0x1CED}, {0x1CF2, 0x1CF4}, + {0x1CF8, 0x1CF9}, {0x1DC0, 0x1DF5}, {0x1DFB, 0x1DFF}, + {0x20D0, 0x20F0}, {0x2CEF, 0x2CF1}, {0x2D7F, 0x2D7F}, + {0x2DE0, 0x2DFF}, {0x302A, 0x302F}, {0x3099, 0x309A}, + {0xA66F, 0xA672}, {0xA674, 0xA67D}, {0xA69E, 0xA69F}, + {0xA6F0, 0xA6F1}, {0xA802, 0xA802}, {0xA806, 0xA806}, + {0xA80B, 0xA80B}, {0xA823, 0xA827}, {0xA880, 0xA881}, + {0xA8B4, 0xA8C5}, {0xA8E0, 0xA8F1}, {0xA926, 0xA92D}, + {0xA947, 0xA953}, {0xA980, 0xA983}, {0xA9B3, 0xA9C0}, + {0xA9E5, 0xA9E5}, {0xAA29, 0xAA36}, {0xAA43, 0xAA43}, + {0xAA4C, 0xAA4D}, {0xAA7B, 0xAA7D}, {0xAAB0, 0xAAB0}, + {0xAAB2, 0xAAB4}, {0xAAB7, 0xAAB8}, {0xAABE, 0xAABF}, + {0xAAC1, 0xAAC1}, {0xAAEB, 0xAAEF}, {0xAAF5, 0xAAF6}, + {0xABE3, 0xABEA}, {0xABEC, 0xABED}, {0xFB1E, 0xFB1E}, + {0xFE00, 0xFE0F}, {0xFE20, 0xFE2F}, {0x101FD, 0x101FD}, + {0x102E0, 0x102E0}, {0x10376, 0x1037A}, {0x10A01, 0x10A03}, + {0x10A05, 0x10A06}, {0x10A0C, 0x10A0F}, {0x10A38, 0x10A3A}, + {0x10A3F, 0x10A3F}, {0x10AE5, 0x10AE6}, {0x11000, 0x11002}, + {0x11038, 0x11046}, {0x1107F, 0x11082}, {0x110B0, 0x110BA}, + {0x11100, 0x11102}, {0x11127, 0x11134}, {0x11173, 0x11173}, + {0x11180, 0x11182}, {0x111B3, 0x111C0}, {0x111CA, 0x111CC}, + {0x1122C, 0x11237}, {0x1123E, 0x1123E}, {0x112DF, 0x112EA}, + {0x11300, 0x11303}, {0x1133C, 0x1133C}, {0x1133E, 0x11344}, + {0x11347, 0x11348}, {0x1134B, 0x1134D}, {0x11357, 0x11357}, + {0x11362, 0x11363}, {0x11366, 0x1136C}, {0x11370, 0x11374}, + {0x11435, 0x11446}, {0x114B0, 0x114C3}, {0x115AF, 0x115B5}, + {0x115B8, 0x115C0}, {0x115DC, 0x115DD}, {0x11630, 0x11640}, + {0x116AB, 0x116B7}, {0x1171D, 0x1172B}, {0x11C2F, 0x11C36}, + {0x11C38, 0x11C3F}, {0x11C92, 0x11CA7}, {0x11CA9, 0x11CB6}, + {0x16AF0, 0x16AF4}, {0x16B30, 0x16B36}, {0x16F51, 0x16F7E}, + {0x16F8F, 0x16F92}, {0x1BC9D, 0x1BC9E}, {0x1D165, 0x1D169}, + {0x1D16D, 0x1D172}, {0x1D17B, 0x1D182}, {0x1D185, 0x1D18B}, + {0x1D1AA, 0x1D1AD}, {0x1D242, 0x1D244}, {0x1DA00, 0x1DA36}, + {0x1DA3B, 0x1DA6C}, {0x1DA75, 0x1DA75}, {0x1DA84, 0x1DA84}, + {0x1DA9B, 0x1DA9F}, {0x1DAA1, 0x1DAAF}, {0x1E000, 0x1E006}, + {0x1E008, 0x1E018}, {0x1E01B, 0x1E021}, {0x1E023, 0x1E024}, + {0x1E026, 0x1E02A}, {0x1E8D0, 0x1E8D6}, {0x1E944, 0x1E94A}, + {0xE0100, 0xE01EF}, +} + +var doublewidth = table{ + {0x1100, 0x115F}, {0x231A, 0x231B}, {0x2329, 0x232A}, + {0x23E9, 0x23EC}, {0x23F0, 0x23F0}, {0x23F3, 0x23F3}, + {0x25FD, 0x25FE}, {0x2614, 0x2615}, {0x2648, 0x2653}, + {0x267F, 0x267F}, {0x2693, 0x2693}, {0x26A1, 0x26A1}, + {0x26AA, 0x26AB}, {0x26BD, 0x26BE}, {0x26C4, 0x26C5}, + {0x26CE, 0x26CE}, {0x26D4, 0x26D4}, {0x26EA, 0x26EA}, + {0x26F2, 0x26F3}, {0x26F5, 0x26F5}, {0x26FA, 0x26FA}, + {0x26FD, 0x26FD}, {0x2705, 0x2705}, {0x270A, 0x270B}, + {0x2728, 0x2728}, {0x274C, 0x274C}, {0x274E, 0x274E}, + {0x2753, 0x2755}, {0x2757, 0x2757}, {0x2795, 0x2797}, + {0x27B0, 0x27B0}, {0x27BF, 0x27BF}, {0x2B1B, 0x2B1C}, + {0x2B50, 0x2B50}, {0x2B55, 0x2B55}, {0x2E80, 0x2E99}, + {0x2E9B, 0x2EF3}, {0x2F00, 0x2FD5}, {0x2FF0, 0x2FFB}, + {0x3000, 0x303E}, {0x3041, 0x3096}, {0x3099, 0x30FF}, + {0x3105, 0x312D}, {0x3131, 0x318E}, {0x3190, 0x31BA}, + {0x31C0, 0x31E3}, {0x31F0, 0x321E}, {0x3220, 0x3247}, + {0x3250, 0x32FE}, {0x3300, 0x4DBF}, {0x4E00, 0xA48C}, + {0xA490, 0xA4C6}, {0xA960, 0xA97C}, {0xAC00, 0xD7A3}, + {0xF900, 0xFAFF}, {0xFE10, 0xFE19}, {0xFE30, 0xFE52}, + {0xFE54, 0xFE66}, {0xFE68, 0xFE6B}, {0xFF01, 0xFF60}, + {0xFFE0, 0xFFE6}, {0x16FE0, 0x16FE0}, {0x17000, 0x187EC}, + {0x18800, 0x18AF2}, {0x1B000, 0x1B001}, {0x1F004, 0x1F004}, + {0x1F0CF, 0x1F0CF}, {0x1F18E, 0x1F18E}, {0x1F191, 0x1F19A}, + {0x1F200, 0x1F202}, {0x1F210, 0x1F23B}, {0x1F240, 0x1F248}, + {0x1F250, 0x1F251}, {0x1F300, 0x1F320}, {0x1F32D, 0x1F335}, + {0x1F337, 0x1F37C}, {0x1F37E, 0x1F393}, {0x1F3A0, 0x1F3CA}, + {0x1F3CF, 0x1F3D3}, {0x1F3E0, 0x1F3F0}, {0x1F3F4, 0x1F3F4}, + {0x1F3F8, 0x1F43E}, {0x1F440, 0x1F440}, {0x1F442, 0x1F4FC}, + {0x1F4FF, 0x1F53D}, {0x1F54B, 0x1F54E}, {0x1F550, 0x1F567}, + {0x1F57A, 0x1F57A}, {0x1F595, 0x1F596}, {0x1F5A4, 0x1F5A4}, + {0x1F5FB, 0x1F64F}, {0x1F680, 0x1F6C5}, {0x1F6CC, 0x1F6CC}, + {0x1F6D0, 0x1F6D2}, {0x1F6EB, 0x1F6EC}, {0x1F6F4, 0x1F6F6}, + {0x1F910, 0x1F91E}, {0x1F920, 0x1F927}, {0x1F930, 0x1F930}, + {0x1F933, 0x1F93E}, {0x1F940, 0x1F94B}, {0x1F950, 0x1F95E}, + {0x1F980, 0x1F991}, {0x1F9C0, 0x1F9C0}, {0x20000, 0x2FFFD}, + {0x30000, 0x3FFFD}, +} + +var ambiguous = table{ + {0x00A1, 0x00A1}, {0x00A4, 0x00A4}, {0x00A7, 0x00A8}, + {0x00AA, 0x00AA}, {0x00AD, 0x00AE}, {0x00B0, 0x00B4}, + {0x00B6, 0x00BA}, {0x00BC, 0x00BF}, {0x00C6, 0x00C6}, + {0x00D0, 0x00D0}, {0x00D7, 0x00D8}, {0x00DE, 0x00E1}, + {0x00E6, 0x00E6}, {0x00E8, 0x00EA}, {0x00EC, 0x00ED}, + {0x00F0, 0x00F0}, {0x00F2, 0x00F3}, {0x00F7, 0x00FA}, + {0x00FC, 0x00FC}, {0x00FE, 0x00FE}, {0x0101, 0x0101}, + {0x0111, 0x0111}, {0x0113, 0x0113}, {0x011B, 0x011B}, + {0x0126, 0x0127}, {0x012B, 0x012B}, {0x0131, 0x0133}, + {0x0138, 0x0138}, {0x013F, 0x0142}, {0x0144, 0x0144}, + {0x0148, 0x014B}, {0x014D, 0x014D}, {0x0152, 0x0153}, + {0x0166, 0x0167}, {0x016B, 0x016B}, {0x01CE, 0x01CE}, + {0x01D0, 0x01D0}, {0x01D2, 0x01D2}, {0x01D4, 0x01D4}, + {0x01D6, 0x01D6}, {0x01D8, 0x01D8}, {0x01DA, 0x01DA}, + {0x01DC, 0x01DC}, {0x0251, 0x0251}, {0x0261, 0x0261}, + {0x02C4, 0x02C4}, {0x02C7, 0x02C7}, {0x02C9, 0x02CB}, + {0x02CD, 0x02CD}, {0x02D0, 0x02D0}, {0x02D8, 0x02DB}, + {0x02DD, 0x02DD}, {0x02DF, 0x02DF}, {0x0300, 0x036F}, + {0x0391, 0x03A1}, {0x03A3, 0x03A9}, {0x03B1, 0x03C1}, + {0x03C3, 0x03C9}, {0x0401, 0x0401}, {0x0410, 0x044F}, + {0x0451, 0x0451}, {0x2010, 0x2010}, {0x2013, 0x2016}, + {0x2018, 0x2019}, {0x201C, 0x201D}, {0x2020, 0x2022}, + {0x2024, 0x2027}, {0x2030, 0x2030}, {0x2032, 0x2033}, + {0x2035, 0x2035}, {0x203B, 0x203B}, {0x203E, 0x203E}, + {0x2074, 0x2074}, {0x207F, 0x207F}, {0x2081, 0x2084}, + {0x20AC, 0x20AC}, {0x2103, 0x2103}, {0x2105, 0x2105}, + {0x2109, 0x2109}, {0x2113, 0x2113}, {0x2116, 0x2116}, + {0x2121, 0x2122}, {0x2126, 0x2126}, {0x212B, 0x212B}, + {0x2153, 0x2154}, {0x215B, 0x215E}, {0x2160, 0x216B}, + {0x2170, 0x2179}, {0x2189, 0x2189}, {0x2190, 0x2199}, + {0x21B8, 0x21B9}, {0x21D2, 0x21D2}, {0x21D4, 0x21D4}, + {0x21E7, 0x21E7}, {0x2200, 0x2200}, {0x2202, 0x2203}, + {0x2207, 0x2208}, {0x220B, 0x220B}, {0x220F, 0x220F}, + {0x2211, 0x2211}, {0x2215, 0x2215}, {0x221A, 0x221A}, + {0x221D, 0x2220}, {0x2223, 0x2223}, {0x2225, 0x2225}, + {0x2227, 0x222C}, {0x222E, 0x222E}, {0x2234, 0x2237}, + {0x223C, 0x223D}, {0x2248, 0x2248}, {0x224C, 0x224C}, + {0x2252, 0x2252}, {0x2260, 0x2261}, {0x2264, 0x2267}, + {0x226A, 0x226B}, {0x226E, 0x226F}, {0x2282, 0x2283}, + {0x2286, 0x2287}, {0x2295, 0x2295}, {0x2299, 0x2299}, + {0x22A5, 0x22A5}, {0x22BF, 0x22BF}, {0x2312, 0x2312}, + {0x2460, 0x24E9}, {0x24EB, 0x254B}, {0x2550, 0x2573}, + {0x2580, 0x258F}, {0x2592, 0x2595}, {0x25A0, 0x25A1}, + {0x25A3, 0x25A9}, {0x25B2, 0x25B3}, {0x25B6, 0x25B7}, + {0x25BC, 0x25BD}, {0x25C0, 0x25C1}, {0x25C6, 0x25C8}, + {0x25CB, 0x25CB}, {0x25CE, 0x25D1}, {0x25E2, 0x25E5}, + {0x25EF, 0x25EF}, {0x2605, 0x2606}, {0x2609, 0x2609}, + {0x260E, 0x260F}, {0x261C, 0x261C}, {0x261E, 0x261E}, + {0x2640, 0x2640}, {0x2642, 0x2642}, {0x2660, 0x2661}, + {0x2663, 0x2665}, {0x2667, 0x266A}, {0x266C, 0x266D}, + {0x266F, 0x266F}, {0x269E, 0x269F}, {0x26BF, 0x26BF}, + {0x26C6, 0x26CD}, {0x26CF, 0x26D3}, {0x26D5, 0x26E1}, + {0x26E3, 0x26E3}, {0x26E8, 0x26E9}, {0x26EB, 0x26F1}, + {0x26F4, 0x26F4}, {0x26F6, 0x26F9}, {0x26FB, 0x26FC}, + {0x26FE, 0x26FF}, {0x273D, 0x273D}, {0x2776, 0x277F}, + {0x2B56, 0x2B59}, {0x3248, 0x324F}, {0xE000, 0xF8FF}, + {0xFE00, 0xFE0F}, {0xFFFD, 0xFFFD}, {0x1F100, 0x1F10A}, + {0x1F110, 0x1F12D}, {0x1F130, 0x1F169}, {0x1F170, 0x1F18D}, + {0x1F18F, 0x1F190}, {0x1F19B, 0x1F1AC}, {0xE0100, 0xE01EF}, + {0xF0000, 0xFFFFD}, {0x100000, 0x10FFFD}, +} + +var emoji = table{ + {0x1F1E6, 0x1F1FF}, {0x1F321, 0x1F321}, {0x1F324, 0x1F32C}, + {0x1F336, 0x1F336}, {0x1F37D, 0x1F37D}, {0x1F396, 0x1F397}, + {0x1F399, 0x1F39B}, {0x1F39E, 0x1F39F}, {0x1F3CB, 0x1F3CE}, + {0x1F3D4, 0x1F3DF}, {0x1F3F3, 0x1F3F5}, {0x1F3F7, 0x1F3F7}, + {0x1F43F, 0x1F43F}, {0x1F441, 0x1F441}, {0x1F4FD, 0x1F4FD}, + {0x1F549, 0x1F54A}, {0x1F56F, 0x1F570}, {0x1F573, 0x1F579}, + {0x1F587, 0x1F587}, {0x1F58A, 0x1F58D}, {0x1F590, 0x1F590}, + {0x1F5A5, 0x1F5A5}, {0x1F5A8, 0x1F5A8}, {0x1F5B1, 0x1F5B2}, + {0x1F5BC, 0x1F5BC}, {0x1F5C2, 0x1F5C4}, {0x1F5D1, 0x1F5D3}, + {0x1F5DC, 0x1F5DE}, {0x1F5E1, 0x1F5E1}, {0x1F5E3, 0x1F5E3}, + {0x1F5E8, 0x1F5E8}, {0x1F5EF, 0x1F5EF}, {0x1F5F3, 0x1F5F3}, + {0x1F5FA, 0x1F5FA}, {0x1F6CB, 0x1F6CF}, {0x1F6E0, 0x1F6E5}, + {0x1F6E9, 0x1F6E9}, {0x1F6F0, 0x1F6F0}, {0x1F6F3, 0x1F6F3}, +} + +var notassigned = table{ + {0x0378, 0x0379}, {0x0380, 0x0383}, {0x038B, 0x038B}, + {0x038D, 0x038D}, {0x03A2, 0x03A2}, {0x0530, 0x0530}, + {0x0557, 0x0558}, {0x0560, 0x0560}, {0x0588, 0x0588}, + {0x058B, 0x058C}, {0x0590, 0x0590}, {0x05C8, 0x05CF}, + {0x05EB, 0x05EF}, {0x05F5, 0x05FF}, {0x061D, 0x061D}, + {0x070E, 0x070E}, {0x074B, 0x074C}, {0x07B2, 0x07BF}, + {0x07FB, 0x07FF}, {0x082E, 0x082F}, {0x083F, 0x083F}, + {0x085C, 0x085D}, {0x085F, 0x089F}, {0x08B5, 0x08B5}, + {0x08BE, 0x08D3}, {0x0984, 0x0984}, {0x098D, 0x098E}, + {0x0991, 0x0992}, {0x09A9, 0x09A9}, {0x09B1, 0x09B1}, + {0x09B3, 0x09B5}, {0x09BA, 0x09BB}, {0x09C5, 0x09C6}, + {0x09C9, 0x09CA}, {0x09CF, 0x09D6}, {0x09D8, 0x09DB}, + {0x09DE, 0x09DE}, {0x09E4, 0x09E5}, {0x09FC, 0x0A00}, + {0x0A04, 0x0A04}, {0x0A0B, 0x0A0E}, {0x0A11, 0x0A12}, + {0x0A29, 0x0A29}, {0x0A31, 0x0A31}, {0x0A34, 0x0A34}, + {0x0A37, 0x0A37}, {0x0A3A, 0x0A3B}, {0x0A3D, 0x0A3D}, + {0x0A43, 0x0A46}, {0x0A49, 0x0A4A}, {0x0A4E, 0x0A50}, + {0x0A52, 0x0A58}, {0x0A5D, 0x0A5D}, {0x0A5F, 0x0A65}, + {0x0A76, 0x0A80}, {0x0A84, 0x0A84}, {0x0A8E, 0x0A8E}, + {0x0A92, 0x0A92}, {0x0AA9, 0x0AA9}, {0x0AB1, 0x0AB1}, + {0x0AB4, 0x0AB4}, {0x0ABA, 0x0ABB}, {0x0AC6, 0x0AC6}, + {0x0ACA, 0x0ACA}, {0x0ACE, 0x0ACF}, {0x0AD1, 0x0ADF}, + {0x0AE4, 0x0AE5}, {0x0AF2, 0x0AF8}, {0x0AFA, 0x0B00}, + {0x0B04, 0x0B04}, {0x0B0D, 0x0B0E}, {0x0B11, 0x0B12}, + {0x0B29, 0x0B29}, {0x0B31, 0x0B31}, {0x0B34, 0x0B34}, + {0x0B3A, 0x0B3B}, {0x0B45, 0x0B46}, {0x0B49, 0x0B4A}, + {0x0B4E, 0x0B55}, {0x0B58, 0x0B5B}, {0x0B5E, 0x0B5E}, + {0x0B64, 0x0B65}, {0x0B78, 0x0B81}, {0x0B84, 0x0B84}, + {0x0B8B, 0x0B8D}, {0x0B91, 0x0B91}, {0x0B96, 0x0B98}, + {0x0B9B, 0x0B9B}, {0x0B9D, 0x0B9D}, {0x0BA0, 0x0BA2}, + {0x0BA5, 0x0BA7}, {0x0BAB, 0x0BAD}, {0x0BBA, 0x0BBD}, + {0x0BC3, 0x0BC5}, {0x0BC9, 0x0BC9}, {0x0BCE, 0x0BCF}, + {0x0BD1, 0x0BD6}, {0x0BD8, 0x0BE5}, {0x0BFB, 0x0BFF}, + {0x0C04, 0x0C04}, {0x0C0D, 0x0C0D}, {0x0C11, 0x0C11}, + {0x0C29, 0x0C29}, {0x0C3A, 0x0C3C}, {0x0C45, 0x0C45}, + {0x0C49, 0x0C49}, {0x0C4E, 0x0C54}, {0x0C57, 0x0C57}, + {0x0C5B, 0x0C5F}, {0x0C64, 0x0C65}, {0x0C70, 0x0C77}, + {0x0C84, 0x0C84}, {0x0C8D, 0x0C8D}, {0x0C91, 0x0C91}, + {0x0CA9, 0x0CA9}, {0x0CB4, 0x0CB4}, {0x0CBA, 0x0CBB}, + {0x0CC5, 0x0CC5}, {0x0CC9, 0x0CC9}, {0x0CCE, 0x0CD4}, + {0x0CD7, 0x0CDD}, {0x0CDF, 0x0CDF}, {0x0CE4, 0x0CE5}, + {0x0CF0, 0x0CF0}, {0x0CF3, 0x0D00}, {0x0D04, 0x0D04}, + {0x0D0D, 0x0D0D}, {0x0D11, 0x0D11}, {0x0D3B, 0x0D3C}, + {0x0D45, 0x0D45}, {0x0D49, 0x0D49}, {0x0D50, 0x0D53}, + {0x0D64, 0x0D65}, {0x0D80, 0x0D81}, {0x0D84, 0x0D84}, + {0x0D97, 0x0D99}, {0x0DB2, 0x0DB2}, {0x0DBC, 0x0DBC}, + {0x0DBE, 0x0DBF}, {0x0DC7, 0x0DC9}, {0x0DCB, 0x0DCE}, + {0x0DD5, 0x0DD5}, {0x0DD7, 0x0DD7}, {0x0DE0, 0x0DE5}, + {0x0DF0, 0x0DF1}, {0x0DF5, 0x0E00}, {0x0E3B, 0x0E3E}, + {0x0E5C, 0x0E80}, {0x0E83, 0x0E83}, {0x0E85, 0x0E86}, + {0x0E89, 0x0E89}, {0x0E8B, 0x0E8C}, {0x0E8E, 0x0E93}, + {0x0E98, 0x0E98}, {0x0EA0, 0x0EA0}, {0x0EA4, 0x0EA4}, + {0x0EA6, 0x0EA6}, {0x0EA8, 0x0EA9}, {0x0EAC, 0x0EAC}, + {0x0EBA, 0x0EBA}, {0x0EBE, 0x0EBF}, {0x0EC5, 0x0EC5}, + {0x0EC7, 0x0EC7}, {0x0ECE, 0x0ECF}, {0x0EDA, 0x0EDB}, + {0x0EE0, 0x0EFF}, {0x0F48, 0x0F48}, {0x0F6D, 0x0F70}, + {0x0F98, 0x0F98}, {0x0FBD, 0x0FBD}, {0x0FCD, 0x0FCD}, + {0x0FDB, 0x0FFF}, {0x10C6, 0x10C6}, {0x10C8, 0x10CC}, + {0x10CE, 0x10CF}, {0x1249, 0x1249}, {0x124E, 0x124F}, + {0x1257, 0x1257}, {0x1259, 0x1259}, {0x125E, 0x125F}, + {0x1289, 0x1289}, {0x128E, 0x128F}, {0x12B1, 0x12B1}, + {0x12B6, 0x12B7}, {0x12BF, 0x12BF}, {0x12C1, 0x12C1}, + {0x12C6, 0x12C7}, {0x12D7, 0x12D7}, {0x1311, 0x1311}, + {0x1316, 0x1317}, {0x135B, 0x135C}, {0x137D, 0x137F}, + {0x139A, 0x139F}, {0x13F6, 0x13F7}, {0x13FE, 0x13FF}, + {0x169D, 0x169F}, {0x16F9, 0x16FF}, {0x170D, 0x170D}, + {0x1715, 0x171F}, {0x1737, 0x173F}, {0x1754, 0x175F}, + {0x176D, 0x176D}, {0x1771, 0x1771}, {0x1774, 0x177F}, + {0x17DE, 0x17DF}, {0x17EA, 0x17EF}, {0x17FA, 0x17FF}, + {0x180F, 0x180F}, {0x181A, 0x181F}, {0x1878, 0x187F}, + {0x18AB, 0x18AF}, {0x18F6, 0x18FF}, {0x191F, 0x191F}, + {0x192C, 0x192F}, {0x193C, 0x193F}, {0x1941, 0x1943}, + {0x196E, 0x196F}, {0x1975, 0x197F}, {0x19AC, 0x19AF}, + {0x19CA, 0x19CF}, {0x19DB, 0x19DD}, {0x1A1C, 0x1A1D}, + {0x1A5F, 0x1A5F}, {0x1A7D, 0x1A7E}, {0x1A8A, 0x1A8F}, + {0x1A9A, 0x1A9F}, {0x1AAE, 0x1AAF}, {0x1ABF, 0x1AFF}, + {0x1B4C, 0x1B4F}, {0x1B7D, 0x1B7F}, {0x1BF4, 0x1BFB}, + {0x1C38, 0x1C3A}, {0x1C4A, 0x1C4C}, {0x1C89, 0x1CBF}, + {0x1CC8, 0x1CCF}, {0x1CF7, 0x1CF7}, {0x1CFA, 0x1CFF}, + {0x1DF6, 0x1DFA}, {0x1F16, 0x1F17}, {0x1F1E, 0x1F1F}, + {0x1F46, 0x1F47}, {0x1F4E, 0x1F4F}, {0x1F58, 0x1F58}, + {0x1F5A, 0x1F5A}, {0x1F5C, 0x1F5C}, {0x1F5E, 0x1F5E}, + {0x1F7E, 0x1F7F}, {0x1FB5, 0x1FB5}, {0x1FC5, 0x1FC5}, + {0x1FD4, 0x1FD5}, {0x1FDC, 0x1FDC}, {0x1FF0, 0x1FF1}, + {0x1FF5, 0x1FF5}, {0x1FFF, 0x1FFF}, {0x2065, 0x2065}, + {0x2072, 0x2073}, {0x208F, 0x208F}, {0x209D, 0x209F}, + {0x20BF, 0x20CF}, {0x20F1, 0x20FF}, {0x218C, 0x218F}, + {0x23FF, 0x23FF}, {0x2427, 0x243F}, {0x244B, 0x245F}, + {0x2B74, 0x2B75}, {0x2B96, 0x2B97}, {0x2BBA, 0x2BBC}, + {0x2BC9, 0x2BC9}, {0x2BD2, 0x2BEB}, {0x2BF0, 0x2BFF}, + {0x2C2F, 0x2C2F}, {0x2C5F, 0x2C5F}, {0x2CF4, 0x2CF8}, + {0x2D26, 0x2D26}, {0x2D28, 0x2D2C}, {0x2D2E, 0x2D2F}, + {0x2D68, 0x2D6E}, {0x2D71, 0x2D7E}, {0x2D97, 0x2D9F}, + {0x2DA7, 0x2DA7}, {0x2DAF, 0x2DAF}, {0x2DB7, 0x2DB7}, + {0x2DBF, 0x2DBF}, {0x2DC7, 0x2DC7}, {0x2DCF, 0x2DCF}, + {0x2DD7, 0x2DD7}, {0x2DDF, 0x2DDF}, {0x2E45, 0x2E7F}, + {0x2E9A, 0x2E9A}, {0x2EF4, 0x2EFF}, {0x2FD6, 0x2FEF}, + {0x2FFC, 0x2FFF}, {0x3040, 0x3040}, {0x3097, 0x3098}, + {0x3100, 0x3104}, {0x312E, 0x3130}, {0x318F, 0x318F}, + {0x31BB, 0x31BF}, {0x31E4, 0x31EF}, {0x321F, 0x321F}, + {0x32FF, 0x32FF}, {0x4DB6, 0x4DBF}, {0x9FD6, 0x9FFF}, + {0xA48D, 0xA48F}, {0xA4C7, 0xA4CF}, {0xA62C, 0xA63F}, + {0xA6F8, 0xA6FF}, {0xA7AF, 0xA7AF}, {0xA7B8, 0xA7F6}, + {0xA82C, 0xA82F}, {0xA83A, 0xA83F}, {0xA878, 0xA87F}, + {0xA8C6, 0xA8CD}, {0xA8DA, 0xA8DF}, {0xA8FE, 0xA8FF}, + {0xA954, 0xA95E}, {0xA97D, 0xA97F}, {0xA9CE, 0xA9CE}, + {0xA9DA, 0xA9DD}, {0xA9FF, 0xA9FF}, {0xAA37, 0xAA3F}, + {0xAA4E, 0xAA4F}, {0xAA5A, 0xAA5B}, {0xAAC3, 0xAADA}, + {0xAAF7, 0xAB00}, {0xAB07, 0xAB08}, {0xAB0F, 0xAB10}, + {0xAB17, 0xAB1F}, {0xAB27, 0xAB27}, {0xAB2F, 0xAB2F}, + {0xAB66, 0xAB6F}, {0xABEE, 0xABEF}, {0xABFA, 0xABFF}, + {0xD7A4, 0xD7AF}, {0xD7C7, 0xD7CA}, {0xD7FC, 0xD7FF}, + {0xFA6E, 0xFA6F}, {0xFADA, 0xFAFF}, {0xFB07, 0xFB12}, + {0xFB18, 0xFB1C}, {0xFB37, 0xFB37}, {0xFB3D, 0xFB3D}, + {0xFB3F, 0xFB3F}, {0xFB42, 0xFB42}, {0xFB45, 0xFB45}, + {0xFBC2, 0xFBD2}, {0xFD40, 0xFD4F}, {0xFD90, 0xFD91}, + {0xFDC8, 0xFDEF}, {0xFDFE, 0xFDFF}, {0xFE1A, 0xFE1F}, + {0xFE53, 0xFE53}, {0xFE67, 0xFE67}, {0xFE6C, 0xFE6F}, + {0xFE75, 0xFE75}, {0xFEFD, 0xFEFE}, {0xFF00, 0xFF00}, + {0xFFBF, 0xFFC1}, {0xFFC8, 0xFFC9}, {0xFFD0, 0xFFD1}, + {0xFFD8, 0xFFD9}, {0xFFDD, 0xFFDF}, {0xFFE7, 0xFFE7}, + {0xFFEF, 0xFFF8}, {0xFFFE, 0xFFFF}, {0x1000C, 0x1000C}, + {0x10027, 0x10027}, {0x1003B, 0x1003B}, {0x1003E, 0x1003E}, + {0x1004E, 0x1004F}, {0x1005E, 0x1007F}, {0x100FB, 0x100FF}, + {0x10103, 0x10106}, {0x10134, 0x10136}, {0x1018F, 0x1018F}, + {0x1019C, 0x1019F}, {0x101A1, 0x101CF}, {0x101FE, 0x1027F}, + {0x1029D, 0x1029F}, {0x102D1, 0x102DF}, {0x102FC, 0x102FF}, + {0x10324, 0x1032F}, {0x1034B, 0x1034F}, {0x1037B, 0x1037F}, + {0x1039E, 0x1039E}, {0x103C4, 0x103C7}, {0x103D6, 0x103FF}, + {0x1049E, 0x1049F}, {0x104AA, 0x104AF}, {0x104D4, 0x104D7}, + {0x104FC, 0x104FF}, {0x10528, 0x1052F}, {0x10564, 0x1056E}, + {0x10570, 0x105FF}, {0x10737, 0x1073F}, {0x10756, 0x1075F}, + {0x10768, 0x107FF}, {0x10806, 0x10807}, {0x10809, 0x10809}, + {0x10836, 0x10836}, {0x10839, 0x1083B}, {0x1083D, 0x1083E}, + {0x10856, 0x10856}, {0x1089F, 0x108A6}, {0x108B0, 0x108DF}, + {0x108F3, 0x108F3}, {0x108F6, 0x108FA}, {0x1091C, 0x1091E}, + {0x1093A, 0x1093E}, {0x10940, 0x1097F}, {0x109B8, 0x109BB}, + {0x109D0, 0x109D1}, {0x10A04, 0x10A04}, {0x10A07, 0x10A0B}, + {0x10A14, 0x10A14}, {0x10A18, 0x10A18}, {0x10A34, 0x10A37}, + {0x10A3B, 0x10A3E}, {0x10A48, 0x10A4F}, {0x10A59, 0x10A5F}, + {0x10AA0, 0x10ABF}, {0x10AE7, 0x10AEA}, {0x10AF7, 0x10AFF}, + {0x10B36, 0x10B38}, {0x10B56, 0x10B57}, {0x10B73, 0x10B77}, + {0x10B92, 0x10B98}, {0x10B9D, 0x10BA8}, {0x10BB0, 0x10BFF}, + {0x10C49, 0x10C7F}, {0x10CB3, 0x10CBF}, {0x10CF3, 0x10CF9}, + {0x10D00, 0x10E5F}, {0x10E7F, 0x10FFF}, {0x1104E, 0x11051}, + {0x11070, 0x1107E}, {0x110C2, 0x110CF}, {0x110E9, 0x110EF}, + {0x110FA, 0x110FF}, {0x11135, 0x11135}, {0x11144, 0x1114F}, + {0x11177, 0x1117F}, {0x111CE, 0x111CF}, {0x111E0, 0x111E0}, + {0x111F5, 0x111FF}, {0x11212, 0x11212}, {0x1123F, 0x1127F}, + {0x11287, 0x11287}, {0x11289, 0x11289}, {0x1128E, 0x1128E}, + {0x1129E, 0x1129E}, {0x112AA, 0x112AF}, {0x112EB, 0x112EF}, + {0x112FA, 0x112FF}, {0x11304, 0x11304}, {0x1130D, 0x1130E}, + {0x11311, 0x11312}, {0x11329, 0x11329}, {0x11331, 0x11331}, + {0x11334, 0x11334}, {0x1133A, 0x1133B}, {0x11345, 0x11346}, + {0x11349, 0x1134A}, {0x1134E, 0x1134F}, {0x11351, 0x11356}, + {0x11358, 0x1135C}, {0x11364, 0x11365}, {0x1136D, 0x1136F}, + {0x11375, 0x113FF}, {0x1145A, 0x1145A}, {0x1145C, 0x1145C}, + {0x1145E, 0x1147F}, {0x114C8, 0x114CF}, {0x114DA, 0x1157F}, + {0x115B6, 0x115B7}, {0x115DE, 0x115FF}, {0x11645, 0x1164F}, + {0x1165A, 0x1165F}, {0x1166D, 0x1167F}, {0x116B8, 0x116BF}, + {0x116CA, 0x116FF}, {0x1171A, 0x1171C}, {0x1172C, 0x1172F}, + {0x11740, 0x1189F}, {0x118F3, 0x118FE}, {0x11900, 0x11ABF}, + {0x11AF9, 0x11BFF}, {0x11C09, 0x11C09}, {0x11C37, 0x11C37}, + {0x11C46, 0x11C4F}, {0x11C6D, 0x11C6F}, {0x11C90, 0x11C91}, + {0x11CA8, 0x11CA8}, {0x11CB7, 0x11FFF}, {0x1239A, 0x123FF}, + {0x1246F, 0x1246F}, {0x12475, 0x1247F}, {0x12544, 0x12FFF}, + {0x1342F, 0x143FF}, {0x14647, 0x167FF}, {0x16A39, 0x16A3F}, + {0x16A5F, 0x16A5F}, {0x16A6A, 0x16A6D}, {0x16A70, 0x16ACF}, + {0x16AEE, 0x16AEF}, {0x16AF6, 0x16AFF}, {0x16B46, 0x16B4F}, + {0x16B5A, 0x16B5A}, {0x16B62, 0x16B62}, {0x16B78, 0x16B7C}, + {0x16B90, 0x16EFF}, {0x16F45, 0x16F4F}, {0x16F7F, 0x16F8E}, + {0x16FA0, 0x16FDF}, {0x16FE1, 0x16FFF}, {0x187ED, 0x187FF}, + {0x18AF3, 0x1AFFF}, {0x1B002, 0x1BBFF}, {0x1BC6B, 0x1BC6F}, + {0x1BC7D, 0x1BC7F}, {0x1BC89, 0x1BC8F}, {0x1BC9A, 0x1BC9B}, + {0x1BCA4, 0x1CFFF}, {0x1D0F6, 0x1D0FF}, {0x1D127, 0x1D128}, + {0x1D1E9, 0x1D1FF}, {0x1D246, 0x1D2FF}, {0x1D357, 0x1D35F}, + {0x1D372, 0x1D3FF}, {0x1D455, 0x1D455}, {0x1D49D, 0x1D49D}, + {0x1D4A0, 0x1D4A1}, {0x1D4A3, 0x1D4A4}, {0x1D4A7, 0x1D4A8}, + {0x1D4AD, 0x1D4AD}, {0x1D4BA, 0x1D4BA}, {0x1D4BC, 0x1D4BC}, + {0x1D4C4, 0x1D4C4}, {0x1D506, 0x1D506}, {0x1D50B, 0x1D50C}, + {0x1D515, 0x1D515}, {0x1D51D, 0x1D51D}, {0x1D53A, 0x1D53A}, + {0x1D53F, 0x1D53F}, {0x1D545, 0x1D545}, {0x1D547, 0x1D549}, + {0x1D551, 0x1D551}, {0x1D6A6, 0x1D6A7}, {0x1D7CC, 0x1D7CD}, + {0x1DA8C, 0x1DA9A}, {0x1DAA0, 0x1DAA0}, {0x1DAB0, 0x1DFFF}, + {0x1E007, 0x1E007}, {0x1E019, 0x1E01A}, {0x1E022, 0x1E022}, + {0x1E025, 0x1E025}, {0x1E02B, 0x1E7FF}, {0x1E8C5, 0x1E8C6}, + {0x1E8D7, 0x1E8FF}, {0x1E94B, 0x1E94F}, {0x1E95A, 0x1E95D}, + {0x1E960, 0x1EDFF}, {0x1EE04, 0x1EE04}, {0x1EE20, 0x1EE20}, + {0x1EE23, 0x1EE23}, {0x1EE25, 0x1EE26}, {0x1EE28, 0x1EE28}, + {0x1EE33, 0x1EE33}, {0x1EE38, 0x1EE38}, {0x1EE3A, 0x1EE3A}, + {0x1EE3C, 0x1EE41}, {0x1EE43, 0x1EE46}, {0x1EE48, 0x1EE48}, + {0x1EE4A, 0x1EE4A}, {0x1EE4C, 0x1EE4C}, {0x1EE50, 0x1EE50}, + {0x1EE53, 0x1EE53}, {0x1EE55, 0x1EE56}, {0x1EE58, 0x1EE58}, + {0x1EE5A, 0x1EE5A}, {0x1EE5C, 0x1EE5C}, {0x1EE5E, 0x1EE5E}, + {0x1EE60, 0x1EE60}, {0x1EE63, 0x1EE63}, {0x1EE65, 0x1EE66}, + {0x1EE6B, 0x1EE6B}, {0x1EE73, 0x1EE73}, {0x1EE78, 0x1EE78}, + {0x1EE7D, 0x1EE7D}, {0x1EE7F, 0x1EE7F}, {0x1EE8A, 0x1EE8A}, + {0x1EE9C, 0x1EEA0}, {0x1EEA4, 0x1EEA4}, {0x1EEAA, 0x1EEAA}, + {0x1EEBC, 0x1EEEF}, {0x1EEF2, 0x1EFFF}, {0x1F02C, 0x1F02F}, + {0x1F094, 0x1F09F}, {0x1F0AF, 0x1F0B0}, {0x1F0C0, 0x1F0C0}, + {0x1F0D0, 0x1F0D0}, {0x1F0F6, 0x1F0FF}, {0x1F10D, 0x1F10F}, + {0x1F12F, 0x1F12F}, {0x1F16C, 0x1F16F}, {0x1F1AD, 0x1F1E5}, + {0x1F203, 0x1F20F}, {0x1F23C, 0x1F23F}, {0x1F249, 0x1F24F}, + {0x1F252, 0x1F2FF}, {0x1F6D3, 0x1F6DF}, {0x1F6ED, 0x1F6EF}, + {0x1F6F7, 0x1F6FF}, {0x1F774, 0x1F77F}, {0x1F7D5, 0x1F7FF}, + {0x1F80C, 0x1F80F}, {0x1F848, 0x1F84F}, {0x1F85A, 0x1F85F}, + {0x1F888, 0x1F88F}, {0x1F8AE, 0x1F90F}, {0x1F91F, 0x1F91F}, + {0x1F928, 0x1F92F}, {0x1F931, 0x1F932}, {0x1F93F, 0x1F93F}, + {0x1F94C, 0x1F94F}, {0x1F95F, 0x1F97F}, {0x1F992, 0x1F9BF}, + {0x1F9C1, 0x1FFFF}, {0x2A6D7, 0x2A6FF}, {0x2B735, 0x2B73F}, + {0x2B81E, 0x2B81F}, {0x2CEA2, 0x2F7FF}, {0x2FA1E, 0xE0000}, + {0xE0002, 0xE001F}, {0xE0080, 0xE00FF}, {0xE01F0, 0xEFFFF}, + {0xFFFFE, 0xFFFFF}, +} + +var neutral = table{ + {0x0000, 0x001F}, {0x007F, 0x007F}, {0x0080, 0x009F}, + {0x00A0, 0x00A0}, {0x00A9, 0x00A9}, {0x00AB, 0x00AB}, + {0x00B5, 0x00B5}, {0x00BB, 0x00BB}, {0x00C0, 0x00C5}, + {0x00C7, 0x00CF}, {0x00D1, 0x00D6}, {0x00D9, 0x00DD}, + {0x00E2, 0x00E5}, {0x00E7, 0x00E7}, {0x00EB, 0x00EB}, + {0x00EE, 0x00EF}, {0x00F1, 0x00F1}, {0x00F4, 0x00F6}, + {0x00FB, 0x00FB}, {0x00FD, 0x00FD}, {0x00FF, 0x00FF}, + {0x0100, 0x0100}, {0x0102, 0x0110}, {0x0112, 0x0112}, + {0x0114, 0x011A}, {0x011C, 0x0125}, {0x0128, 0x012A}, + {0x012C, 0x0130}, {0x0134, 0x0137}, {0x0139, 0x013E}, + {0x0143, 0x0143}, {0x0145, 0x0147}, {0x014C, 0x014C}, + {0x014E, 0x0151}, {0x0154, 0x0165}, {0x0168, 0x016A}, + {0x016C, 0x017F}, {0x0180, 0x01BA}, {0x01BB, 0x01BB}, + {0x01BC, 0x01BF}, {0x01C0, 0x01C3}, {0x01C4, 0x01CD}, + {0x01CF, 0x01CF}, {0x01D1, 0x01D1}, {0x01D3, 0x01D3}, + {0x01D5, 0x01D5}, {0x01D7, 0x01D7}, {0x01D9, 0x01D9}, + {0x01DB, 0x01DB}, {0x01DD, 0x024F}, {0x0250, 0x0250}, + {0x0252, 0x0260}, {0x0262, 0x0293}, {0x0294, 0x0294}, + {0x0295, 0x02AF}, {0x02B0, 0x02C1}, {0x02C2, 0x02C3}, + {0x02C5, 0x02C5}, {0x02C6, 0x02C6}, {0x02C8, 0x02C8}, + {0x02CC, 0x02CC}, {0x02CE, 0x02CF}, {0x02D1, 0x02D1}, + {0x02D2, 0x02D7}, {0x02DC, 0x02DC}, {0x02DE, 0x02DE}, + {0x02E0, 0x02E4}, {0x02E5, 0x02EB}, {0x02EC, 0x02EC}, + {0x02ED, 0x02ED}, {0x02EE, 0x02EE}, {0x02EF, 0x02FF}, + {0x0370, 0x0373}, {0x0374, 0x0374}, {0x0375, 0x0375}, + {0x0376, 0x0377}, {0x037A, 0x037A}, {0x037B, 0x037D}, + {0x037E, 0x037E}, {0x037F, 0x037F}, {0x0384, 0x0385}, + {0x0386, 0x0386}, {0x0387, 0x0387}, {0x0388, 0x038A}, + {0x038C, 0x038C}, {0x038E, 0x0390}, {0x03AA, 0x03B0}, + {0x03C2, 0x03C2}, {0x03CA, 0x03F5}, {0x03F6, 0x03F6}, + {0x03F7, 0x03FF}, {0x0400, 0x0400}, {0x0402, 0x040F}, + {0x0450, 0x0450}, {0x0452, 0x0481}, {0x0482, 0x0482}, + {0x0483, 0x0487}, {0x0488, 0x0489}, {0x048A, 0x04FF}, + {0x0500, 0x052F}, {0x0531, 0x0556}, {0x0559, 0x0559}, + {0x055A, 0x055F}, {0x0561, 0x0587}, {0x0589, 0x0589}, + {0x058A, 0x058A}, {0x058D, 0x058E}, {0x058F, 0x058F}, + {0x0591, 0x05BD}, {0x05BE, 0x05BE}, {0x05BF, 0x05BF}, + {0x05C0, 0x05C0}, {0x05C1, 0x05C2}, {0x05C3, 0x05C3}, + {0x05C4, 0x05C5}, {0x05C6, 0x05C6}, {0x05C7, 0x05C7}, + {0x05D0, 0x05EA}, {0x05F0, 0x05F2}, {0x05F3, 0x05F4}, + {0x0600, 0x0605}, {0x0606, 0x0608}, {0x0609, 0x060A}, + {0x060B, 0x060B}, {0x060C, 0x060D}, {0x060E, 0x060F}, + {0x0610, 0x061A}, {0x061B, 0x061B}, {0x061C, 0x061C}, + {0x061E, 0x061F}, {0x0620, 0x063F}, {0x0640, 0x0640}, + {0x0641, 0x064A}, {0x064B, 0x065F}, {0x0660, 0x0669}, + {0x066A, 0x066D}, {0x066E, 0x066F}, {0x0670, 0x0670}, + {0x0671, 0x06D3}, {0x06D4, 0x06D4}, {0x06D5, 0x06D5}, + {0x06D6, 0x06DC}, {0x06DD, 0x06DD}, {0x06DE, 0x06DE}, + {0x06DF, 0x06E4}, {0x06E5, 0x06E6}, {0x06E7, 0x06E8}, + {0x06E9, 0x06E9}, {0x06EA, 0x06ED}, {0x06EE, 0x06EF}, + {0x06F0, 0x06F9}, {0x06FA, 0x06FC}, {0x06FD, 0x06FE}, + {0x06FF, 0x06FF}, {0x0700, 0x070D}, {0x070F, 0x070F}, + {0x0710, 0x0710}, {0x0711, 0x0711}, {0x0712, 0x072F}, + {0x0730, 0x074A}, {0x074D, 0x074F}, {0x0750, 0x077F}, + {0x0780, 0x07A5}, {0x07A6, 0x07B0}, {0x07B1, 0x07B1}, + {0x07C0, 0x07C9}, {0x07CA, 0x07EA}, {0x07EB, 0x07F3}, + {0x07F4, 0x07F5}, {0x07F6, 0x07F6}, {0x07F7, 0x07F9}, + {0x07FA, 0x07FA}, {0x0800, 0x0815}, {0x0816, 0x0819}, + {0x081A, 0x081A}, {0x081B, 0x0823}, {0x0824, 0x0824}, + {0x0825, 0x0827}, {0x0828, 0x0828}, {0x0829, 0x082D}, + {0x0830, 0x083E}, {0x0840, 0x0858}, {0x0859, 0x085B}, + {0x085E, 0x085E}, {0x08A0, 0x08B4}, {0x08B6, 0x08BD}, + {0x08D4, 0x08E1}, {0x08E2, 0x08E2}, {0x08E3, 0x08FF}, + {0x0900, 0x0902}, {0x0903, 0x0903}, {0x0904, 0x0939}, + {0x093A, 0x093A}, {0x093B, 0x093B}, {0x093C, 0x093C}, + {0x093D, 0x093D}, {0x093E, 0x0940}, {0x0941, 0x0948}, + {0x0949, 0x094C}, {0x094D, 0x094D}, {0x094E, 0x094F}, + {0x0950, 0x0950}, {0x0951, 0x0957}, {0x0958, 0x0961}, + {0x0962, 0x0963}, {0x0964, 0x0965}, {0x0966, 0x096F}, + {0x0970, 0x0970}, {0x0971, 0x0971}, {0x0972, 0x097F}, + {0x0980, 0x0980}, {0x0981, 0x0981}, {0x0982, 0x0983}, + {0x0985, 0x098C}, {0x098F, 0x0990}, {0x0993, 0x09A8}, + {0x09AA, 0x09B0}, {0x09B2, 0x09B2}, {0x09B6, 0x09B9}, + {0x09BC, 0x09BC}, {0x09BD, 0x09BD}, {0x09BE, 0x09C0}, + {0x09C1, 0x09C4}, {0x09C7, 0x09C8}, {0x09CB, 0x09CC}, + {0x09CD, 0x09CD}, {0x09CE, 0x09CE}, {0x09D7, 0x09D7}, + {0x09DC, 0x09DD}, {0x09DF, 0x09E1}, {0x09E2, 0x09E3}, + {0x09E6, 0x09EF}, {0x09F0, 0x09F1}, {0x09F2, 0x09F3}, + {0x09F4, 0x09F9}, {0x09FA, 0x09FA}, {0x09FB, 0x09FB}, + {0x0A01, 0x0A02}, {0x0A03, 0x0A03}, {0x0A05, 0x0A0A}, + {0x0A0F, 0x0A10}, {0x0A13, 0x0A28}, {0x0A2A, 0x0A30}, + {0x0A32, 0x0A33}, {0x0A35, 0x0A36}, {0x0A38, 0x0A39}, + {0x0A3C, 0x0A3C}, {0x0A3E, 0x0A40}, {0x0A41, 0x0A42}, + {0x0A47, 0x0A48}, {0x0A4B, 0x0A4D}, {0x0A51, 0x0A51}, + {0x0A59, 0x0A5C}, {0x0A5E, 0x0A5E}, {0x0A66, 0x0A6F}, + {0x0A70, 0x0A71}, {0x0A72, 0x0A74}, {0x0A75, 0x0A75}, + {0x0A81, 0x0A82}, {0x0A83, 0x0A83}, {0x0A85, 0x0A8D}, + {0x0A8F, 0x0A91}, {0x0A93, 0x0AA8}, {0x0AAA, 0x0AB0}, + {0x0AB2, 0x0AB3}, {0x0AB5, 0x0AB9}, {0x0ABC, 0x0ABC}, + {0x0ABD, 0x0ABD}, {0x0ABE, 0x0AC0}, {0x0AC1, 0x0AC5}, + {0x0AC7, 0x0AC8}, {0x0AC9, 0x0AC9}, {0x0ACB, 0x0ACC}, + {0x0ACD, 0x0ACD}, {0x0AD0, 0x0AD0}, {0x0AE0, 0x0AE1}, + {0x0AE2, 0x0AE3}, {0x0AE6, 0x0AEF}, {0x0AF0, 0x0AF0}, + {0x0AF1, 0x0AF1}, {0x0AF9, 0x0AF9}, {0x0B01, 0x0B01}, + {0x0B02, 0x0B03}, {0x0B05, 0x0B0C}, {0x0B0F, 0x0B10}, + {0x0B13, 0x0B28}, {0x0B2A, 0x0B30}, {0x0B32, 0x0B33}, + {0x0B35, 0x0B39}, {0x0B3C, 0x0B3C}, {0x0B3D, 0x0B3D}, + {0x0B3E, 0x0B3E}, {0x0B3F, 0x0B3F}, {0x0B40, 0x0B40}, + {0x0B41, 0x0B44}, {0x0B47, 0x0B48}, {0x0B4B, 0x0B4C}, + {0x0B4D, 0x0B4D}, {0x0B56, 0x0B56}, {0x0B57, 0x0B57}, + {0x0B5C, 0x0B5D}, {0x0B5F, 0x0B61}, {0x0B62, 0x0B63}, + {0x0B66, 0x0B6F}, {0x0B70, 0x0B70}, {0x0B71, 0x0B71}, + {0x0B72, 0x0B77}, {0x0B82, 0x0B82}, {0x0B83, 0x0B83}, + {0x0B85, 0x0B8A}, {0x0B8E, 0x0B90}, {0x0B92, 0x0B95}, + {0x0B99, 0x0B9A}, {0x0B9C, 0x0B9C}, {0x0B9E, 0x0B9F}, + {0x0BA3, 0x0BA4}, {0x0BA8, 0x0BAA}, {0x0BAE, 0x0BB9}, + {0x0BBE, 0x0BBF}, {0x0BC0, 0x0BC0}, {0x0BC1, 0x0BC2}, + {0x0BC6, 0x0BC8}, {0x0BCA, 0x0BCC}, {0x0BCD, 0x0BCD}, + {0x0BD0, 0x0BD0}, {0x0BD7, 0x0BD7}, {0x0BE6, 0x0BEF}, + {0x0BF0, 0x0BF2}, {0x0BF3, 0x0BF8}, {0x0BF9, 0x0BF9}, + {0x0BFA, 0x0BFA}, {0x0C00, 0x0C00}, {0x0C01, 0x0C03}, + {0x0C05, 0x0C0C}, {0x0C0E, 0x0C10}, {0x0C12, 0x0C28}, + {0x0C2A, 0x0C39}, {0x0C3D, 0x0C3D}, {0x0C3E, 0x0C40}, + {0x0C41, 0x0C44}, {0x0C46, 0x0C48}, {0x0C4A, 0x0C4D}, + {0x0C55, 0x0C56}, {0x0C58, 0x0C5A}, {0x0C60, 0x0C61}, + {0x0C62, 0x0C63}, {0x0C66, 0x0C6F}, {0x0C78, 0x0C7E}, + {0x0C7F, 0x0C7F}, {0x0C80, 0x0C80}, {0x0C81, 0x0C81}, + {0x0C82, 0x0C83}, {0x0C85, 0x0C8C}, {0x0C8E, 0x0C90}, + {0x0C92, 0x0CA8}, {0x0CAA, 0x0CB3}, {0x0CB5, 0x0CB9}, + {0x0CBC, 0x0CBC}, {0x0CBD, 0x0CBD}, {0x0CBE, 0x0CBE}, + {0x0CBF, 0x0CBF}, {0x0CC0, 0x0CC4}, {0x0CC6, 0x0CC6}, + {0x0CC7, 0x0CC8}, {0x0CCA, 0x0CCB}, {0x0CCC, 0x0CCD}, + {0x0CD5, 0x0CD6}, {0x0CDE, 0x0CDE}, {0x0CE0, 0x0CE1}, + {0x0CE2, 0x0CE3}, {0x0CE6, 0x0CEF}, {0x0CF1, 0x0CF2}, + {0x0D01, 0x0D01}, {0x0D02, 0x0D03}, {0x0D05, 0x0D0C}, + {0x0D0E, 0x0D10}, {0x0D12, 0x0D3A}, {0x0D3D, 0x0D3D}, + {0x0D3E, 0x0D40}, {0x0D41, 0x0D44}, {0x0D46, 0x0D48}, + {0x0D4A, 0x0D4C}, {0x0D4D, 0x0D4D}, {0x0D4E, 0x0D4E}, + {0x0D4F, 0x0D4F}, {0x0D54, 0x0D56}, {0x0D57, 0x0D57}, + {0x0D58, 0x0D5E}, {0x0D5F, 0x0D61}, {0x0D62, 0x0D63}, + {0x0D66, 0x0D6F}, {0x0D70, 0x0D78}, {0x0D79, 0x0D79}, + {0x0D7A, 0x0D7F}, {0x0D82, 0x0D83}, {0x0D85, 0x0D96}, + {0x0D9A, 0x0DB1}, {0x0DB3, 0x0DBB}, {0x0DBD, 0x0DBD}, + {0x0DC0, 0x0DC6}, {0x0DCA, 0x0DCA}, {0x0DCF, 0x0DD1}, + {0x0DD2, 0x0DD4}, {0x0DD6, 0x0DD6}, {0x0DD8, 0x0DDF}, + {0x0DE6, 0x0DEF}, {0x0DF2, 0x0DF3}, {0x0DF4, 0x0DF4}, + {0x0E01, 0x0E30}, {0x0E31, 0x0E31}, {0x0E32, 0x0E33}, + {0x0E34, 0x0E3A}, {0x0E3F, 0x0E3F}, {0x0E40, 0x0E45}, + {0x0E46, 0x0E46}, {0x0E47, 0x0E4E}, {0x0E4F, 0x0E4F}, + {0x0E50, 0x0E59}, {0x0E5A, 0x0E5B}, {0x0E81, 0x0E82}, + {0x0E84, 0x0E84}, {0x0E87, 0x0E88}, {0x0E8A, 0x0E8A}, + {0x0E8D, 0x0E8D}, {0x0E94, 0x0E97}, {0x0E99, 0x0E9F}, + {0x0EA1, 0x0EA3}, {0x0EA5, 0x0EA5}, {0x0EA7, 0x0EA7}, + {0x0EAA, 0x0EAB}, {0x0EAD, 0x0EB0}, {0x0EB1, 0x0EB1}, + {0x0EB2, 0x0EB3}, {0x0EB4, 0x0EB9}, {0x0EBB, 0x0EBC}, + {0x0EBD, 0x0EBD}, {0x0EC0, 0x0EC4}, {0x0EC6, 0x0EC6}, + {0x0EC8, 0x0ECD}, {0x0ED0, 0x0ED9}, {0x0EDC, 0x0EDF}, + {0x0F00, 0x0F00}, {0x0F01, 0x0F03}, {0x0F04, 0x0F12}, + {0x0F13, 0x0F13}, {0x0F14, 0x0F14}, {0x0F15, 0x0F17}, + {0x0F18, 0x0F19}, {0x0F1A, 0x0F1F}, {0x0F20, 0x0F29}, + {0x0F2A, 0x0F33}, {0x0F34, 0x0F34}, {0x0F35, 0x0F35}, + {0x0F36, 0x0F36}, {0x0F37, 0x0F37}, {0x0F38, 0x0F38}, + {0x0F39, 0x0F39}, {0x0F3A, 0x0F3A}, {0x0F3B, 0x0F3B}, + {0x0F3C, 0x0F3C}, {0x0F3D, 0x0F3D}, {0x0F3E, 0x0F3F}, + {0x0F40, 0x0F47}, {0x0F49, 0x0F6C}, {0x0F71, 0x0F7E}, + {0x0F7F, 0x0F7F}, {0x0F80, 0x0F84}, {0x0F85, 0x0F85}, + {0x0F86, 0x0F87}, {0x0F88, 0x0F8C}, {0x0F8D, 0x0F97}, + {0x0F99, 0x0FBC}, {0x0FBE, 0x0FC5}, {0x0FC6, 0x0FC6}, + {0x0FC7, 0x0FCC}, {0x0FCE, 0x0FCF}, {0x0FD0, 0x0FD4}, + {0x0FD5, 0x0FD8}, {0x0FD9, 0x0FDA}, {0x1000, 0x102A}, + {0x102B, 0x102C}, {0x102D, 0x1030}, {0x1031, 0x1031}, + {0x1032, 0x1037}, {0x1038, 0x1038}, {0x1039, 0x103A}, + {0x103B, 0x103C}, {0x103D, 0x103E}, {0x103F, 0x103F}, + {0x1040, 0x1049}, {0x104A, 0x104F}, {0x1050, 0x1055}, + {0x1056, 0x1057}, {0x1058, 0x1059}, {0x105A, 0x105D}, + {0x105E, 0x1060}, {0x1061, 0x1061}, {0x1062, 0x1064}, + {0x1065, 0x1066}, {0x1067, 0x106D}, {0x106E, 0x1070}, + {0x1071, 0x1074}, {0x1075, 0x1081}, {0x1082, 0x1082}, + {0x1083, 0x1084}, {0x1085, 0x1086}, {0x1087, 0x108C}, + {0x108D, 0x108D}, {0x108E, 0x108E}, {0x108F, 0x108F}, + {0x1090, 0x1099}, {0x109A, 0x109C}, {0x109D, 0x109D}, + {0x109E, 0x109F}, {0x10A0, 0x10C5}, {0x10C7, 0x10C7}, + {0x10CD, 0x10CD}, {0x10D0, 0x10FA}, {0x10FB, 0x10FB}, + {0x10FC, 0x10FC}, {0x10FD, 0x10FF}, {0x1160, 0x11FF}, + {0x1200, 0x1248}, {0x124A, 0x124D}, {0x1250, 0x1256}, + {0x1258, 0x1258}, {0x125A, 0x125D}, {0x1260, 0x1288}, + {0x128A, 0x128D}, {0x1290, 0x12B0}, {0x12B2, 0x12B5}, + {0x12B8, 0x12BE}, {0x12C0, 0x12C0}, {0x12C2, 0x12C5}, + {0x12C8, 0x12D6}, {0x12D8, 0x1310}, {0x1312, 0x1315}, + {0x1318, 0x135A}, {0x135D, 0x135F}, {0x1360, 0x1368}, + {0x1369, 0x137C}, {0x1380, 0x138F}, {0x1390, 0x1399}, + {0x13A0, 0x13F5}, {0x13F8, 0x13FD}, {0x1400, 0x1400}, + {0x1401, 0x166C}, {0x166D, 0x166E}, {0x166F, 0x167F}, + {0x1680, 0x1680}, {0x1681, 0x169A}, {0x169B, 0x169B}, + {0x169C, 0x169C}, {0x16A0, 0x16EA}, {0x16EB, 0x16ED}, + {0x16EE, 0x16F0}, {0x16F1, 0x16F8}, {0x1700, 0x170C}, + {0x170E, 0x1711}, {0x1712, 0x1714}, {0x1720, 0x1731}, + {0x1732, 0x1734}, {0x1735, 0x1736}, {0x1740, 0x1751}, + {0x1752, 0x1753}, {0x1760, 0x176C}, {0x176E, 0x1770}, + {0x1772, 0x1773}, {0x1780, 0x17B3}, {0x17B4, 0x17B5}, + {0x17B6, 0x17B6}, {0x17B7, 0x17BD}, {0x17BE, 0x17C5}, + {0x17C6, 0x17C6}, {0x17C7, 0x17C8}, {0x17C9, 0x17D3}, + {0x17D4, 0x17D6}, {0x17D7, 0x17D7}, {0x17D8, 0x17DA}, + {0x17DB, 0x17DB}, {0x17DC, 0x17DC}, {0x17DD, 0x17DD}, + {0x17E0, 0x17E9}, {0x17F0, 0x17F9}, {0x1800, 0x1805}, + {0x1806, 0x1806}, {0x1807, 0x180A}, {0x180B, 0x180D}, + {0x180E, 0x180E}, {0x1810, 0x1819}, {0x1820, 0x1842}, + {0x1843, 0x1843}, {0x1844, 0x1877}, {0x1880, 0x1884}, + {0x1885, 0x1886}, {0x1887, 0x18A8}, {0x18A9, 0x18A9}, + {0x18AA, 0x18AA}, {0x18B0, 0x18F5}, {0x1900, 0x191E}, + {0x1920, 0x1922}, {0x1923, 0x1926}, {0x1927, 0x1928}, + {0x1929, 0x192B}, {0x1930, 0x1931}, {0x1932, 0x1932}, + {0x1933, 0x1938}, {0x1939, 0x193B}, {0x1940, 0x1940}, + {0x1944, 0x1945}, {0x1946, 0x194F}, {0x1950, 0x196D}, + {0x1970, 0x1974}, {0x1980, 0x19AB}, {0x19B0, 0x19C9}, + {0x19D0, 0x19D9}, {0x19DA, 0x19DA}, {0x19DE, 0x19DF}, + {0x19E0, 0x19FF}, {0x1A00, 0x1A16}, {0x1A17, 0x1A18}, + {0x1A19, 0x1A1A}, {0x1A1B, 0x1A1B}, {0x1A1E, 0x1A1F}, + {0x1A20, 0x1A54}, {0x1A55, 0x1A55}, {0x1A56, 0x1A56}, + {0x1A57, 0x1A57}, {0x1A58, 0x1A5E}, {0x1A60, 0x1A60}, + {0x1A61, 0x1A61}, {0x1A62, 0x1A62}, {0x1A63, 0x1A64}, + {0x1A65, 0x1A6C}, {0x1A6D, 0x1A72}, {0x1A73, 0x1A7C}, + {0x1A7F, 0x1A7F}, {0x1A80, 0x1A89}, {0x1A90, 0x1A99}, + {0x1AA0, 0x1AA6}, {0x1AA7, 0x1AA7}, {0x1AA8, 0x1AAD}, + {0x1AB0, 0x1ABD}, {0x1ABE, 0x1ABE}, {0x1B00, 0x1B03}, + {0x1B04, 0x1B04}, {0x1B05, 0x1B33}, {0x1B34, 0x1B34}, + {0x1B35, 0x1B35}, {0x1B36, 0x1B3A}, {0x1B3B, 0x1B3B}, + {0x1B3C, 0x1B3C}, {0x1B3D, 0x1B41}, {0x1B42, 0x1B42}, + {0x1B43, 0x1B44}, {0x1B45, 0x1B4B}, {0x1B50, 0x1B59}, + {0x1B5A, 0x1B60}, {0x1B61, 0x1B6A}, {0x1B6B, 0x1B73}, + {0x1B74, 0x1B7C}, {0x1B80, 0x1B81}, {0x1B82, 0x1B82}, + {0x1B83, 0x1BA0}, {0x1BA1, 0x1BA1}, {0x1BA2, 0x1BA5}, + {0x1BA6, 0x1BA7}, {0x1BA8, 0x1BA9}, {0x1BAA, 0x1BAA}, + {0x1BAB, 0x1BAD}, {0x1BAE, 0x1BAF}, {0x1BB0, 0x1BB9}, + {0x1BBA, 0x1BBF}, {0x1BC0, 0x1BE5}, {0x1BE6, 0x1BE6}, + {0x1BE7, 0x1BE7}, {0x1BE8, 0x1BE9}, {0x1BEA, 0x1BEC}, + {0x1BED, 0x1BED}, {0x1BEE, 0x1BEE}, {0x1BEF, 0x1BF1}, + {0x1BF2, 0x1BF3}, {0x1BFC, 0x1BFF}, {0x1C00, 0x1C23}, + {0x1C24, 0x1C2B}, {0x1C2C, 0x1C33}, {0x1C34, 0x1C35}, + {0x1C36, 0x1C37}, {0x1C3B, 0x1C3F}, {0x1C40, 0x1C49}, + {0x1C4D, 0x1C4F}, {0x1C50, 0x1C59}, {0x1C5A, 0x1C77}, + {0x1C78, 0x1C7D}, {0x1C7E, 0x1C7F}, {0x1C80, 0x1C88}, + {0x1CC0, 0x1CC7}, {0x1CD0, 0x1CD2}, {0x1CD3, 0x1CD3}, + {0x1CD4, 0x1CE0}, {0x1CE1, 0x1CE1}, {0x1CE2, 0x1CE8}, + {0x1CE9, 0x1CEC}, {0x1CED, 0x1CED}, {0x1CEE, 0x1CF1}, + {0x1CF2, 0x1CF3}, {0x1CF4, 0x1CF4}, {0x1CF5, 0x1CF6}, + {0x1CF8, 0x1CF9}, {0x1D00, 0x1D2B}, {0x1D2C, 0x1D6A}, + {0x1D6B, 0x1D77}, {0x1D78, 0x1D78}, {0x1D79, 0x1D7F}, + {0x1D80, 0x1D9A}, {0x1D9B, 0x1DBF}, {0x1DC0, 0x1DF5}, + {0x1DFB, 0x1DFF}, {0x1E00, 0x1EFF}, {0x1F00, 0x1F15}, + {0x1F18, 0x1F1D}, {0x1F20, 0x1F45}, {0x1F48, 0x1F4D}, + {0x1F50, 0x1F57}, {0x1F59, 0x1F59}, {0x1F5B, 0x1F5B}, + {0x1F5D, 0x1F5D}, {0x1F5F, 0x1F7D}, {0x1F80, 0x1FB4}, + {0x1FB6, 0x1FBC}, {0x1FBD, 0x1FBD}, {0x1FBE, 0x1FBE}, + {0x1FBF, 0x1FC1}, {0x1FC2, 0x1FC4}, {0x1FC6, 0x1FCC}, + {0x1FCD, 0x1FCF}, {0x1FD0, 0x1FD3}, {0x1FD6, 0x1FDB}, + {0x1FDD, 0x1FDF}, {0x1FE0, 0x1FEC}, {0x1FED, 0x1FEF}, + {0x1FF2, 0x1FF4}, {0x1FF6, 0x1FFC}, {0x1FFD, 0x1FFE}, + {0x2000, 0x200A}, {0x200B, 0x200F}, {0x2011, 0x2012}, + {0x2017, 0x2017}, {0x201A, 0x201A}, {0x201B, 0x201B}, + {0x201E, 0x201E}, {0x201F, 0x201F}, {0x2023, 0x2023}, + {0x2028, 0x2028}, {0x2029, 0x2029}, {0x202A, 0x202E}, + {0x202F, 0x202F}, {0x2031, 0x2031}, {0x2034, 0x2034}, + {0x2036, 0x2038}, {0x2039, 0x2039}, {0x203A, 0x203A}, + {0x203C, 0x203D}, {0x203F, 0x2040}, {0x2041, 0x2043}, + {0x2044, 0x2044}, {0x2045, 0x2045}, {0x2046, 0x2046}, + {0x2047, 0x2051}, {0x2052, 0x2052}, {0x2053, 0x2053}, + {0x2054, 0x2054}, {0x2055, 0x205E}, {0x205F, 0x205F}, + {0x2060, 0x2064}, {0x2066, 0x206F}, {0x2070, 0x2070}, + {0x2071, 0x2071}, {0x2075, 0x2079}, {0x207A, 0x207C}, + {0x207D, 0x207D}, {0x207E, 0x207E}, {0x2080, 0x2080}, + {0x2085, 0x2089}, {0x208A, 0x208C}, {0x208D, 0x208D}, + {0x208E, 0x208E}, {0x2090, 0x209C}, {0x20A0, 0x20A8}, + {0x20AA, 0x20AB}, {0x20AD, 0x20BE}, {0x20D0, 0x20DC}, + {0x20DD, 0x20E0}, {0x20E1, 0x20E1}, {0x20E2, 0x20E4}, + {0x20E5, 0x20F0}, {0x2100, 0x2101}, {0x2102, 0x2102}, + {0x2104, 0x2104}, {0x2106, 0x2106}, {0x2107, 0x2107}, + {0x2108, 0x2108}, {0x210A, 0x2112}, {0x2114, 0x2114}, + {0x2115, 0x2115}, {0x2117, 0x2117}, {0x2118, 0x2118}, + {0x2119, 0x211D}, {0x211E, 0x2120}, {0x2123, 0x2123}, + {0x2124, 0x2124}, {0x2125, 0x2125}, {0x2127, 0x2127}, + {0x2128, 0x2128}, {0x2129, 0x2129}, {0x212A, 0x212A}, + {0x212C, 0x212D}, {0x212E, 0x212E}, {0x212F, 0x2134}, + {0x2135, 0x2138}, {0x2139, 0x2139}, {0x213A, 0x213B}, + {0x213C, 0x213F}, {0x2140, 0x2144}, {0x2145, 0x2149}, + {0x214A, 0x214A}, {0x214B, 0x214B}, {0x214C, 0x214D}, + {0x214E, 0x214E}, {0x214F, 0x214F}, {0x2150, 0x2152}, + {0x2155, 0x215A}, {0x215F, 0x215F}, {0x216C, 0x216F}, + {0x217A, 0x2182}, {0x2183, 0x2184}, {0x2185, 0x2188}, + {0x218A, 0x218B}, {0x219A, 0x219B}, {0x219C, 0x219F}, + {0x21A0, 0x21A0}, {0x21A1, 0x21A2}, {0x21A3, 0x21A3}, + {0x21A4, 0x21A5}, {0x21A6, 0x21A6}, {0x21A7, 0x21AD}, + {0x21AE, 0x21AE}, {0x21AF, 0x21B7}, {0x21BA, 0x21CD}, + {0x21CE, 0x21CF}, {0x21D0, 0x21D1}, {0x21D3, 0x21D3}, + {0x21D5, 0x21E6}, {0x21E8, 0x21F3}, {0x21F4, 0x21FF}, + {0x2201, 0x2201}, {0x2204, 0x2206}, {0x2209, 0x220A}, + {0x220C, 0x220E}, {0x2210, 0x2210}, {0x2212, 0x2214}, + {0x2216, 0x2219}, {0x221B, 0x221C}, {0x2221, 0x2222}, + {0x2224, 0x2224}, {0x2226, 0x2226}, {0x222D, 0x222D}, + {0x222F, 0x2233}, {0x2238, 0x223B}, {0x223E, 0x2247}, + {0x2249, 0x224B}, {0x224D, 0x2251}, {0x2253, 0x225F}, + {0x2262, 0x2263}, {0x2268, 0x2269}, {0x226C, 0x226D}, + {0x2270, 0x2281}, {0x2284, 0x2285}, {0x2288, 0x2294}, + {0x2296, 0x2298}, {0x229A, 0x22A4}, {0x22A6, 0x22BE}, + {0x22C0, 0x22FF}, {0x2300, 0x2307}, {0x2308, 0x2308}, + {0x2309, 0x2309}, {0x230A, 0x230A}, {0x230B, 0x230B}, + {0x230C, 0x2311}, {0x2313, 0x2319}, {0x231C, 0x231F}, + {0x2320, 0x2321}, {0x2322, 0x2328}, {0x232B, 0x237B}, + {0x237C, 0x237C}, {0x237D, 0x239A}, {0x239B, 0x23B3}, + {0x23B4, 0x23DB}, {0x23DC, 0x23E1}, {0x23E2, 0x23E8}, + {0x23ED, 0x23EF}, {0x23F1, 0x23F2}, {0x23F4, 0x23FE}, + {0x2400, 0x2426}, {0x2440, 0x244A}, {0x24EA, 0x24EA}, + {0x254C, 0x254F}, {0x2574, 0x257F}, {0x2590, 0x2591}, + {0x2596, 0x259F}, {0x25A2, 0x25A2}, {0x25AA, 0x25B1}, + {0x25B4, 0x25B5}, {0x25B8, 0x25BB}, {0x25BE, 0x25BF}, + {0x25C2, 0x25C5}, {0x25C9, 0x25CA}, {0x25CC, 0x25CD}, + {0x25D2, 0x25E1}, {0x25E6, 0x25EE}, {0x25F0, 0x25F7}, + {0x25F8, 0x25FC}, {0x25FF, 0x25FF}, {0x2600, 0x2604}, + {0x2607, 0x2608}, {0x260A, 0x260D}, {0x2610, 0x2613}, + {0x2616, 0x261B}, {0x261D, 0x261D}, {0x261F, 0x263F}, + {0x2641, 0x2641}, {0x2643, 0x2647}, {0x2654, 0x265F}, + {0x2662, 0x2662}, {0x2666, 0x2666}, {0x266B, 0x266B}, + {0x266E, 0x266E}, {0x2670, 0x267E}, {0x2680, 0x2692}, + {0x2694, 0x269D}, {0x26A0, 0x26A0}, {0x26A2, 0x26A9}, + {0x26AC, 0x26BC}, {0x26C0, 0x26C3}, {0x26E2, 0x26E2}, + {0x26E4, 0x26E7}, {0x2700, 0x2704}, {0x2706, 0x2709}, + {0x270C, 0x2727}, {0x2729, 0x273C}, {0x273E, 0x274B}, + {0x274D, 0x274D}, {0x274F, 0x2752}, {0x2756, 0x2756}, + {0x2758, 0x2767}, {0x2768, 0x2768}, {0x2769, 0x2769}, + {0x276A, 0x276A}, {0x276B, 0x276B}, {0x276C, 0x276C}, + {0x276D, 0x276D}, {0x276E, 0x276E}, {0x276F, 0x276F}, + {0x2770, 0x2770}, {0x2771, 0x2771}, {0x2772, 0x2772}, + {0x2773, 0x2773}, {0x2774, 0x2774}, {0x2775, 0x2775}, + {0x2780, 0x2793}, {0x2794, 0x2794}, {0x2798, 0x27AF}, + {0x27B1, 0x27BE}, {0x27C0, 0x27C4}, {0x27C5, 0x27C5}, + {0x27C6, 0x27C6}, {0x27C7, 0x27E5}, {0x27EE, 0x27EE}, + {0x27EF, 0x27EF}, {0x27F0, 0x27FF}, {0x2800, 0x28FF}, + {0x2900, 0x297F}, {0x2980, 0x2982}, {0x2983, 0x2983}, + {0x2984, 0x2984}, {0x2987, 0x2987}, {0x2988, 0x2988}, + {0x2989, 0x2989}, {0x298A, 0x298A}, {0x298B, 0x298B}, + {0x298C, 0x298C}, {0x298D, 0x298D}, {0x298E, 0x298E}, + {0x298F, 0x298F}, {0x2990, 0x2990}, {0x2991, 0x2991}, + {0x2992, 0x2992}, {0x2993, 0x2993}, {0x2994, 0x2994}, + {0x2995, 0x2995}, {0x2996, 0x2996}, {0x2997, 0x2997}, + {0x2998, 0x2998}, {0x2999, 0x29D7}, {0x29D8, 0x29D8}, + {0x29D9, 0x29D9}, {0x29DA, 0x29DA}, {0x29DB, 0x29DB}, + {0x29DC, 0x29FB}, {0x29FC, 0x29FC}, {0x29FD, 0x29FD}, + {0x29FE, 0x29FF}, {0x2A00, 0x2AFF}, {0x2B00, 0x2B1A}, + {0x2B1D, 0x2B2F}, {0x2B30, 0x2B44}, {0x2B45, 0x2B46}, + {0x2B47, 0x2B4C}, {0x2B4D, 0x2B4F}, {0x2B51, 0x2B54}, + {0x2B5A, 0x2B73}, {0x2B76, 0x2B95}, {0x2B98, 0x2BB9}, + {0x2BBD, 0x2BC8}, {0x2BCA, 0x2BD1}, {0x2BEC, 0x2BEF}, + {0x2C00, 0x2C2E}, {0x2C30, 0x2C5E}, {0x2C60, 0x2C7B}, + {0x2C7C, 0x2C7D}, {0x2C7E, 0x2C7F}, {0x2C80, 0x2CE4}, + {0x2CE5, 0x2CEA}, {0x2CEB, 0x2CEE}, {0x2CEF, 0x2CF1}, + {0x2CF2, 0x2CF3}, {0x2CF9, 0x2CFC}, {0x2CFD, 0x2CFD}, + {0x2CFE, 0x2CFF}, {0x2D00, 0x2D25}, {0x2D27, 0x2D27}, + {0x2D2D, 0x2D2D}, {0x2D30, 0x2D67}, {0x2D6F, 0x2D6F}, + {0x2D70, 0x2D70}, {0x2D7F, 0x2D7F}, {0x2D80, 0x2D96}, + {0x2DA0, 0x2DA6}, {0x2DA8, 0x2DAE}, {0x2DB0, 0x2DB6}, + {0x2DB8, 0x2DBE}, {0x2DC0, 0x2DC6}, {0x2DC8, 0x2DCE}, + {0x2DD0, 0x2DD6}, {0x2DD8, 0x2DDE}, {0x2DE0, 0x2DFF}, + {0x2E00, 0x2E01}, {0x2E02, 0x2E02}, {0x2E03, 0x2E03}, + {0x2E04, 0x2E04}, {0x2E05, 0x2E05}, {0x2E06, 0x2E08}, + {0x2E09, 0x2E09}, {0x2E0A, 0x2E0A}, {0x2E0B, 0x2E0B}, + {0x2E0C, 0x2E0C}, {0x2E0D, 0x2E0D}, {0x2E0E, 0x2E16}, + {0x2E17, 0x2E17}, {0x2E18, 0x2E19}, {0x2E1A, 0x2E1A}, + {0x2E1B, 0x2E1B}, {0x2E1C, 0x2E1C}, {0x2E1D, 0x2E1D}, + {0x2E1E, 0x2E1F}, {0x2E20, 0x2E20}, {0x2E21, 0x2E21}, + {0x2E22, 0x2E22}, {0x2E23, 0x2E23}, {0x2E24, 0x2E24}, + {0x2E25, 0x2E25}, {0x2E26, 0x2E26}, {0x2E27, 0x2E27}, + {0x2E28, 0x2E28}, {0x2E29, 0x2E29}, {0x2E2A, 0x2E2E}, + {0x2E2F, 0x2E2F}, {0x2E30, 0x2E39}, {0x2E3A, 0x2E3B}, + {0x2E3C, 0x2E3F}, {0x2E40, 0x2E40}, {0x2E41, 0x2E41}, + {0x2E42, 0x2E42}, {0x2E43, 0x2E44}, {0x303F, 0x303F}, + {0x4DC0, 0x4DFF}, {0xA4D0, 0xA4F7}, {0xA4F8, 0xA4FD}, + {0xA4FE, 0xA4FF}, {0xA500, 0xA60B}, {0xA60C, 0xA60C}, + {0xA60D, 0xA60F}, {0xA610, 0xA61F}, {0xA620, 0xA629}, + {0xA62A, 0xA62B}, {0xA640, 0xA66D}, {0xA66E, 0xA66E}, + {0xA66F, 0xA66F}, {0xA670, 0xA672}, {0xA673, 0xA673}, + {0xA674, 0xA67D}, {0xA67E, 0xA67E}, {0xA67F, 0xA67F}, + {0xA680, 0xA69B}, {0xA69C, 0xA69D}, {0xA69E, 0xA69F}, + {0xA6A0, 0xA6E5}, {0xA6E6, 0xA6EF}, {0xA6F0, 0xA6F1}, + {0xA6F2, 0xA6F7}, {0xA700, 0xA716}, {0xA717, 0xA71F}, + {0xA720, 0xA721}, {0xA722, 0xA76F}, {0xA770, 0xA770}, + {0xA771, 0xA787}, {0xA788, 0xA788}, {0xA789, 0xA78A}, + {0xA78B, 0xA78E}, {0xA78F, 0xA78F}, {0xA790, 0xA7AE}, + {0xA7B0, 0xA7B7}, {0xA7F7, 0xA7F7}, {0xA7F8, 0xA7F9}, + {0xA7FA, 0xA7FA}, {0xA7FB, 0xA7FF}, {0xA800, 0xA801}, + {0xA802, 0xA802}, {0xA803, 0xA805}, {0xA806, 0xA806}, + {0xA807, 0xA80A}, {0xA80B, 0xA80B}, {0xA80C, 0xA822}, + {0xA823, 0xA824}, {0xA825, 0xA826}, {0xA827, 0xA827}, + {0xA828, 0xA82B}, {0xA830, 0xA835}, {0xA836, 0xA837}, + {0xA838, 0xA838}, {0xA839, 0xA839}, {0xA840, 0xA873}, + {0xA874, 0xA877}, {0xA880, 0xA881}, {0xA882, 0xA8B3}, + {0xA8B4, 0xA8C3}, {0xA8C4, 0xA8C5}, {0xA8CE, 0xA8CF}, + {0xA8D0, 0xA8D9}, {0xA8E0, 0xA8F1}, {0xA8F2, 0xA8F7}, + {0xA8F8, 0xA8FA}, {0xA8FB, 0xA8FB}, {0xA8FC, 0xA8FC}, + {0xA8FD, 0xA8FD}, {0xA900, 0xA909}, {0xA90A, 0xA925}, + {0xA926, 0xA92D}, {0xA92E, 0xA92F}, {0xA930, 0xA946}, + {0xA947, 0xA951}, {0xA952, 0xA953}, {0xA95F, 0xA95F}, + {0xA980, 0xA982}, {0xA983, 0xA983}, {0xA984, 0xA9B2}, + {0xA9B3, 0xA9B3}, {0xA9B4, 0xA9B5}, {0xA9B6, 0xA9B9}, + {0xA9BA, 0xA9BB}, {0xA9BC, 0xA9BC}, {0xA9BD, 0xA9C0}, + {0xA9C1, 0xA9CD}, {0xA9CF, 0xA9CF}, {0xA9D0, 0xA9D9}, + {0xA9DE, 0xA9DF}, {0xA9E0, 0xA9E4}, {0xA9E5, 0xA9E5}, + {0xA9E6, 0xA9E6}, {0xA9E7, 0xA9EF}, {0xA9F0, 0xA9F9}, + {0xA9FA, 0xA9FE}, {0xAA00, 0xAA28}, {0xAA29, 0xAA2E}, + {0xAA2F, 0xAA30}, {0xAA31, 0xAA32}, {0xAA33, 0xAA34}, + {0xAA35, 0xAA36}, {0xAA40, 0xAA42}, {0xAA43, 0xAA43}, + {0xAA44, 0xAA4B}, {0xAA4C, 0xAA4C}, {0xAA4D, 0xAA4D}, + {0xAA50, 0xAA59}, {0xAA5C, 0xAA5F}, {0xAA60, 0xAA6F}, + {0xAA70, 0xAA70}, {0xAA71, 0xAA76}, {0xAA77, 0xAA79}, + {0xAA7A, 0xAA7A}, {0xAA7B, 0xAA7B}, {0xAA7C, 0xAA7C}, + {0xAA7D, 0xAA7D}, {0xAA7E, 0xAA7F}, {0xAA80, 0xAAAF}, + {0xAAB0, 0xAAB0}, {0xAAB1, 0xAAB1}, {0xAAB2, 0xAAB4}, + {0xAAB5, 0xAAB6}, {0xAAB7, 0xAAB8}, {0xAAB9, 0xAABD}, + {0xAABE, 0xAABF}, {0xAAC0, 0xAAC0}, {0xAAC1, 0xAAC1}, + {0xAAC2, 0xAAC2}, {0xAADB, 0xAADC}, {0xAADD, 0xAADD}, + {0xAADE, 0xAADF}, {0xAAE0, 0xAAEA}, {0xAAEB, 0xAAEB}, + {0xAAEC, 0xAAED}, {0xAAEE, 0xAAEF}, {0xAAF0, 0xAAF1}, + {0xAAF2, 0xAAF2}, {0xAAF3, 0xAAF4}, {0xAAF5, 0xAAF5}, + {0xAAF6, 0xAAF6}, {0xAB01, 0xAB06}, {0xAB09, 0xAB0E}, + {0xAB11, 0xAB16}, {0xAB20, 0xAB26}, {0xAB28, 0xAB2E}, + {0xAB30, 0xAB5A}, {0xAB5B, 0xAB5B}, {0xAB5C, 0xAB5F}, + {0xAB60, 0xAB65}, {0xAB70, 0xABBF}, {0xABC0, 0xABE2}, + {0xABE3, 0xABE4}, {0xABE5, 0xABE5}, {0xABE6, 0xABE7}, + {0xABE8, 0xABE8}, {0xABE9, 0xABEA}, {0xABEB, 0xABEB}, + {0xABEC, 0xABEC}, {0xABED, 0xABED}, {0xABF0, 0xABF9}, + {0xD7B0, 0xD7C6}, {0xD7CB, 0xD7FB}, {0xD800, 0xDB7F}, + {0xDB80, 0xDBFF}, {0xDC00, 0xDFFF}, {0xFB00, 0xFB06}, + {0xFB13, 0xFB17}, {0xFB1D, 0xFB1D}, {0xFB1E, 0xFB1E}, + {0xFB1F, 0xFB28}, {0xFB29, 0xFB29}, {0xFB2A, 0xFB36}, + {0xFB38, 0xFB3C}, {0xFB3E, 0xFB3E}, {0xFB40, 0xFB41}, + {0xFB43, 0xFB44}, {0xFB46, 0xFB4F}, {0xFB50, 0xFBB1}, + {0xFBB2, 0xFBC1}, {0xFBD3, 0xFD3D}, {0xFD3E, 0xFD3E}, + {0xFD3F, 0xFD3F}, {0xFD50, 0xFD8F}, {0xFD92, 0xFDC7}, + {0xFDF0, 0xFDFB}, {0xFDFC, 0xFDFC}, {0xFDFD, 0xFDFD}, + {0xFE20, 0xFE2F}, {0xFE70, 0xFE74}, {0xFE76, 0xFEFC}, + {0xFEFF, 0xFEFF}, {0xFFF9, 0xFFFB}, {0xFFFC, 0xFFFC}, + {0x10000, 0x1000B}, {0x1000D, 0x10026}, {0x10028, 0x1003A}, + {0x1003C, 0x1003D}, {0x1003F, 0x1004D}, {0x10050, 0x1005D}, + {0x10080, 0x100FA}, {0x10100, 0x10102}, {0x10107, 0x10133}, + {0x10137, 0x1013F}, {0x10140, 0x10174}, {0x10175, 0x10178}, + {0x10179, 0x10189}, {0x1018A, 0x1018B}, {0x1018C, 0x1018E}, + {0x10190, 0x1019B}, {0x101A0, 0x101A0}, {0x101D0, 0x101FC}, + {0x101FD, 0x101FD}, {0x10280, 0x1029C}, {0x102A0, 0x102D0}, + {0x102E0, 0x102E0}, {0x102E1, 0x102FB}, {0x10300, 0x1031F}, + {0x10320, 0x10323}, {0x10330, 0x10340}, {0x10341, 0x10341}, + {0x10342, 0x10349}, {0x1034A, 0x1034A}, {0x10350, 0x10375}, + {0x10376, 0x1037A}, {0x10380, 0x1039D}, {0x1039F, 0x1039F}, + {0x103A0, 0x103C3}, {0x103C8, 0x103CF}, {0x103D0, 0x103D0}, + {0x103D1, 0x103D5}, {0x10400, 0x1044F}, {0x10450, 0x1047F}, + {0x10480, 0x1049D}, {0x104A0, 0x104A9}, {0x104B0, 0x104D3}, + {0x104D8, 0x104FB}, {0x10500, 0x10527}, {0x10530, 0x10563}, + {0x1056F, 0x1056F}, {0x10600, 0x10736}, {0x10740, 0x10755}, + {0x10760, 0x10767}, {0x10800, 0x10805}, {0x10808, 0x10808}, + {0x1080A, 0x10835}, {0x10837, 0x10838}, {0x1083C, 0x1083C}, + {0x1083F, 0x1083F}, {0x10840, 0x10855}, {0x10857, 0x10857}, + {0x10858, 0x1085F}, {0x10860, 0x10876}, {0x10877, 0x10878}, + {0x10879, 0x1087F}, {0x10880, 0x1089E}, {0x108A7, 0x108AF}, + {0x108E0, 0x108F2}, {0x108F4, 0x108F5}, {0x108FB, 0x108FF}, + {0x10900, 0x10915}, {0x10916, 0x1091B}, {0x1091F, 0x1091F}, + {0x10920, 0x10939}, {0x1093F, 0x1093F}, {0x10980, 0x1099F}, + {0x109A0, 0x109B7}, {0x109BC, 0x109BD}, {0x109BE, 0x109BF}, + {0x109C0, 0x109CF}, {0x109D2, 0x109FF}, {0x10A00, 0x10A00}, + {0x10A01, 0x10A03}, {0x10A05, 0x10A06}, {0x10A0C, 0x10A0F}, + {0x10A10, 0x10A13}, {0x10A15, 0x10A17}, {0x10A19, 0x10A33}, + {0x10A38, 0x10A3A}, {0x10A3F, 0x10A3F}, {0x10A40, 0x10A47}, + {0x10A50, 0x10A58}, {0x10A60, 0x10A7C}, {0x10A7D, 0x10A7E}, + {0x10A7F, 0x10A7F}, {0x10A80, 0x10A9C}, {0x10A9D, 0x10A9F}, + {0x10AC0, 0x10AC7}, {0x10AC8, 0x10AC8}, {0x10AC9, 0x10AE4}, + {0x10AE5, 0x10AE6}, {0x10AEB, 0x10AEF}, {0x10AF0, 0x10AF6}, + {0x10B00, 0x10B35}, {0x10B39, 0x10B3F}, {0x10B40, 0x10B55}, + {0x10B58, 0x10B5F}, {0x10B60, 0x10B72}, {0x10B78, 0x10B7F}, + {0x10B80, 0x10B91}, {0x10B99, 0x10B9C}, {0x10BA9, 0x10BAF}, + {0x10C00, 0x10C48}, {0x10C80, 0x10CB2}, {0x10CC0, 0x10CF2}, + {0x10CFA, 0x10CFF}, {0x10E60, 0x10E7E}, {0x11000, 0x11000}, + {0x11001, 0x11001}, {0x11002, 0x11002}, {0x11003, 0x11037}, + {0x11038, 0x11046}, {0x11047, 0x1104D}, {0x11052, 0x11065}, + {0x11066, 0x1106F}, {0x1107F, 0x1107F}, {0x11080, 0x11081}, + {0x11082, 0x11082}, {0x11083, 0x110AF}, {0x110B0, 0x110B2}, + {0x110B3, 0x110B6}, {0x110B7, 0x110B8}, {0x110B9, 0x110BA}, + {0x110BB, 0x110BC}, {0x110BD, 0x110BD}, {0x110BE, 0x110C1}, + {0x110D0, 0x110E8}, {0x110F0, 0x110F9}, {0x11100, 0x11102}, + {0x11103, 0x11126}, {0x11127, 0x1112B}, {0x1112C, 0x1112C}, + {0x1112D, 0x11134}, {0x11136, 0x1113F}, {0x11140, 0x11143}, + {0x11150, 0x11172}, {0x11173, 0x11173}, {0x11174, 0x11175}, + {0x11176, 0x11176}, {0x11180, 0x11181}, {0x11182, 0x11182}, + {0x11183, 0x111B2}, {0x111B3, 0x111B5}, {0x111B6, 0x111BE}, + {0x111BF, 0x111C0}, {0x111C1, 0x111C4}, {0x111C5, 0x111C9}, + {0x111CA, 0x111CC}, {0x111CD, 0x111CD}, {0x111D0, 0x111D9}, + {0x111DA, 0x111DA}, {0x111DB, 0x111DB}, {0x111DC, 0x111DC}, + {0x111DD, 0x111DF}, {0x111E1, 0x111F4}, {0x11200, 0x11211}, + {0x11213, 0x1122B}, {0x1122C, 0x1122E}, {0x1122F, 0x11231}, + {0x11232, 0x11233}, {0x11234, 0x11234}, {0x11235, 0x11235}, + {0x11236, 0x11237}, {0x11238, 0x1123D}, {0x1123E, 0x1123E}, + {0x11280, 0x11286}, {0x11288, 0x11288}, {0x1128A, 0x1128D}, + {0x1128F, 0x1129D}, {0x1129F, 0x112A8}, {0x112A9, 0x112A9}, + {0x112B0, 0x112DE}, {0x112DF, 0x112DF}, {0x112E0, 0x112E2}, + {0x112E3, 0x112EA}, {0x112F0, 0x112F9}, {0x11300, 0x11301}, + {0x11302, 0x11303}, {0x11305, 0x1130C}, {0x1130F, 0x11310}, + {0x11313, 0x11328}, {0x1132A, 0x11330}, {0x11332, 0x11333}, + {0x11335, 0x11339}, {0x1133C, 0x1133C}, {0x1133D, 0x1133D}, + {0x1133E, 0x1133F}, {0x11340, 0x11340}, {0x11341, 0x11344}, + {0x11347, 0x11348}, {0x1134B, 0x1134D}, {0x11350, 0x11350}, + {0x11357, 0x11357}, {0x1135D, 0x11361}, {0x11362, 0x11363}, + {0x11366, 0x1136C}, {0x11370, 0x11374}, {0x11400, 0x11434}, + {0x11435, 0x11437}, {0x11438, 0x1143F}, {0x11440, 0x11441}, + {0x11442, 0x11444}, {0x11445, 0x11445}, {0x11446, 0x11446}, + {0x11447, 0x1144A}, {0x1144B, 0x1144F}, {0x11450, 0x11459}, + {0x1145B, 0x1145B}, {0x1145D, 0x1145D}, {0x11480, 0x114AF}, + {0x114B0, 0x114B2}, {0x114B3, 0x114B8}, {0x114B9, 0x114B9}, + {0x114BA, 0x114BA}, {0x114BB, 0x114BE}, {0x114BF, 0x114C0}, + {0x114C1, 0x114C1}, {0x114C2, 0x114C3}, {0x114C4, 0x114C5}, + {0x114C6, 0x114C6}, {0x114C7, 0x114C7}, {0x114D0, 0x114D9}, + {0x11580, 0x115AE}, {0x115AF, 0x115B1}, {0x115B2, 0x115B5}, + {0x115B8, 0x115BB}, {0x115BC, 0x115BD}, {0x115BE, 0x115BE}, + {0x115BF, 0x115C0}, {0x115C1, 0x115D7}, {0x115D8, 0x115DB}, + {0x115DC, 0x115DD}, {0x11600, 0x1162F}, {0x11630, 0x11632}, + {0x11633, 0x1163A}, {0x1163B, 0x1163C}, {0x1163D, 0x1163D}, + {0x1163E, 0x1163E}, {0x1163F, 0x11640}, {0x11641, 0x11643}, + {0x11644, 0x11644}, {0x11650, 0x11659}, {0x11660, 0x1166C}, + {0x11680, 0x116AA}, {0x116AB, 0x116AB}, {0x116AC, 0x116AC}, + {0x116AD, 0x116AD}, {0x116AE, 0x116AF}, {0x116B0, 0x116B5}, + {0x116B6, 0x116B6}, {0x116B7, 0x116B7}, {0x116C0, 0x116C9}, + {0x11700, 0x11719}, {0x1171D, 0x1171F}, {0x11720, 0x11721}, + {0x11722, 0x11725}, {0x11726, 0x11726}, {0x11727, 0x1172B}, + {0x11730, 0x11739}, {0x1173A, 0x1173B}, {0x1173C, 0x1173E}, + {0x1173F, 0x1173F}, {0x118A0, 0x118DF}, {0x118E0, 0x118E9}, + {0x118EA, 0x118F2}, {0x118FF, 0x118FF}, {0x11AC0, 0x11AF8}, + {0x11C00, 0x11C08}, {0x11C0A, 0x11C2E}, {0x11C2F, 0x11C2F}, + {0x11C30, 0x11C36}, {0x11C38, 0x11C3D}, {0x11C3E, 0x11C3E}, + {0x11C3F, 0x11C3F}, {0x11C40, 0x11C40}, {0x11C41, 0x11C45}, + {0x11C50, 0x11C59}, {0x11C5A, 0x11C6C}, {0x11C70, 0x11C71}, + {0x11C72, 0x11C8F}, {0x11C92, 0x11CA7}, {0x11CA9, 0x11CA9}, + {0x11CAA, 0x11CB0}, {0x11CB1, 0x11CB1}, {0x11CB2, 0x11CB3}, + {0x11CB4, 0x11CB4}, {0x11CB5, 0x11CB6}, {0x12000, 0x12399}, + {0x12400, 0x1246E}, {0x12470, 0x12474}, {0x12480, 0x12543}, + {0x13000, 0x1342E}, {0x14400, 0x14646}, {0x16800, 0x16A38}, + {0x16A40, 0x16A5E}, {0x16A60, 0x16A69}, {0x16A6E, 0x16A6F}, + {0x16AD0, 0x16AED}, {0x16AF0, 0x16AF4}, {0x16AF5, 0x16AF5}, + {0x16B00, 0x16B2F}, {0x16B30, 0x16B36}, {0x16B37, 0x16B3B}, + {0x16B3C, 0x16B3F}, {0x16B40, 0x16B43}, {0x16B44, 0x16B44}, + {0x16B45, 0x16B45}, {0x16B50, 0x16B59}, {0x16B5B, 0x16B61}, + {0x16B63, 0x16B77}, {0x16B7D, 0x16B8F}, {0x16F00, 0x16F44}, + {0x16F50, 0x16F50}, {0x16F51, 0x16F7E}, {0x16F8F, 0x16F92}, + {0x16F93, 0x16F9F}, {0x1BC00, 0x1BC6A}, {0x1BC70, 0x1BC7C}, + {0x1BC80, 0x1BC88}, {0x1BC90, 0x1BC99}, {0x1BC9C, 0x1BC9C}, + {0x1BC9D, 0x1BC9E}, {0x1BC9F, 0x1BC9F}, {0x1BCA0, 0x1BCA3}, + {0x1D000, 0x1D0F5}, {0x1D100, 0x1D126}, {0x1D129, 0x1D164}, + {0x1D165, 0x1D166}, {0x1D167, 0x1D169}, {0x1D16A, 0x1D16C}, + {0x1D16D, 0x1D172}, {0x1D173, 0x1D17A}, {0x1D17B, 0x1D182}, + {0x1D183, 0x1D184}, {0x1D185, 0x1D18B}, {0x1D18C, 0x1D1A9}, + {0x1D1AA, 0x1D1AD}, {0x1D1AE, 0x1D1E8}, {0x1D200, 0x1D241}, + {0x1D242, 0x1D244}, {0x1D245, 0x1D245}, {0x1D300, 0x1D356}, + {0x1D360, 0x1D371}, {0x1D400, 0x1D454}, {0x1D456, 0x1D49C}, + {0x1D49E, 0x1D49F}, {0x1D4A2, 0x1D4A2}, {0x1D4A5, 0x1D4A6}, + {0x1D4A9, 0x1D4AC}, {0x1D4AE, 0x1D4B9}, {0x1D4BB, 0x1D4BB}, + {0x1D4BD, 0x1D4C3}, {0x1D4C5, 0x1D505}, {0x1D507, 0x1D50A}, + {0x1D50D, 0x1D514}, {0x1D516, 0x1D51C}, {0x1D51E, 0x1D539}, + {0x1D53B, 0x1D53E}, {0x1D540, 0x1D544}, {0x1D546, 0x1D546}, + {0x1D54A, 0x1D550}, {0x1D552, 0x1D6A5}, {0x1D6A8, 0x1D6C0}, + {0x1D6C1, 0x1D6C1}, {0x1D6C2, 0x1D6DA}, {0x1D6DB, 0x1D6DB}, + {0x1D6DC, 0x1D6FA}, {0x1D6FB, 0x1D6FB}, {0x1D6FC, 0x1D714}, + {0x1D715, 0x1D715}, {0x1D716, 0x1D734}, {0x1D735, 0x1D735}, + {0x1D736, 0x1D74E}, {0x1D74F, 0x1D74F}, {0x1D750, 0x1D76E}, + {0x1D76F, 0x1D76F}, {0x1D770, 0x1D788}, {0x1D789, 0x1D789}, + {0x1D78A, 0x1D7A8}, {0x1D7A9, 0x1D7A9}, {0x1D7AA, 0x1D7C2}, + {0x1D7C3, 0x1D7C3}, {0x1D7C4, 0x1D7CB}, {0x1D7CE, 0x1D7FF}, + {0x1D800, 0x1D9FF}, {0x1DA00, 0x1DA36}, {0x1DA37, 0x1DA3A}, + {0x1DA3B, 0x1DA6C}, {0x1DA6D, 0x1DA74}, {0x1DA75, 0x1DA75}, + {0x1DA76, 0x1DA83}, {0x1DA84, 0x1DA84}, {0x1DA85, 0x1DA86}, + {0x1DA87, 0x1DA8B}, {0x1DA9B, 0x1DA9F}, {0x1DAA1, 0x1DAAF}, + {0x1E000, 0x1E006}, {0x1E008, 0x1E018}, {0x1E01B, 0x1E021}, + {0x1E023, 0x1E024}, {0x1E026, 0x1E02A}, {0x1E800, 0x1E8C4}, + {0x1E8C7, 0x1E8CF}, {0x1E8D0, 0x1E8D6}, {0x1E900, 0x1E943}, + {0x1E944, 0x1E94A}, {0x1E950, 0x1E959}, {0x1E95E, 0x1E95F}, + {0x1EE00, 0x1EE03}, {0x1EE05, 0x1EE1F}, {0x1EE21, 0x1EE22}, + {0x1EE24, 0x1EE24}, {0x1EE27, 0x1EE27}, {0x1EE29, 0x1EE32}, + {0x1EE34, 0x1EE37}, {0x1EE39, 0x1EE39}, {0x1EE3B, 0x1EE3B}, + {0x1EE42, 0x1EE42}, {0x1EE47, 0x1EE47}, {0x1EE49, 0x1EE49}, + {0x1EE4B, 0x1EE4B}, {0x1EE4D, 0x1EE4F}, {0x1EE51, 0x1EE52}, + {0x1EE54, 0x1EE54}, {0x1EE57, 0x1EE57}, {0x1EE59, 0x1EE59}, + {0x1EE5B, 0x1EE5B}, {0x1EE5D, 0x1EE5D}, {0x1EE5F, 0x1EE5F}, + {0x1EE61, 0x1EE62}, {0x1EE64, 0x1EE64}, {0x1EE67, 0x1EE6A}, + {0x1EE6C, 0x1EE72}, {0x1EE74, 0x1EE77}, {0x1EE79, 0x1EE7C}, + {0x1EE7E, 0x1EE7E}, {0x1EE80, 0x1EE89}, {0x1EE8B, 0x1EE9B}, + {0x1EEA1, 0x1EEA3}, {0x1EEA5, 0x1EEA9}, {0x1EEAB, 0x1EEBB}, + {0x1EEF0, 0x1EEF1}, {0x1F000, 0x1F003}, {0x1F005, 0x1F02B}, + {0x1F030, 0x1F093}, {0x1F0A0, 0x1F0AE}, {0x1F0B1, 0x1F0BF}, + {0x1F0C1, 0x1F0CE}, {0x1F0D1, 0x1F0F5}, {0x1F10B, 0x1F10C}, + {0x1F12E, 0x1F12E}, {0x1F16A, 0x1F16B}, {0x1F1E6, 0x1F1FF}, + {0x1F321, 0x1F32C}, {0x1F336, 0x1F336}, {0x1F37D, 0x1F37D}, + {0x1F394, 0x1F39F}, {0x1F3CB, 0x1F3CE}, {0x1F3D4, 0x1F3DF}, + {0x1F3F1, 0x1F3F3}, {0x1F3F5, 0x1F3F7}, {0x1F43F, 0x1F43F}, + {0x1F441, 0x1F441}, {0x1F4FD, 0x1F4FE}, {0x1F53E, 0x1F54A}, + {0x1F54F, 0x1F54F}, {0x1F568, 0x1F579}, {0x1F57B, 0x1F594}, + {0x1F597, 0x1F5A3}, {0x1F5A5, 0x1F5FA}, {0x1F650, 0x1F67F}, + {0x1F6C6, 0x1F6CB}, {0x1F6CD, 0x1F6CF}, {0x1F6E0, 0x1F6EA}, + {0x1F6F0, 0x1F6F3}, {0x1F700, 0x1F773}, {0x1F780, 0x1F7D4}, + {0x1F800, 0x1F80B}, {0x1F810, 0x1F847}, {0x1F850, 0x1F859}, + {0x1F860, 0x1F887}, {0x1F890, 0x1F8AD}, {0xE0001, 0xE0001}, + {0xE0020, 0xE007F}, +} + +// Condition have flag EastAsianWidth whether the current locale is CJK or not. +type Condition struct { + EastAsianWidth bool +} + +// NewCondition return new instance of Condition which is current locale. +func NewCondition() *Condition { + return &Condition{EastAsianWidth} +} + +// RuneWidth returns the number of cells in r. +// See http://www.unicode.org/reports/tr11/ +func (c *Condition) RuneWidth(r rune) int { + switch { + case r < 0 || r > 0x10FFFF || + inTables(r, nonprint, combining, notassigned): + return 0 + case (c.EastAsianWidth && IsAmbiguousWidth(r)) || + inTables(r, doublewidth, emoji): + return 2 + default: + return 1 + } +} + +// StringWidth return width as you can see +func (c *Condition) StringWidth(s string) (width int) { + for _, r := range []rune(s) { + width += c.RuneWidth(r) + } + return width +} + +// Truncate return string truncated with w cells +func (c *Condition) Truncate(s string, w int, tail string) string { + if c.StringWidth(s) <= w { + return s + } + r := []rune(s) + tw := c.StringWidth(tail) + w -= tw + width := 0 + i := 0 + for ; i < len(r); i++ { + cw := c.RuneWidth(r[i]) + if width+cw > w { + break + } + width += cw + } + return string(r[0:i]) + tail +} + +// Wrap return string wrapped with w cells +func (c *Condition) Wrap(s string, w int) string { + width := 0 + out := "" + for _, r := range []rune(s) { + cw := RuneWidth(r) + if r == '\n' { + out += string(r) + width = 0 + continue + } else if width+cw > w { + out += "\n" + width = 0 + out += string(r) + width += cw + continue + } + out += string(r) + width += cw + } + return out +} + +// FillLeft return string filled in left by spaces in w cells +func (c *Condition) FillLeft(s string, w int) string { + width := c.StringWidth(s) + count := w - width + if count > 0 { + b := make([]byte, count) + for i := range b { + b[i] = ' ' + } + return string(b) + s + } + return s +} + +// FillRight return string filled in left by spaces in w cells +func (c *Condition) FillRight(s string, w int) string { + width := c.StringWidth(s) + count := w - width + if count > 0 { + b := make([]byte, count) + for i := range b { + b[i] = ' ' + } + return s + string(b) + } + return s +} + +// RuneWidth returns the number of cells in r. +// See http://www.unicode.org/reports/tr11/ +func RuneWidth(r rune) int { + return DefaultCondition.RuneWidth(r) +} + +// IsAmbiguousWidth returns whether is ambiguous width or not. +func IsAmbiguousWidth(r rune) bool { + return inTables(r, private, ambiguous) +} + +// IsNeutralWidth returns whether is neutral width or not. +func IsNeutralWidth(r rune) bool { + return inTable(r, neutral) +} + +// StringWidth return width as you can see +func StringWidth(s string) (width int) { + return DefaultCondition.StringWidth(s) +} + +// Truncate return string truncated with w cells +func Truncate(s string, w int, tail string) string { + return DefaultCondition.Truncate(s, w, tail) +} + +// Wrap return string wrapped with w cells +func Wrap(s string, w int) string { + return DefaultCondition.Wrap(s, w) +} + +// FillLeft return string filled in left by spaces in w cells +func FillLeft(s string, w int) string { + return DefaultCondition.FillLeft(s, w) +} + +// FillRight return string filled in left by spaces in w cells +func FillRight(s string, w int) string { + return DefaultCondition.FillRight(s, w) +} diff --git a/vendor/github.com/mattn/go-runewidth/runewidth_js.go b/vendor/github.com/mattn/go-runewidth/runewidth_js.go new file mode 100644 index 000000000..0ce32c5e7 --- /dev/null +++ b/vendor/github.com/mattn/go-runewidth/runewidth_js.go @@ -0,0 +1,8 @@ +// +build js + +package runewidth + +func IsEastAsian() bool { + // TODO: Implement this for the web. Detect east asian in a compatible way, and return true. + return false +} diff --git a/vendor/github.com/mattn/go-runewidth/runewidth_posix.go b/vendor/github.com/mattn/go-runewidth/runewidth_posix.go new file mode 100644 index 000000000..c579e9a31 --- /dev/null +++ b/vendor/github.com/mattn/go-runewidth/runewidth_posix.go @@ -0,0 +1,77 @@ +// +build !windows,!js + +package runewidth + +import ( + "os" + "regexp" + "strings" +) + +var reLoc = regexp.MustCompile(`^[a-z][a-z][a-z]?(?:_[A-Z][A-Z])?\.(.+)`) + +var mblenTable = map[string]int{ + "utf-8": 6, + "utf8": 6, + "jis": 8, + "eucjp": 3, + "euckr": 2, + "euccn": 2, + "sjis": 2, + "cp932": 2, + "cp51932": 2, + "cp936": 2, + "cp949": 2, + "cp950": 2, + "big5": 2, + "gbk": 2, + "gb2312": 2, +} + +func isEastAsian(locale string) bool { + charset := strings.ToLower(locale) + r := reLoc.FindStringSubmatch(locale) + if len(r) == 2 { + charset = strings.ToLower(r[1]) + } + + if strings.HasSuffix(charset, "@cjk_narrow") { + return false + } + + for pos, b := range []byte(charset) { + if b == '@' { + charset = charset[:pos] + break + } + } + max := 1 + if m, ok := mblenTable[charset]; ok { + max = m + } + if max > 1 && (charset[0] != 'u' || + strings.HasPrefix(locale, "ja") || + strings.HasPrefix(locale, "ko") || + strings.HasPrefix(locale, "zh")) { + return true + } + return false +} + +// IsEastAsian return true if the current locale is CJK +func IsEastAsian() bool { + locale := os.Getenv("LC_CTYPE") + if locale == "" { + locale = os.Getenv("LANG") + } + + // ignore C locale + if locale == "POSIX" || locale == "C" { + return false + } + if len(locale) > 1 && locale[0] == 'C' && (locale[1] == '.' || locale[1] == '-') { + return false + } + + return isEastAsian(locale) +} diff --git a/vendor/github.com/mattn/go-runewidth/runewidth_windows.go b/vendor/github.com/mattn/go-runewidth/runewidth_windows.go new file mode 100644 index 000000000..0258876b9 --- /dev/null +++ b/vendor/github.com/mattn/go-runewidth/runewidth_windows.go @@ -0,0 +1,25 @@ +package runewidth + +import ( + "syscall" +) + +var ( + kernel32 = syscall.NewLazyDLL("kernel32") + procGetConsoleOutputCP = kernel32.NewProc("GetConsoleOutputCP") +) + +// IsEastAsian return true if the current locale is CJK +func IsEastAsian() bool { + r1, _, _ := procGetConsoleOutputCP.Call() + if r1 == 0 { + return false + } + + switch int(r1) { + case 932, 51932, 936, 949, 950: + return true + } + + return false +} diff --git a/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/LICENSE b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/LICENSE new file mode 100644 index 000000000..8dada3eda --- /dev/null +++ b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go new file mode 100644 index 000000000..258c0636a --- /dev/null +++ b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go @@ -0,0 +1,75 @@ +// Copyright 2013 Matt T. Proud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pbutil + +import ( + "encoding/binary" + "errors" + "io" + + "github.com/golang/protobuf/proto" +) + +var errInvalidVarint = errors.New("invalid varint32 encountered") + +// ReadDelimited decodes a message from the provided length-delimited stream, +// where the length is encoded as 32-bit varint prefix to the message body. +// It returns the total number of bytes read and any applicable error. This is +// roughly equivalent to the companion Java API's +// MessageLite#parseDelimitedFrom. As per the reader contract, this function +// calls r.Read repeatedly as required until exactly one message including its +// prefix is read and decoded (or an error has occurred). The function never +// reads more bytes from the stream than required. The function never returns +// an error if a message has been read and decoded correctly, even if the end +// of the stream has been reached in doing so. In that case, any subsequent +// calls return (0, io.EOF). +func ReadDelimited(r io.Reader, m proto.Message) (n int, err error) { + // Per AbstractParser#parsePartialDelimitedFrom with + // CodedInputStream#readRawVarint32. + var headerBuf [binary.MaxVarintLen32]byte + var bytesRead, varIntBytes int + var messageLength uint64 + for varIntBytes == 0 { // i.e. no varint has been decoded yet. + if bytesRead >= len(headerBuf) { + return bytesRead, errInvalidVarint + } + // We have to read byte by byte here to avoid reading more bytes + // than required. Each read byte is appended to what we have + // read before. + newBytesRead, err := r.Read(headerBuf[bytesRead : bytesRead+1]) + if newBytesRead == 0 { + if err != nil { + return bytesRead, err + } + // A Reader should not return (0, nil), but if it does, + // it should be treated as no-op (according to the + // Reader contract). So let's go on... + continue + } + bytesRead += newBytesRead + // Now present everything read so far to the varint decoder and + // see if a varint can be decoded already. + messageLength, varIntBytes = proto.DecodeVarint(headerBuf[:bytesRead]) + } + + messageBuf := make([]byte, messageLength) + newBytesRead, err := io.ReadFull(r, messageBuf) + bytesRead += newBytesRead + if err != nil { + return bytesRead, err + } + + return bytesRead, proto.Unmarshal(messageBuf, m) +} diff --git a/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go new file mode 100644 index 000000000..c318385cb --- /dev/null +++ b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go @@ -0,0 +1,16 @@ +// Copyright 2013 Matt T. Proud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package pbutil provides record length-delimited Protocol Buffer streaming. +package pbutil diff --git a/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go new file mode 100644 index 000000000..8fb59ad22 --- /dev/null +++ b/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go @@ -0,0 +1,46 @@ +// Copyright 2013 Matt T. Proud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pbutil + +import ( + "encoding/binary" + "io" + + "github.com/golang/protobuf/proto" +) + +// WriteDelimited encodes and dumps a message to the provided writer prefixed +// with a 32-bit varint indicating the length of the encoded message, producing +// a length-delimited record stream, which can be used to chain together +// encoded messages of the same type together in a file. It returns the total +// number of bytes written and any applicable error. This is roughly +// equivalent to the companion Java API's MessageLite#writeDelimitedTo. +func WriteDelimited(w io.Writer, m proto.Message) (n int, err error) { + buffer, err := proto.Marshal(m) + if err != nil { + return 0, err + } + + var buf [binary.MaxVarintLen32]byte + encodedLength := binary.PutUvarint(buf[:], uint64(len(buffer))) + + sync, err := w.Write(buf[:encodedLength]) + if err != nil { + return sync, err + } + + n, err = w.Write(buffer) + return n + sync, err +} diff --git a/vendor/github.com/minio/cli/LICENSE b/vendor/github.com/minio/cli/LICENSE new file mode 100644 index 000000000..42a597e29 --- /dev/null +++ b/vendor/github.com/minio/cli/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Jeremy Saenz & Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/minio/cli/altsrc/altsrc.go b/vendor/github.com/minio/cli/altsrc/altsrc.go new file mode 100644 index 000000000..ac34bf633 --- /dev/null +++ b/vendor/github.com/minio/cli/altsrc/altsrc.go @@ -0,0 +1,3 @@ +package altsrc + +//go:generate python ../generate-flag-types altsrc -i ../flag-types.json -o flag_generated.go diff --git a/vendor/github.com/minio/cli/altsrc/flag.go b/vendor/github.com/minio/cli/altsrc/flag.go new file mode 100644 index 000000000..84ef009a5 --- /dev/null +++ b/vendor/github.com/minio/cli/altsrc/flag.go @@ -0,0 +1,261 @@ +package altsrc + +import ( + "fmt" + "strconv" + "strings" + "syscall" + + "gopkg.in/urfave/cli.v1" +) + +// FlagInputSourceExtension is an extension interface of cli.Flag that +// allows a value to be set on the existing parsed flags. +type FlagInputSourceExtension interface { + cli.Flag + ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error +} + +// ApplyInputSourceValues iterates over all provided flags and +// executes ApplyInputSourceValue on flags implementing the +// FlagInputSourceExtension interface to initialize these flags +// to an alternate input source. +func ApplyInputSourceValues(context *cli.Context, inputSourceContext InputSourceContext, flags []cli.Flag) error { + for _, f := range flags { + inputSourceExtendedFlag, isType := f.(FlagInputSourceExtension) + if isType { + err := inputSourceExtendedFlag.ApplyInputSourceValue(context, inputSourceContext) + if err != nil { + return err + } + } + } + + return nil +} + +// InitInputSource is used to to setup an InputSourceContext on a cli.Command Before method. It will create a new +// input source based on the func provided. If there is no error it will then apply the new input source to any flags +// that are supported by the input source +func InitInputSource(flags []cli.Flag, createInputSource func() (InputSourceContext, error)) cli.BeforeFunc { + return func(context *cli.Context) error { + inputSource, err := createInputSource() + if err != nil { + return fmt.Errorf("Unable to create input source: inner error: \n'%v'", err.Error()) + } + + return ApplyInputSourceValues(context, inputSource, flags) + } +} + +// InitInputSourceWithContext is used to to setup an InputSourceContext on a cli.Command Before method. It will create a new +// input source based on the func provided with potentially using existing cli.Context values to initialize itself. If there is +// no error it will then apply the new input source to any flags that are supported by the input source +func InitInputSourceWithContext(flags []cli.Flag, createInputSource func(context *cli.Context) (InputSourceContext, error)) cli.BeforeFunc { + return func(context *cli.Context) error { + inputSource, err := createInputSource(context) + if err != nil { + return fmt.Errorf("Unable to create input source with context: inner error: \n'%v'", err.Error()) + } + + return ApplyInputSourceValues(context, inputSource, flags) + } +} + +// ApplyInputSourceValue applies a generic value to the flagSet if required +func (f *GenericFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.Generic(f.GenericFlag.Name) + if err != nil { + return err + } + if value != nil { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, value.String()) + }) + } + } + } + + return nil +} + +// ApplyInputSourceValue applies a StringSlice value to the flagSet if required +func (f *StringSliceFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.StringSlice(f.StringSliceFlag.Name) + if err != nil { + return err + } + if value != nil { + var sliceValue cli.StringSlice = value + eachName(f.Name, func(name string) { + underlyingFlag := f.set.Lookup(f.Name) + if underlyingFlag != nil { + underlyingFlag.Value = &sliceValue + } + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a IntSlice value if required +func (f *IntSliceFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.IntSlice(f.IntSliceFlag.Name) + if err != nil { + return err + } + if value != nil { + var sliceValue cli.IntSlice = value + eachName(f.Name, func(name string) { + underlyingFlag := f.set.Lookup(f.Name) + if underlyingFlag != nil { + underlyingFlag.Value = &sliceValue + } + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a Bool value to the flagSet if required +func (f *BoolFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.Bool(f.BoolFlag.Name) + if err != nil { + return err + } + if value { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, strconv.FormatBool(value)) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a BoolT value to the flagSet if required +func (f *BoolTFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.BoolT(f.BoolTFlag.Name) + if err != nil { + return err + } + if !value { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, strconv.FormatBool(value)) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a String value to the flagSet if required +func (f *StringFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !(context.IsSet(f.Name) || isEnvVarSet(f.EnvVar)) { + value, err := isc.String(f.StringFlag.Name) + if err != nil { + return err + } + if value != "" { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, value) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a int value to the flagSet if required +func (f *IntFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !(context.IsSet(f.Name) || isEnvVarSet(f.EnvVar)) { + value, err := isc.Int(f.IntFlag.Name) + if err != nil { + return err + } + if value > 0 { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, strconv.FormatInt(int64(value), 10)) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a Duration value to the flagSet if required +func (f *DurationFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !(context.IsSet(f.Name) || isEnvVarSet(f.EnvVar)) { + value, err := isc.Duration(f.DurationFlag.Name) + if err != nil { + return err + } + if value > 0 { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, value.String()) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a Float64 value to the flagSet if required +func (f *Float64Flag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !(context.IsSet(f.Name) || isEnvVarSet(f.EnvVar)) { + value, err := isc.Float64(f.Float64Flag.Name) + if err != nil { + return err + } + if value > 0 { + floatStr := float64ToString(value) + eachName(f.Name, func(name string) { + f.set.Set(f.Name, floatStr) + }) + } + } + } + return nil +} + +func isEnvVarSet(envVars string) bool { + for _, envVar := range strings.Split(envVars, ",") { + envVar = strings.TrimSpace(envVar) + if _, ok := syscall.Getenv(envVar); ok { + // TODO: Can't use this for bools as + // set means that it was true or false based on + // Bool flag type, should work for other types + return true + } + } + + return false +} + +func float64ToString(f float64) string { + return fmt.Sprintf("%v", f) +} + +func eachName(longName string, fn func(string)) { + parts := strings.Split(longName, ",") + for _, name := range parts { + name = strings.Trim(name, " ") + fn(name) + } +} diff --git a/vendor/github.com/minio/cli/altsrc/flag_generated.go b/vendor/github.com/minio/cli/altsrc/flag_generated.go new file mode 100644 index 000000000..0aeb0b041 --- /dev/null +++ b/vendor/github.com/minio/cli/altsrc/flag_generated.go @@ -0,0 +1,347 @@ +package altsrc + +import ( + "flag" + + "gopkg.in/urfave/cli.v1" +) + +// WARNING: This file is generated! + +// BoolFlag is the flag type that wraps cli.BoolFlag to allow +// for other values to be specified +type BoolFlag struct { + cli.BoolFlag + set *flag.FlagSet +} + +// NewBoolFlag creates a new BoolFlag +func NewBoolFlag(fl cli.BoolFlag) *BoolFlag { + return &BoolFlag{BoolFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped BoolFlag.Apply +func (f *BoolFlag) Apply(set *flag.FlagSet) { + f.set = set + f.BoolFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped BoolFlag.ApplyWithError +func (f *BoolFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.BoolFlag.ApplyWithError(set) +} + +// BoolTFlag is the flag type that wraps cli.BoolTFlag to allow +// for other values to be specified +type BoolTFlag struct { + cli.BoolTFlag + set *flag.FlagSet +} + +// NewBoolTFlag creates a new BoolTFlag +func NewBoolTFlag(fl cli.BoolTFlag) *BoolTFlag { + return &BoolTFlag{BoolTFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped BoolTFlag.Apply +func (f *BoolTFlag) Apply(set *flag.FlagSet) { + f.set = set + f.BoolTFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped BoolTFlag.ApplyWithError +func (f *BoolTFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.BoolTFlag.ApplyWithError(set) +} + +// DurationFlag is the flag type that wraps cli.DurationFlag to allow +// for other values to be specified +type DurationFlag struct { + cli.DurationFlag + set *flag.FlagSet +} + +// NewDurationFlag creates a new DurationFlag +func NewDurationFlag(fl cli.DurationFlag) *DurationFlag { + return &DurationFlag{DurationFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped DurationFlag.Apply +func (f *DurationFlag) Apply(set *flag.FlagSet) { + f.set = set + f.DurationFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped DurationFlag.ApplyWithError +func (f *DurationFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.DurationFlag.ApplyWithError(set) +} + +// Float64Flag is the flag type that wraps cli.Float64Flag to allow +// for other values to be specified +type Float64Flag struct { + cli.Float64Flag + set *flag.FlagSet +} + +// NewFloat64Flag creates a new Float64Flag +func NewFloat64Flag(fl cli.Float64Flag) *Float64Flag { + return &Float64Flag{Float64Flag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped Float64Flag.Apply +func (f *Float64Flag) Apply(set *flag.FlagSet) { + f.set = set + f.Float64Flag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped Float64Flag.ApplyWithError +func (f *Float64Flag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Float64Flag.ApplyWithError(set) +} + +// GenericFlag is the flag type that wraps cli.GenericFlag to allow +// for other values to be specified +type GenericFlag struct { + cli.GenericFlag + set *flag.FlagSet +} + +// NewGenericFlag creates a new GenericFlag +func NewGenericFlag(fl cli.GenericFlag) *GenericFlag { + return &GenericFlag{GenericFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped GenericFlag.Apply +func (f *GenericFlag) Apply(set *flag.FlagSet) { + f.set = set + f.GenericFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped GenericFlag.ApplyWithError +func (f *GenericFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.GenericFlag.ApplyWithError(set) +} + +// Int64Flag is the flag type that wraps cli.Int64Flag to allow +// for other values to be specified +type Int64Flag struct { + cli.Int64Flag + set *flag.FlagSet +} + +// NewInt64Flag creates a new Int64Flag +func NewInt64Flag(fl cli.Int64Flag) *Int64Flag { + return &Int64Flag{Int64Flag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped Int64Flag.Apply +func (f *Int64Flag) Apply(set *flag.FlagSet) { + f.set = set + f.Int64Flag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped Int64Flag.ApplyWithError +func (f *Int64Flag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Int64Flag.ApplyWithError(set) +} + +// IntFlag is the flag type that wraps cli.IntFlag to allow +// for other values to be specified +type IntFlag struct { + cli.IntFlag + set *flag.FlagSet +} + +// NewIntFlag creates a new IntFlag +func NewIntFlag(fl cli.IntFlag) *IntFlag { + return &IntFlag{IntFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped IntFlag.Apply +func (f *IntFlag) Apply(set *flag.FlagSet) { + f.set = set + f.IntFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped IntFlag.ApplyWithError +func (f *IntFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.IntFlag.ApplyWithError(set) +} + +// IntSliceFlag is the flag type that wraps cli.IntSliceFlag to allow +// for other values to be specified +type IntSliceFlag struct { + cli.IntSliceFlag + set *flag.FlagSet +} + +// NewIntSliceFlag creates a new IntSliceFlag +func NewIntSliceFlag(fl cli.IntSliceFlag) *IntSliceFlag { + return &IntSliceFlag{IntSliceFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped IntSliceFlag.Apply +func (f *IntSliceFlag) Apply(set *flag.FlagSet) { + f.set = set + f.IntSliceFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped IntSliceFlag.ApplyWithError +func (f *IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.IntSliceFlag.ApplyWithError(set) +} + +// Int64SliceFlag is the flag type that wraps cli.Int64SliceFlag to allow +// for other values to be specified +type Int64SliceFlag struct { + cli.Int64SliceFlag + set *flag.FlagSet +} + +// NewInt64SliceFlag creates a new Int64SliceFlag +func NewInt64SliceFlag(fl cli.Int64SliceFlag) *Int64SliceFlag { + return &Int64SliceFlag{Int64SliceFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped Int64SliceFlag.Apply +func (f *Int64SliceFlag) Apply(set *flag.FlagSet) { + f.set = set + f.Int64SliceFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped Int64SliceFlag.ApplyWithError +func (f *Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Int64SliceFlag.ApplyWithError(set) +} + +// StringFlag is the flag type that wraps cli.StringFlag to allow +// for other values to be specified +type StringFlag struct { + cli.StringFlag + set *flag.FlagSet +} + +// NewStringFlag creates a new StringFlag +func NewStringFlag(fl cli.StringFlag) *StringFlag { + return &StringFlag{StringFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped StringFlag.Apply +func (f *StringFlag) Apply(set *flag.FlagSet) { + f.set = set + f.StringFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped StringFlag.ApplyWithError +func (f *StringFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.StringFlag.ApplyWithError(set) +} + +// StringSliceFlag is the flag type that wraps cli.StringSliceFlag to allow +// for other values to be specified +type StringSliceFlag struct { + cli.StringSliceFlag + set *flag.FlagSet +} + +// NewStringSliceFlag creates a new StringSliceFlag +func NewStringSliceFlag(fl cli.StringSliceFlag) *StringSliceFlag { + return &StringSliceFlag{StringSliceFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped StringSliceFlag.Apply +func (f *StringSliceFlag) Apply(set *flag.FlagSet) { + f.set = set + f.StringSliceFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped StringSliceFlag.ApplyWithError +func (f *StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.StringSliceFlag.ApplyWithError(set) +} + +// Uint64Flag is the flag type that wraps cli.Uint64Flag to allow +// for other values to be specified +type Uint64Flag struct { + cli.Uint64Flag + set *flag.FlagSet +} + +// NewUint64Flag creates a new Uint64Flag +func NewUint64Flag(fl cli.Uint64Flag) *Uint64Flag { + return &Uint64Flag{Uint64Flag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped Uint64Flag.Apply +func (f *Uint64Flag) Apply(set *flag.FlagSet) { + f.set = set + f.Uint64Flag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped Uint64Flag.ApplyWithError +func (f *Uint64Flag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Uint64Flag.ApplyWithError(set) +} + +// UintFlag is the flag type that wraps cli.UintFlag to allow +// for other values to be specified +type UintFlag struct { + cli.UintFlag + set *flag.FlagSet +} + +// NewUintFlag creates a new UintFlag +func NewUintFlag(fl cli.UintFlag) *UintFlag { + return &UintFlag{UintFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped UintFlag.Apply +func (f *UintFlag) Apply(set *flag.FlagSet) { + f.set = set + f.UintFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped UintFlag.ApplyWithError +func (f *UintFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.UintFlag.ApplyWithError(set) +} diff --git a/vendor/github.com/minio/cli/altsrc/input_source_context.go b/vendor/github.com/minio/cli/altsrc/input_source_context.go new file mode 100644 index 000000000..276dcda08 --- /dev/null +++ b/vendor/github.com/minio/cli/altsrc/input_source_context.go @@ -0,0 +1,21 @@ +package altsrc + +import ( + "time" + + "gopkg.in/urfave/cli.v1" +) + +// InputSourceContext is an interface used to allow +// other input sources to be implemented as needed. +type InputSourceContext interface { + Int(name string) (int, error) + Duration(name string) (time.Duration, error) + Float64(name string) (float64, error) + String(name string) (string, error) + StringSlice(name string) ([]string, error) + IntSlice(name string) ([]int, error) + Generic(name string) (cli.Generic, error) + Bool(name string) (bool, error) + BoolT(name string) (bool, error) +} diff --git a/vendor/github.com/minio/cli/altsrc/map_input_source.go b/vendor/github.com/minio/cli/altsrc/map_input_source.go new file mode 100644 index 000000000..b3169e0ec --- /dev/null +++ b/vendor/github.com/minio/cli/altsrc/map_input_source.go @@ -0,0 +1,262 @@ +package altsrc + +import ( + "fmt" + "reflect" + "strings" + "time" + + "gopkg.in/urfave/cli.v1" +) + +// MapInputSource implements InputSourceContext to return +// data from the map that is loaded. +type MapInputSource struct { + valueMap map[interface{}]interface{} +} + +// nestedVal checks if the name has '.' delimiters. +// If so, it tries to traverse the tree by the '.' delimited sections to find +// a nested value for the key. +func nestedVal(name string, tree map[interface{}]interface{}) (interface{}, bool) { + if sections := strings.Split(name, "."); len(sections) > 1 { + node := tree + for _, section := range sections[:len(sections)-1] { + if child, ok := node[section]; !ok { + return nil, false + } else { + if ctype, ok := child.(map[interface{}]interface{}); !ok { + return nil, false + } else { + node = ctype + } + } + } + if val, ok := node[sections[len(sections)-1]]; ok { + return val, true + } + } + return nil, false +} + +// Int returns an int from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Int(name string) (int, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(int) + if !isType { + return 0, incorrectTypeForFlagError(name, "int", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(int) + if !isType { + return 0, incorrectTypeForFlagError(name, "int", nestedGenericValue) + } + return otherValue, nil + } + + return 0, nil +} + +// Duration returns a duration from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Duration(name string) (time.Duration, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(time.Duration) + if !isType { + return 0, incorrectTypeForFlagError(name, "duration", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(time.Duration) + if !isType { + return 0, incorrectTypeForFlagError(name, "duration", nestedGenericValue) + } + return otherValue, nil + } + + return 0, nil +} + +// Float64 returns an float64 from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Float64(name string) (float64, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(float64) + if !isType { + return 0, incorrectTypeForFlagError(name, "float64", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(float64) + if !isType { + return 0, incorrectTypeForFlagError(name, "float64", nestedGenericValue) + } + return otherValue, nil + } + + return 0, nil +} + +// String returns a string from the map if it exists otherwise returns an empty string +func (fsm *MapInputSource) String(name string) (string, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(string) + if !isType { + return "", incorrectTypeForFlagError(name, "string", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(string) + if !isType { + return "", incorrectTypeForFlagError(name, "string", nestedGenericValue) + } + return otherValue, nil + } + + return "", nil +} + +// StringSlice returns an []string from the map if it exists otherwise returns nil +func (fsm *MapInputSource) StringSlice(name string) ([]string, error) { + otherGenericValue, exists := fsm.valueMap[name] + if !exists { + otherGenericValue, exists = nestedVal(name, fsm.valueMap) + if !exists { + return nil, nil + } + } + + otherValue, isType := otherGenericValue.([]interface{}) + if !isType { + return nil, incorrectTypeForFlagError(name, "[]interface{}", otherGenericValue) + } + + var stringSlice = make([]string, 0, len(otherValue)) + for i, v := range otherValue { + stringValue, isType := v.(string) + + if !isType { + return nil, incorrectTypeForFlagError(fmt.Sprintf("%s[%d]", name, i), "string", v) + } + + stringSlice = append(stringSlice, stringValue) + } + + return stringSlice, nil +} + +// IntSlice returns an []int from the map if it exists otherwise returns nil +func (fsm *MapInputSource) IntSlice(name string) ([]int, error) { + otherGenericValue, exists := fsm.valueMap[name] + if !exists { + otherGenericValue, exists = nestedVal(name, fsm.valueMap) + if !exists { + return nil, nil + } + } + + otherValue, isType := otherGenericValue.([]interface{}) + if !isType { + return nil, incorrectTypeForFlagError(name, "[]interface{}", otherGenericValue) + } + + var intSlice = make([]int, 0, len(otherValue)) + for i, v := range otherValue { + intValue, isType := v.(int) + + if !isType { + return nil, incorrectTypeForFlagError(fmt.Sprintf("%s[%d]", name, i), "int", v) + } + + intSlice = append(intSlice, intValue) + } + + return intSlice, nil +} + +// Generic returns an cli.Generic from the map if it exists otherwise returns nil +func (fsm *MapInputSource) Generic(name string) (cli.Generic, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(cli.Generic) + if !isType { + return nil, incorrectTypeForFlagError(name, "cli.Generic", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(cli.Generic) + if !isType { + return nil, incorrectTypeForFlagError(name, "cli.Generic", nestedGenericValue) + } + return otherValue, nil + } + + return nil, nil +} + +// Bool returns an bool from the map otherwise returns false +func (fsm *MapInputSource) Bool(name string) (bool, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(bool) + if !isType { + return false, incorrectTypeForFlagError(name, "bool", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(bool) + if !isType { + return false, incorrectTypeForFlagError(name, "bool", nestedGenericValue) + } + return otherValue, nil + } + + return false, nil +} + +// BoolT returns an bool from the map otherwise returns true +func (fsm *MapInputSource) BoolT(name string) (bool, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(bool) + if !isType { + return true, incorrectTypeForFlagError(name, "bool", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(bool) + if !isType { + return true, incorrectTypeForFlagError(name, "bool", nestedGenericValue) + } + return otherValue, nil + } + + return true, nil +} + +func incorrectTypeForFlagError(name, expectedTypeName string, value interface{}) error { + valueType := reflect.TypeOf(value) + valueTypeName := "" + if valueType != nil { + valueTypeName = valueType.Name() + } + + return fmt.Errorf("Mismatched type for flag '%s'. Expected '%s' but actual is '%s'", name, expectedTypeName, valueTypeName) +} diff --git a/vendor/github.com/minio/cli/altsrc/toml_file_loader.go b/vendor/github.com/minio/cli/altsrc/toml_file_loader.go new file mode 100644 index 000000000..37870fcbe --- /dev/null +++ b/vendor/github.com/minio/cli/altsrc/toml_file_loader.go @@ -0,0 +1,113 @@ +// Disabling building of toml support in cases where golang is 1.0 or 1.1 +// as the encoding library is not implemented or supported. + +// +build go1.2 + +package altsrc + +import ( + "fmt" + "reflect" + + "github.com/BurntSushi/toml" + "gopkg.in/urfave/cli.v1" +) + +type tomlMap struct { + Map map[interface{}]interface{} +} + +func unmarshalMap(i interface{}) (ret map[interface{}]interface{}, err error) { + ret = make(map[interface{}]interface{}) + m := i.(map[string]interface{}) + for key, val := range m { + v := reflect.ValueOf(val) + switch v.Kind() { + case reflect.Bool: + ret[key] = val.(bool) + case reflect.String: + ret[key] = val.(string) + case reflect.Int: + ret[key] = int(val.(int)) + case reflect.Int8: + ret[key] = int(val.(int8)) + case reflect.Int16: + ret[key] = int(val.(int16)) + case reflect.Int32: + ret[key] = int(val.(int32)) + case reflect.Int64: + ret[key] = int(val.(int64)) + case reflect.Uint: + ret[key] = int(val.(uint)) + case reflect.Uint8: + ret[key] = int(val.(uint8)) + case reflect.Uint16: + ret[key] = int(val.(uint16)) + case reflect.Uint32: + ret[key] = int(val.(uint32)) + case reflect.Uint64: + ret[key] = int(val.(uint64)) + case reflect.Float32: + ret[key] = float64(val.(float32)) + case reflect.Float64: + ret[key] = float64(val.(float64)) + case reflect.Map: + if tmp, err := unmarshalMap(val); err == nil { + ret[key] = tmp + } else { + return nil, err + } + case reflect.Array, reflect.Slice: + ret[key] = val.([]interface{}) + default: + return nil, fmt.Errorf("Unsupported: type = %#v", v.Kind()) + } + } + return ret, nil +} + +func (self *tomlMap) UnmarshalTOML(i interface{}) error { + if tmp, err := unmarshalMap(i); err == nil { + self.Map = tmp + } else { + return err + } + return nil +} + +type tomlSourceContext struct { + FilePath string +} + +// NewTomlSourceFromFile creates a new TOML InputSourceContext from a filepath. +func NewTomlSourceFromFile(file string) (InputSourceContext, error) { + tsc := &tomlSourceContext{FilePath: file} + var results tomlMap = tomlMap{} + if err := readCommandToml(tsc.FilePath, &results); err != nil { + return nil, fmt.Errorf("Unable to load TOML file '%s': inner error: \n'%v'", tsc.FilePath, err.Error()) + } + return &MapInputSource{valueMap: results.Map}, nil +} + +// NewTomlSourceFromFlagFunc creates a new TOML InputSourceContext from a provided flag name and source context. +func NewTomlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) { + return func(context *cli.Context) (InputSourceContext, error) { + filePath := context.String(flagFileName) + return NewTomlSourceFromFile(filePath) + } +} + +func readCommandToml(filePath string, container interface{}) (err error) { + b, err := loadDataFrom(filePath) + if err != nil { + return err + } + + err = toml.Unmarshal(b, container) + if err != nil { + return err + } + + err = nil + return +} diff --git a/vendor/github.com/minio/cli/altsrc/yaml_file_loader.go b/vendor/github.com/minio/cli/altsrc/yaml_file_loader.go new file mode 100644 index 000000000..dd808d523 --- /dev/null +++ b/vendor/github.com/minio/cli/altsrc/yaml_file_loader.go @@ -0,0 +1,92 @@ +// Disabling building of yaml support in cases where golang is 1.0 or 1.1 +// as the encoding library is not implemented or supported. + +// +build go1.2 + +package altsrc + +import ( + "fmt" + "io/ioutil" + "net/http" + "net/url" + "os" + "runtime" + "strings" + + "gopkg.in/urfave/cli.v1" + + "gopkg.in/yaml.v2" +) + +type yamlSourceContext struct { + FilePath string +} + +// NewYamlSourceFromFile creates a new Yaml InputSourceContext from a filepath. +func NewYamlSourceFromFile(file string) (InputSourceContext, error) { + ysc := &yamlSourceContext{FilePath: file} + var results map[interface{}]interface{} + err := readCommandYaml(ysc.FilePath, &results) + if err != nil { + return nil, fmt.Errorf("Unable to load Yaml file '%s': inner error: \n'%v'", ysc.FilePath, err.Error()) + } + + return &MapInputSource{valueMap: results}, nil +} + +// NewYamlSourceFromFlagFunc creates a new Yaml InputSourceContext from a provided flag name and source context. +func NewYamlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) { + return func(context *cli.Context) (InputSourceContext, error) { + filePath := context.String(flagFileName) + return NewYamlSourceFromFile(filePath) + } +} + +func readCommandYaml(filePath string, container interface{}) (err error) { + b, err := loadDataFrom(filePath) + if err != nil { + return err + } + + err = yaml.Unmarshal(b, container) + if err != nil { + return err + } + + err = nil + return +} + +func loadDataFrom(filePath string) ([]byte, error) { + u, err := url.Parse(filePath) + if err != nil { + return nil, err + } + + if u.Host != "" { // i have a host, now do i support the scheme? + switch u.Scheme { + case "http", "https": + res, err := http.Get(filePath) + if err != nil { + return nil, err + } + return ioutil.ReadAll(res.Body) + default: + return nil, fmt.Errorf("scheme of %s is unsupported", filePath) + } + } else if u.Path != "" { // i dont have a host, but I have a path. I am a local file. + if _, notFoundFileErr := os.Stat(filePath); notFoundFileErr != nil { + return nil, fmt.Errorf("Cannot read from file: '%s' because it does not exist.", filePath) + } + return ioutil.ReadFile(filePath) + } else if runtime.GOOS == "windows" && strings.Contains(u.String(), "\\") { + // on Windows systems u.Path is always empty, so we need to check the string directly. + if _, notFoundFileErr := os.Stat(filePath); notFoundFileErr != nil { + return nil, fmt.Errorf("Cannot read from file: '%s' because it does not exist.", filePath) + } + return ioutil.ReadFile(filePath) + } else { + return nil, fmt.Errorf("unable to determine how to load from path %s", filePath) + } +} diff --git a/vendor/github.com/minio/cli/app.go b/vendor/github.com/minio/cli/app.go new file mode 100644 index 000000000..ce5f89f9a --- /dev/null +++ b/vendor/github.com/minio/cli/app.go @@ -0,0 +1,504 @@ +package cli + +import ( + "fmt" + "io" + "io/ioutil" + "os" + "path/filepath" + "sort" + "time" +) + +var ( + changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" + appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) + runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL) + + contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you." + + errInvalidActionType = NewExitError("ERROR invalid Action type. "+ + fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+ + fmt.Sprintf("See %s", appActionDeprecationURL), 2) +) + +// App is the main structure of a cli application. It is recommended that +// an app be created with the cli.NewApp() function +type App struct { + // The name of the program. Defaults to path.Base(os.Args[0]) + Name string + // Full name of command for help, defaults to Name + HelpName string + // Description of the program. + Usage string + // Text to override the USAGE section of help + UsageText string + // Description of the program argument format. + ArgsUsage string + // Version of the program + Version string + // Description of the program + Description string + // List of commands to execute + Commands []Command + // List of flags to parse + Flags []Flag + // Boolean to enable bash completion commands + EnableBashCompletion bool + // Boolean to hide built-in help flag + HideHelp bool + // Boolean to hide built-in help command + HideHelpCommand bool + // Boolean to hide built-in version flag and the VERSION section of help + HideVersion bool + // Populate on app startup, only gettable through method Categories() + categories CommandCategories + // An action to execute when the bash-completion flag is set + BashComplete BashCompleteFunc + // An action to execute before any subcommands are run, but after the context is ready + // If a non-nil error is returned, no subcommands are run + Before BeforeFunc + // An action to execute after any subcommands are run, but after the subcommand has finished + // It is run even if Action() panics + After AfterFunc + + // The action to execute when no subcommands are specified + // Expects a `cli.ActionFunc` but will accept the *deprecated* signature of `func(*cli.Context) {}` + // *Note*: support for the deprecated `Action` signature will be removed in a future version + Action interface{} + + // Execute this function if the proper command cannot be found + CommandNotFound CommandNotFoundFunc + // Execute this function if an usage error occurs + OnUsageError OnUsageErrorFunc + // Compilation date + Compiled time.Time + // List of all authors who contributed + Authors []Author + // Copyright of the binary if any + Copyright string + // Name of Author (Note: Use App.Authors, this is deprecated) + Author string + // Email of Author (Note: Use App.Authors, this is deprecated) + Email string + // Writer writer to write output to + Writer io.Writer + // ErrWriter writes error output + ErrWriter io.Writer + // Other custom info + Metadata map[string]interface{} + // Carries a function which returns app specific info. + ExtraInfo func() map[string]string + // CustomAppHelpTemplate the text template for app help topic. + // cli.go uses text/template to render templates. You can + // render custom help text by setting this variable. + CustomAppHelpTemplate string + + didSetup bool +} + +// Tries to find out when this binary was compiled. +// Returns the current time if it fails to find it. +func compileTime() time.Time { + info, err := os.Stat(os.Args[0]) + if err != nil { + return time.Now() + } + return info.ModTime() +} + +// NewApp creates a new cli Application with some reasonable defaults for Name, +// Usage, Version and Action. +func NewApp() *App { + return &App{ + Name: filepath.Base(os.Args[0]), + HelpName: filepath.Base(os.Args[0]), + Usage: "A new cli application", + UsageText: "", + Version: "0.0.0", + BashComplete: DefaultAppComplete, + Action: helpCommand.Action, + Compiled: compileTime(), + Writer: os.Stdout, + } +} + +// Setup runs initialization code to ensure all data structures are ready for +// `Run` or inspection prior to `Run`. It is internally called by `Run`, but +// will return early if setup has already happened. +func (a *App) Setup() { + if a.didSetup { + return + } + + a.didSetup = true + + if a.Author != "" || a.Email != "" { + a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email}) + } + + newCmds := []Command{} + for _, c := range a.Commands { + if c.HelpName == "" { + c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) + } + newCmds = append(newCmds, c) + } + a.Commands = newCmds + + if a.Command(helpCommand.Name) == nil { + if !a.HideHelpCommand { + a.Commands = append(a.Commands, helpCommand) + } + if !a.HideHelp && (HelpFlag != BoolFlag{}) { + a.appendFlag(HelpFlag) + } + } + + if !a.HideVersion { + a.appendFlag(VersionFlag) + } + + a.categories = CommandCategories{} + for _, command := range a.Commands { + a.categories = a.categories.AddCommand(command.Category, command) + } + sort.Sort(a.categories) + + if a.Metadata == nil { + a.Metadata = make(map[string]interface{}) + } + + if a.Writer == nil { + a.Writer = os.Stdout + } +} + +// Run is the entry point to the cli app. Parses the arguments slice and routes +// to the proper flag/args combination +func (a *App) Run(arguments []string) (err error) { + a.Setup() + + // handle the completion flag separately from the flagset since + // completion could be attempted after a flag, but before its value was put + // on the command line. this causes the flagset to interpret the completion + // flag name as the value of the flag before it which is undesirable + // note that we can only do this because the shell autocomplete function + // always appends the completion flag at the end of the command + shellComplete, arguments := checkShellCompleteFlag(a, arguments) + + // parse flags + set, err := flagSet(a.Name, a.Flags) + if err != nil { + return err + } + + set.SetOutput(ioutil.Discard) + err = set.Parse(arguments[1:]) + nerr := normalizeFlags(a.Flags, set) + context := NewContext(a, set, nil) + if nerr != nil { + fmt.Fprintln(a.Writer, nerr) + ShowAppHelp(context) + return nerr + } + context.shellComplete = shellComplete + + if checkCompletions(context) { + return nil + } + + if err != nil { + if a.OnUsageError != nil { + err := a.OnUsageError(context, err, false) + HandleExitCoder(err) + return err + } + fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) + ShowAppHelp(context) + return err + } + + if !a.HideHelp && checkHelp(context) { + ShowAppHelp(context) + return nil + } + + if !a.HideVersion && checkVersion(context) { + ShowVersion(context) + return nil + } + + if a.After != nil { + defer func() { + if afterErr := a.After(context); afterErr != nil { + if err != nil { + err = NewMultiError(err, afterErr) + } else { + err = afterErr + } + } + }() + } + + if a.Before != nil { + beforeErr := a.Before(context) + if beforeErr != nil { + fmt.Fprintf(a.Writer, "%v\n\n", beforeErr) + ShowAppHelp(context) + HandleExitCoder(beforeErr) + err = beforeErr + return err + } + } + + args := context.Args() + if args.Present() { + name := args.First() + c := a.Command(name) + if c != nil { + return c.Run(context) + } + } + + if a.Action == nil { + a.Action = helpCommand.Action + } + + // Run default Action + err = HandleAction(a.Action, context) + + HandleExitCoder(err) + return err +} + +// RunAndExitOnError calls .Run() and exits non-zero if an error was returned +// +// Deprecated: instead you should return an error that fulfills cli.ExitCoder +// to cli.App.Run. This will cause the application to exit with the given eror +// code in the cli.ExitCoder +func (a *App) RunAndExitOnError() { + if err := a.Run(os.Args); err != nil { + fmt.Fprintln(a.errWriter(), err) + OsExiter(1) + } +} + +// RunAsSubcommand invokes the subcommand given the context, parses ctx.Args() to +// generate command-specific flags +func (a *App) RunAsSubcommand(ctx *Context) (err error) { + // append help to commands + if len(a.Commands) > 0 { + if a.Command(helpCommand.Name) == nil { + if !a.HideHelpCommand { + a.Commands = append(a.Commands, helpCommand) + } + if !a.HideHelp && (HelpFlag != BoolFlag{}) { + a.appendFlag(HelpFlag) + } + } + } + + newCmds := []Command{} + for _, c := range a.Commands { + if c.HelpName == "" { + c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) + } + newCmds = append(newCmds, c) + } + a.Commands = newCmds + + // parse flags + set, err := flagSet(a.Name, a.Flags) + if err != nil { + return err + } + + set.SetOutput(ioutil.Discard) + err = set.Parse(ctx.Args().Tail()) + nerr := normalizeFlags(a.Flags, set) + context := NewContext(a, set, ctx) + + if nerr != nil { + fmt.Fprintln(a.Writer, nerr) + fmt.Fprintln(a.Writer) + if len(a.Commands) > 0 { + ShowSubcommandHelp(context) + } else { + ShowCommandHelp(ctx, context.Args().First()) + } + return nerr + } + + if checkCompletions(context) { + return nil + } + + if err != nil { + if a.OnUsageError != nil { + err = a.OnUsageError(context, err, true) + HandleExitCoder(err) + return err + } + fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) + ShowSubcommandHelp(context) + return err + } + + if len(a.Commands) > 0 { + if checkSubcommandHelp(context) { + return nil + } + } else { + if checkCommandHelp(ctx, context.Args().First()) { + return nil + } + } + + if a.After != nil { + defer func() { + afterErr := a.After(context) + if afterErr != nil { + HandleExitCoder(err) + if err != nil { + err = NewMultiError(err, afterErr) + } else { + err = afterErr + } + } + }() + } + + if a.Before != nil { + beforeErr := a.Before(context) + if beforeErr != nil { + HandleExitCoder(beforeErr) + err = beforeErr + return err + } + } + + args := context.Args() + if args.Present() { + name := args.First() + c := a.Command(name) + if c != nil { + return c.Run(context) + } + } + + // Run default Action + err = HandleAction(a.Action, context) + + HandleExitCoder(err) + return err +} + +// Command returns the named command on App. Returns nil if the command does not exist +func (a *App) Command(name string) *Command { + for _, c := range a.Commands { + if c.HasName(name) { + return &c + } + } + + return nil +} + +// Categories returns a slice containing all the categories with the commands they contain +func (a *App) Categories() CommandCategories { + return a.categories +} + +// VisibleCategories returns a slice of categories and commands that are +// Hidden=false +func (a *App) VisibleCategories() []*CommandCategory { + ret := []*CommandCategory{} + for _, category := range a.categories { + if visible := func() *CommandCategory { + for _, command := range category.Commands { + if !command.Hidden { + return category + } + } + return nil + }(); visible != nil { + ret = append(ret, visible) + } + } + return ret +} + +// VisibleCommands returns a slice of the Commands with Hidden=false +func (a *App) VisibleCommands() []Command { + ret := []Command{} + for _, command := range a.Commands { + if !command.Hidden { + ret = append(ret, command) + } + } + return ret +} + +// VisibleFlags returns a slice of the Flags with Hidden=false +func (a *App) VisibleFlags() []Flag { + return visibleFlags(a.Flags) +} + +func (a *App) hasFlag(flag Flag) bool { + for _, f := range a.Flags { + if flag == f { + return true + } + } + + return false +} + +func (a *App) errWriter() io.Writer { + + // When the app ErrWriter is nil use the package level one. + if a.ErrWriter == nil { + return ErrWriter + } + + return a.ErrWriter +} + +func (a *App) appendFlag(flag Flag) { + if !a.hasFlag(flag) { + a.Flags = append(a.Flags, flag) + } +} + +// Author represents someone who has contributed to a cli project. +type Author struct { + Name string // The Authors name + Email string // The Authors email +} + +// String makes Author comply to the Stringer interface, to allow an easy print in the templating process +func (a Author) String() string { + e := "" + if a.Email != "" { + e = " <" + a.Email + ">" + } + + return fmt.Sprintf("%v%v", a.Name, e) +} + +// HandleAction attempts to figure out which Action signature was used. If +// it's an ActionFunc or a func with the legacy signature for Action, the func +// is run! +func HandleAction(action interface{}, context *Context) (err error) { + if a, ok := action.(ActionFunc); ok { + return a(context) + } else if a, ok := action.(func(*Context) error); ok { + return a(context) + } else if a, ok := action.(func(*Context)); ok { // deprecated function signature + a(context) + return nil + } else { + return errInvalidActionType + } +} diff --git a/vendor/github.com/minio/cli/category.go b/vendor/github.com/minio/cli/category.go new file mode 100644 index 000000000..1a6055023 --- /dev/null +++ b/vendor/github.com/minio/cli/category.go @@ -0,0 +1,44 @@ +package cli + +// CommandCategories is a slice of *CommandCategory. +type CommandCategories []*CommandCategory + +// CommandCategory is a category containing commands. +type CommandCategory struct { + Name string + Commands Commands +} + +func (c CommandCategories) Less(i, j int) bool { + return c[i].Name < c[j].Name +} + +func (c CommandCategories) Len() int { + return len(c) +} + +func (c CommandCategories) Swap(i, j int) { + c[i], c[j] = c[j], c[i] +} + +// AddCommand adds a command to a category. +func (c CommandCategories) AddCommand(category string, command Command) CommandCategories { + for _, commandCategory := range c { + if commandCategory.Name == category { + commandCategory.Commands = append(commandCategory.Commands, command) + return c + } + } + return append(c, &CommandCategory{Name: category, Commands: []Command{command}}) +} + +// VisibleCommands returns a slice of the Commands with Hidden=false +func (c *CommandCategory) VisibleCommands() []Command { + ret := []Command{} + for _, command := range c.Commands { + if !command.Hidden { + ret = append(ret, command) + } + } + return ret +} diff --git a/vendor/github.com/minio/cli/cli.go b/vendor/github.com/minio/cli/cli.go new file mode 100644 index 000000000..74fd101f4 --- /dev/null +++ b/vendor/github.com/minio/cli/cli.go @@ -0,0 +1,21 @@ +// Package cli provides a minimal framework for creating and organizing command line +// Go applications. cli is designed to be easy to understand and write, the most simple +// cli application can be written as follows: +// func main() { +// cli.NewApp().Run(os.Args) +// } +// +// Of course this application does not do much, so let's make this an actual application: +// func main() { +// app := cli.NewApp() +// app.Name = "greet" +// app.Usage = "say a greeting" +// app.Action = func(c *cli.Context) error { +// println("Greetings") +// } +// +// app.Run(os.Args) +// } +package cli + +//go:generate python ./generate-flag-types cli -i flag-types.json -o flag_generated.go diff --git a/vendor/github.com/minio/cli/command.go b/vendor/github.com/minio/cli/command.go new file mode 100644 index 000000000..908a2ef27 --- /dev/null +++ b/vendor/github.com/minio/cli/command.go @@ -0,0 +1,316 @@ +package cli + +import ( + "fmt" + "io/ioutil" + "sort" + "strings" +) + +// Command is a subcommand for a cli.App. +type Command struct { + // The name of the command + Name string + // short name of the command. Typically one character (deprecated, use `Aliases`) + ShortName string + // A list of aliases for the command + Aliases []string + // A short description of the usage of this command + Usage string + // Custom text to show on USAGE section of help + UsageText string + // A longer explanation of how the command works + Description string + // A short description of the arguments of this command + ArgsUsage string + // The category the command is part of + Category string + // The function to call when checking for bash command completions + BashComplete BashCompleteFunc + // An action to execute before any sub-subcommands are run, but after the context is ready + // If a non-nil error is returned, no sub-subcommands are run + Before BeforeFunc + // An action to execute after any subcommands are run, but after the subcommand has finished + // It is run even if Action() panics + After AfterFunc + // The function to call when this command is invoked + Action interface{} + // TODO: replace `Action: interface{}` with `Action: ActionFunc` once some kind + // of deprecation period has passed, maybe? + + // Execute this function if a usage error occurs. + OnUsageError OnUsageErrorFunc + // List of child commands + Subcommands Commands + // List of flags to parse + Flags []Flag + // Treat all flags as normal arguments if true + SkipFlagParsing bool + // Skip argument reordering which attempts to move flags before arguments, + // but only works if all flags appear after all arguments. This behavior was + // removed n version 2 since it only works under specific conditions so we + // backport here by exposing it as an option for compatibility. + SkipArgReorder bool + // Boolean to hide built-in help flag + HideHelp bool + // Boolean to hide built-in help command + HideHelpCommand bool + // Boolean to hide this command from help or completion + Hidden bool + + // Full name of command for help, defaults to full command name, including parent commands. + HelpName string + commandNamePath []string + + // CustomHelpTemplate the text template for the command help topic. + // cli.go uses text/template to render templates. You can + // render custom help text by setting this variable. + CustomHelpTemplate string +} + +type CommandsByName []Command + +func (c CommandsByName) Len() int { + return len(c) +} + +func (c CommandsByName) Less(i, j int) bool { + return c[i].Name < c[j].Name +} + +func (c CommandsByName) Swap(i, j int) { + c[i], c[j] = c[j], c[i] +} + +// FullName returns the full name of the command. +// For subcommands this ensures that parent commands are part of the command path +func (c Command) FullName() string { + if c.commandNamePath == nil { + return c.Name + } + return strings.Join(c.commandNamePath, " ") +} + +// Commands is a slice of Command +type Commands []Command + +// Run invokes the command given the context, parses ctx.Args() to generate command-specific flags +func (c Command) Run(ctx *Context) (err error) { + if len(c.Subcommands) > 0 { + return c.startApp(ctx) + } + + if !c.HideHelp && (HelpFlag != BoolFlag{}) { + // append help to flags + c.Flags = append( + c.Flags, + HelpFlag, + ) + } + + set, err := flagSet(c.Name, c.Flags) + if err != nil { + return err + } + set.SetOutput(ioutil.Discard) + + if c.SkipFlagParsing { + err = set.Parse(append([]string{"--"}, ctx.Args().Tail()...)) + } else if !c.SkipArgReorder { + firstFlagIndex := -1 + terminatorIndex := -1 + for index, arg := range ctx.Args() { + if arg == "--" { + terminatorIndex = index + break + } else if arg == "-" { + // Do nothing. A dash alone is not really a flag. + continue + } else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 { + firstFlagIndex = index + } + } + + if firstFlagIndex > -1 { + args := ctx.Args() + regularArgs := make([]string, len(args[1:firstFlagIndex])) + copy(regularArgs, args[1:firstFlagIndex]) + + var flagArgs []string + if terminatorIndex > -1 { + flagArgs = args[firstFlagIndex:terminatorIndex] + regularArgs = append(regularArgs, args[terminatorIndex:]...) + } else { + flagArgs = args[firstFlagIndex:] + } + + err = set.Parse(append(flagArgs, regularArgs...)) + } else { + err = set.Parse(ctx.Args().Tail()) + } + } else { + err = set.Parse(ctx.Args().Tail()) + } + + nerr := normalizeFlags(c.Flags, set) + if nerr != nil { + fmt.Fprintln(ctx.App.Writer, nerr) + fmt.Fprintln(ctx.App.Writer) + ShowCommandHelp(ctx, c.Name) + return nerr + } + + context := NewContext(ctx.App, set, ctx) + context.Command = c + if checkCommandCompletions(context, c.Name) { + return nil + } + + if err != nil { + if c.OnUsageError != nil { + err := c.OnUsageError(context, err, false) + HandleExitCoder(err) + return err + } + fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error()) + fmt.Fprintln(context.App.Writer) + ShowCommandHelp(context, c.Name) + return err + } + + if checkCommandHelp(context, c.Name) { + return nil + } + + if c.After != nil { + defer func() { + afterErr := c.After(context) + if afterErr != nil { + HandleExitCoder(err) + if err != nil { + err = NewMultiError(err, afterErr) + } else { + err = afterErr + } + } + }() + } + + if c.Before != nil { + err = c.Before(context) + if err != nil { + fmt.Fprintln(context.App.Writer, err) + fmt.Fprintln(context.App.Writer) + ShowCommandHelp(context, c.Name) + HandleExitCoder(err) + return err + } + } + + if c.Action == nil { + c.Action = helpSubcommand.Action + } + + err = HandleAction(c.Action, context) + + if err != nil { + HandleExitCoder(err) + } + return err +} + +// Names returns the names including short names and aliases. +func (c Command) Names() []string { + names := []string{c.Name} + + if c.ShortName != "" { + names = append(names, c.ShortName) + } + + return append(names, c.Aliases...) +} + +// HasName returns true if Command.Name or Command.ShortName matches given name +func (c Command) HasName(name string) bool { + for _, n := range c.Names() { + if n == name { + return true + } + } + return false +} + +func (c Command) startApp(ctx *Context) error { + app := NewApp() + app.Metadata = ctx.App.Metadata + // set the name and usage + app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name) + if c.HelpName == "" { + app.HelpName = c.HelpName + } else { + app.HelpName = app.Name + } + + app.Usage = c.Usage + app.Description = c.Description + app.ArgsUsage = c.ArgsUsage + + // set CommandNotFound + app.CommandNotFound = ctx.App.CommandNotFound + app.CustomAppHelpTemplate = c.CustomHelpTemplate + + // set the flags and commands + app.Commands = c.Subcommands + app.Flags = c.Flags + app.HideHelp = c.HideHelp + app.HideHelpCommand = c.HideHelpCommand + + app.Version = ctx.App.Version + app.HideVersion = ctx.App.HideVersion + app.Compiled = ctx.App.Compiled + app.Author = ctx.App.Author + app.Email = ctx.App.Email + app.Writer = ctx.App.Writer + app.ErrWriter = ctx.App.ErrWriter + + app.categories = CommandCategories{} + for _, command := range c.Subcommands { + app.categories = app.categories.AddCommand(command.Category, command) + } + + sort.Sort(app.categories) + + // bash completion + app.EnableBashCompletion = ctx.App.EnableBashCompletion + if c.BashComplete != nil { + app.BashComplete = c.BashComplete + } + + // set the actions + app.Before = c.Before + app.After = c.After + if c.Action != nil { + app.Action = c.Action + } else { + app.Action = helpSubcommand.Action + } + + for index, cc := range app.Commands { + app.Commands[index].commandNamePath = []string{c.Name, cc.Name} + } + + return app.RunAsSubcommand(ctx) +} + +// VisibleFlags returns a slice of the Flags with Hidden=false +func (c Command) VisibleFlags() []Flag { + flags := c.Flags + if !c.HideHelp && (HelpFlag != BoolFlag{}) { + // append help to flags + flags = append( + flags, + HelpFlag, + ) + } + return visibleFlags(flags) +} diff --git a/vendor/github.com/minio/cli/context.go b/vendor/github.com/minio/cli/context.go new file mode 100644 index 000000000..cb89e92a0 --- /dev/null +++ b/vendor/github.com/minio/cli/context.go @@ -0,0 +1,276 @@ +package cli + +import ( + "errors" + "flag" + "reflect" + "strings" + "syscall" +) + +// Context is a type that is passed through to +// each Handler action in a cli application. Context +// can be used to retrieve context-specific Args and +// parsed command-line options. +type Context struct { + App *App + Command Command + shellComplete bool + flagSet *flag.FlagSet + setFlags map[string]bool + parentContext *Context +} + +// NewContext creates a new context. For use in when invoking an App or Command action. +func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context { + c := &Context{App: app, flagSet: set, parentContext: parentCtx} + + if parentCtx != nil { + c.shellComplete = parentCtx.shellComplete + } + + return c +} + +// NumFlags returns the number of flags set +func (c *Context) NumFlags() int { + return c.flagSet.NFlag() +} + +// Set sets a context flag to a value. +func (c *Context) Set(name, value string) error { + return c.flagSet.Set(name, value) +} + +// GlobalSet sets a context flag to a value on the global flagset +func (c *Context) GlobalSet(name, value string) error { + return globalContext(c).flagSet.Set(name, value) +} + +// IsSet determines if the flag was actually set +func (c *Context) IsSet(name string) bool { + if c.setFlags == nil { + c.setFlags = make(map[string]bool) + + c.flagSet.Visit(func(f *flag.Flag) { + c.setFlags[f.Name] = true + }) + + c.flagSet.VisitAll(func(f *flag.Flag) { + if _, ok := c.setFlags[f.Name]; ok { + return + } + c.setFlags[f.Name] = false + }) + + // XXX hack to support IsSet for flags with EnvVar + // + // There isn't an easy way to do this with the current implementation since + // whether a flag was set via an environment variable is very difficult to + // determine here. Instead, we intend to introduce a backwards incompatible + // change in version 2 to add `IsSet` to the Flag interface to push the + // responsibility closer to where the information required to determine + // whether a flag is set by non-standard means such as environment + // variables is avaliable. + // + // See https://github.com/urfave/cli/issues/294 for additional discussion + flags := c.Command.Flags + if c.Command.Name == "" { // cannot == Command{} since it contains slice types + if c.App != nil { + flags = c.App.Flags + } + } + for _, f := range flags { + eachName(f.GetName(), func(name string) { + if isSet, ok := c.setFlags[name]; isSet || !ok { + return + } + + val := reflect.ValueOf(f) + if val.Kind() == reflect.Ptr { + val = val.Elem() + } + + envVarValue := val.FieldByName("EnvVar") + if !envVarValue.IsValid() { + return + } + + eachName(envVarValue.String(), func(envVar string) { + envVar = strings.TrimSpace(envVar) + if _, ok := syscall.Getenv(envVar); ok { + c.setFlags[name] = true + return + } + }) + }) + } + } + + return c.setFlags[name] +} + +// GlobalIsSet determines if the global flag was actually set +func (c *Context) GlobalIsSet(name string) bool { + ctx := c + if ctx.parentContext != nil { + ctx = ctx.parentContext + } + + for ; ctx != nil; ctx = ctx.parentContext { + if ctx.IsSet(name) { + return true + } + } + return false +} + +// FlagNames returns a slice of flag names used in this context. +func (c *Context) FlagNames() (names []string) { + for _, flag := range c.Command.Flags { + name := strings.Split(flag.GetName(), ",")[0] + if name == "help" { + continue + } + names = append(names, name) + } + return +} + +// GlobalFlagNames returns a slice of global flag names used by the app. +func (c *Context) GlobalFlagNames() (names []string) { + for _, flag := range c.App.Flags { + name := strings.Split(flag.GetName(), ",")[0] + if name == "help" || name == "version" { + continue + } + names = append(names, name) + } + return +} + +// Parent returns the parent context, if any +func (c *Context) Parent() *Context { + return c.parentContext +} + +// value returns the value of the flag coressponding to `name` +func (c *Context) value(name string) interface{} { + return c.flagSet.Lookup(name).Value.(flag.Getter).Get() +} + +// Args contains apps console arguments +type Args []string + +// Args returns the command line arguments associated with the context. +func (c *Context) Args() Args { + args := Args(c.flagSet.Args()) + return args +} + +// NArg returns the number of the command line arguments. +func (c *Context) NArg() int { + return len(c.Args()) +} + +// Get returns the nth argument, or else a blank string +func (a Args) Get(n int) string { + if len(a) > n { + return a[n] + } + return "" +} + +// First returns the first argument, or else a blank string +func (a Args) First() string { + return a.Get(0) +} + +// Tail returns the rest of the arguments (not the first one) +// or else an empty string slice +func (a Args) Tail() []string { + if len(a) >= 2 { + return []string(a)[1:] + } + return []string{} +} + +// Present checks if there are any arguments present +func (a Args) Present() bool { + return len(a) != 0 +} + +// Swap swaps arguments at the given indexes +func (a Args) Swap(from, to int) error { + if from >= len(a) || to >= len(a) { + return errors.New("index out of range") + } + a[from], a[to] = a[to], a[from] + return nil +} + +func globalContext(ctx *Context) *Context { + if ctx == nil { + return nil + } + + for { + if ctx.parentContext == nil { + return ctx + } + ctx = ctx.parentContext + } +} + +func lookupGlobalFlagSet(name string, ctx *Context) *flag.FlagSet { + if ctx.parentContext != nil { + ctx = ctx.parentContext + } + for ; ctx != nil; ctx = ctx.parentContext { + if f := ctx.flagSet.Lookup(name); f != nil { + return ctx.flagSet + } + } + return nil +} + +func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) { + switch ff.Value.(type) { + case *StringSlice: + default: + set.Set(name, ff.Value.String()) + } +} + +func normalizeFlags(flags []Flag, set *flag.FlagSet) error { + visited := make(map[string]bool) + set.Visit(func(f *flag.Flag) { + visited[f.Name] = true + }) + for _, f := range flags { + parts := strings.Split(f.GetName(), ",") + if len(parts) == 1 { + continue + } + var ff *flag.Flag + for _, name := range parts { + name = strings.Trim(name, " ") + if visited[name] { + if ff != nil { + return errors.New("Cannot use two forms of the same flag: " + name + " " + ff.Name) + } + ff = set.Lookup(name) + } + } + if ff == nil { + continue + } + for _, name := range parts { + name = strings.Trim(name, " ") + if !visited[name] { + copyFlag(name, ff, set) + } + } + } + return nil +} diff --git a/vendor/github.com/minio/cli/errors.go b/vendor/github.com/minio/cli/errors.go new file mode 100644 index 000000000..562b2953c --- /dev/null +++ b/vendor/github.com/minio/cli/errors.go @@ -0,0 +1,115 @@ +package cli + +import ( + "fmt" + "io" + "os" + "strings" +) + +// OsExiter is the function used when the app exits. If not set defaults to os.Exit. +var OsExiter = os.Exit + +// ErrWriter is used to write errors to the user. This can be anything +// implementing the io.Writer interface and defaults to os.Stderr. +var ErrWriter io.Writer = os.Stderr + +// MultiError is an error that wraps multiple errors. +type MultiError struct { + Errors []error +} + +// NewMultiError creates a new MultiError. Pass in one or more errors. +func NewMultiError(err ...error) MultiError { + return MultiError{Errors: err} +} + +// Error implements the error interface. +func (m MultiError) Error() string { + errs := make([]string, len(m.Errors)) + for i, err := range m.Errors { + errs[i] = err.Error() + } + + return strings.Join(errs, "\n") +} + +type ErrorFormatter interface { + Format(s fmt.State, verb rune) +} + +// ExitCoder is the interface checked by `App` and `Command` for a custom exit +// code +type ExitCoder interface { + error + ExitCode() int +} + +// ExitError fulfills both the builtin `error` interface and `ExitCoder` +type ExitError struct { + exitCode int + message interface{} +} + +// NewExitError makes a new *ExitError +func NewExitError(message interface{}, exitCode int) *ExitError { + return &ExitError{ + exitCode: exitCode, + message: message, + } +} + +// Error returns the string message, fulfilling the interface required by +// `error` +func (ee *ExitError) Error() string { + return fmt.Sprintf("%v", ee.message) +} + +// ExitCode returns the exit code, fulfilling the interface required by +// `ExitCoder` +func (ee *ExitError) ExitCode() int { + return ee.exitCode +} + +// HandleExitCoder checks if the error fulfills the ExitCoder interface, and if +// so prints the error to stderr (if it is non-empty) and calls OsExiter with the +// given exit code. If the given error is a MultiError, then this func is +// called on all members of the Errors slice and calls OsExiter with the last exit code. +func HandleExitCoder(err error) { + if err == nil { + return + } + + if exitErr, ok := err.(ExitCoder); ok { + if err.Error() != "" { + if _, ok := exitErr.(ErrorFormatter); ok { + fmt.Fprintf(ErrWriter, "%+v\n", err) + } else { + fmt.Fprintln(ErrWriter, err) + } + } + OsExiter(exitErr.ExitCode()) + return + } + + if multiErr, ok := err.(MultiError); ok { + code := handleMultiError(multiErr) + OsExiter(code) + return + } +} + +func handleMultiError(multiErr MultiError) int { + code := 1 + for _, merr := range multiErr.Errors { + if multiErr2, ok := merr.(MultiError); ok { + code = handleMultiError(multiErr2) + } else { + fmt.Fprintln(ErrWriter, merr) + if exitErr, ok := merr.(ExitCoder); ok { + code = exitErr.ExitCode() + } + } + } + return code +} diff --git a/vendor/github.com/minio/cli/flag.go b/vendor/github.com/minio/cli/flag.go new file mode 100644 index 000000000..877ff3523 --- /dev/null +++ b/vendor/github.com/minio/cli/flag.go @@ -0,0 +1,799 @@ +package cli + +import ( + "flag" + "fmt" + "reflect" + "runtime" + "strconv" + "strings" + "syscall" + "time" +) + +const defaultPlaceholder = "value" + +// BashCompletionFlag enables bash-completion for all commands and subcommands +var BashCompletionFlag Flag = BoolFlag{ + Name: "generate-bash-completion", + Hidden: true, +} + +// VersionFlag prints the version for the application +var VersionFlag Flag = BoolFlag{ + Name: "version, v", + Usage: "print the version", +} + +// HelpFlag prints the help for all commands and subcommands +// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand +// unless HideHelp is set to true) +var HelpFlag Flag = BoolFlag{ + Name: "help, h", + Usage: "show help", +} + +// FlagStringer converts a flag definition to a string. This is used by help +// to display a flag. +var FlagStringer FlagStringFunc = stringifyFlag + +// FlagsByName is a slice of Flag. +type FlagsByName []Flag + +func (f FlagsByName) Len() int { + return len(f) +} + +func (f FlagsByName) Less(i, j int) bool { + return f[i].GetName() < f[j].GetName() +} + +func (f FlagsByName) Swap(i, j int) { + f[i], f[j] = f[j], f[i] +} + +// Flag is a common interface related to parsing flags in cli. +// For more advanced flag parsing techniques, it is recommended that +// this interface be implemented. +type Flag interface { + fmt.Stringer + // Apply Flag settings to the given flag set + Apply(*flag.FlagSet) + GetName() string +} + +// errorableFlag is an interface that allows us to return errors during apply +// it allows flags defined in this library to return errors in a fashion backwards compatible +// TODO remove in v2 and modify the existing Flag interface to return errors +type errorableFlag interface { + Flag + + ApplyWithError(*flag.FlagSet) error +} + +func flagSet(name string, flags []Flag) (*flag.FlagSet, error) { + set := flag.NewFlagSet(name, flag.ContinueOnError) + + for _, f := range flags { + //TODO remove in v2 when errorableFlag is removed + if ef, ok := f.(errorableFlag); ok { + if err := ef.ApplyWithError(set); err != nil { + return nil, err + } + } else { + f.Apply(set) + } + } + return set, nil +} + +func eachName(longName string, fn func(string)) { + parts := strings.Split(longName, ",") + for _, name := range parts { + name = strings.Trim(name, " ") + fn(name) + } +} + +// Generic is a generic parseable type identified by a specific flag +type Generic interface { + Set(value string) error + String() string +} + +// Apply takes the flagset and calls Set on the generic flag with the value +// provided by the user for parsing by the flag +// Ignores parsing errors +func (f GenericFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError takes the flagset and calls Set on the generic flag with the value +// provided by the user for parsing by the flag +func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error { + val := f.Value + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + if err := val.Set(envVal); err != nil { + return fmt.Errorf("could not parse %s as value for flag %s: %s", envVal, f.Name, err) + } + break + } + } + } + + eachName(f.Name, func(name string) { + set.Var(f.Value, name, f.Usage) + }) + + return nil +} + +// StringSlice is an opaque type for []string to satisfy flag.Value and flag.Getter +type StringSlice []string + +// Set appends the string value to the list of values +func (f *StringSlice) Set(value string) error { + *f = append(*f, value) + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (f *StringSlice) String() string { + return fmt.Sprintf("%s", *f) +} + +// Value returns the slice of strings set by this flag +func (f *StringSlice) Value() []string { + return *f +} + +// Get returns the slice of strings set by this flag +func (f *StringSlice) Get() interface{} { + return *f +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f StringSliceFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + newVal := &StringSlice{} + for _, s := range strings.Split(envVal, ",") { + s = strings.TrimSpace(s) + if err := newVal.Set(s); err != nil { + return fmt.Errorf("could not parse %s as string value for flag %s: %s", envVal, f.Name, err) + } + } + f.Value = newVal + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Value == nil { + f.Value = &StringSlice{} + } + set.Var(f.Value, name, f.Usage) + }) + + return nil +} + +// IntSlice is an opaque type for []int to satisfy flag.Value and flag.Getter +type IntSlice []int + +// Set parses the value into an integer and appends it to the list of values +func (f *IntSlice) Set(value string) error { + tmp, err := strconv.Atoi(value) + if err != nil { + return err + } + *f = append(*f, tmp) + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (f *IntSlice) String() string { + return fmt.Sprintf("%#v", *f) +} + +// Value returns the slice of ints set by this flag +func (f *IntSlice) Value() []int { + return *f +} + +// Get returns the slice of ints set by this flag +func (f *IntSlice) Get() interface{} { + return *f +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f IntSliceFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + newVal := &IntSlice{} + for _, s := range strings.Split(envVal, ",") { + s = strings.TrimSpace(s) + if err := newVal.Set(s); err != nil { + return fmt.Errorf("could not parse %s as int slice value for flag %s: %s", envVal, f.Name, err) + } + } + f.Value = newVal + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Value == nil { + f.Value = &IntSlice{} + } + set.Var(f.Value, name, f.Usage) + }) + + return nil +} + +// Int64Slice is an opaque type for []int to satisfy flag.Value and flag.Getter +type Int64Slice []int64 + +// Set parses the value into an integer and appends it to the list of values +func (f *Int64Slice) Set(value string) error { + tmp, err := strconv.ParseInt(value, 10, 64) + if err != nil { + return err + } + *f = append(*f, tmp) + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (f *Int64Slice) String() string { + return fmt.Sprintf("%#v", *f) +} + +// Value returns the slice of ints set by this flag +func (f *Int64Slice) Value() []int64 { + return *f +} + +// Get returns the slice of ints set by this flag +func (f *Int64Slice) Get() interface{} { + return *f +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f Int64SliceFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + newVal := &Int64Slice{} + for _, s := range strings.Split(envVal, ",") { + s = strings.TrimSpace(s) + if err := newVal.Set(s); err != nil { + return fmt.Errorf("could not parse %s as int64 slice value for flag %s: %s", envVal, f.Name, err) + } + } + f.Value = newVal + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Value == nil { + f.Value = &Int64Slice{} + } + set.Var(f.Value, name, f.Usage) + }) + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f BoolFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error { + val := false + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + if envVal == "" { + val = false + break + } + + envValBool, err := strconv.ParseBool(envVal) + if err != nil { + return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) + } + + val = envValBool + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.BoolVar(f.Destination, name, val, f.Usage) + return + } + set.Bool(name, val, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f BoolTFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error { + val := true + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + if envVal == "" { + val = false + break + } + + envValBool, err := strconv.ParseBool(envVal) + if err != nil { + return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) + } + + val = envValBool + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.BoolVar(f.Destination, name, val, f.Usage) + return + } + set.Bool(name, val, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f StringFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f StringFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + f.Value = envVal + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.StringVar(f.Destination, name, f.Value, f.Usage) + return + } + set.String(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f IntFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f IntFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValInt, err := strconv.ParseInt(envVal, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) + } + f.Value = int(envValInt) + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.IntVar(f.Destination, name, f.Value, f.Usage) + return + } + set.Int(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f Int64Flag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValInt, err := strconv.ParseInt(envVal, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) + } + + f.Value = envValInt + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.Int64Var(f.Destination, name, f.Value, f.Usage) + return + } + set.Int64(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f UintFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f UintFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValInt, err := strconv.ParseUint(envVal, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %s as uint value for flag %s: %s", envVal, f.Name, err) + } + + f.Value = uint(envValInt) + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.UintVar(f.Destination, name, f.Value, f.Usage) + return + } + set.Uint(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f Uint64Flag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValInt, err := strconv.ParseUint(envVal, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %s as uint64 value for flag %s: %s", envVal, f.Name, err) + } + + f.Value = uint64(envValInt) + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.Uint64Var(f.Destination, name, f.Value, f.Usage) + return + } + set.Uint64(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f DurationFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValDuration, err := time.ParseDuration(envVal) + if err != nil { + return fmt.Errorf("could not parse %s as duration for flag %s: %s", envVal, f.Name, err) + } + + f.Value = envValDuration + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.DurationVar(f.Destination, name, f.Value, f.Usage) + return + } + set.Duration(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f Float64Flag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValFloat, err := strconv.ParseFloat(envVal, 10) + if err != nil { + return fmt.Errorf("could not parse %s as float64 value for flag %s: %s", envVal, f.Name, err) + } + + f.Value = float64(envValFloat) + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.Float64Var(f.Destination, name, f.Value, f.Usage) + return + } + set.Float64(name, f.Value, f.Usage) + }) + + return nil +} + +func visibleFlags(fl []Flag) []Flag { + visible := []Flag{} + for _, flag := range fl { + field := flagValue(flag).FieldByName("Hidden") + if !field.IsValid() || !field.Bool() { + visible = append(visible, flag) + } + } + return visible +} + +func prefixFor(name string) (prefix string) { + if len(name) == 1 { + prefix = "-" + } else { + prefix = "--" + } + + return +} + +// Returns the placeholder, if any, and the unquoted usage string. +func unquoteUsage(usage string) (string, string) { + for i := 0; i < len(usage); i++ { + if usage[i] == '`' { + for j := i + 1; j < len(usage); j++ { + if usage[j] == '`' { + name := usage[i+1 : j] + usage = usage[:i] + name + usage[j+1:] + return name, usage + } + } + break + } + } + return "", usage +} + +func prefixedNames(fullName, placeholder string) string { + var prefixed string + parts := strings.Split(fullName, ",") + for i, name := range parts { + name = strings.Trim(name, " ") + prefixed += prefixFor(name) + name + if placeholder != "" { + prefixed += " " + placeholder + } + if i < len(parts)-1 { + prefixed += ", " + } + } + return prefixed +} + +func withEnvHint(envVar, str string) string { + envText := "" + if envVar != "" { + prefix := "$" + suffix := "" + sep := ", $" + if runtime.GOOS == "windows" { + prefix = "%" + suffix = "%" + sep = "%, %" + } + envText = fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(strings.Split(envVar, ","), sep), suffix) + } + return str + envText +} + +func flagValue(f Flag) reflect.Value { + fv := reflect.ValueOf(f) + for fv.Kind() == reflect.Ptr { + fv = reflect.Indirect(fv) + } + return fv +} + +func stringifyFlag(f Flag) string { + fv := flagValue(f) + + switch f.(type) { + case IntSliceFlag: + return withEnvHint(fv.FieldByName("EnvVar").String(), + stringifyIntSliceFlag(f.(IntSliceFlag))) + case Int64SliceFlag: + return withEnvHint(fv.FieldByName("EnvVar").String(), + stringifyInt64SliceFlag(f.(Int64SliceFlag))) + case StringSliceFlag: + return withEnvHint(fv.FieldByName("EnvVar").String(), + stringifyStringSliceFlag(f.(StringSliceFlag))) + } + + placeholder, usage := unquoteUsage(fv.FieldByName("Usage").String()) + + needsPlaceholder := false + defaultValueString := "" + + if val := fv.FieldByName("Value"); val.IsValid() { + needsPlaceholder = true + defaultValueString = fmt.Sprintf(" (default: %v)", val.Interface()) + + if val.Kind() == reflect.String && val.String() != "" { + defaultValueString = fmt.Sprintf(" (default: %q)", val.String()) + } + } + + if defaultValueString == " (default: )" { + defaultValueString = "" + } + + if needsPlaceholder && placeholder == "" { + placeholder = defaultPlaceholder + } + + usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultValueString)) + + return withEnvHint(fv.FieldByName("EnvVar").String(), + fmt.Sprintf("%s\t%s", prefixedNames(fv.FieldByName("Name").String(), placeholder), usageWithDefault)) +} + +func stringifyIntSliceFlag(f IntSliceFlag) string { + defaultVals := []string{} + if f.Value != nil && len(f.Value.Value()) > 0 { + for _, i := range f.Value.Value() { + defaultVals = append(defaultVals, fmt.Sprintf("%d", i)) + } + } + + return stringifySliceFlag(f.Usage, f.Name, defaultVals) +} + +func stringifyInt64SliceFlag(f Int64SliceFlag) string { + defaultVals := []string{} + if f.Value != nil && len(f.Value.Value()) > 0 { + for _, i := range f.Value.Value() { + defaultVals = append(defaultVals, fmt.Sprintf("%d", i)) + } + } + + return stringifySliceFlag(f.Usage, f.Name, defaultVals) +} + +func stringifyStringSliceFlag(f StringSliceFlag) string { + defaultVals := []string{} + if f.Value != nil && len(f.Value.Value()) > 0 { + for _, s := range f.Value.Value() { + if len(s) > 0 { + defaultVals = append(defaultVals, fmt.Sprintf("%q", s)) + } + } + } + + return stringifySliceFlag(f.Usage, f.Name, defaultVals) +} + +func stringifySliceFlag(usage, name string, defaultVals []string) string { + placeholder, usage := unquoteUsage(usage) + if placeholder == "" { + placeholder = defaultPlaceholder + } + + defaultVal := "" + if len(defaultVals) > 0 { + defaultVal = fmt.Sprintf(" (default: %s)", strings.Join(defaultVals, ", ")) + } + + usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultVal)) + return fmt.Sprintf("%s\t%s", prefixedNames(name, placeholder), usageWithDefault) +} diff --git a/vendor/github.com/minio/cli/flag_generated.go b/vendor/github.com/minio/cli/flag_generated.go new file mode 100644 index 000000000..491b61956 --- /dev/null +++ b/vendor/github.com/minio/cli/flag_generated.go @@ -0,0 +1,627 @@ +package cli + +import ( + "flag" + "strconv" + "time" +) + +// WARNING: This file is generated! + +// BoolFlag is a flag with type bool +type BoolFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Destination *bool +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f BoolFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f BoolFlag) GetName() string { + return f.Name +} + +// Bool looks up the value of a local BoolFlag, returns +// false if not found +func (c *Context) Bool(name string) bool { + return lookupBool(name, c.flagSet) +} + +// GlobalBool looks up the value of a global BoolFlag, returns +// false if not found +func (c *Context) GlobalBool(name string) bool { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupBool(name, fs) + } + return false +} + +func lookupBool(name string, set *flag.FlagSet) bool { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseBool(f.Value.String()) + if err != nil { + return false + } + return parsed + } + return false +} + +// BoolTFlag is a flag with type bool that is true by default +type BoolTFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Destination *bool +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f BoolTFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f BoolTFlag) GetName() string { + return f.Name +} + +// BoolT looks up the value of a local BoolTFlag, returns +// false if not found +func (c *Context) BoolT(name string) bool { + return lookupBoolT(name, c.flagSet) +} + +// GlobalBoolT looks up the value of a global BoolTFlag, returns +// false if not found +func (c *Context) GlobalBoolT(name string) bool { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupBoolT(name, fs) + } + return false +} + +func lookupBoolT(name string, set *flag.FlagSet) bool { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseBool(f.Value.String()) + if err != nil { + return false + } + return parsed + } + return false +} + +// DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration) +type DurationFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value time.Duration + Destination *time.Duration +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f DurationFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f DurationFlag) GetName() string { + return f.Name +} + +// Duration looks up the value of a local DurationFlag, returns +// 0 if not found +func (c *Context) Duration(name string) time.Duration { + return lookupDuration(name, c.flagSet) +} + +// GlobalDuration looks up the value of a global DurationFlag, returns +// 0 if not found +func (c *Context) GlobalDuration(name string) time.Duration { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupDuration(name, fs) + } + return 0 +} + +func lookupDuration(name string, set *flag.FlagSet) time.Duration { + f := set.Lookup(name) + if f != nil { + parsed, err := time.ParseDuration(f.Value.String()) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// Float64Flag is a flag with type float64 +type Float64Flag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value float64 + Destination *float64 +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Float64Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Float64Flag) GetName() string { + return f.Name +} + +// Float64 looks up the value of a local Float64Flag, returns +// 0 if not found +func (c *Context) Float64(name string) float64 { + return lookupFloat64(name, c.flagSet) +} + +// GlobalFloat64 looks up the value of a global Float64Flag, returns +// 0 if not found +func (c *Context) GlobalFloat64(name string) float64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupFloat64(name, fs) + } + return 0 +} + +func lookupFloat64(name string, set *flag.FlagSet) float64 { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseFloat(f.Value.String(), 64) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// GenericFlag is a flag with type Generic +type GenericFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value Generic +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f GenericFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f GenericFlag) GetName() string { + return f.Name +} + +// Generic looks up the value of a local GenericFlag, returns +// nil if not found +func (c *Context) Generic(name string) interface{} { + return lookupGeneric(name, c.flagSet) +} + +// GlobalGeneric looks up the value of a global GenericFlag, returns +// nil if not found +func (c *Context) GlobalGeneric(name string) interface{} { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupGeneric(name, fs) + } + return nil +} + +func lookupGeneric(name string, set *flag.FlagSet) interface{} { + f := set.Lookup(name) + if f != nil { + parsed, err := f.Value, error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// Int64Flag is a flag with type int64 +type Int64Flag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value int64 + Destination *int64 +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Int64Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Int64Flag) GetName() string { + return f.Name +} + +// Int64 looks up the value of a local Int64Flag, returns +// 0 if not found +func (c *Context) Int64(name string) int64 { + return lookupInt64(name, c.flagSet) +} + +// GlobalInt64 looks up the value of a global Int64Flag, returns +// 0 if not found +func (c *Context) GlobalInt64(name string) int64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupInt64(name, fs) + } + return 0 +} + +func lookupInt64(name string, set *flag.FlagSet) int64 { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// IntFlag is a flag with type int +type IntFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value int + Destination *int +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f IntFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f IntFlag) GetName() string { + return f.Name +} + +// Int looks up the value of a local IntFlag, returns +// 0 if not found +func (c *Context) Int(name string) int { + return lookupInt(name, c.flagSet) +} + +// GlobalInt looks up the value of a global IntFlag, returns +// 0 if not found +func (c *Context) GlobalInt(name string) int { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupInt(name, fs) + } + return 0 +} + +func lookupInt(name string, set *flag.FlagSet) int { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return int(parsed) + } + return 0 +} + +// IntSliceFlag is a flag with type *IntSlice +type IntSliceFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value *IntSlice +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f IntSliceFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f IntSliceFlag) GetName() string { + return f.Name +} + +// IntSlice looks up the value of a local IntSliceFlag, returns +// nil if not found +func (c *Context) IntSlice(name string) []int { + return lookupIntSlice(name, c.flagSet) +} + +// GlobalIntSlice looks up the value of a global IntSliceFlag, returns +// nil if not found +func (c *Context) GlobalIntSlice(name string) []int { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupIntSlice(name, fs) + } + return nil +} + +func lookupIntSlice(name string, set *flag.FlagSet) []int { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*IntSlice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// Int64SliceFlag is a flag with type *Int64Slice +type Int64SliceFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value *Int64Slice +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Int64SliceFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Int64SliceFlag) GetName() string { + return f.Name +} + +// Int64Slice looks up the value of a local Int64SliceFlag, returns +// nil if not found +func (c *Context) Int64Slice(name string) []int64 { + return lookupInt64Slice(name, c.flagSet) +} + +// GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns +// nil if not found +func (c *Context) GlobalInt64Slice(name string) []int64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupInt64Slice(name, fs) + } + return nil +} + +func lookupInt64Slice(name string, set *flag.FlagSet) []int64 { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// StringFlag is a flag with type string +type StringFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value string + Destination *string +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f StringFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f StringFlag) GetName() string { + return f.Name +} + +// String looks up the value of a local StringFlag, returns +// "" if not found +func (c *Context) String(name string) string { + return lookupString(name, c.flagSet) +} + +// GlobalString looks up the value of a global StringFlag, returns +// "" if not found +func (c *Context) GlobalString(name string) string { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupString(name, fs) + } + return "" +} + +func lookupString(name string, set *flag.FlagSet) string { + f := set.Lookup(name) + if f != nil { + parsed, err := f.Value.String(), error(nil) + if err != nil { + return "" + } + return parsed + } + return "" +} + +// StringSliceFlag is a flag with type *StringSlice +type StringSliceFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value *StringSlice +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f StringSliceFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f StringSliceFlag) GetName() string { + return f.Name +} + +// StringSlice looks up the value of a local StringSliceFlag, returns +// nil if not found +func (c *Context) StringSlice(name string) []string { + return lookupStringSlice(name, c.flagSet) +} + +// GlobalStringSlice looks up the value of a global StringSliceFlag, returns +// nil if not found +func (c *Context) GlobalStringSlice(name string) []string { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupStringSlice(name, fs) + } + return nil +} + +func lookupStringSlice(name string, set *flag.FlagSet) []string { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*StringSlice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// Uint64Flag is a flag with type uint64 +type Uint64Flag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value uint64 + Destination *uint64 +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Uint64Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Uint64Flag) GetName() string { + return f.Name +} + +// Uint64 looks up the value of a local Uint64Flag, returns +// 0 if not found +func (c *Context) Uint64(name string) uint64 { + return lookupUint64(name, c.flagSet) +} + +// GlobalUint64 looks up the value of a global Uint64Flag, returns +// 0 if not found +func (c *Context) GlobalUint64(name string) uint64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupUint64(name, fs) + } + return 0 +} + +func lookupUint64(name string, set *flag.FlagSet) uint64 { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// UintFlag is a flag with type uint +type UintFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value uint + Destination *uint +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f UintFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f UintFlag) GetName() string { + return f.Name +} + +// Uint looks up the value of a local UintFlag, returns +// 0 if not found +func (c *Context) Uint(name string) uint { + return lookupUint(name, c.flagSet) +} + +// GlobalUint looks up the value of a global UintFlag, returns +// 0 if not found +func (c *Context) GlobalUint(name string) uint { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupUint(name, fs) + } + return 0 +} + +func lookupUint(name string, set *flag.FlagSet) uint { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return uint(parsed) + } + return 0 +} diff --git a/vendor/github.com/minio/cli/funcs.go b/vendor/github.com/minio/cli/funcs.go new file mode 100644 index 000000000..cba5e6cb0 --- /dev/null +++ b/vendor/github.com/minio/cli/funcs.go @@ -0,0 +1,28 @@ +package cli + +// BashCompleteFunc is an action to execute when the bash-completion flag is set +type BashCompleteFunc func(*Context) + +// BeforeFunc is an action to execute before any subcommands are run, but after +// the context is ready if a non-nil error is returned, no subcommands are run +type BeforeFunc func(*Context) error + +// AfterFunc is an action to execute after any subcommands are run, but after the +// subcommand has finished it is run even if Action() panics +type AfterFunc func(*Context) error + +// ActionFunc is the action to execute when no subcommands are specified +type ActionFunc func(*Context) error + +// CommandNotFoundFunc is executed if the proper command cannot be found +type CommandNotFoundFunc func(*Context, string) + +// OnUsageErrorFunc is executed if an usage error occurs. This is useful for displaying +// customized usage error messages. This function is able to replace the +// original error messages. If this function is not set, the "Incorrect usage" +// is displayed and the execution is interrupted. +type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error + +// FlagStringFunc is used by the help generation to display a flag, which is +// expected to be a single line. +type FlagStringFunc func(Flag) string diff --git a/vendor/github.com/minio/cli/help.go b/vendor/github.com/minio/cli/help.go new file mode 100644 index 000000000..e6cb66a4c --- /dev/null +++ b/vendor/github.com/minio/cli/help.go @@ -0,0 +1,337 @@ +package cli + +import ( + "fmt" + "io" + "os" + "strings" + "text/tabwriter" + "text/template" +) + +// AppHelpTemplate is the text template for the Default help topic. +// cli.go uses text/template to render templates. You can +// render custom help text by setting this variable. +var AppHelpTemplate = `NAME: + {{.Name}}{{if .Usage}} - {{.Usage}}{{end}} + +USAGE: + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} + +VERSION: + {{.Version}}{{end}}{{end}}{{if .Description}} + +DESCRIPTION: + {{.Description}}{{end}}{{if len .Authors}} + +AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: + {{range $index, $author := .Authors}}{{if $index}} + {{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}} + +COMMANDS:{{range .VisibleCategories}}{{if .Name}} + {{.Name}}:{{end}}{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} + +GLOBAL FLAGS: + {{range $index, $option := .VisibleFlags}}{{if $index}} + {{end}}{{$option}}{{end}}{{end}}{{if .Copyright}} + +COPYRIGHT: + {{.Copyright}}{{end}} +` + +// CommandHelpTemplate is the text template for the command help topic. +// cli.go uses text/template to render templates. You can +// render custom help text by setting this variable. +var CommandHelpTemplate = `NAME: + {{.HelpName}} - {{.Usage}} + +USAGE: + {{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{if .Category}} + +CATEGORY: + {{.Category}}{{end}}{{if .Description}} + +DESCRIPTION: + {{.Description}}{{end}}{{if .VisibleFlags}} + +FLAGS: + {{range .VisibleFlags}}{{.}} + {{end}}{{end}} +` + +// SubcommandHelpTemplate is the text template for the subcommand help topic. +// cli.go uses text/template to render templates. You can +// render custom help text by setting this variable. +var SubcommandHelpTemplate = `NAME: + {{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}} + +USAGE: + {{.HelpName}} COMMAND{{if .VisibleFlags}} [COMMAND FLAGS | -h]{{end}} [ARGUMENTS...] + +COMMANDS: + {{range .VisibleCommands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} + {{end}}{{if .VisibleFlags}} +FLAGS: + {{range .VisibleFlags}}{{.}} + {{end}}{{end}} +` + +var helpCommand = Command{ + Name: "help", + Aliases: []string{"h"}, + Usage: "Shows a list of commands or help for one command", + ArgsUsage: "[command]", + Action: func(c *Context) error { + args := c.Args() + if args.Present() { + return ShowCommandHelp(c, args.First()) + } + + ShowAppHelp(c) + return nil + }, +} + +var helpSubcommand = Command{ + Name: "help", + Aliases: []string{"h"}, + Usage: "Shows a list of commands or help for one command", + ArgsUsage: "[command]", + Action: func(c *Context) error { + args := c.Args() + if args.Present() { + return ShowCommandHelp(c, args.First()) + } + + return ShowSubcommandHelp(c) + }, +} + +// Prints help for the App or Command +type helpPrinter func(w io.Writer, templ string, data interface{}) + +// Prints help for the App or Command with custom template function. +type helpPrinterCustom func(w io.Writer, templ string, data interface{}, customFunc map[string]interface{}) + +// HelpPrinter is a function that writes the help output. If not set a default +// is used. The function signature is: +// func(w io.Writer, templ string, data interface{}) +var HelpPrinter helpPrinter = printHelp + +// HelpPrinterCustom is same as HelpPrinter but +// takes a custom function for template function map. +var HelpPrinterCustom helpPrinterCustom = printHelpCustom + +// VersionPrinter prints the version for the App +var VersionPrinter = printVersion + +// ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code. +func ShowAppHelpAndExit(c *Context, exitCode int) { + ShowAppHelp(c) + os.Exit(exitCode) +} + +// ShowAppHelp is an action that displays the help. +func ShowAppHelp(c *Context) (err error) { + if c.App.CustomAppHelpTemplate == "" { + HelpPrinter(c.App.Writer, AppHelpTemplate, c.App) + return + } + customAppData := func() map[string]interface{} { + if c.App.ExtraInfo == nil { + return nil + } + return map[string]interface{}{ + "ExtraInfo": c.App.ExtraInfo, + } + } + HelpPrinterCustom(c.App.Writer, c.App.CustomAppHelpTemplate, c.App, customAppData()) + return nil +} + +// DefaultAppComplete prints the list of subcommands as the default app completion method +func DefaultAppComplete(c *Context) { + for _, command := range c.App.Commands { + if command.Hidden { + continue + } + for _, name := range command.Names() { + fmt.Fprintln(c.App.Writer, name) + } + } +} + +// ShowCommandHelpAndExit - exits with code after showing help +func ShowCommandHelpAndExit(c *Context, command string, code int) { + ShowCommandHelp(c, command) + os.Exit(code) +} + +// ShowCommandHelp prints help for the given command +func ShowCommandHelp(ctx *Context, command string) error { + // show the subcommand help for a command with subcommands + if command == "" { + HelpPrinter(ctx.App.Writer, SubcommandHelpTemplate, ctx.App) + return nil + } + + for _, c := range ctx.App.Commands { + if c.HasName(command) { + if c.CustomHelpTemplate != "" { + HelpPrinterCustom(ctx.App.Writer, c.CustomHelpTemplate, c, nil) + } else { + HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c) + } + return nil + } + } + + if ctx.App.CommandNotFound == nil { + return NewExitError(fmt.Sprintf("No help topic for '%v'", command), 3) + } + + ctx.App.CommandNotFound(ctx, command) + return nil +} + +// ShowSubcommandHelp prints help for the given subcommand +func ShowSubcommandHelp(c *Context) error { + return ShowCommandHelp(c, c.Command.Name) +} + +// ShowVersion prints the version number of the App +func ShowVersion(c *Context) { + VersionPrinter(c) +} + +func printVersion(c *Context) { + fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version) +} + +// ShowCompletions prints the lists of commands within a given context +func ShowCompletions(c *Context) { + a := c.App + if a != nil && a.BashComplete != nil { + a.BashComplete(c) + } +} + +// ShowCommandCompletions prints the custom completions for a given command +func ShowCommandCompletions(ctx *Context, command string) { + c := ctx.App.Command(command) + if c != nil && c.BashComplete != nil { + c.BashComplete(ctx) + } +} + +func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc map[string]interface{}) { + funcMap := template.FuncMap{ + "join": strings.Join, + } + if customFunc != nil { + for key, value := range customFunc { + funcMap[key] = value + } + } + + w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0) + t := template.Must(template.New("help").Funcs(funcMap).Parse(templ)) + err := t.Execute(w, data) + if err != nil { + // If the writer is closed, t.Execute will fail, and there's nothing + // we can do to recover. + if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" { + fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err) + } + return + } + w.Flush() +} + +func printHelp(out io.Writer, templ string, data interface{}) { + printHelpCustom(out, templ, data, nil) +} + +func checkVersion(c *Context) bool { + found := false + if VersionFlag.GetName() != "" { + eachName(VersionFlag.GetName(), func(name string) { + if c.GlobalBool(name) || c.Bool(name) { + found = true + } + }) + } + return found +} + +func checkHelp(c *Context) bool { + found := false + if HelpFlag.GetName() != "" { + eachName(HelpFlag.GetName(), func(name string) { + if c.GlobalBool(name) || c.Bool(name) { + found = true + } + }) + } + return found +} + +func checkCommandHelp(c *Context, name string) bool { + if c.Bool("h") || c.Bool("help") { + ShowCommandHelp(c, name) + return true + } + + return false +} + +func checkSubcommandHelp(c *Context) bool { + if c.Bool("h") || c.Bool("help") { + ShowSubcommandHelp(c) + return true + } + + return false +} + +func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) { + if !a.EnableBashCompletion { + return false, arguments + } + + pos := len(arguments) - 1 + lastArg := arguments[pos] + + if lastArg != "--"+BashCompletionFlag.GetName() { + return false, arguments + } + + return true, arguments[:pos] +} + +func checkCompletions(c *Context) bool { + if !c.shellComplete { + return false + } + + if args := c.Args(); args.Present() { + name := args.First() + if cmd := c.App.Command(name); cmd != nil { + // let the command handle the completion + return false + } + } + + ShowCompletions(c) + return true +} + +func checkCommandCompletions(c *Context, name string) bool { + if !c.shellComplete { + return false + } + + ShowCommandCompletions(c, name) + return true +} diff --git a/vendor/github.com/minio/minio-go/LICENSE b/vendor/github.com/minio/minio-go/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/vendor/github.com/minio/minio-go/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/minio/minio-go/api-compose-object.go b/vendor/github.com/minio/minio-go/api-compose-object.go new file mode 100644 index 000000000..81314e3b4 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-compose-object.go @@ -0,0 +1,629 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "encoding/base64" + "fmt" + "net/http" + "net/url" + "strconv" + "strings" + "time" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// SSEInfo - represents Server-Side-Encryption parameters specified by +// a user. +type SSEInfo struct { + key []byte + algo string +} + +// NewSSEInfo - specifies (binary or un-encoded) encryption key and +// algorithm name. If algo is empty, it defaults to "AES256". Ref: +// https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerSideEncryptionCustomerKeys.html +func NewSSEInfo(key []byte, algo string) SSEInfo { + if algo == "" { + algo = "AES256" + } + return SSEInfo{key, algo} +} + +// internal method that computes SSE-C headers +func (s *SSEInfo) getSSEHeaders(isCopySource bool) map[string]string { + if s == nil { + return nil + } + + cs := "" + if isCopySource { + cs = "copy-source-" + } + return map[string]string{ + "x-amz-" + cs + "server-side-encryption-customer-algorithm": s.algo, + "x-amz-" + cs + "server-side-encryption-customer-key": base64.StdEncoding.EncodeToString(s.key), + "x-amz-" + cs + "server-side-encryption-customer-key-MD5": sumMD5Base64(s.key), + } +} + +// GetSSEHeaders - computes and returns headers for SSE-C as key-value +// pairs. They can be set as metadata in PutObject* requests (for +// encryption) or be set as request headers in `Core.GetObject` (for +// decryption). +func (s *SSEInfo) GetSSEHeaders() map[string]string { + return s.getSSEHeaders(false) +} + +// DestinationInfo - type with information about the object to be +// created via server-side copy requests, using the Compose API. +type DestinationInfo struct { + bucket, object string + + // key for encrypting destination + encryption *SSEInfo + + // if no user-metadata is provided, it is copied from source + // (when there is only once source object in the compose + // request) + userMetadata map[string]string +} + +// NewDestinationInfo - creates a compose-object/copy-source +// destination info object. +// +// `encSSEC` is the key info for server-side-encryption with customer +// provided key. If it is nil, no encryption is performed. +// +// `userMeta` is the user-metadata key-value pairs to be set on the +// destination. The keys are automatically prefixed with `x-amz-meta-` +// if needed. If nil is passed, and if only a single source (of any +// size) is provided in the ComposeObject call, then metadata from the +// source is copied to the destination. +func NewDestinationInfo(bucket, object string, encryptSSEC *SSEInfo, + userMeta map[string]string) (d DestinationInfo, err error) { + + // Input validation. + if err = s3utils.CheckValidBucketName(bucket); err != nil { + return d, err + } + if err = s3utils.CheckValidObjectName(object); err != nil { + return d, err + } + + // Process custom-metadata to remove a `x-amz-meta-` prefix if + // present and validate that keys are distinct (after this + // prefix removal). + m := make(map[string]string) + for k, v := range userMeta { + if strings.HasPrefix(strings.ToLower(k), "x-amz-meta-") { + k = k[len("x-amz-meta-"):] + } + if _, ok := m[k]; ok { + return d, ErrInvalidArgument(fmt.Sprintf("Cannot add both %s and x-amz-meta-%s keys as custom metadata", k, k)) + } + m[k] = v + } + + return DestinationInfo{ + bucket: bucket, + object: object, + encryption: encryptSSEC, + userMetadata: m, + }, nil +} + +// getUserMetaHeadersMap - construct appropriate key-value pairs to send +// as headers from metadata map to pass into copy-object request. For +// single part copy-object (i.e. non-multipart object), enable the +// withCopyDirectiveHeader to set the `x-amz-metadata-directive` to +// `REPLACE`, so that metadata headers from the source are not copied +// over. +func (d *DestinationInfo) getUserMetaHeadersMap(withCopyDirectiveHeader bool) map[string]string { + if len(d.userMetadata) == 0 { + return nil + } + r := make(map[string]string) + if withCopyDirectiveHeader { + r["x-amz-metadata-directive"] = "REPLACE" + } + for k, v := range d.userMetadata { + r["x-amz-meta-"+k] = v + } + return r +} + +// SourceInfo - represents a source object to be copied, using +// server-side copying APIs. +type SourceInfo struct { + bucket, object string + + start, end int64 + + decryptKey *SSEInfo + // Headers to send with the upload-part-copy request involving + // this source object. + Headers http.Header +} + +// NewSourceInfo - create a compose-object/copy-object source info +// object. +// +// `decryptSSEC` is the decryption key using server-side-encryption +// with customer provided key. It may be nil if the source is not +// encrypted. +func NewSourceInfo(bucket, object string, decryptSSEC *SSEInfo) SourceInfo { + r := SourceInfo{ + bucket: bucket, + object: object, + start: -1, // range is unspecified by default + decryptKey: decryptSSEC, + Headers: make(http.Header), + } + + // Set the source header + r.Headers.Set("x-amz-copy-source", s3utils.EncodePath(bucket+"/"+object)) + + // Assemble decryption headers for upload-part-copy request + for k, v := range decryptSSEC.getSSEHeaders(true) { + r.Headers.Set(k, v) + } + + return r +} + +// SetRange - Set the start and end offset of the source object to be +// copied. If this method is not called, the whole source object is +// copied. +func (s *SourceInfo) SetRange(start, end int64) error { + if start > end || start < 0 { + return ErrInvalidArgument("start must be non-negative, and start must be at most end.") + } + // Note that 0 <= start <= end + s.start, s.end = start, end + return nil +} + +// SetMatchETagCond - Set ETag match condition. The object is copied +// only if the etag of the source matches the value given here. +func (s *SourceInfo) SetMatchETagCond(etag string) error { + if etag == "" { + return ErrInvalidArgument("ETag cannot be empty.") + } + s.Headers.Set("x-amz-copy-source-if-match", etag) + return nil +} + +// SetMatchETagExceptCond - Set the ETag match exception +// condition. The object is copied only if the etag of the source is +// not the value given here. +func (s *SourceInfo) SetMatchETagExceptCond(etag string) error { + if etag == "" { + return ErrInvalidArgument("ETag cannot be empty.") + } + s.Headers.Set("x-amz-copy-source-if-none-match", etag) + return nil +} + +// SetModifiedSinceCond - Set the modified since condition. +func (s *SourceInfo) SetModifiedSinceCond(modTime time.Time) error { + if modTime.IsZero() { + return ErrInvalidArgument("Input time cannot be 0.") + } + s.Headers.Set("x-amz-copy-source-if-modified-since", modTime.Format(http.TimeFormat)) + return nil +} + +// SetUnmodifiedSinceCond - Set the unmodified since condition. +func (s *SourceInfo) SetUnmodifiedSinceCond(modTime time.Time) error { + if modTime.IsZero() { + return ErrInvalidArgument("Input time cannot be 0.") + } + s.Headers.Set("x-amz-copy-source-if-unmodified-since", modTime.Format(http.TimeFormat)) + return nil +} + +// Helper to fetch size and etag of an object using a StatObject call. +func (s *SourceInfo) getProps(c Client) (size int64, etag string, userMeta map[string]string, err error) { + // Get object info - need size and etag here. Also, decryption + // headers are added to the stat request if given. + var objInfo ObjectInfo + opts := StatObjectOptions{} + for k, v := range s.decryptKey.getSSEHeaders(false) { + opts.Set(k, v) + } + objInfo, err = c.statObject(context.Background(), s.bucket, s.object, opts) + if err != nil { + err = ErrInvalidArgument(fmt.Sprintf("Could not stat object - %s/%s: %v", s.bucket, s.object, err)) + } else { + size = objInfo.Size + etag = objInfo.ETag + userMeta = make(map[string]string) + for k, v := range objInfo.Metadata { + if strings.HasPrefix(k, "x-amz-meta-") { + if len(v) > 0 { + userMeta[k] = v[0] + } + } + } + } + return +} + +// Low level implementation of CopyObject API, supports only upto 5GiB worth of copy. +func (c Client) copyObjectDo(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, + metadata map[string]string) (ObjectInfo, error) { + + // Build headers. + headers := make(http.Header) + + // Set all the metadata headers. + for k, v := range metadata { + headers.Set(k, v) + } + + // Set the source header + headers.Set("x-amz-copy-source", s3utils.EncodePath(srcBucket+"/"+srcObject)) + + // Send upload-part-copy request + resp, err := c.executeMethod(ctx, "PUT", requestMetadata{ + bucketName: destBucket, + objectName: destObject, + customHeader: headers, + }) + defer closeResponse(resp) + if err != nil { + return ObjectInfo{}, err + } + + // Check if we got an error response. + if resp.StatusCode != http.StatusOK { + return ObjectInfo{}, httpRespToErrorResponse(resp, srcBucket, srcObject) + } + + cpObjRes := copyObjectResult{} + err = xmlDecoder(resp.Body, &cpObjRes) + if err != nil { + return ObjectInfo{}, err + } + + objInfo := ObjectInfo{ + Key: destObject, + ETag: strings.Trim(cpObjRes.ETag, "\""), + LastModified: cpObjRes.LastModified, + } + return objInfo, nil +} + +func (c Client) copyObjectPartDo(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, uploadID string, + partID int, startOffset int64, length int64, metadata map[string]string) (p CompletePart, err error) { + + headers := make(http.Header) + + // Set source + headers.Set("x-amz-copy-source", s3utils.EncodePath(srcBucket+"/"+srcObject)) + + if startOffset < 0 { + return p, ErrInvalidArgument("startOffset must be non-negative") + } + + if length >= 0 { + headers.Set("x-amz-copy-source-range", fmt.Sprintf("bytes=%d-%d", startOffset, startOffset+length-1)) + } + + for k, v := range metadata { + headers.Set(k, v) + } + + queryValues := make(url.Values) + queryValues.Set("partNumber", strconv.Itoa(partID)) + queryValues.Set("uploadId", uploadID) + + resp, err := c.executeMethod(ctx, "PUT", requestMetadata{ + bucketName: destBucket, + objectName: destObject, + customHeader: headers, + queryValues: queryValues, + }) + defer closeResponse(resp) + if err != nil { + return + } + + // Check if we got an error response. + if resp.StatusCode != http.StatusOK { + return p, httpRespToErrorResponse(resp, destBucket, destObject) + } + + // Decode copy-part response on success. + cpObjRes := copyObjectResult{} + err = xmlDecoder(resp.Body, &cpObjRes) + if err != nil { + return p, err + } + p.PartNumber, p.ETag = partID, cpObjRes.ETag + return p, nil +} + +// uploadPartCopy - helper function to create a part in a multipart +// upload via an upload-part-copy request +// https://docs.aws.amazon.com/AmazonS3/latest/API/mpUploadUploadPartCopy.html +func (c Client) uploadPartCopy(ctx context.Context, bucket, object, uploadID string, partNumber int, + headers http.Header) (p CompletePart, err error) { + + // Build query parameters + urlValues := make(url.Values) + urlValues.Set("partNumber", strconv.Itoa(partNumber)) + urlValues.Set("uploadId", uploadID) + + // Send upload-part-copy request + resp, err := c.executeMethod(ctx, "PUT", requestMetadata{ + bucketName: bucket, + objectName: object, + customHeader: headers, + queryValues: urlValues, + }) + defer closeResponse(resp) + if err != nil { + return p, err + } + + // Check if we got an error response. + if resp.StatusCode != http.StatusOK { + return p, httpRespToErrorResponse(resp, bucket, object) + } + + // Decode copy-part response on success. + cpObjRes := copyObjectResult{} + err = xmlDecoder(resp.Body, &cpObjRes) + if err != nil { + return p, err + } + p.PartNumber, p.ETag = partNumber, cpObjRes.ETag + return p, nil +} + +// ComposeObject - creates an object using server-side copying of +// existing objects. It takes a list of source objects (with optional +// offsets) and concatenates them into a new object using only +// server-side copying operations. +func (c Client) ComposeObject(dst DestinationInfo, srcs []SourceInfo) error { + if len(srcs) < 1 || len(srcs) > maxPartsCount { + return ErrInvalidArgument("There must be as least one and up to 10000 source objects.") + } + ctx := context.Background() + srcSizes := make([]int64, len(srcs)) + var totalSize, size, totalParts int64 + var srcUserMeta map[string]string + var etag string + var err error + for i, src := range srcs { + size, etag, srcUserMeta, err = src.getProps(c) + if err != nil { + return err + } + + // Error out if client side encryption is used in this source object when + // more than one source objects are given. + if len(srcs) > 1 && src.Headers.Get("x-amz-meta-x-amz-key") != "" { + return ErrInvalidArgument( + fmt.Sprintf("Client side encryption is used in source object %s/%s", src.bucket, src.object)) + } + + // Since we did a HEAD to get size, we use the ETag + // value to make sure the object has not changed by + // the time we perform the copy. This is done, only if + // the user has not set their own ETag match + // condition. + if src.Headers.Get("x-amz-copy-source-if-match") == "" { + src.SetMatchETagCond(etag) + } + + // Check if a segment is specified, and if so, is the + // segment within object bounds? + if src.start != -1 { + // Since range is specified, + // 0 <= src.start <= src.end + // so only invalid case to check is: + if src.end >= size { + return ErrInvalidArgument( + fmt.Sprintf("SourceInfo %d has invalid segment-to-copy [%d, %d] (size is %d)", + i, src.start, src.end, size)) + } + size = src.end - src.start + 1 + } + + // Only the last source may be less than `absMinPartSize` + if size < absMinPartSize && i < len(srcs)-1 { + return ErrInvalidArgument( + fmt.Sprintf("SourceInfo %d is too small (%d) and it is not the last part", i, size)) + } + + // Is data to copy too large? + totalSize += size + if totalSize > maxMultipartPutObjectSize { + return ErrInvalidArgument(fmt.Sprintf("Cannot compose an object of size %d (> 5TiB)", totalSize)) + } + + // record source size + srcSizes[i] = size + + // calculate parts needed for current source + totalParts += partsRequired(size) + // Do we need more parts than we are allowed? + if totalParts > maxPartsCount { + return ErrInvalidArgument(fmt.Sprintf( + "Your proposed compose object requires more than %d parts", maxPartsCount)) + } + } + + // Single source object case (i.e. when only one source is + // involved, it is being copied wholly and at most 5GiB in + // size). + if totalParts == 1 && srcs[0].start == -1 && totalSize <= maxPartSize { + h := srcs[0].Headers + // Add destination encryption headers + for k, v := range dst.encryption.getSSEHeaders(false) { + h.Set(k, v) + } + + // If no user metadata is specified (and so, the + // for-loop below is not entered), metadata from the + // source is copied to the destination (due to + // single-part copy-object PUT request behaviour). + for k, v := range dst.getUserMetaHeadersMap(true) { + h.Set(k, v) + } + + // Send copy request + resp, err := c.executeMethod(ctx, "PUT", requestMetadata{ + bucketName: dst.bucket, + objectName: dst.object, + customHeader: h, + }) + defer closeResponse(resp) + if err != nil { + return err + } + // Check if we got an error response. + if resp.StatusCode != http.StatusOK { + return httpRespToErrorResponse(resp, dst.bucket, dst.object) + } + + // Return nil on success. + return nil + } + + // Now, handle multipart-copy cases. + + // 1. Initiate a new multipart upload. + + // Set user-metadata on the destination object. If no + // user-metadata is specified, and there is only one source, + // (only) then metadata from source is copied. + userMeta := dst.getUserMetaHeadersMap(false) + metaMap := userMeta + if len(userMeta) == 0 && len(srcs) == 1 { + metaMap = srcUserMeta + } + metaHeaders := make(map[string]string) + for k, v := range metaMap { + metaHeaders[k] = v + } + uploadID, err := c.newUploadID(ctx, dst.bucket, dst.object, PutObjectOptions{UserMetadata: metaHeaders}) + if err != nil { + return err + } + + // 2. Perform copy part uploads + objParts := []CompletePart{} + partIndex := 1 + for i, src := range srcs { + h := src.Headers + // Add destination encryption headers + for k, v := range dst.encryption.getSSEHeaders(false) { + h.Set(k, v) + } + + // calculate start/end indices of parts after + // splitting. + startIdx, endIdx := calculateEvenSplits(srcSizes[i], src) + for j, start := range startIdx { + end := endIdx[j] + + // Add (or reset) source range header for + // upload part copy request. + h.Set("x-amz-copy-source-range", + fmt.Sprintf("bytes=%d-%d", start, end)) + + // make upload-part-copy request + complPart, err := c.uploadPartCopy(ctx, dst.bucket, + dst.object, uploadID, partIndex, h) + if err != nil { + return err + } + objParts = append(objParts, complPart) + partIndex++ + } + } + + // 3. Make final complete-multipart request. + _, err = c.completeMultipartUpload(ctx, dst.bucket, dst.object, uploadID, + completeMultipartUpload{Parts: objParts}) + if err != nil { + return err + } + return nil +} + +// partsRequired is ceiling(size / copyPartSize) +func partsRequired(size int64) int64 { + r := size / copyPartSize + if size%copyPartSize > 0 { + r++ + } + return r +} + +// calculateEvenSplits - computes splits for a source and returns +// start and end index slices. Splits happen evenly to be sure that no +// part is less than 5MiB, as that could fail the multipart request if +// it is not the last part. +func calculateEvenSplits(size int64, src SourceInfo) (startIndex, endIndex []int64) { + if size == 0 { + return + } + + reqParts := partsRequired(size) + startIndex = make([]int64, reqParts) + endIndex = make([]int64, reqParts) + // Compute number of required parts `k`, as: + // + // k = ceiling(size / copyPartSize) + // + // Now, distribute the `size` bytes in the source into + // k parts as evenly as possible: + // + // r parts sized (q+1) bytes, and + // (k - r) parts sized q bytes, where + // + // size = q * k + r (by simple division of size by k, + // so that 0 <= r < k) + // + start := src.start + if start == -1 { + start = 0 + } + quot, rem := size/reqParts, size%reqParts + nextStart := start + for j := int64(0); j < reqParts; j++ { + curPartSize := quot + if j < rem { + curPartSize++ + } + + cStart := nextStart + cEnd := cStart + curPartSize - 1 + nextStart = cEnd + 1 + + startIndex[j], endIndex[j] = cStart, cEnd + } + return +} diff --git a/vendor/github.com/minio/minio-go/api-datatypes.go b/vendor/github.com/minio/minio-go/api-datatypes.go new file mode 100644 index 000000000..63fc08905 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-datatypes.go @@ -0,0 +1,84 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "net/http" + "time" +) + +// BucketInfo container for bucket metadata. +type BucketInfo struct { + // The name of the bucket. + Name string `json:"name"` + // Date the bucket was created. + CreationDate time.Time `json:"creationDate"` +} + +// ObjectInfo container for object metadata. +type ObjectInfo struct { + // An ETag is optionally set to md5sum of an object. In case of multipart objects, + // ETag is of the form MD5SUM-N where MD5SUM is md5sum of all individual md5sums of + // each parts concatenated into one string. + ETag string `json:"etag"` + + Key string `json:"name"` // Name of the object + LastModified time.Time `json:"lastModified"` // Date and time the object was last modified. + Size int64 `json:"size"` // Size in bytes of the object. + ContentType string `json:"contentType"` // A standard MIME type describing the format of the object data. + + // Collection of additional metadata on the object. + // eg: x-amz-meta-*, content-encoding etc. + Metadata http.Header `json:"metadata" xml:"-"` + + // Owner name. + Owner struct { + DisplayName string `json:"name"` + ID string `json:"id"` + } `json:"owner"` + + // The class of storage used to store the object. + StorageClass string `json:"storageClass"` + + // Error + Err error `json:"-"` +} + +// ObjectMultipartInfo container for multipart object metadata. +type ObjectMultipartInfo struct { + // Date and time at which the multipart upload was initiated. + Initiated time.Time `type:"timestamp" timestampFormat:"iso8601"` + + Initiator initiator + Owner owner + + // The type of storage to use for the object. Defaults to 'STANDARD'. + StorageClass string + + // Key of the object for which the multipart upload was initiated. + Key string + + // Size in bytes of the object. + Size int64 + + // Upload ID that identifies the multipart upload. + UploadID string `xml:"UploadId"` + + // Error + Err error +} diff --git a/vendor/github.com/minio/minio-go/api-error-response.go b/vendor/github.com/minio/minio-go/api-error-response.go new file mode 100644 index 000000000..655991cff --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-error-response.go @@ -0,0 +1,286 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "encoding/xml" + "fmt" + "net/http" +) + +/* **** SAMPLE ERROR RESPONSE **** + + + AccessDenied + Access Denied + bucketName + objectName + F19772218238A85A + GuWkjyviSiGHizehqpmsD1ndz5NClSP19DOT+s2mv7gXGQ8/X1lhbDGiIJEXpGFD + +*/ + +// ErrorResponse - Is the typed error returned by all API operations. +type ErrorResponse struct { + XMLName xml.Name `xml:"Error" json:"-"` + Code string + Message string + BucketName string + Key string + RequestID string `xml:"RequestId"` + HostID string `xml:"HostId"` + + // Region where the bucket is located. This header is returned + // only in HEAD bucket and ListObjects response. + Region string + + // Underlying HTTP status code for the returned error + StatusCode int `xml:"-" json:"-"` + + // Headers of the returned S3 XML error + Headers http.Header `xml:"-" json:"-"` +} + +// ToErrorResponse - Returns parsed ErrorResponse struct from body and +// http headers. +// +// For example: +// +// import s3 "github.com/minio/minio-go" +// ... +// ... +// reader, stat, err := s3.GetObject(...) +// if err != nil { +// resp := s3.ToErrorResponse(err) +// } +// ... +func ToErrorResponse(err error) ErrorResponse { + switch err := err.(type) { + case ErrorResponse: + return err + default: + return ErrorResponse{} + } +} + +// Error - Returns S3 error string. +func (e ErrorResponse) Error() string { + if e.Message == "" { + msg, ok := s3ErrorResponseMap[e.Code] + if !ok { + msg = fmt.Sprintf("Error response code %s.", e.Code) + } + return msg + } + return e.Message +} + +// Common string for errors to report issue location in unexpected +// cases. +const ( + reportIssue = "Please report this issue at https://github.com/minio/minio-go/issues." +) + +// httpRespToErrorResponse returns a new encoded ErrorResponse +// structure as error. +func httpRespToErrorResponse(resp *http.Response, bucketName, objectName string) error { + if resp == nil { + msg := "Response is empty. " + reportIssue + return ErrInvalidArgument(msg) + } + + errResp := ErrorResponse{ + StatusCode: resp.StatusCode, + } + + err := xmlDecoder(resp.Body, &errResp) + // Xml decoding failed with no body, fall back to HTTP headers. + if err != nil { + switch resp.StatusCode { + case http.StatusNotFound: + if objectName == "" { + errResp = ErrorResponse{ + StatusCode: resp.StatusCode, + Code: "NoSuchBucket", + Message: "The specified bucket does not exist.", + BucketName: bucketName, + } + } else { + errResp = ErrorResponse{ + StatusCode: resp.StatusCode, + Code: "NoSuchKey", + Message: "The specified key does not exist.", + BucketName: bucketName, + Key: objectName, + } + } + case http.StatusForbidden: + errResp = ErrorResponse{ + StatusCode: resp.StatusCode, + Code: "AccessDenied", + Message: "Access Denied.", + BucketName: bucketName, + Key: objectName, + } + case http.StatusConflict: + errResp = ErrorResponse{ + StatusCode: resp.StatusCode, + Code: "Conflict", + Message: "Bucket not empty.", + BucketName: bucketName, + } + case http.StatusPreconditionFailed: + errResp = ErrorResponse{ + StatusCode: resp.StatusCode, + Code: "PreconditionFailed", + Message: s3ErrorResponseMap["PreconditionFailed"], + BucketName: bucketName, + Key: objectName, + } + default: + errResp = ErrorResponse{ + StatusCode: resp.StatusCode, + Code: resp.Status, + Message: resp.Status, + BucketName: bucketName, + } + } + } + + // Save hostID, requestID and region information + // from headers if not available through error XML. + if errResp.RequestID == "" { + errResp.RequestID = resp.Header.Get("x-amz-request-id") + } + if errResp.HostID == "" { + errResp.HostID = resp.Header.Get("x-amz-id-2") + } + if errResp.Region == "" { + errResp.Region = resp.Header.Get("x-amz-bucket-region") + } + if errResp.Code == "InvalidRegion" && errResp.Region != "" { + errResp.Message = fmt.Sprintf("Region does not match, expecting region ‘%s’.", errResp.Region) + } + + // Save headers returned in the API XML error + errResp.Headers = resp.Header + + return errResp +} + +// ErrTransferAccelerationBucket - bucket name is invalid to be used with transfer acceleration. +func ErrTransferAccelerationBucket(bucketName string) error { + return ErrorResponse{ + StatusCode: http.StatusBadRequest, + Code: "InvalidArgument", + Message: "The name of the bucket used for Transfer Acceleration must be DNS-compliant and must not contain periods ‘.’.", + BucketName: bucketName, + } +} + +// ErrEntityTooLarge - Input size is larger than supported maximum. +func ErrEntityTooLarge(totalSize, maxObjectSize int64, bucketName, objectName string) error { + msg := fmt.Sprintf("Your proposed upload size ‘%d’ exceeds the maximum allowed object size ‘%d’ for single PUT operation.", totalSize, maxObjectSize) + return ErrorResponse{ + StatusCode: http.StatusBadRequest, + Code: "EntityTooLarge", + Message: msg, + BucketName: bucketName, + Key: objectName, + } +} + +// ErrEntityTooSmall - Input size is smaller than supported minimum. +func ErrEntityTooSmall(totalSize int64, bucketName, objectName string) error { + msg := fmt.Sprintf("Your proposed upload size ‘%d’ is below the minimum allowed object size ‘0B’ for single PUT operation.", totalSize) + return ErrorResponse{ + StatusCode: http.StatusBadRequest, + Code: "EntityTooSmall", + Message: msg, + BucketName: bucketName, + Key: objectName, + } +} + +// ErrUnexpectedEOF - Unexpected end of file reached. +func ErrUnexpectedEOF(totalRead, totalSize int64, bucketName, objectName string) error { + msg := fmt.Sprintf("Data read ‘%d’ is not equal to the size ‘%d’ of the input Reader.", totalRead, totalSize) + return ErrorResponse{ + StatusCode: http.StatusBadRequest, + Code: "UnexpectedEOF", + Message: msg, + BucketName: bucketName, + Key: objectName, + } +} + +// ErrInvalidBucketName - Invalid bucket name response. +func ErrInvalidBucketName(message string) error { + return ErrorResponse{ + StatusCode: http.StatusBadRequest, + Code: "InvalidBucketName", + Message: message, + RequestID: "minio", + } +} + +// ErrInvalidObjectName - Invalid object name response. +func ErrInvalidObjectName(message string) error { + return ErrorResponse{ + StatusCode: http.StatusNotFound, + Code: "NoSuchKey", + Message: message, + RequestID: "minio", + } +} + +// ErrInvalidObjectPrefix - Invalid object prefix response is +// similar to object name response. +var ErrInvalidObjectPrefix = ErrInvalidObjectName + +// ErrInvalidArgument - Invalid argument response. +func ErrInvalidArgument(message string) error { + return ErrorResponse{ + StatusCode: http.StatusBadRequest, + Code: "InvalidArgument", + Message: message, + RequestID: "minio", + } +} + +// ErrNoSuchBucketPolicy - No Such Bucket Policy response +// The specified bucket does not have a bucket policy. +func ErrNoSuchBucketPolicy(message string) error { + return ErrorResponse{ + StatusCode: http.StatusNotFound, + Code: "NoSuchBucketPolicy", + Message: message, + RequestID: "minio", + } +} + +// ErrAPINotSupported - API not supported response +// The specified API call is not supported +func ErrAPINotSupported(message string) error { + return ErrorResponse{ + StatusCode: http.StatusNotImplemented, + Code: "APINotSupported", + Message: message, + RequestID: "minio", + } +} diff --git a/vendor/github.com/minio/minio-go/api-get-object-context.go b/vendor/github.com/minio/minio-go/api-get-object-context.go new file mode 100644 index 000000000..f8dfac7d6 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-get-object-context.go @@ -0,0 +1,26 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import "context" + +// GetObjectWithContext - returns an seekable, readable object. +// The options can be used to specify the GET request further. +func (c Client) GetObjectWithContext(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (*Object, error) { + return c.getObjectWithContext(ctx, bucketName, objectName, opts) +} diff --git a/vendor/github.com/minio/minio-go/api-get-object-file.go b/vendor/github.com/minio/minio-go/api-get-object-file.go new file mode 100644 index 000000000..2b58220a6 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-get-object-file.go @@ -0,0 +1,136 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "io" + "os" + "path/filepath" + + "github.com/minio/minio-go/pkg/encrypt" + + "context" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// FGetObjectWithContext - download contents of an object to a local file. +// The options can be used to specify the GET request further. +func (c Client) FGetObjectWithContext(ctx context.Context, bucketName, objectName, filePath string, opts GetObjectOptions) error { + return c.fGetObjectWithContext(ctx, bucketName, objectName, filePath, opts) +} + +// FGetObject - download contents of an object to a local file. +func (c Client) FGetObject(bucketName, objectName, filePath string, opts GetObjectOptions) error { + return c.fGetObjectWithContext(context.Background(), bucketName, objectName, filePath, opts) +} + +// FGetEncryptedObject - Decrypt and store an object at filePath. +func (c Client) FGetEncryptedObject(bucketName, objectName, filePath string, materials encrypt.Materials) error { + if materials == nil { + return ErrInvalidArgument("Unable to recognize empty encryption properties") + } + return c.FGetObject(bucketName, objectName, filePath, GetObjectOptions{Materials: materials}) +} + +// fGetObjectWithContext - fgetObject wrapper function with context +func (c Client) fGetObjectWithContext(ctx context.Context, bucketName, objectName, filePath string, opts GetObjectOptions) error { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return err + } + + // Verify if destination already exists. + st, err := os.Stat(filePath) + if err == nil { + // If the destination exists and is a directory. + if st.IsDir() { + return ErrInvalidArgument("fileName is a directory.") + } + } + + // Proceed if file does not exist. return for all other errors. + if err != nil { + if !os.IsNotExist(err) { + return err + } + } + + // Extract top level directory. + objectDir, _ := filepath.Split(filePath) + if objectDir != "" { + // Create any missing top level directories. + if err := os.MkdirAll(objectDir, 0700); err != nil { + return err + } + } + + // Gather md5sum. + objectStat, err := c.StatObject(bucketName, objectName, StatObjectOptions{opts}) + if err != nil { + return err + } + + // Write to a temporary file "fileName.part.minio" before saving. + filePartPath := filePath + objectStat.ETag + ".part.minio" + + // If exists, open in append mode. If not create it as a part file. + filePart, err := os.OpenFile(filePartPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) + if err != nil { + return err + } + + // Issue Stat to get the current offset. + st, err = filePart.Stat() + if err != nil { + return err + } + + // Initialize get object request headers to set the + // appropriate range offsets to read from. + if st.Size() > 0 { + opts.SetRange(st.Size(), 0) + } + + // Seek to current position for incoming reader. + objectReader, objectStat, err := c.getObject(ctx, bucketName, objectName, opts) + if err != nil { + return err + } + + // Write to the part file. + if _, err = io.CopyN(filePart, objectReader, objectStat.Size); err != nil { + return err + } + + // Close the file before rename, this is specifically needed for Windows users. + if err = filePart.Close(); err != nil { + return err + } + + // Safely completed. Now commit by renaming to actual filename. + if err = os.Rename(filePartPath, filePath); err != nil { + return err + } + + // Return. + return nil +} diff --git a/vendor/github.com/minio/minio-go/api-get-object.go b/vendor/github.com/minio/minio-go/api-get-object.go new file mode 100644 index 000000000..50bbc2201 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-get-object.go @@ -0,0 +1,676 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "errors" + "fmt" + "io" + "net/http" + "strings" + "sync" + "time" + + "github.com/minio/minio-go/pkg/encrypt" + "github.com/minio/minio-go/pkg/s3utils" +) + +// GetEncryptedObject deciphers and streams data stored in the server after applying a specified encryption materials, +// returned stream should be closed by the caller. +func (c Client) GetEncryptedObject(bucketName, objectName string, encryptMaterials encrypt.Materials) (io.ReadCloser, error) { + if encryptMaterials == nil { + return nil, ErrInvalidArgument("Unable to recognize empty encryption properties") + } + + return c.GetObject(bucketName, objectName, GetObjectOptions{Materials: encryptMaterials}) +} + +// GetObject - returns an seekable, readable object. +func (c Client) GetObject(bucketName, objectName string, opts GetObjectOptions) (*Object, error) { + return c.getObjectWithContext(context.Background(), bucketName, objectName, opts) +} + +// GetObject wrapper function that accepts a request context +func (c Client) getObjectWithContext(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (*Object, error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return nil, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return nil, err + } + + var httpReader io.ReadCloser + var objectInfo ObjectInfo + var err error + + // Create request channel. + reqCh := make(chan getRequest) + // Create response channel. + resCh := make(chan getResponse) + // Create done channel. + doneCh := make(chan struct{}) + + // This routine feeds partial object data as and when the caller reads. + go func() { + defer close(reqCh) + defer close(resCh) + + // Used to verify if etag of object has changed since last read. + var etag string + + // Loop through the incoming control messages and read data. + for { + select { + // When the done channel is closed exit our routine. + case <-doneCh: + // Close the http response body before returning. + // This ends the connection with the server. + if httpReader != nil { + httpReader.Close() + } + return + + // Gather incoming request. + case req := <-reqCh: + // If this is the first request we may not need to do a getObject request yet. + if req.isFirstReq { + // First request is a Read/ReadAt. + if req.isReadOp { + // Differentiate between wanting the whole object and just a range. + if req.isReadAt { + // If this is a ReadAt request only get the specified range. + // Range is set with respect to the offset and length of the buffer requested. + // Do not set objectInfo from the first readAt request because it will not get + // the whole object. + opts.SetRange(req.Offset, req.Offset+int64(len(req.Buffer))-1) + } else if req.Offset > 0 { + opts.SetRange(req.Offset, 0) + } + httpReader, objectInfo, err = c.getObject(ctx, bucketName, objectName, opts) + if err != nil { + resCh <- getResponse{Error: err} + return + } + etag = objectInfo.ETag + // Read at least firstReq.Buffer bytes, if not we have + // reached our EOF. + size, err := io.ReadFull(httpReader, req.Buffer) + if size > 0 && err == io.ErrUnexpectedEOF { + // If an EOF happens after reading some but not + // all the bytes ReadFull returns ErrUnexpectedEOF + err = io.EOF + } + // Send back the first response. + resCh <- getResponse{ + objectInfo: objectInfo, + Size: int(size), + Error: err, + didRead: true, + } + } else { + // First request is a Stat or Seek call. + // Only need to run a StatObject until an actual Read or ReadAt request comes through. + objectInfo, err = c.statObject(ctx, bucketName, objectName, StatObjectOptions{opts}) + if err != nil { + resCh <- getResponse{ + Error: err, + } + // Exit the go-routine. + return + } + etag = objectInfo.ETag + // Send back the first response. + resCh <- getResponse{ + objectInfo: objectInfo, + } + } + } else if req.settingObjectInfo { // Request is just to get objectInfo. + if etag != "" { + opts.SetMatchETag(etag) + } + objectInfo, err := c.statObject(ctx, bucketName, objectName, StatObjectOptions{opts}) + if err != nil { + resCh <- getResponse{ + Error: err, + } + // Exit the goroutine. + return + } + // Send back the objectInfo. + resCh <- getResponse{ + objectInfo: objectInfo, + } + } else { + // Offset changes fetch the new object at an Offset. + // Because the httpReader may not be set by the first + // request if it was a stat or seek it must be checked + // if the object has been read or not to only initialize + // new ones when they haven't been already. + // All readAt requests are new requests. + if req.DidOffsetChange || !req.beenRead { + if etag != "" { + opts.SetMatchETag(etag) + } + if httpReader != nil { + // Close previously opened http reader. + httpReader.Close() + } + // If this request is a readAt only get the specified range. + if req.isReadAt { + // Range is set with respect to the offset and length of the buffer requested. + opts.SetRange(req.Offset, req.Offset+int64(len(req.Buffer))-1) + } else if req.Offset > 0 { // Range is set with respect to the offset. + opts.SetRange(req.Offset, 0) + } + httpReader, objectInfo, err = c.getObject(ctx, bucketName, objectName, opts) + if err != nil { + resCh <- getResponse{ + Error: err, + } + return + } + } + + // Read at least req.Buffer bytes, if not we have + // reached our EOF. + size, err := io.ReadFull(httpReader, req.Buffer) + if err == io.ErrUnexpectedEOF { + // If an EOF happens after reading some but not + // all the bytes ReadFull returns ErrUnexpectedEOF + err = io.EOF + } + // Reply back how much was read. + resCh <- getResponse{ + Size: int(size), + Error: err, + didRead: true, + objectInfo: objectInfo, + } + } + } + } + }() + + // Create a newObject through the information sent back by reqCh. + return newObject(reqCh, resCh, doneCh), nil +} + +// get request message container to communicate with internal +// go-routine. +type getRequest struct { + Buffer []byte + Offset int64 // readAt offset. + DidOffsetChange bool // Tracks the offset changes for Seek requests. + beenRead bool // Determines if this is the first time an object is being read. + isReadAt bool // Determines if this request is a request to a specific range + isReadOp bool // Determines if this request is a Read or Read/At request. + isFirstReq bool // Determines if this request is the first time an object is being accessed. + settingObjectInfo bool // Determines if this request is to set the objectInfo of an object. +} + +// get response message container to reply back for the request. +type getResponse struct { + Size int + Error error + didRead bool // Lets subsequent calls know whether or not httpReader has been initiated. + objectInfo ObjectInfo // Used for the first request. +} + +// Object represents an open object. It implements +// Reader, ReaderAt, Seeker, Closer for a HTTP stream. +type Object struct { + // Mutex. + mutex *sync.Mutex + + // User allocated and defined. + reqCh chan<- getRequest + resCh <-chan getResponse + doneCh chan<- struct{} + currOffset int64 + objectInfo ObjectInfo + + // Ask lower level to initiate data fetching based on currOffset + seekData bool + + // Keeps track of closed call. + isClosed bool + + // Keeps track of if this is the first call. + isStarted bool + + // Previous error saved for future calls. + prevErr error + + // Keeps track of if this object has been read yet. + beenRead bool + + // Keeps track of if objectInfo has been set yet. + objectInfoSet bool +} + +// doGetRequest - sends and blocks on the firstReqCh and reqCh of an object. +// Returns back the size of the buffer read, if anything was read, as well +// as any error encountered. For all first requests sent on the object +// it is also responsible for sending back the objectInfo. +func (o *Object) doGetRequest(request getRequest) (getResponse, error) { + o.reqCh <- request + response := <-o.resCh + + // Return any error to the top level. + if response.Error != nil { + return response, response.Error + } + + // This was the first request. + if !o.isStarted { + // The object has been operated on. + o.isStarted = true + } + // Set the objectInfo if the request was not readAt + // and it hasn't been set before. + if !o.objectInfoSet && !request.isReadAt { + o.objectInfo = response.objectInfo + o.objectInfoSet = true + } + // Set beenRead only if it has not been set before. + if !o.beenRead { + o.beenRead = response.didRead + } + // Data are ready on the wire, no need to reinitiate connection in lower level + o.seekData = false + + return response, nil +} + +// setOffset - handles the setting of offsets for +// Read/ReadAt/Seek requests. +func (o *Object) setOffset(bytesRead int64) error { + // Update the currentOffset. + o.currOffset += bytesRead + + if o.objectInfo.Size > -1 && o.currOffset >= o.objectInfo.Size { + return io.EOF + } + return nil +} + +// Read reads up to len(b) bytes into b. It returns the number of +// bytes read (0 <= n <= len(b)) and any error encountered. Returns +// io.EOF upon end of file. +func (o *Object) Read(b []byte) (n int, err error) { + if o == nil { + return 0, ErrInvalidArgument("Object is nil") + } + + // Locking. + o.mutex.Lock() + defer o.mutex.Unlock() + + // prevErr is previous error saved from previous operation. + if o.prevErr != nil || o.isClosed { + return 0, o.prevErr + } + // Create a new request. + readReq := getRequest{ + isReadOp: true, + beenRead: o.beenRead, + Buffer: b, + } + + // Alert that this is the first request. + if !o.isStarted { + readReq.isFirstReq = true + } + + // Ask to establish a new data fetch routine based on seekData flag + readReq.DidOffsetChange = o.seekData + readReq.Offset = o.currOffset + + // Send and receive from the first request. + response, err := o.doGetRequest(readReq) + if err != nil && err != io.EOF { + // Save the error for future calls. + o.prevErr = err + return response.Size, err + } + + // Bytes read. + bytesRead := int64(response.Size) + + // Set the new offset. + oerr := o.setOffset(bytesRead) + if oerr != nil { + // Save the error for future calls. + o.prevErr = oerr + return response.Size, oerr + } + + // Return the response. + return response.Size, err +} + +// Stat returns the ObjectInfo structure describing Object. +func (o *Object) Stat() (ObjectInfo, error) { + if o == nil { + return ObjectInfo{}, ErrInvalidArgument("Object is nil") + } + // Locking. + o.mutex.Lock() + defer o.mutex.Unlock() + + if o.prevErr != nil && o.prevErr != io.EOF || o.isClosed { + return ObjectInfo{}, o.prevErr + } + + // This is the first request. + if !o.isStarted || !o.objectInfoSet { + statReq := getRequest{ + isFirstReq: !o.isStarted, + settingObjectInfo: !o.objectInfoSet, + } + + // Send the request and get the response. + _, err := o.doGetRequest(statReq) + if err != nil { + o.prevErr = err + return ObjectInfo{}, err + } + } + + return o.objectInfo, nil +} + +// ReadAt reads len(b) bytes from the File starting at byte offset +// off. It returns the number of bytes read and the error, if any. +// ReadAt always returns a non-nil error when n < len(b). At end of +// file, that error is io.EOF. +func (o *Object) ReadAt(b []byte, offset int64) (n int, err error) { + if o == nil { + return 0, ErrInvalidArgument("Object is nil") + } + + // Locking. + o.mutex.Lock() + defer o.mutex.Unlock() + + // prevErr is error which was saved in previous operation. + if o.prevErr != nil || o.isClosed { + return 0, o.prevErr + } + + // Can only compare offsets to size when size has been set. + if o.objectInfoSet { + // If offset is negative than we return io.EOF. + // If offset is greater than or equal to object size we return io.EOF. + if (o.objectInfo.Size > -1 && offset >= o.objectInfo.Size) || offset < 0 { + return 0, io.EOF + } + } + + // Create the new readAt request. + readAtReq := getRequest{ + isReadOp: true, + isReadAt: true, + DidOffsetChange: true, // Offset always changes. + beenRead: o.beenRead, // Set if this is the first request to try and read. + Offset: offset, // Set the offset. + Buffer: b, + } + + // Alert that this is the first request. + if !o.isStarted { + readAtReq.isFirstReq = true + } + + // Send and receive from the first request. + response, err := o.doGetRequest(readAtReq) + if err != nil && err != io.EOF { + // Save the error. + o.prevErr = err + return response.Size, err + } + // Bytes read. + bytesRead := int64(response.Size) + // There is no valid objectInfo yet + // to compare against for EOF. + if !o.objectInfoSet { + // Update the currentOffset. + o.currOffset += bytesRead + } else { + // If this was not the first request update + // the offsets and compare against objectInfo + // for EOF. + oerr := o.setOffset(bytesRead) + if oerr != nil { + o.prevErr = oerr + return response.Size, oerr + } + } + return response.Size, err +} + +// Seek sets the offset for the next Read or Write to offset, +// interpreted according to whence: 0 means relative to the +// origin of the file, 1 means relative to the current offset, +// and 2 means relative to the end. +// Seek returns the new offset and an error, if any. +// +// Seeking to a negative offset is an error. Seeking to any positive +// offset is legal, subsequent io operations succeed until the +// underlying object is not closed. +func (o *Object) Seek(offset int64, whence int) (n int64, err error) { + if o == nil { + return 0, ErrInvalidArgument("Object is nil") + } + + // Locking. + o.mutex.Lock() + defer o.mutex.Unlock() + + if o.prevErr != nil { + // At EOF seeking is legal allow only io.EOF, for any other errors we return. + if o.prevErr != io.EOF { + return 0, o.prevErr + } + } + + // Negative offset is valid for whence of '2'. + if offset < 0 && whence != 2 { + return 0, ErrInvalidArgument(fmt.Sprintf("Negative position not allowed for %d.", whence)) + } + + // This is the first request. So before anything else + // get the ObjectInfo. + if !o.isStarted || !o.objectInfoSet { + // Create the new Seek request. + seekReq := getRequest{ + isReadOp: false, + Offset: offset, + isFirstReq: true, + } + // Send and receive from the seek request. + _, err := o.doGetRequest(seekReq) + if err != nil { + // Save the error. + o.prevErr = err + return 0, err + } + } + + // Switch through whence. + switch whence { + default: + return 0, ErrInvalidArgument(fmt.Sprintf("Invalid whence %d", whence)) + case 0: + if o.objectInfo.Size > -1 && offset > o.objectInfo.Size { + return 0, io.EOF + } + o.currOffset = offset + case 1: + if o.objectInfo.Size > -1 && o.currOffset+offset > o.objectInfo.Size { + return 0, io.EOF + } + o.currOffset += offset + case 2: + // If we don't know the object size return an error for io.SeekEnd + if o.objectInfo.Size < 0 { + return 0, ErrInvalidArgument("Whence END is not supported when the object size is unknown") + } + // Seeking to positive offset is valid for whence '2', but + // since we are backing a Reader we have reached 'EOF' if + // offset is positive. + if offset > 0 { + return 0, io.EOF + } + // Seeking to negative position not allowed for whence. + if o.objectInfo.Size+offset < 0 { + return 0, ErrInvalidArgument(fmt.Sprintf("Seeking at negative offset not allowed for %d", whence)) + } + o.currOffset = o.objectInfo.Size + offset + } + // Reset the saved error since we successfully seeked, let the Read + // and ReadAt decide. + if o.prevErr == io.EOF { + o.prevErr = nil + } + + // Ask lower level to fetch again from source + o.seekData = true + + // Return the effective offset. + return o.currOffset, nil +} + +// Close - The behavior of Close after the first call returns error +// for subsequent Close() calls. +func (o *Object) Close() (err error) { + if o == nil { + return ErrInvalidArgument("Object is nil") + } + // Locking. + o.mutex.Lock() + defer o.mutex.Unlock() + + // if already closed return an error. + if o.isClosed { + return o.prevErr + } + + // Close successfully. + close(o.doneCh) + + // Save for future operations. + errMsg := "Object is already closed. Bad file descriptor." + o.prevErr = errors.New(errMsg) + // Save here that we closed done channel successfully. + o.isClosed = true + return nil +} + +// newObject instantiates a new *minio.Object* +// ObjectInfo will be set by setObjectInfo +func newObject(reqCh chan<- getRequest, resCh <-chan getResponse, doneCh chan<- struct{}) *Object { + return &Object{ + mutex: &sync.Mutex{}, + reqCh: reqCh, + resCh: resCh, + doneCh: doneCh, + } +} + +// getObject - retrieve object from Object Storage. +// +// Additionally this function also takes range arguments to download the specified +// range bytes of an object. Setting offset and length = 0 will download the full object. +// +// For more information about the HTTP Range header. +// go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35. +func (c Client) getObject(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (io.ReadCloser, ObjectInfo, error) { + // Validate input arguments. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return nil, ObjectInfo{}, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return nil, ObjectInfo{}, err + } + + // Execute GET on objectName. + resp, err := c.executeMethod(ctx, "GET", requestMetadata{ + bucketName: bucketName, + objectName: objectName, + customHeader: opts.Header(), + contentSHA256Hex: emptySHA256Hex, + }) + if err != nil { + return nil, ObjectInfo{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent { + return nil, ObjectInfo{}, httpRespToErrorResponse(resp, bucketName, objectName) + } + } + + // Trim off the odd double quotes from ETag in the beginning and end. + md5sum := strings.TrimPrefix(resp.Header.Get("ETag"), "\"") + md5sum = strings.TrimSuffix(md5sum, "\"") + + // Parse the date. + date, err := time.Parse(http.TimeFormat, resp.Header.Get("Last-Modified")) + if err != nil { + msg := "Last-Modified time format not recognized. " + reportIssue + return nil, ObjectInfo{}, ErrorResponse{ + Code: "InternalError", + Message: msg, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + Region: resp.Header.Get("x-amz-bucket-region"), + } + } + + // Get content-type. + contentType := strings.TrimSpace(resp.Header.Get("Content-Type")) + if contentType == "" { + contentType = "application/octet-stream" + } + + objectStat := ObjectInfo{ + ETag: md5sum, + Key: objectName, + Size: resp.ContentLength, + LastModified: date, + ContentType: contentType, + // Extract only the relevant header keys describing the object. + // following function filters out a list of standard set of keys + // which are not part of object metadata. + Metadata: extractObjMetadata(resp.Header), + } + + reader := resp.Body + if opts.Materials != nil { + err = opts.Materials.SetupDecryptMode(reader, objectStat.Metadata.Get(amzHeaderIV), objectStat.Metadata.Get(amzHeaderKey)) + if err != nil { + return nil, ObjectInfo{}, err + } + reader = opts.Materials + } + + // do not close body here, caller will close + return reader, objectStat, nil +} diff --git a/vendor/github.com/minio/minio-go/api-get-options.go b/vendor/github.com/minio/minio-go/api-get-options.go new file mode 100644 index 000000000..dd70415cd --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-get-options.go @@ -0,0 +1,126 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "fmt" + "net/http" + "time" + + "github.com/minio/minio-go/pkg/encrypt" +) + +// GetObjectOptions are used to specify additional headers or options +// during GET requests. +type GetObjectOptions struct { + headers map[string]string + + Materials encrypt.Materials +} + +// StatObjectOptions are used to specify additional headers or options +// during GET info/stat requests. +type StatObjectOptions struct { + GetObjectOptions +} + +// Header returns the http.Header representation of the GET options. +func (o GetObjectOptions) Header() http.Header { + headers := make(http.Header, len(o.headers)) + for k, v := range o.headers { + headers.Set(k, v) + } + return headers +} + +// Set adds a key value pair to the options. The +// key-value pair will be part of the HTTP GET request +// headers. +func (o *GetObjectOptions) Set(key, value string) { + if o.headers == nil { + o.headers = make(map[string]string) + } + o.headers[http.CanonicalHeaderKey(key)] = value +} + +// SetMatchETag - set match etag. +func (o *GetObjectOptions) SetMatchETag(etag string) error { + if etag == "" { + return ErrInvalidArgument("ETag cannot be empty.") + } + o.Set("If-Match", "\""+etag+"\"") + return nil +} + +// SetMatchETagExcept - set match etag except. +func (o *GetObjectOptions) SetMatchETagExcept(etag string) error { + if etag == "" { + return ErrInvalidArgument("ETag cannot be empty.") + } + o.Set("If-None-Match", "\""+etag+"\"") + return nil +} + +// SetUnmodified - set unmodified time since. +func (o *GetObjectOptions) SetUnmodified(modTime time.Time) error { + if modTime.IsZero() { + return ErrInvalidArgument("Modified since cannot be empty.") + } + o.Set("If-Unmodified-Since", modTime.Format(http.TimeFormat)) + return nil +} + +// SetModified - set modified time since. +func (o *GetObjectOptions) SetModified(modTime time.Time) error { + if modTime.IsZero() { + return ErrInvalidArgument("Modified since cannot be empty.") + } + o.Set("If-Modified-Since", modTime.Format(http.TimeFormat)) + return nil +} + +// SetRange - set the start and end offset of the object to be read. +// See https://tools.ietf.org/html/rfc7233#section-3.1 for reference. +func (o *GetObjectOptions) SetRange(start, end int64) error { + switch { + case start == 0 && end < 0: + // Read last '-end' bytes. `bytes=-N`. + o.Set("Range", fmt.Sprintf("bytes=%d", end)) + case 0 < start && end == 0: + // Read everything starting from offset + // 'start'. `bytes=N-`. + o.Set("Range", fmt.Sprintf("bytes=%d-", start)) + case 0 <= start && start <= end: + // Read everything starting at 'start' till the + // 'end'. `bytes=N-M` + o.Set("Range", fmt.Sprintf("bytes=%d-%d", start, end)) + default: + // All other cases such as + // bytes=-3- + // bytes=5-3 + // bytes=-2-4 + // bytes=-3-0 + // bytes=-3--2 + // are invalid. + return ErrInvalidArgument( + fmt.Sprintf( + "Invalid range specified: start=%d end=%d", + start, end)) + } + return nil +} diff --git a/vendor/github.com/minio/minio-go/api-get-policy.go b/vendor/github.com/minio/minio-go/api-get-policy.go new file mode 100644 index 000000000..a4259c9d7 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-get-policy.go @@ -0,0 +1,109 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "encoding/json" + "io/ioutil" + "net/http" + "net/url" + + "github.com/minio/minio-go/pkg/policy" + "github.com/minio/minio-go/pkg/s3utils" +) + +// GetBucketPolicy - get bucket policy at a given path. +func (c Client) GetBucketPolicy(bucketName, objectPrefix string) (bucketPolicy policy.BucketPolicy, err error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return policy.BucketPolicyNone, err + } + if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { + return policy.BucketPolicyNone, err + } + policyInfo, err := c.getBucketPolicy(bucketName) + if err != nil { + errResponse := ToErrorResponse(err) + if errResponse.Code == "NoSuchBucketPolicy" { + return policy.BucketPolicyNone, nil + } + return policy.BucketPolicyNone, err + } + return policy.GetPolicy(policyInfo.Statements, bucketName, objectPrefix), nil +} + +// ListBucketPolicies - list all policies for a given prefix and all its children. +func (c Client) ListBucketPolicies(bucketName, objectPrefix string) (bucketPolicies map[string]policy.BucketPolicy, err error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return map[string]policy.BucketPolicy{}, err + } + if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { + return map[string]policy.BucketPolicy{}, err + } + policyInfo, err := c.getBucketPolicy(bucketName) + if err != nil { + errResponse := ToErrorResponse(err) + if errResponse.Code == "NoSuchBucketPolicy" { + return map[string]policy.BucketPolicy{}, nil + } + return map[string]policy.BucketPolicy{}, err + } + return policy.GetPolicies(policyInfo.Statements, bucketName), nil +} + +// Default empty bucket access policy. +var emptyBucketAccessPolicy = policy.BucketAccessPolicy{ + Version: "2012-10-17", +} + +// Request server for current bucket policy. +func (c Client) getBucketPolicy(bucketName string) (policy.BucketAccessPolicy, error) { + // Get resources properly escaped and lined up before + // using them in http request. + urlValues := make(url.Values) + urlValues.Set("policy", "") + + // Execute GET on bucket to list objects. + resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentSHA256Hex: emptySHA256Hex, + }) + + defer closeResponse(resp) + if err != nil { + return emptyBucketAccessPolicy, err + } + + if resp != nil { + if resp.StatusCode != http.StatusOK { + return emptyBucketAccessPolicy, httpRespToErrorResponse(resp, bucketName, "") + } + } + + bucketPolicyBuf, err := ioutil.ReadAll(resp.Body) + if err != nil { + return emptyBucketAccessPolicy, err + } + + policy := policy.BucketAccessPolicy{} + err = json.Unmarshal(bucketPolicyBuf, &policy) + return policy, err +} diff --git a/vendor/github.com/minio/minio-go/api-list.go b/vendor/github.com/minio/minio-go/api-list.go new file mode 100644 index 000000000..3cfb47d37 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-list.go @@ -0,0 +1,717 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// ListBuckets list all buckets owned by this authenticated user. +// +// This call requires explicit authentication, no anonymous requests are +// allowed for listing buckets. +// +// api := client.New(....) +// for message := range api.ListBuckets() { +// fmt.Println(message) +// } +// +func (c Client) ListBuckets() ([]BucketInfo, error) { + // Execute GET on service. + resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{contentSHA256Hex: emptySHA256Hex}) + defer closeResponse(resp) + if err != nil { + return nil, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return nil, httpRespToErrorResponse(resp, "", "") + } + } + listAllMyBucketsResult := listAllMyBucketsResult{} + err = xmlDecoder(resp.Body, &listAllMyBucketsResult) + if err != nil { + return nil, err + } + return listAllMyBucketsResult.Buckets.Bucket, nil +} + +/// Bucket Read Operations. + +// ListObjectsV2 lists all objects matching the objectPrefix from +// the specified bucket. If recursion is enabled it would list +// all subdirectories and all its contents. +// +// Your input parameters are just bucketName, objectPrefix, recursive +// and a done channel for pro-actively closing the internal go +// routine. If you enable recursive as 'true' this function will +// return back all the objects in a given bucket name and object +// prefix. +// +// api := client.New(....) +// // Create a done channel. +// doneCh := make(chan struct{}) +// defer close(doneCh) +// // Recursively list all objects in 'mytestbucket' +// recursive := true +// for message := range api.ListObjectsV2("mytestbucket", "starthere", recursive, doneCh) { +// fmt.Println(message) +// } +// +func (c Client) ListObjectsV2(bucketName, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan ObjectInfo { + // Allocate new list objects channel. + objectStatCh := make(chan ObjectInfo, 1) + // Default listing is delimited at "/" + delimiter := "/" + if recursive { + // If recursive we do not delimit. + delimiter = "" + } + + // Return object owner information by default + fetchOwner := true + + // Validate bucket name. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + defer close(objectStatCh) + objectStatCh <- ObjectInfo{ + Err: err, + } + return objectStatCh + } + + // Validate incoming object prefix. + if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { + defer close(objectStatCh) + objectStatCh <- ObjectInfo{ + Err: err, + } + return objectStatCh + } + + // Initiate list objects goroutine here. + go func(objectStatCh chan<- ObjectInfo) { + defer close(objectStatCh) + // Save continuationToken for next request. + var continuationToken string + for { + // Get list of objects a maximum of 1000 per request. + result, err := c.listObjectsV2Query(bucketName, objectPrefix, continuationToken, fetchOwner, delimiter, 1000) + if err != nil { + objectStatCh <- ObjectInfo{ + Err: err, + } + return + } + + // If contents are available loop through and send over channel. + for _, object := range result.Contents { + select { + // Send object content. + case objectStatCh <- object: + // If receives done from the caller, return here. + case <-doneCh: + return + } + } + + // Send all common prefixes if any. + // NOTE: prefixes are only present if the request is delimited. + for _, obj := range result.CommonPrefixes { + select { + // Send object prefixes. + case objectStatCh <- ObjectInfo{ + Key: obj.Prefix, + Size: 0, + }: + // If receives done from the caller, return here. + case <-doneCh: + return + } + } + + // If continuation token present, save it for next request. + if result.NextContinuationToken != "" { + continuationToken = result.NextContinuationToken + } + + // Listing ends result is not truncated, return right here. + if !result.IsTruncated { + return + } + } + }(objectStatCh) + return objectStatCh +} + +// listObjectsV2Query - (List Objects V2) - List some or all (up to 1000) of the objects in a bucket. +// +// You can use the request parameters as selection criteria to return a subset of the objects in a bucket. +// request parameters :- +// --------- +// ?continuation-token - Specifies the key to start with when listing objects in a bucket. +// ?delimiter - A delimiter is a character you use to group keys. +// ?prefix - Limits the response to keys that begin with the specified prefix. +// ?max-keys - Sets the maximum number of keys returned in the response body. +func (c Client) listObjectsV2Query(bucketName, objectPrefix, continuationToken string, fetchOwner bool, delimiter string, maxkeys int) (ListBucketV2Result, error) { + // Validate bucket name. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return ListBucketV2Result{}, err + } + // Validate object prefix. + if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { + return ListBucketV2Result{}, err + } + // Get resources properly escaped and lined up before + // using them in http request. + urlValues := make(url.Values) + + // Always set list-type in ListObjects V2 + urlValues.Set("list-type", "2") + + // Set object prefix. + if objectPrefix != "" { + urlValues.Set("prefix", objectPrefix) + } + // Set continuation token + if continuationToken != "" { + urlValues.Set("continuation-token", continuationToken) + } + // Set delimiter. + if delimiter != "" { + urlValues.Set("delimiter", delimiter) + } + + // Fetch owner when listing + if fetchOwner { + urlValues.Set("fetch-owner", "true") + } + + // maxkeys should default to 1000 or less. + if maxkeys == 0 || maxkeys > 1000 { + maxkeys = 1000 + } + // Set max keys. + urlValues.Set("max-keys", fmt.Sprintf("%d", maxkeys)) + + // Execute GET on bucket to list objects. + resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentSHA256Hex: emptySHA256Hex, + }) + defer closeResponse(resp) + if err != nil { + return ListBucketV2Result{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return ListBucketV2Result{}, httpRespToErrorResponse(resp, bucketName, "") + } + } + + // Decode listBuckets XML. + listBucketResult := ListBucketV2Result{} + if err = xmlDecoder(resp.Body, &listBucketResult); err != nil { + return listBucketResult, err + } + + // This is an additional verification check to make + // sure proper responses are received. + if listBucketResult.IsTruncated && listBucketResult.NextContinuationToken == "" { + return listBucketResult, errors.New("Truncated response should have continuation token set") + } + + // Success. + return listBucketResult, nil +} + +// ListObjects - (List Objects) - List some objects or all recursively. +// +// ListObjects lists all objects matching the objectPrefix from +// the specified bucket. If recursion is enabled it would list +// all subdirectories and all its contents. +// +// Your input parameters are just bucketName, objectPrefix, recursive +// and a done channel for pro-actively closing the internal go +// routine. If you enable recursive as 'true' this function will +// return back all the objects in a given bucket name and object +// prefix. +// +// api := client.New(....) +// // Create a done channel. +// doneCh := make(chan struct{}) +// defer close(doneCh) +// // Recurively list all objects in 'mytestbucket' +// recursive := true +// for message := range api.ListObjects("mytestbucket", "starthere", recursive, doneCh) { +// fmt.Println(message) +// } +// +func (c Client) ListObjects(bucketName, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan ObjectInfo { + // Allocate new list objects channel. + objectStatCh := make(chan ObjectInfo, 1) + // Default listing is delimited at "/" + delimiter := "/" + if recursive { + // If recursive we do not delimit. + delimiter = "" + } + // Validate bucket name. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + defer close(objectStatCh) + objectStatCh <- ObjectInfo{ + Err: err, + } + return objectStatCh + } + // Validate incoming object prefix. + if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { + defer close(objectStatCh) + objectStatCh <- ObjectInfo{ + Err: err, + } + return objectStatCh + } + + // Initiate list objects goroutine here. + go func(objectStatCh chan<- ObjectInfo) { + defer close(objectStatCh) + // Save marker for next request. + var marker string + for { + // Get list of objects a maximum of 1000 per request. + result, err := c.listObjectsQuery(bucketName, objectPrefix, marker, delimiter, 1000) + if err != nil { + objectStatCh <- ObjectInfo{ + Err: err, + } + return + } + + // If contents are available loop through and send over channel. + for _, object := range result.Contents { + // Save the marker. + marker = object.Key + select { + // Send object content. + case objectStatCh <- object: + // If receives done from the caller, return here. + case <-doneCh: + return + } + } + + // Send all common prefixes if any. + // NOTE: prefixes are only present if the request is delimited. + for _, obj := range result.CommonPrefixes { + object := ObjectInfo{} + object.Key = obj.Prefix + object.Size = 0 + select { + // Send object prefixes. + case objectStatCh <- object: + // If receives done from the caller, return here. + case <-doneCh: + return + } + } + + // If next marker present, save it for next request. + if result.NextMarker != "" { + marker = result.NextMarker + } + + // Listing ends result is not truncated, return right here. + if !result.IsTruncated { + return + } + } + }(objectStatCh) + return objectStatCh +} + +// listObjects - (List Objects) - List some or all (up to 1000) of the objects in a bucket. +// +// You can use the request parameters as selection criteria to return a subset of the objects in a bucket. +// request parameters :- +// --------- +// ?marker - Specifies the key to start with when listing objects in a bucket. +// ?delimiter - A delimiter is a character you use to group keys. +// ?prefix - Limits the response to keys that begin with the specified prefix. +// ?max-keys - Sets the maximum number of keys returned in the response body. +func (c Client) listObjectsQuery(bucketName, objectPrefix, objectMarker, delimiter string, maxkeys int) (ListBucketResult, error) { + // Validate bucket name. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return ListBucketResult{}, err + } + // Validate object prefix. + if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { + return ListBucketResult{}, err + } + // Get resources properly escaped and lined up before + // using them in http request. + urlValues := make(url.Values) + // Set object prefix. + if objectPrefix != "" { + urlValues.Set("prefix", objectPrefix) + } + // Set object marker. + if objectMarker != "" { + urlValues.Set("marker", objectMarker) + } + // Set delimiter. + if delimiter != "" { + urlValues.Set("delimiter", delimiter) + } + + // maxkeys should default to 1000 or less. + if maxkeys == 0 || maxkeys > 1000 { + maxkeys = 1000 + } + // Set max keys. + urlValues.Set("max-keys", fmt.Sprintf("%d", maxkeys)) + + // Execute GET on bucket to list objects. + resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentSHA256Hex: emptySHA256Hex, + }) + defer closeResponse(resp) + if err != nil { + return ListBucketResult{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return ListBucketResult{}, httpRespToErrorResponse(resp, bucketName, "") + } + } + // Decode listBuckets XML. + listBucketResult := ListBucketResult{} + err = xmlDecoder(resp.Body, &listBucketResult) + if err != nil { + return listBucketResult, err + } + return listBucketResult, nil +} + +// ListIncompleteUploads - List incompletely uploaded multipart objects. +// +// ListIncompleteUploads lists all incompleted objects matching the +// objectPrefix from the specified bucket. If recursion is enabled +// it would list all subdirectories and all its contents. +// +// Your input parameters are just bucketName, objectPrefix, recursive +// and a done channel to pro-actively close the internal go routine. +// If you enable recursive as 'true' this function will return back all +// the multipart objects in a given bucket name. +// +// api := client.New(....) +// // Create a done channel. +// doneCh := make(chan struct{}) +// defer close(doneCh) +// // Recurively list all objects in 'mytestbucket' +// recursive := true +// for message := range api.ListIncompleteUploads("mytestbucket", "starthere", recursive) { +// fmt.Println(message) +// } +// +func (c Client) ListIncompleteUploads(bucketName, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan ObjectMultipartInfo { + // Turn on size aggregation of individual parts. + isAggregateSize := true + return c.listIncompleteUploads(bucketName, objectPrefix, recursive, isAggregateSize, doneCh) +} + +// listIncompleteUploads lists all incomplete uploads. +func (c Client) listIncompleteUploads(bucketName, objectPrefix string, recursive, aggregateSize bool, doneCh <-chan struct{}) <-chan ObjectMultipartInfo { + // Allocate channel for multipart uploads. + objectMultipartStatCh := make(chan ObjectMultipartInfo, 1) + // Delimiter is set to "/" by default. + delimiter := "/" + if recursive { + // If recursive do not delimit. + delimiter = "" + } + // Validate bucket name. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + defer close(objectMultipartStatCh) + objectMultipartStatCh <- ObjectMultipartInfo{ + Err: err, + } + return objectMultipartStatCh + } + // Validate incoming object prefix. + if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { + defer close(objectMultipartStatCh) + objectMultipartStatCh <- ObjectMultipartInfo{ + Err: err, + } + return objectMultipartStatCh + } + go func(objectMultipartStatCh chan<- ObjectMultipartInfo) { + defer close(objectMultipartStatCh) + // object and upload ID marker for future requests. + var objectMarker string + var uploadIDMarker string + for { + // list all multipart uploads. + result, err := c.listMultipartUploadsQuery(bucketName, objectMarker, uploadIDMarker, objectPrefix, delimiter, 1000) + if err != nil { + objectMultipartStatCh <- ObjectMultipartInfo{ + Err: err, + } + return + } + // Save objectMarker and uploadIDMarker for next request. + objectMarker = result.NextKeyMarker + uploadIDMarker = result.NextUploadIDMarker + // Send all multipart uploads. + for _, obj := range result.Uploads { + // Calculate total size of the uploaded parts if 'aggregateSize' is enabled. + if aggregateSize { + // Get total multipart size. + obj.Size, err = c.getTotalMultipartSize(bucketName, obj.Key, obj.UploadID) + if err != nil { + objectMultipartStatCh <- ObjectMultipartInfo{ + Err: err, + } + continue + } + } + select { + // Send individual uploads here. + case objectMultipartStatCh <- obj: + // If done channel return here. + case <-doneCh: + return + } + } + // Send all common prefixes if any. + // NOTE: prefixes are only present if the request is delimited. + for _, obj := range result.CommonPrefixes { + object := ObjectMultipartInfo{} + object.Key = obj.Prefix + object.Size = 0 + select { + // Send delimited prefixes here. + case objectMultipartStatCh <- object: + // If done channel return here. + case <-doneCh: + return + } + } + // Listing ends if result not truncated, return right here. + if !result.IsTruncated { + return + } + } + }(objectMultipartStatCh) + // return. + return objectMultipartStatCh +} + +// listMultipartUploads - (List Multipart Uploads). +// - Lists some or all (up to 1000) in-progress multipart uploads in a bucket. +// +// You can use the request parameters as selection criteria to return a subset of the uploads in a bucket. +// request parameters. :- +// --------- +// ?key-marker - Specifies the multipart upload after which listing should begin. +// ?upload-id-marker - Together with key-marker specifies the multipart upload after which listing should begin. +// ?delimiter - A delimiter is a character you use to group keys. +// ?prefix - Limits the response to keys that begin with the specified prefix. +// ?max-uploads - Sets the maximum number of multipart uploads returned in the response body. +func (c Client) listMultipartUploadsQuery(bucketName, keyMarker, uploadIDMarker, prefix, delimiter string, maxUploads int) (ListMultipartUploadsResult, error) { + // Get resources properly escaped and lined up before using them in http request. + urlValues := make(url.Values) + // Set uploads. + urlValues.Set("uploads", "") + // Set object key marker. + if keyMarker != "" { + urlValues.Set("key-marker", keyMarker) + } + // Set upload id marker. + if uploadIDMarker != "" { + urlValues.Set("upload-id-marker", uploadIDMarker) + } + // Set prefix marker. + if prefix != "" { + urlValues.Set("prefix", prefix) + } + // Set delimiter. + if delimiter != "" { + urlValues.Set("delimiter", delimiter) + } + + // maxUploads should be 1000 or less. + if maxUploads == 0 || maxUploads > 1000 { + maxUploads = 1000 + } + // Set max-uploads. + urlValues.Set("max-uploads", fmt.Sprintf("%d", maxUploads)) + + // Execute GET on bucketName to list multipart uploads. + resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentSHA256Hex: emptySHA256Hex, + }) + defer closeResponse(resp) + if err != nil { + return ListMultipartUploadsResult{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return ListMultipartUploadsResult{}, httpRespToErrorResponse(resp, bucketName, "") + } + } + // Decode response body. + listMultipartUploadsResult := ListMultipartUploadsResult{} + err = xmlDecoder(resp.Body, &listMultipartUploadsResult) + if err != nil { + return listMultipartUploadsResult, err + } + return listMultipartUploadsResult, nil +} + +// listObjectParts list all object parts recursively. +func (c Client) listObjectParts(bucketName, objectName, uploadID string) (partsInfo map[int]ObjectPart, err error) { + // Part number marker for the next batch of request. + var nextPartNumberMarker int + partsInfo = make(map[int]ObjectPart) + for { + // Get list of uploaded parts a maximum of 1000 per request. + listObjPartsResult, err := c.listObjectPartsQuery(bucketName, objectName, uploadID, nextPartNumberMarker, 1000) + if err != nil { + return nil, err + } + // Append to parts info. + for _, part := range listObjPartsResult.ObjectParts { + // Trim off the odd double quotes from ETag in the beginning and end. + part.ETag = strings.TrimPrefix(part.ETag, "\"") + part.ETag = strings.TrimSuffix(part.ETag, "\"") + partsInfo[part.PartNumber] = part + } + // Keep part number marker, for the next iteration. + nextPartNumberMarker = listObjPartsResult.NextPartNumberMarker + // Listing ends result is not truncated, return right here. + if !listObjPartsResult.IsTruncated { + break + } + } + + // Return all the parts. + return partsInfo, nil +} + +// findUploadID lists all incomplete uploads and finds the uploadID of the matching object name. +func (c Client) findUploadID(bucketName, objectName string) (uploadID string, err error) { + // Make list incomplete uploads recursive. + isRecursive := true + // Turn off size aggregation of individual parts, in this request. + isAggregateSize := false + // latestUpload to track the latest multipart info for objectName. + var latestUpload ObjectMultipartInfo + // Create done channel to cleanup the routine. + doneCh := make(chan struct{}) + defer close(doneCh) + // List all incomplete uploads. + for mpUpload := range c.listIncompleteUploads(bucketName, objectName, isRecursive, isAggregateSize, doneCh) { + if mpUpload.Err != nil { + return "", mpUpload.Err + } + if objectName == mpUpload.Key { + if mpUpload.Initiated.Sub(latestUpload.Initiated) > 0 { + latestUpload = mpUpload + } + } + } + // Return the latest upload id. + return latestUpload.UploadID, nil +} + +// getTotalMultipartSize - calculate total uploaded size for the a given multipart object. +func (c Client) getTotalMultipartSize(bucketName, objectName, uploadID string) (size int64, err error) { + // Iterate over all parts and aggregate the size. + partsInfo, err := c.listObjectParts(bucketName, objectName, uploadID) + if err != nil { + return 0, err + } + for _, partInfo := range partsInfo { + size += partInfo.Size + } + return size, nil +} + +// listObjectPartsQuery (List Parts query) +// - lists some or all (up to 1000) parts that have been uploaded +// for a specific multipart upload +// +// You can use the request parameters as selection criteria to return +// a subset of the uploads in a bucket, request parameters :- +// --------- +// ?part-number-marker - Specifies the part after which listing should +// begin. +// ?max-parts - Maximum parts to be listed per request. +func (c Client) listObjectPartsQuery(bucketName, objectName, uploadID string, partNumberMarker, maxParts int) (ListObjectPartsResult, error) { + // Get resources properly escaped and lined up before using them in http request. + urlValues := make(url.Values) + // Set part number marker. + urlValues.Set("part-number-marker", fmt.Sprintf("%d", partNumberMarker)) + // Set upload id. + urlValues.Set("uploadId", uploadID) + + // maxParts should be 1000 or less. + if maxParts == 0 || maxParts > 1000 { + maxParts = 1000 + } + // Set max parts. + urlValues.Set("max-parts", fmt.Sprintf("%d", maxParts)) + + // Execute GET on objectName to get list of parts. + resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{ + bucketName: bucketName, + objectName: objectName, + queryValues: urlValues, + contentSHA256Hex: emptySHA256Hex, + }) + defer closeResponse(resp) + if err != nil { + return ListObjectPartsResult{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return ListObjectPartsResult{}, httpRespToErrorResponse(resp, bucketName, objectName) + } + } + // Decode list object parts XML. + listObjectPartsResult := ListObjectPartsResult{} + err = xmlDecoder(resp.Body, &listObjectPartsResult) + if err != nil { + return listObjectPartsResult, err + } + return listObjectPartsResult, nil +} diff --git a/vendor/github.com/minio/minio-go/api-notification.go b/vendor/github.com/minio/minio-go/api-notification.go new file mode 100644 index 000000000..3f5b30a3b --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-notification.go @@ -0,0 +1,230 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "bufio" + "context" + "encoding/json" + "io" + "net/http" + "net/url" + "time" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// GetBucketNotification - get bucket notification at a given path. +func (c Client) GetBucketNotification(bucketName string) (bucketNotification BucketNotification, err error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return BucketNotification{}, err + } + notification, err := c.getBucketNotification(bucketName) + if err != nil { + return BucketNotification{}, err + } + return notification, nil +} + +// Request server for notification rules. +func (c Client) getBucketNotification(bucketName string) (BucketNotification, error) { + urlValues := make(url.Values) + urlValues.Set("notification", "") + + // Execute GET on bucket to list objects. + resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentSHA256Hex: emptySHA256Hex, + }) + + defer closeResponse(resp) + if err != nil { + return BucketNotification{}, err + } + return processBucketNotificationResponse(bucketName, resp) + +} + +// processes the GetNotification http response from the server. +func processBucketNotificationResponse(bucketName string, resp *http.Response) (BucketNotification, error) { + if resp.StatusCode != http.StatusOK { + errResponse := httpRespToErrorResponse(resp, bucketName, "") + return BucketNotification{}, errResponse + } + var bucketNotification BucketNotification + err := xmlDecoder(resp.Body, &bucketNotification) + if err != nil { + return BucketNotification{}, err + } + return bucketNotification, nil +} + +// Indentity represents the user id, this is a compliance field. +type identity struct { + PrincipalID string `json:"principalId"` +} + +// Notification event bucket metadata. +type bucketMeta struct { + Name string `json:"name"` + OwnerIdentity identity `json:"ownerIdentity"` + ARN string `json:"arn"` +} + +// Notification event object metadata. +type objectMeta struct { + Key string `json:"key"` + Size int64 `json:"size,omitempty"` + ETag string `json:"eTag,omitempty"` + VersionID string `json:"versionId,omitempty"` + Sequencer string `json:"sequencer"` +} + +// Notification event server specific metadata. +type eventMeta struct { + SchemaVersion string `json:"s3SchemaVersion"` + ConfigurationID string `json:"configurationId"` + Bucket bucketMeta `json:"bucket"` + Object objectMeta `json:"object"` +} + +// sourceInfo represents information on the client that +// triggered the event notification. +type sourceInfo struct { + Host string `json:"host"` + Port string `json:"port"` + UserAgent string `json:"userAgent"` +} + +// NotificationEvent represents an Amazon an S3 bucket notification event. +type NotificationEvent struct { + EventVersion string `json:"eventVersion"` + EventSource string `json:"eventSource"` + AwsRegion string `json:"awsRegion"` + EventTime string `json:"eventTime"` + EventName string `json:"eventName"` + UserIdentity identity `json:"userIdentity"` + RequestParameters map[string]string `json:"requestParameters"` + ResponseElements map[string]string `json:"responseElements"` + S3 eventMeta `json:"s3"` + Source sourceInfo `json:"source"` +} + +// NotificationInfo - represents the collection of notification events, additionally +// also reports errors if any while listening on bucket notifications. +type NotificationInfo struct { + Records []NotificationEvent + Err error +} + +// ListenBucketNotification - listen on bucket notifications. +func (c Client) ListenBucketNotification(bucketName, prefix, suffix string, events []string, doneCh <-chan struct{}) <-chan NotificationInfo { + notificationInfoCh := make(chan NotificationInfo, 1) + // Only success, start a routine to start reading line by line. + go func(notificationInfoCh chan<- NotificationInfo) { + defer close(notificationInfoCh) + + // Validate the bucket name. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + notificationInfoCh <- NotificationInfo{ + Err: err, + } + return + } + + // Check ARN partition to verify if listening bucket is supported + if s3utils.IsAmazonEndpoint(c.endpointURL) || s3utils.IsGoogleEndpoint(c.endpointURL) { + notificationInfoCh <- NotificationInfo{ + Err: ErrAPINotSupported("Listening for bucket notification is specific only to `minio` server endpoints"), + } + return + } + + // Continuously run and listen on bucket notification. + // Create a done channel to control 'ListObjects' go routine. + retryDoneCh := make(chan struct{}, 1) + + // Indicate to our routine to exit cleanly upon return. + defer close(retryDoneCh) + + // Wait on the jitter retry loop. + for range c.newRetryTimerContinous(time.Second, time.Second*30, MaxJitter, retryDoneCh) { + urlValues := make(url.Values) + urlValues.Set("prefix", prefix) + urlValues.Set("suffix", suffix) + urlValues["events"] = events + + // Execute GET on bucket to list objects. + resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentSHA256Hex: emptySHA256Hex, + }) + if err != nil { + notificationInfoCh <- NotificationInfo{ + Err: err, + } + return + } + + // Validate http response, upon error return quickly. + if resp.StatusCode != http.StatusOK { + errResponse := httpRespToErrorResponse(resp, bucketName, "") + notificationInfoCh <- NotificationInfo{ + Err: errResponse, + } + return + } + + // Initialize a new bufio scanner, to read line by line. + bio := bufio.NewScanner(resp.Body) + + // Close the response body. + defer resp.Body.Close() + + // Unmarshal each line, returns marshalled values. + for bio.Scan() { + var notificationInfo NotificationInfo + if err = json.Unmarshal(bio.Bytes(), ¬ificationInfo); err != nil { + continue + } + // Send notifications on channel only if there are events received. + if len(notificationInfo.Records) > 0 { + select { + case notificationInfoCh <- notificationInfo: + case <-doneCh: + return + } + } + } + // Look for any underlying errors. + if err = bio.Err(); err != nil { + // For an unexpected connection drop from server, we close the body + // and re-connect. + if err == io.ErrUnexpectedEOF { + resp.Body.Close() + } + } + } + }(notificationInfoCh) + + // Returns the notification info channel, for caller to start reading from. + return notificationInfoCh +} diff --git a/vendor/github.com/minio/minio-go/api-presigned.go b/vendor/github.com/minio/minio-go/api-presigned.go new file mode 100644 index 000000000..123ad4453 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-presigned.go @@ -0,0 +1,213 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "errors" + "net/http" + "net/url" + "time" + + "github.com/minio/minio-go/pkg/s3signer" + "github.com/minio/minio-go/pkg/s3utils" +) + +// presignURL - Returns a presigned URL for an input 'method'. +// Expires maximum is 7days - ie. 604800 and minimum is 1. +func (c Client) presignURL(method string, bucketName string, objectName string, expires time.Duration, reqParams url.Values) (u *url.URL, err error) { + // Input validation. + if method == "" { + return nil, ErrInvalidArgument("method cannot be empty.") + } + if err = s3utils.CheckValidBucketName(bucketName); err != nil { + return nil, err + } + if err = isValidExpiry(expires); err != nil { + return nil, err + } + + // Convert expires into seconds. + expireSeconds := int64(expires / time.Second) + reqMetadata := requestMetadata{ + presignURL: true, + bucketName: bucketName, + objectName: objectName, + expires: expireSeconds, + queryValues: reqParams, + } + + // Instantiate a new request. + // Since expires is set newRequest will presign the request. + var req *http.Request + if req, err = c.newRequest(method, reqMetadata); err != nil { + return nil, err + } + return req.URL, nil +} + +// PresignedGetObject - Returns a presigned URL to access an object +// data without credentials. URL can have a maximum expiry of +// upto 7days or a minimum of 1sec. Additionally you can override +// a set of response headers using the query parameters. +func (c Client) PresignedGetObject(bucketName string, objectName string, expires time.Duration, reqParams url.Values) (u *url.URL, err error) { + if err = s3utils.CheckValidObjectName(objectName); err != nil { + return nil, err + } + return c.presignURL("GET", bucketName, objectName, expires, reqParams) +} + +// PresignedHeadObject - Returns a presigned URL to access object +// metadata without credentials. URL can have a maximum expiry of +// upto 7days or a minimum of 1sec. Additionally you can override +// a set of response headers using the query parameters. +func (c Client) PresignedHeadObject(bucketName string, objectName string, expires time.Duration, reqParams url.Values) (u *url.URL, err error) { + if err = s3utils.CheckValidObjectName(objectName); err != nil { + return nil, err + } + return c.presignURL("HEAD", bucketName, objectName, expires, reqParams) +} + +// PresignedPutObject - Returns a presigned URL to upload an object +// without credentials. URL can have a maximum expiry of upto 7days +// or a minimum of 1sec. +func (c Client) PresignedPutObject(bucketName string, objectName string, expires time.Duration) (u *url.URL, err error) { + if err = s3utils.CheckValidObjectName(objectName); err != nil { + return nil, err + } + return c.presignURL("PUT", bucketName, objectName, expires, nil) +} + +// Presign - returns a presigned URL for any http method of your choice +// along with custom request params. URL can have a maximum expiry of +// upto 7days or a minimum of 1sec. +func (c Client) Presign(method string, bucketName string, objectName string, expires time.Duration, reqParams url.Values) (u *url.URL, err error) { + return c.presignURL(method, bucketName, objectName, expires, reqParams) +} + +// PresignedPostPolicy - Returns POST urlString, form data to upload an object. +func (c Client) PresignedPostPolicy(p *PostPolicy) (u *url.URL, formData map[string]string, err error) { + // Validate input arguments. + if p.expiration.IsZero() { + return nil, nil, errors.New("Expiration time must be specified") + } + if _, ok := p.formData["key"]; !ok { + return nil, nil, errors.New("object key must be specified") + } + if _, ok := p.formData["bucket"]; !ok { + return nil, nil, errors.New("bucket name must be specified") + } + + bucketName := p.formData["bucket"] + // Fetch the bucket location. + location, err := c.getBucketLocation(bucketName) + if err != nil { + return nil, nil, err + } + + u, err = c.makeTargetURL(bucketName, "", location, nil) + if err != nil { + return nil, nil, err + } + + // Get credentials from the configured credentials provider. + credValues, err := c.credsProvider.Get() + if err != nil { + return nil, nil, err + } + + var ( + signerType = credValues.SignerType + sessionToken = credValues.SessionToken + accessKeyID = credValues.AccessKeyID + secretAccessKey = credValues.SecretAccessKey + ) + + if signerType.IsAnonymous() { + return nil, nil, ErrInvalidArgument("Presigned operations are not supported for anonymous credentials") + } + + // Keep time. + t := time.Now().UTC() + // For signature version '2' handle here. + if signerType.IsV2() { + policyBase64 := p.base64() + p.formData["policy"] = policyBase64 + // For Google endpoint set this value to be 'GoogleAccessId'. + if s3utils.IsGoogleEndpoint(c.endpointURL) { + p.formData["GoogleAccessId"] = accessKeyID + } else { + // For all other endpoints set this value to be 'AWSAccessKeyId'. + p.formData["AWSAccessKeyId"] = accessKeyID + } + // Sign the policy. + p.formData["signature"] = s3signer.PostPresignSignatureV2(policyBase64, secretAccessKey) + return u, p.formData, nil + } + + // Add date policy. + if err = p.addNewPolicy(policyCondition{ + matchType: "eq", + condition: "$x-amz-date", + value: t.Format(iso8601DateFormat), + }); err != nil { + return nil, nil, err + } + + // Add algorithm policy. + if err = p.addNewPolicy(policyCondition{ + matchType: "eq", + condition: "$x-amz-algorithm", + value: signV4Algorithm, + }); err != nil { + return nil, nil, err + } + + // Add a credential policy. + credential := s3signer.GetCredential(accessKeyID, location, t) + if err = p.addNewPolicy(policyCondition{ + matchType: "eq", + condition: "$x-amz-credential", + value: credential, + }); err != nil { + return nil, nil, err + } + + if sessionToken != "" { + if err = p.addNewPolicy(policyCondition{ + matchType: "eq", + condition: "$x-amz-security-token", + value: sessionToken, + }); err != nil { + return nil, nil, err + } + } + + // Get base64 encoded policy. + policyBase64 := p.base64() + + // Fill in the form data. + p.formData["policy"] = policyBase64 + p.formData["x-amz-algorithm"] = signV4Algorithm + p.formData["x-amz-credential"] = credential + p.formData["x-amz-date"] = t.Format(iso8601DateFormat) + if sessionToken != "" { + p.formData["x-amz-security-token"] = sessionToken + } + p.formData["x-amz-signature"] = s3signer.PostPresignSignatureV4(policyBase64, t, secretAccessKey, location) + return u, p.formData, nil +} diff --git a/vendor/github.com/minio/minio-go/api-put-bucket.go b/vendor/github.com/minio/minio-go/api-put-bucket.go new file mode 100644 index 000000000..bb583a78f --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-bucket.go @@ -0,0 +1,255 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "fmt" + "net/http" + "net/url" + + "github.com/minio/minio-go/pkg/policy" + "github.com/minio/minio-go/pkg/s3utils" +) + +/// Bucket operations + +// MakeBucket creates a new bucket with bucketName. +// +// Location is an optional argument, by default all buckets are +// created in US Standard Region. +// +// For Amazon S3 for more supported regions - http://docs.aws.amazon.com/general/latest/gr/rande.html +// For Google Cloud Storage for more supported regions - https://cloud.google.com/storage/docs/bucket-locations +func (c Client) MakeBucket(bucketName string, location string) (err error) { + defer func() { + // Save the location into cache on a successful makeBucket response. + if err == nil { + c.bucketLocCache.Set(bucketName, location) + } + }() + + // Validate the input arguments. + if err := s3utils.CheckValidBucketNameStrict(bucketName); err != nil { + return err + } + + // If location is empty, treat is a default region 'us-east-1'. + if location == "" { + location = "us-east-1" + // For custom region clients, default + // to custom region instead not 'us-east-1'. + if c.region != "" { + location = c.region + } + } + // PUT bucket request metadata. + reqMetadata := requestMetadata{ + bucketName: bucketName, + bucketLocation: location, + } + + // If location is not 'us-east-1' create bucket location config. + if location != "us-east-1" && location != "" { + createBucketConfig := createBucketConfiguration{} + createBucketConfig.Location = location + var createBucketConfigBytes []byte + createBucketConfigBytes, err = xml.Marshal(createBucketConfig) + if err != nil { + return err + } + reqMetadata.contentMD5Base64 = sumMD5Base64(createBucketConfigBytes) + reqMetadata.contentSHA256Hex = sum256Hex(createBucketConfigBytes) + reqMetadata.contentBody = bytes.NewReader(createBucketConfigBytes) + reqMetadata.contentLength = int64(len(createBucketConfigBytes)) + } + + // Execute PUT to create a new bucket. + resp, err := c.executeMethod(context.Background(), "PUT", reqMetadata) + defer closeResponse(resp) + if err != nil { + return err + } + + if resp != nil { + if resp.StatusCode != http.StatusOK { + return httpRespToErrorResponse(resp, bucketName, "") + } + } + + // Success. + return nil +} + +// SetBucketPolicy set the access permissions on an existing bucket. +// +// For example +// +// none - owner gets full access [default]. +// readonly - anonymous get access for everyone at a given object prefix. +// readwrite - anonymous list/put/delete access to a given object prefix. +// writeonly - anonymous put/delete access to a given object prefix. +func (c Client) SetBucketPolicy(bucketName string, objectPrefix string, bucketPolicy policy.BucketPolicy) error { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return err + } + if err := s3utils.CheckValidObjectNamePrefix(objectPrefix); err != nil { + return err + } + + if !bucketPolicy.IsValidBucketPolicy() { + return ErrInvalidArgument(fmt.Sprintf("Invalid bucket policy provided. %s", bucketPolicy)) + } + + policyInfo, err := c.getBucketPolicy(bucketName) + errResponse := ToErrorResponse(err) + if err != nil && errResponse.Code != "NoSuchBucketPolicy" { + return err + } + + if bucketPolicy == policy.BucketPolicyNone && policyInfo.Statements == nil { + // As the request is for removing policy and the bucket + // has empty policy statements, just return success. + return nil + } + + policyInfo.Statements = policy.SetPolicy(policyInfo.Statements, bucketPolicy, bucketName, objectPrefix) + + // Save the updated policies. + return c.putBucketPolicy(bucketName, policyInfo) +} + +// Saves a new bucket policy. +func (c Client) putBucketPolicy(bucketName string, policyInfo policy.BucketAccessPolicy) error { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return err + } + + // If there are no policy statements, we should remove entire policy. + if len(policyInfo.Statements) == 0 { + return c.removeBucketPolicy(bucketName) + } + + // Get resources properly escaped and lined up before + // using them in http request. + urlValues := make(url.Values) + urlValues.Set("policy", "") + + policyBytes, err := json.Marshal(&policyInfo) + if err != nil { + return err + } + + policyBuffer := bytes.NewReader(policyBytes) + reqMetadata := requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentBody: policyBuffer, + contentLength: int64(len(policyBytes)), + contentMD5Base64: sumMD5Base64(policyBytes), + contentSHA256Hex: sum256Hex(policyBytes), + } + + // Execute PUT to upload a new bucket policy. + resp, err := c.executeMethod(context.Background(), "PUT", reqMetadata) + defer closeResponse(resp) + if err != nil { + return err + } + if resp != nil { + if resp.StatusCode != http.StatusNoContent { + return httpRespToErrorResponse(resp, bucketName, "") + } + } + return nil +} + +// Removes all policies on a bucket. +func (c Client) removeBucketPolicy(bucketName string) error { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return err + } + // Get resources properly escaped and lined up before + // using them in http request. + urlValues := make(url.Values) + urlValues.Set("policy", "") + + // Execute DELETE on objectName. + resp, err := c.executeMethod(context.Background(), "DELETE", requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentSHA256Hex: emptySHA256Hex, + }) + defer closeResponse(resp) + if err != nil { + return err + } + return nil +} + +// SetBucketNotification saves a new bucket notification. +func (c Client) SetBucketNotification(bucketName string, bucketNotification BucketNotification) error { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return err + } + + // Get resources properly escaped and lined up before + // using them in http request. + urlValues := make(url.Values) + urlValues.Set("notification", "") + + notifBytes, err := xml.Marshal(bucketNotification) + if err != nil { + return err + } + + notifBuffer := bytes.NewReader(notifBytes) + reqMetadata := requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentBody: notifBuffer, + contentLength: int64(len(notifBytes)), + contentMD5Base64: sumMD5Base64(notifBytes), + contentSHA256Hex: sum256Hex(notifBytes), + } + + // Execute PUT to upload a new bucket notification. + resp, err := c.executeMethod(context.Background(), "PUT", reqMetadata) + defer closeResponse(resp) + if err != nil { + return err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return httpRespToErrorResponse(resp, bucketName, "") + } + } + return nil +} + +// RemoveAllBucketNotification - Remove bucket notification clears all previously specified config +func (c Client) RemoveAllBucketNotification(bucketName string) error { + return c.SetBucketNotification(bucketName, BucketNotification{}) +} diff --git a/vendor/github.com/minio/minio-go/api-put-object-common.go b/vendor/github.com/minio/minio-go/api-put-object-common.go new file mode 100644 index 000000000..c16c3c69a --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-object-common.go @@ -0,0 +1,111 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "io" + "math" + "os" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// Verify if reader is *minio.Object +func isObject(reader io.Reader) (ok bool) { + _, ok = reader.(*Object) + return +} + +// Verify if reader is a generic ReaderAt +func isReadAt(reader io.Reader) (ok bool) { + _, ok = reader.(io.ReaderAt) + if ok { + var v *os.File + v, ok = reader.(*os.File) + if ok { + // Stdin, Stdout and Stderr all have *os.File type + // which happen to also be io.ReaderAt compatible + // we need to add special conditions for them to + // be ignored by this function. + for _, f := range []string{ + "/dev/stdin", + "/dev/stdout", + "/dev/stderr", + } { + if f == v.Name() { + ok = false + break + } + } + } + } + return +} + +// optimalPartInfo - calculate the optimal part info for a given +// object size. +// +// NOTE: Assumption here is that for any object to be uploaded to any S3 compatible +// object storage it will have the following parameters as constants. +// +// maxPartsCount - 10000 +// minPartSize - 64MiB +// maxMultipartPutObjectSize - 5TiB +// +func optimalPartInfo(objectSize int64) (totalPartsCount int, partSize int64, lastPartSize int64, err error) { + // object size is '-1' set it to 5TiB. + if objectSize == -1 { + objectSize = maxMultipartPutObjectSize + } + // object size is larger than supported maximum. + if objectSize > maxMultipartPutObjectSize { + err = ErrEntityTooLarge(objectSize, maxMultipartPutObjectSize, "", "") + return + } + // Use floats for part size for all calculations to avoid + // overflows during float64 to int64 conversions. + partSizeFlt := math.Ceil(float64(objectSize / maxPartsCount)) + partSizeFlt = math.Ceil(partSizeFlt/minPartSize) * minPartSize + // Total parts count. + totalPartsCount = int(math.Ceil(float64(objectSize) / partSizeFlt)) + // Part size. + partSize = int64(partSizeFlt) + // Last part size. + lastPartSize = objectSize - int64(totalPartsCount-1)*partSize + return totalPartsCount, partSize, lastPartSize, nil +} + +// getUploadID - fetch upload id if already present for an object name +// or initiate a new request to fetch a new upload id. +func (c Client) newUploadID(ctx context.Context, bucketName, objectName string, opts PutObjectOptions) (uploadID string, err error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return "", err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return "", err + } + + // Initiate multipart upload for an object. + initMultipartUploadResult, err := c.initiateMultipartUpload(ctx, bucketName, objectName, opts) + if err != nil { + return "", err + } + return initMultipartUploadResult.UploadID, nil +} diff --git a/vendor/github.com/minio/minio-go/api-put-object-context.go b/vendor/github.com/minio/minio-go/api-put-object-context.go new file mode 100644 index 000000000..a6f23dcaa --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-object-context.go @@ -0,0 +1,39 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "io" +) + +// PutObjectWithContext - Identical to PutObject call, but accepts context to facilitate request cancellation. +func (c Client) PutObjectWithContext(ctx context.Context, bucketName, objectName string, reader io.Reader, objectSize int64, + opts PutObjectOptions) (n int64, err error) { + err = opts.validate() + if err != nil { + return 0, err + } + if opts.EncryptMaterials != nil { + if err = opts.EncryptMaterials.SetupEncryptMode(reader); err != nil { + return 0, err + } + return c.putObjectMultipartStreamNoLength(ctx, bucketName, objectName, opts.EncryptMaterials, opts) + } + return c.putObjectCommon(ctx, bucketName, objectName, reader, objectSize, opts) +} diff --git a/vendor/github.com/minio/minio-go/api-put-object-copy.go b/vendor/github.com/minio/minio-go/api-put-object-copy.go new file mode 100644 index 000000000..8032009dc --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-object-copy.go @@ -0,0 +1,23 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +// CopyObject - copy a source object into a new object +func (c Client) CopyObject(dst DestinationInfo, src SourceInfo) error { + return c.ComposeObject(dst, []SourceInfo{src}) +} diff --git a/vendor/github.com/minio/minio-go/api-put-object-encrypted.go b/vendor/github.com/minio/minio-go/api-put-object-encrypted.go new file mode 100644 index 000000000..87dd1ab1a --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-object-encrypted.go @@ -0,0 +1,44 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "io" + + "github.com/minio/minio-go/pkg/encrypt" +) + +// PutEncryptedObject - Encrypt and store object. +func (c Client) PutEncryptedObject(bucketName, objectName string, reader io.Reader, encryptMaterials encrypt.Materials) (n int64, err error) { + + if encryptMaterials == nil { + return 0, ErrInvalidArgument("Unable to recognize empty encryption properties") + } + + if err := encryptMaterials.SetupEncryptMode(reader); err != nil { + return 0, err + } + + return c.PutObjectWithContext(context.Background(), bucketName, objectName, reader, -1, PutObjectOptions{EncryptMaterials: encryptMaterials}) +} + +// FPutEncryptedObject - Encrypt and store an object with contents from file at filePath. +func (c Client) FPutEncryptedObject(bucketName, objectName, filePath string, encryptMaterials encrypt.Materials) (n int64, err error) { + return c.FPutObjectWithContext(context.Background(), bucketName, objectName, filePath, PutObjectOptions{EncryptMaterials: encryptMaterials}) +} diff --git a/vendor/github.com/minio/minio-go/api-put-object-file-context.go b/vendor/github.com/minio/minio-go/api-put-object-file-context.go new file mode 100644 index 000000000..140a9c069 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-object-file-context.go @@ -0,0 +1,64 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "mime" + "os" + "path/filepath" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// FPutObjectWithContext - Create an object in a bucket, with contents from file at filePath. Allows request cancellation. +func (c Client) FPutObjectWithContext(ctx context.Context, bucketName, objectName, filePath string, opts PutObjectOptions) (n int64, err error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return 0, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return 0, err + } + + // Open the referenced file. + fileReader, err := os.Open(filePath) + // If any error fail quickly here. + if err != nil { + return 0, err + } + defer fileReader.Close() + + // Save the file stat. + fileStat, err := fileReader.Stat() + if err != nil { + return 0, err + } + + // Save the file size. + fileSize := fileStat.Size() + + // Set contentType based on filepath extension if not given or default + // value of "application/octet-stream" if the extension has no associated type. + if opts.ContentType == "" { + if opts.ContentType = mime.TypeByExtension(filepath.Ext(filePath)); opts.ContentType == "" { + opts.ContentType = "application/octet-stream" + } + } + return c.PutObjectWithContext(ctx, bucketName, objectName, fileReader, fileSize, opts) +} diff --git a/vendor/github.com/minio/minio-go/api-put-object-file.go b/vendor/github.com/minio/minio-go/api-put-object-file.go new file mode 100644 index 000000000..7c8e05117 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-object-file.go @@ -0,0 +1,27 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" +) + +// FPutObject - Create an object in a bucket, with contents from file at filePath +func (c Client) FPutObject(bucketName, objectName, filePath string, opts PutObjectOptions) (n int64, err error) { + return c.FPutObjectWithContext(context.Background(), bucketName, objectName, filePath, opts) +} diff --git a/vendor/github.com/minio/minio-go/api-put-object-multipart.go b/vendor/github.com/minio/minio-go/api-put-object-multipart.go new file mode 100644 index 000000000..f5b8893e6 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-object-multipart.go @@ -0,0 +1,373 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "bytes" + "context" + "encoding/base64" + "encoding/hex" + "encoding/xml" + "fmt" + "io" + "io/ioutil" + "net/http" + "net/url" + "runtime/debug" + "sort" + "strconv" + "strings" + + "github.com/minio/minio-go/pkg/s3utils" +) + +func (c Client) putObjectMultipart(ctx context.Context, bucketName, objectName string, reader io.Reader, size int64, + opts PutObjectOptions) (n int64, err error) { + n, err = c.putObjectMultipartNoStream(ctx, bucketName, objectName, reader, opts) + if err != nil { + errResp := ToErrorResponse(err) + // Verify if multipart functionality is not available, if not + // fall back to single PutObject operation. + if errResp.Code == "AccessDenied" && strings.Contains(errResp.Message, "Access Denied") { + // Verify if size of reader is greater than '5GiB'. + if size > maxSinglePutObjectSize { + return 0, ErrEntityTooLarge(size, maxSinglePutObjectSize, bucketName, objectName) + } + // Fall back to uploading as single PutObject operation. + return c.putObjectNoChecksum(ctx, bucketName, objectName, reader, size, opts) + } + } + return n, err +} + +func (c Client) putObjectMultipartNoStream(ctx context.Context, bucketName, objectName string, reader io.Reader, opts PutObjectOptions) (n int64, err error) { + // Input validation. + if err = s3utils.CheckValidBucketName(bucketName); err != nil { + return 0, err + } + if err = s3utils.CheckValidObjectName(objectName); err != nil { + return 0, err + } + + // Total data read and written to server. should be equal to + // 'size' at the end of the call. + var totalUploadedSize int64 + + // Complete multipart upload. + var complMultipartUpload completeMultipartUpload + + // Calculate the optimal parts info for a given size. + totalPartsCount, partSize, _, err := optimalPartInfo(-1) + if err != nil { + return 0, err + } + + // Initiate a new multipart upload. + uploadID, err := c.newUploadID(ctx, bucketName, objectName, opts) + if err != nil { + return 0, err + } + + defer func() { + if err != nil { + c.abortMultipartUpload(ctx, bucketName, objectName, uploadID) + } + }() + + // Part number always starts with '1'. + partNumber := 1 + + // Initialize parts uploaded map. + partsInfo := make(map[int]ObjectPart) + + // Create a buffer. + buf := make([]byte, partSize) + defer debug.FreeOSMemory() + + for partNumber <= totalPartsCount { + // Choose hash algorithms to be calculated by hashCopyN, + // avoid sha256 with non-v4 signature request or + // HTTPS connection. + hashAlgos, hashSums := c.hashMaterials() + + length, rErr := io.ReadFull(reader, buf) + if rErr == io.EOF { + break + } + if rErr != nil && rErr != io.ErrUnexpectedEOF { + return 0, rErr + } + + // Calculates hash sums while copying partSize bytes into cw. + for k, v := range hashAlgos { + v.Write(buf[:length]) + hashSums[k] = v.Sum(nil) + } + + // Update progress reader appropriately to the latest offset + // as we read from the source. + rd := newHook(bytes.NewReader(buf[:length]), opts.Progress) + + // Checksums.. + var ( + md5Base64 string + sha256Hex string + ) + if hashSums["md5"] != nil { + md5Base64 = base64.StdEncoding.EncodeToString(hashSums["md5"]) + } + if hashSums["sha256"] != nil { + sha256Hex = hex.EncodeToString(hashSums["sha256"]) + } + + // Proceed to upload the part. + var objPart ObjectPart + objPart, err = c.uploadPart(ctx, bucketName, objectName, uploadID, rd, partNumber, + md5Base64, sha256Hex, int64(length), opts.UserMetadata) + if err != nil { + return totalUploadedSize, err + } + + // Save successfully uploaded part metadata. + partsInfo[partNumber] = objPart + + // Save successfully uploaded size. + totalUploadedSize += int64(length) + + // Increment part number. + partNumber++ + + // For unknown size, Read EOF we break away. + // We do not have to upload till totalPartsCount. + if rErr == io.EOF { + break + } + } + + // Loop over total uploaded parts to save them in + // Parts array before completing the multipart request. + for i := 1; i < partNumber; i++ { + part, ok := partsInfo[i] + if !ok { + return 0, ErrInvalidArgument(fmt.Sprintf("Missing part number %d", i)) + } + complMultipartUpload.Parts = append(complMultipartUpload.Parts, CompletePart{ + ETag: part.ETag, + PartNumber: part.PartNumber, + }) + } + + // Sort all completed parts. + sort.Sort(completedParts(complMultipartUpload.Parts)) + if _, err = c.completeMultipartUpload(ctx, bucketName, objectName, uploadID, complMultipartUpload); err != nil { + return totalUploadedSize, err + } + + // Return final size. + return totalUploadedSize, nil +} + +// initiateMultipartUpload - Initiates a multipart upload and returns an upload ID. +func (c Client) initiateMultipartUpload(ctx context.Context, bucketName, objectName string, opts PutObjectOptions) (initiateMultipartUploadResult, error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return initiateMultipartUploadResult{}, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return initiateMultipartUploadResult{}, err + } + + // Initialize url queries. + urlValues := make(url.Values) + urlValues.Set("uploads", "") + + // Set ContentType header. + customHeader := opts.Header() + + reqMetadata := requestMetadata{ + bucketName: bucketName, + objectName: objectName, + queryValues: urlValues, + customHeader: customHeader, + } + + // Execute POST on an objectName to initiate multipart upload. + resp, err := c.executeMethod(ctx, "POST", reqMetadata) + defer closeResponse(resp) + if err != nil { + return initiateMultipartUploadResult{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return initiateMultipartUploadResult{}, httpRespToErrorResponse(resp, bucketName, objectName) + } + } + // Decode xml for new multipart upload. + initiateMultipartUploadResult := initiateMultipartUploadResult{} + err = xmlDecoder(resp.Body, &initiateMultipartUploadResult) + if err != nil { + return initiateMultipartUploadResult, err + } + return initiateMultipartUploadResult, nil +} + +const serverEncryptionKeyPrefix = "x-amz-server-side-encryption" + +// uploadPart - Uploads a part in a multipart upload. +func (c Client) uploadPart(ctx context.Context, bucketName, objectName, uploadID string, reader io.Reader, + partNumber int, md5Base64, sha256Hex string, size int64, metadata map[string]string) (ObjectPart, error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return ObjectPart{}, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return ObjectPart{}, err + } + if size > maxPartSize { + return ObjectPart{}, ErrEntityTooLarge(size, maxPartSize, bucketName, objectName) + } + if size <= -1 { + return ObjectPart{}, ErrEntityTooSmall(size, bucketName, objectName) + } + if partNumber <= 0 { + return ObjectPart{}, ErrInvalidArgument("Part number cannot be negative or equal to zero.") + } + if uploadID == "" { + return ObjectPart{}, ErrInvalidArgument("UploadID cannot be empty.") + } + + // Get resources properly escaped and lined up before using them in http request. + urlValues := make(url.Values) + // Set part number. + urlValues.Set("partNumber", strconv.Itoa(partNumber)) + // Set upload id. + urlValues.Set("uploadId", uploadID) + + // Set encryption headers, if any. + customHeader := make(http.Header) + for k, v := range metadata { + if len(v) > 0 { + if strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) { + customHeader.Set(k, v) + } + } + } + + reqMetadata := requestMetadata{ + bucketName: bucketName, + objectName: objectName, + queryValues: urlValues, + customHeader: customHeader, + contentBody: reader, + contentLength: size, + contentMD5Base64: md5Base64, + contentSHA256Hex: sha256Hex, + } + + // Execute PUT on each part. + resp, err := c.executeMethod(ctx, "PUT", reqMetadata) + defer closeResponse(resp) + if err != nil { + return ObjectPart{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return ObjectPart{}, httpRespToErrorResponse(resp, bucketName, objectName) + } + } + // Once successfully uploaded, return completed part. + objPart := ObjectPart{} + objPart.Size = size + objPart.PartNumber = partNumber + // Trim off the odd double quotes from ETag in the beginning and end. + objPart.ETag = strings.TrimPrefix(resp.Header.Get("ETag"), "\"") + objPart.ETag = strings.TrimSuffix(objPart.ETag, "\"") + return objPart, nil +} + +// completeMultipartUpload - Completes a multipart upload by assembling previously uploaded parts. +func (c Client) completeMultipartUpload(ctx context.Context, bucketName, objectName, uploadID string, + complete completeMultipartUpload) (completeMultipartUploadResult, error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return completeMultipartUploadResult{}, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return completeMultipartUploadResult{}, err + } + + // Initialize url queries. + urlValues := make(url.Values) + urlValues.Set("uploadId", uploadID) + // Marshal complete multipart body. + completeMultipartUploadBytes, err := xml.Marshal(complete) + if err != nil { + return completeMultipartUploadResult{}, err + } + + // Instantiate all the complete multipart buffer. + completeMultipartUploadBuffer := bytes.NewReader(completeMultipartUploadBytes) + reqMetadata := requestMetadata{ + bucketName: bucketName, + objectName: objectName, + queryValues: urlValues, + contentBody: completeMultipartUploadBuffer, + contentLength: int64(len(completeMultipartUploadBytes)), + contentSHA256Hex: sum256Hex(completeMultipartUploadBytes), + } + + // Execute POST to complete multipart upload for an objectName. + resp, err := c.executeMethod(ctx, "POST", reqMetadata) + defer closeResponse(resp) + if err != nil { + return completeMultipartUploadResult{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return completeMultipartUploadResult{}, httpRespToErrorResponse(resp, bucketName, objectName) + } + } + + // Read resp.Body into a []bytes to parse for Error response inside the body + var b []byte + b, err = ioutil.ReadAll(resp.Body) + if err != nil { + return completeMultipartUploadResult{}, err + } + // Decode completed multipart upload response on success. + completeMultipartUploadResult := completeMultipartUploadResult{} + err = xmlDecoder(bytes.NewReader(b), &completeMultipartUploadResult) + if err != nil { + // xml parsing failure due to presence an ill-formed xml fragment + return completeMultipartUploadResult, err + } else if completeMultipartUploadResult.Bucket == "" { + // xml's Decode method ignores well-formed xml that don't apply to the type of value supplied. + // In this case, it would leave completeMultipartUploadResult with the corresponding zero-values + // of the members. + + // Decode completed multipart upload response on failure + completeMultipartUploadErr := ErrorResponse{} + err = xmlDecoder(bytes.NewReader(b), &completeMultipartUploadErr) + if err != nil { + // xml parsing failure due to presence an ill-formed xml fragment + return completeMultipartUploadResult, err + } + return completeMultipartUploadResult, completeMultipartUploadErr + } + return completeMultipartUploadResult, nil +} diff --git a/vendor/github.com/minio/minio-go/api-put-object-streaming.go b/vendor/github.com/minio/minio-go/api-put-object-streaming.go new file mode 100644 index 000000000..579cb5482 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-object-streaming.go @@ -0,0 +1,417 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "fmt" + "io" + "net/http" + "sort" + "strings" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// putObjectMultipartStream - upload a large object using +// multipart upload and streaming signature for signing payload. +// Comprehensive put object operation involving multipart uploads. +// +// Following code handles these types of readers. +// +// - *minio.Object +// - Any reader which has a method 'ReadAt()' +// +func (c Client) putObjectMultipartStream(ctx context.Context, bucketName, objectName string, + reader io.Reader, size int64, opts PutObjectOptions) (n int64, err error) { + + if !isObject(reader) && isReadAt(reader) { + // Verify if the reader implements ReadAt and it is not a *minio.Object then we will use parallel uploader. + n, err = c.putObjectMultipartStreamFromReadAt(ctx, bucketName, objectName, reader.(io.ReaderAt), size, opts) + } else { + n, err = c.putObjectMultipartStreamNoChecksum(ctx, bucketName, objectName, reader, size, opts) + } + if err != nil { + errResp := ToErrorResponse(err) + // Verify if multipart functionality is not available, if not + // fall back to single PutObject operation. + if errResp.Code == "AccessDenied" && strings.Contains(errResp.Message, "Access Denied") { + // Verify if size of reader is greater than '5GiB'. + if size > maxSinglePutObjectSize { + return 0, ErrEntityTooLarge(size, maxSinglePutObjectSize, bucketName, objectName) + } + // Fall back to uploading as single PutObject operation. + return c.putObjectNoChecksum(ctx, bucketName, objectName, reader, size, opts) + } + } + return n, err +} + +// uploadedPartRes - the response received from a part upload. +type uploadedPartRes struct { + Error error // Any error encountered while uploading the part. + PartNum int // Number of the part uploaded. + Size int64 // Size of the part uploaded. + Part *ObjectPart +} + +type uploadPartReq struct { + PartNum int // Number of the part uploaded. + Part *ObjectPart // Size of the part uploaded. +} + +// putObjectMultipartFromReadAt - Uploads files bigger than 64MiB. +// Supports all readers which implements io.ReaderAt interface +// (ReadAt method). +// +// NOTE: This function is meant to be used for all readers which +// implement io.ReaderAt which allows us for resuming multipart +// uploads but reading at an offset, which would avoid re-read the +// data which was already uploaded. Internally this function uses +// temporary files for staging all the data, these temporary files are +// cleaned automatically when the caller i.e http client closes the +// stream after uploading all the contents successfully. +func (c Client) putObjectMultipartStreamFromReadAt(ctx context.Context, bucketName, objectName string, + reader io.ReaderAt, size int64, opts PutObjectOptions) (n int64, err error) { + // Input validation. + if err = s3utils.CheckValidBucketName(bucketName); err != nil { + return 0, err + } + if err = s3utils.CheckValidObjectName(objectName); err != nil { + return 0, err + } + + // Calculate the optimal parts info for a given size. + totalPartsCount, partSize, lastPartSize, err := optimalPartInfo(size) + if err != nil { + return 0, err + } + + // Initiate a new multipart upload. + uploadID, err := c.newUploadID(ctx, bucketName, objectName, opts) + if err != nil { + return 0, err + } + + // Aborts the multipart upload in progress, if the + // function returns any error, since we do not resume + // we should purge the parts which have been uploaded + // to relinquish storage space. + defer func() { + if err != nil { + c.abortMultipartUpload(ctx, bucketName, objectName, uploadID) + } + }() + + // Total data read and written to server. should be equal to 'size' at the end of the call. + var totalUploadedSize int64 + + // Complete multipart upload. + var complMultipartUpload completeMultipartUpload + + // Declare a channel that sends the next part number to be uploaded. + // Buffered to 10000 because thats the maximum number of parts allowed + // by S3. + uploadPartsCh := make(chan uploadPartReq, 10000) + + // Declare a channel that sends back the response of a part upload. + // Buffered to 10000 because thats the maximum number of parts allowed + // by S3. + uploadedPartsCh := make(chan uploadedPartRes, 10000) + + // Used for readability, lastPartNumber is always totalPartsCount. + lastPartNumber := totalPartsCount + + // Send each part number to the channel to be processed. + for p := 1; p <= totalPartsCount; p++ { + uploadPartsCh <- uploadPartReq{PartNum: p, Part: nil} + } + close(uploadPartsCh) + // Receive each part number from the channel allowing three parallel uploads. + for w := 1; w <= opts.getNumThreads(); w++ { + go func(partSize int64) { + // Each worker will draw from the part channel and upload in parallel. + for uploadReq := range uploadPartsCh { + + // If partNumber was not uploaded we calculate the missing + // part offset and size. For all other part numbers we + // calculate offset based on multiples of partSize. + readOffset := int64(uploadReq.PartNum-1) * partSize + + // As a special case if partNumber is lastPartNumber, we + // calculate the offset based on the last part size. + if uploadReq.PartNum == lastPartNumber { + readOffset = (size - lastPartSize) + partSize = lastPartSize + } + + // Get a section reader on a particular offset. + sectionReader := newHook(io.NewSectionReader(reader, readOffset, partSize), opts.Progress) + + // Proceed to upload the part. + var objPart ObjectPart + objPart, err = c.uploadPart(ctx, bucketName, objectName, uploadID, + sectionReader, uploadReq.PartNum, + "", "", partSize, opts.UserMetadata) + if err != nil { + uploadedPartsCh <- uploadedPartRes{ + Size: 0, + Error: err, + } + // Exit the goroutine. + return + } + + // Save successfully uploaded part metadata. + uploadReq.Part = &objPart + + // Send successful part info through the channel. + uploadedPartsCh <- uploadedPartRes{ + Size: objPart.Size, + PartNum: uploadReq.PartNum, + Part: uploadReq.Part, + Error: nil, + } + } + }(partSize) + } + + // Gather the responses as they occur and update any + // progress bar. + for u := 1; u <= totalPartsCount; u++ { + uploadRes := <-uploadedPartsCh + if uploadRes.Error != nil { + return totalUploadedSize, uploadRes.Error + } + // Retrieve each uploaded part and store it to be completed. + // part, ok := partsInfo[uploadRes.PartNum] + part := uploadRes.Part + if part == nil { + return 0, ErrInvalidArgument(fmt.Sprintf("Missing part number %d", uploadRes.PartNum)) + } + // Update the totalUploadedSize. + totalUploadedSize += uploadRes.Size + // Store the parts to be completed in order. + complMultipartUpload.Parts = append(complMultipartUpload.Parts, CompletePart{ + ETag: part.ETag, + PartNumber: part.PartNumber, + }) + } + + // Verify if we uploaded all the data. + if totalUploadedSize != size { + return totalUploadedSize, ErrUnexpectedEOF(totalUploadedSize, size, bucketName, objectName) + } + + // Sort all completed parts. + sort.Sort(completedParts(complMultipartUpload.Parts)) + _, err = c.completeMultipartUpload(ctx, bucketName, objectName, uploadID, complMultipartUpload) + if err != nil { + return totalUploadedSize, err + } + + // Return final size. + return totalUploadedSize, nil +} + +func (c Client) putObjectMultipartStreamNoChecksum(ctx context.Context, bucketName, objectName string, + reader io.Reader, size int64, opts PutObjectOptions) (n int64, err error) { + // Input validation. + if err = s3utils.CheckValidBucketName(bucketName); err != nil { + return 0, err + } + if err = s3utils.CheckValidObjectName(objectName); err != nil { + return 0, err + } + + // Calculate the optimal parts info for a given size. + totalPartsCount, partSize, lastPartSize, err := optimalPartInfo(size) + if err != nil { + return 0, err + } + // Initiates a new multipart request + uploadID, err := c.newUploadID(ctx, bucketName, objectName, opts) + if err != nil { + return 0, err + } + + // Aborts the multipart upload if the function returns + // any error, since we do not resume we should purge + // the parts which have been uploaded to relinquish + // storage space. + defer func() { + if err != nil { + c.abortMultipartUpload(ctx, bucketName, objectName, uploadID) + } + }() + + // Total data read and written to server. should be equal to 'size' at the end of the call. + var totalUploadedSize int64 + + // Initialize parts uploaded map. + partsInfo := make(map[int]ObjectPart) + + // Part number always starts with '1'. + var partNumber int + for partNumber = 1; partNumber <= totalPartsCount; partNumber++ { + // Update progress reader appropriately to the latest offset + // as we read from the source. + hookReader := newHook(reader, opts.Progress) + + // Proceed to upload the part. + if partNumber == totalPartsCount { + partSize = lastPartSize + } + var objPart ObjectPart + objPart, err = c.uploadPart(ctx, bucketName, objectName, uploadID, + io.LimitReader(hookReader, partSize), + partNumber, "", "", partSize, opts.UserMetadata) + if err != nil { + return totalUploadedSize, err + } + + // Save successfully uploaded part metadata. + partsInfo[partNumber] = objPart + + // Save successfully uploaded size. + totalUploadedSize += partSize + } + + // Verify if we uploaded all the data. + if size > 0 { + if totalUploadedSize != size { + return totalUploadedSize, ErrUnexpectedEOF(totalUploadedSize, size, bucketName, objectName) + } + } + + // Complete multipart upload. + var complMultipartUpload completeMultipartUpload + + // Loop over total uploaded parts to save them in + // Parts array before completing the multipart request. + for i := 1; i < partNumber; i++ { + part, ok := partsInfo[i] + if !ok { + return 0, ErrInvalidArgument(fmt.Sprintf("Missing part number %d", i)) + } + complMultipartUpload.Parts = append(complMultipartUpload.Parts, CompletePart{ + ETag: part.ETag, + PartNumber: part.PartNumber, + }) + } + + // Sort all completed parts. + sort.Sort(completedParts(complMultipartUpload.Parts)) + _, err = c.completeMultipartUpload(ctx, bucketName, objectName, uploadID, complMultipartUpload) + if err != nil { + return totalUploadedSize, err + } + + // Return final size. + return totalUploadedSize, nil +} + +// putObjectNoChecksum special function used Google Cloud Storage. This special function +// is used for Google Cloud Storage since Google's multipart API is not S3 compatible. +func (c Client) putObjectNoChecksum(ctx context.Context, bucketName, objectName string, reader io.Reader, size int64, opts PutObjectOptions) (n int64, err error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return 0, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return 0, err + } + + // Size -1 is only supported on Google Cloud Storage, we error + // out in all other situations. + if size < 0 && !s3utils.IsGoogleEndpoint(c.endpointURL) { + return 0, ErrEntityTooSmall(size, bucketName, objectName) + } + if size > 0 { + if isReadAt(reader) && !isObject(reader) { + seeker, _ := reader.(io.Seeker) + offset, err := seeker.Seek(0, io.SeekCurrent) + if err != nil { + return 0, ErrInvalidArgument(err.Error()) + } + reader = io.NewSectionReader(reader.(io.ReaderAt), offset, size) + } + } + + // Update progress reader appropriately to the latest offset as we + // read from the source. + readSeeker := newHook(reader, opts.Progress) + + // This function does not calculate sha256 and md5sum for payload. + // Execute put object. + st, err := c.putObjectDo(ctx, bucketName, objectName, readSeeker, "", "", size, opts) + if err != nil { + return 0, err + } + if st.Size != size { + return 0, ErrUnexpectedEOF(st.Size, size, bucketName, objectName) + } + return size, nil +} + +// putObjectDo - executes the put object http operation. +// NOTE: You must have WRITE permissions on a bucket to add an object to it. +func (c Client) putObjectDo(ctx context.Context, bucketName, objectName string, reader io.Reader, md5Base64, sha256Hex string, size int64, opts PutObjectOptions) (ObjectInfo, error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return ObjectInfo{}, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return ObjectInfo{}, err + } + // Set headers. + customHeader := opts.Header() + + // Populate request metadata. + reqMetadata := requestMetadata{ + bucketName: bucketName, + objectName: objectName, + customHeader: customHeader, + contentBody: reader, + contentLength: size, + contentMD5Base64: md5Base64, + contentSHA256Hex: sha256Hex, + } + + // Execute PUT an objectName. + resp, err := c.executeMethod(ctx, "PUT", reqMetadata) + defer closeResponse(resp) + if err != nil { + return ObjectInfo{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return ObjectInfo{}, httpRespToErrorResponse(resp, bucketName, objectName) + } + } + + var objInfo ObjectInfo + // Trim off the odd double quotes from ETag in the beginning and end. + objInfo.ETag = strings.TrimPrefix(resp.Header.Get("ETag"), "\"") + objInfo.ETag = strings.TrimSuffix(objInfo.ETag, "\"") + // A success here means data was written to server successfully. + objInfo.Size = size + + // Return here. + return objInfo, nil +} diff --git a/vendor/github.com/minio/minio-go/api-put-object.go b/vendor/github.com/minio/minio-go/api-put-object.go new file mode 100644 index 000000000..d3753484a --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-put-object.go @@ -0,0 +1,258 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "bytes" + "context" + "fmt" + "io" + "net/http" + "runtime/debug" + "sort" + + "github.com/minio/minio-go/pkg/encrypt" + "github.com/minio/minio-go/pkg/s3utils" +) + +// PutObjectOptions represents options specified by user for PutObject call +type PutObjectOptions struct { + UserMetadata map[string]string + Progress io.Reader + ContentType string + ContentEncoding string + ContentDisposition string + CacheControl string + EncryptMaterials encrypt.Materials + NumThreads uint + StorageClass string +} + +// getNumThreads - gets the number of threads to be used in the multipart +// put object operation +func (opts PutObjectOptions) getNumThreads() (numThreads int) { + if opts.NumThreads > 0 { + numThreads = int(opts.NumThreads) + } else { + numThreads = totalWorkers + } + return +} + +// Header - constructs the headers from metadata entered by user in +// PutObjectOptions struct +func (opts PutObjectOptions) Header() (header http.Header) { + header = make(http.Header) + + if opts.ContentType != "" { + header["Content-Type"] = []string{opts.ContentType} + } else { + header["Content-Type"] = []string{"application/octet-stream"} + } + if opts.ContentEncoding != "" { + header["Content-Encoding"] = []string{opts.ContentEncoding} + } + if opts.ContentDisposition != "" { + header["Content-Disposition"] = []string{opts.ContentDisposition} + } + if opts.CacheControl != "" { + header["Cache-Control"] = []string{opts.CacheControl} + } + if opts.EncryptMaterials != nil { + header[amzHeaderIV] = []string{opts.EncryptMaterials.GetIV()} + header[amzHeaderKey] = []string{opts.EncryptMaterials.GetKey()} + header[amzHeaderMatDesc] = []string{opts.EncryptMaterials.GetDesc()} + } + if opts.StorageClass != "" { + header[amzStorageClass] = []string{opts.StorageClass} + } + for k, v := range opts.UserMetadata { + if !isAmzHeader(k) && !isStandardHeader(k) && !isSSEHeader(k) && !isStorageClassHeader(k) { + header["X-Amz-Meta-"+k] = []string{v} + } else { + header[k] = []string{v} + } + } + return +} + +// validate() checks if the UserMetadata map has standard headers or client side +// encryption headers and raises an error if so. +func (opts PutObjectOptions) validate() (err error) { + for k := range opts.UserMetadata { + if isStandardHeader(k) || isCSEHeader(k) || isStorageClassHeader(k) { + return ErrInvalidArgument(k + " unsupported request parameter for user defined metadata from minio-go") + } + } + return nil +} + +// completedParts is a collection of parts sortable by their part numbers. +// used for sorting the uploaded parts before completing the multipart request. +type completedParts []CompletePart + +func (a completedParts) Len() int { return len(a) } +func (a completedParts) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a completedParts) Less(i, j int) bool { return a[i].PartNumber < a[j].PartNumber } + +// PutObject creates an object in a bucket. +// +// You must have WRITE permissions on a bucket to create an object. +// +// - For size smaller than 64MiB PutObject automatically does a +// single atomic Put operation. +// - For size larger than 64MiB PutObject automatically does a +// multipart Put operation. +// - For size input as -1 PutObject does a multipart Put operation +// until input stream reaches EOF. Maximum object size that can +// be uploaded through this operation will be 5TiB. +func (c Client) PutObject(bucketName, objectName string, reader io.Reader, objectSize int64, + opts PutObjectOptions) (n int64, err error) { + return c.PutObjectWithContext(context.Background(), bucketName, objectName, reader, objectSize, opts) +} + +func (c Client) putObjectCommon(ctx context.Context, bucketName, objectName string, reader io.Reader, size int64, opts PutObjectOptions) (n int64, err error) { + // Check for largest object size allowed. + if size > int64(maxMultipartPutObjectSize) { + return 0, ErrEntityTooLarge(size, maxMultipartPutObjectSize, bucketName, objectName) + } + + // NOTE: Streaming signature is not supported by GCS. + if s3utils.IsGoogleEndpoint(c.endpointURL) { + // Do not compute MD5 for Google Cloud Storage. + return c.putObjectNoChecksum(ctx, bucketName, objectName, reader, size, opts) + } + + if c.overrideSignerType.IsV2() { + if size >= 0 && size < minPartSize { + return c.putObjectNoChecksum(ctx, bucketName, objectName, reader, size, opts) + } + return c.putObjectMultipart(ctx, bucketName, objectName, reader, size, opts) + } + if size < 0 { + return c.putObjectMultipartStreamNoLength(ctx, bucketName, objectName, reader, opts) + } + + if size < minPartSize { + return c.putObjectNoChecksum(ctx, bucketName, objectName, reader, size, opts) + } + // For all sizes greater than 64MiB do multipart. + return c.putObjectMultipartStream(ctx, bucketName, objectName, reader, size, opts) +} + +func (c Client) putObjectMultipartStreamNoLength(ctx context.Context, bucketName, objectName string, reader io.Reader, opts PutObjectOptions) (n int64, err error) { + // Input validation. + if err = s3utils.CheckValidBucketName(bucketName); err != nil { + return 0, err + } + if err = s3utils.CheckValidObjectName(objectName); err != nil { + return 0, err + } + + // Total data read and written to server. should be equal to + // 'size' at the end of the call. + var totalUploadedSize int64 + + // Complete multipart upload. + var complMultipartUpload completeMultipartUpload + + // Calculate the optimal parts info for a given size. + totalPartsCount, partSize, _, err := optimalPartInfo(-1) + if err != nil { + return 0, err + } + // Initiate a new multipart upload. + uploadID, err := c.newUploadID(ctx, bucketName, objectName, opts) + if err != nil { + return 0, err + } + + defer func() { + if err != nil { + c.abortMultipartUpload(ctx, bucketName, objectName, uploadID) + } + }() + + // Part number always starts with '1'. + partNumber := 1 + + // Initialize parts uploaded map. + partsInfo := make(map[int]ObjectPart) + + // Create a buffer. + buf := make([]byte, partSize) + defer debug.FreeOSMemory() + + for partNumber <= totalPartsCount { + length, rErr := io.ReadFull(reader, buf) + if rErr == io.EOF && partNumber > 1 { + break + } + if rErr != nil && rErr != io.ErrUnexpectedEOF { + return 0, rErr + } + // Update progress reader appropriately to the latest offset + // as we read from the source. + rd := newHook(bytes.NewReader(buf[:length]), opts.Progress) + + // Proceed to upload the part. + var objPart ObjectPart + objPart, err = c.uploadPart(ctx, bucketName, objectName, uploadID, rd, partNumber, + "", "", int64(length), opts.UserMetadata) + if err != nil { + return totalUploadedSize, err + } + + // Save successfully uploaded part metadata. + partsInfo[partNumber] = objPart + + // Save successfully uploaded size. + totalUploadedSize += int64(length) + + // Increment part number. + partNumber++ + + // For unknown size, Read EOF we break away. + // We do not have to upload till totalPartsCount. + if rErr == io.EOF { + break + } + } + + // Loop over total uploaded parts to save them in + // Parts array before completing the multipart request. + for i := 1; i < partNumber; i++ { + part, ok := partsInfo[i] + if !ok { + return 0, ErrInvalidArgument(fmt.Sprintf("Missing part number %d", i)) + } + complMultipartUpload.Parts = append(complMultipartUpload.Parts, CompletePart{ + ETag: part.ETag, + PartNumber: part.PartNumber, + }) + } + + // Sort all completed parts. + sort.Sort(completedParts(complMultipartUpload.Parts)) + if _, err = c.completeMultipartUpload(ctx, bucketName, objectName, uploadID, complMultipartUpload); err != nil { + return totalUploadedSize, err + } + + // Return final size. + return totalUploadedSize, nil +} diff --git a/vendor/github.com/minio/minio-go/api-remove.go b/vendor/github.com/minio/minio-go/api-remove.go new file mode 100644 index 000000000..f14b2eb7f --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-remove.go @@ -0,0 +1,290 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "bytes" + "context" + "encoding/xml" + "io" + "net/http" + "net/url" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// RemoveBucket deletes the bucket name. +// +// All objects (including all object versions and delete markers). +// in the bucket must be deleted before successfully attempting this request. +func (c Client) RemoveBucket(bucketName string) error { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return err + } + // Execute DELETE on bucket. + resp, err := c.executeMethod(context.Background(), "DELETE", requestMetadata{ + bucketName: bucketName, + contentSHA256Hex: emptySHA256Hex, + }) + defer closeResponse(resp) + if err != nil { + return err + } + if resp != nil { + if resp.StatusCode != http.StatusNoContent { + return httpRespToErrorResponse(resp, bucketName, "") + } + } + + // Remove the location from cache on a successful delete. + c.bucketLocCache.Delete(bucketName) + + return nil +} + +// RemoveObject remove an object from a bucket. +func (c Client) RemoveObject(bucketName, objectName string) error { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return err + } + // Execute DELETE on objectName. + resp, err := c.executeMethod(context.Background(), "DELETE", requestMetadata{ + bucketName: bucketName, + objectName: objectName, + contentSHA256Hex: emptySHA256Hex, + }) + defer closeResponse(resp) + if err != nil { + return err + } + if resp != nil { + // if some unexpected error happened and max retry is reached, we want to let client know + if resp.StatusCode != http.StatusNoContent { + return httpRespToErrorResponse(resp, bucketName, objectName) + } + } + + // DeleteObject always responds with http '204' even for + // objects which do not exist. So no need to handle them + // specifically. + return nil +} + +// RemoveObjectError - container of Multi Delete S3 API error +type RemoveObjectError struct { + ObjectName string + Err error +} + +// generateRemoveMultiObjects - generate the XML request for remove multi objects request +func generateRemoveMultiObjectsRequest(objects []string) []byte { + rmObjects := []deleteObject{} + for _, obj := range objects { + rmObjects = append(rmObjects, deleteObject{Key: obj}) + } + xmlBytes, _ := xml.Marshal(deleteMultiObjects{Objects: rmObjects, Quiet: true}) + return xmlBytes +} + +// processRemoveMultiObjectsResponse - parse the remove multi objects web service +// and return the success/failure result status for each object +func processRemoveMultiObjectsResponse(body io.Reader, objects []string, errorCh chan<- RemoveObjectError) { + // Parse multi delete XML response + rmResult := &deleteMultiObjectsResult{} + err := xmlDecoder(body, rmResult) + if err != nil { + errorCh <- RemoveObjectError{ObjectName: "", Err: err} + return + } + + // Fill deletion that returned an error. + for _, obj := range rmResult.UnDeletedObjects { + errorCh <- RemoveObjectError{ + ObjectName: obj.Key, + Err: ErrorResponse{ + Code: obj.Code, + Message: obj.Message, + }, + } + } +} + +// RemoveObjects remove multiples objects from a bucket. +// The list of objects to remove are received from objectsCh. +// Remove failures are sent back via error channel. +func (c Client) RemoveObjects(bucketName string, objectsCh <-chan string) <-chan RemoveObjectError { + errorCh := make(chan RemoveObjectError, 1) + + // Validate if bucket name is valid. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + defer close(errorCh) + errorCh <- RemoveObjectError{ + Err: err, + } + return errorCh + } + // Validate objects channel to be properly allocated. + if objectsCh == nil { + defer close(errorCh) + errorCh <- RemoveObjectError{ + Err: ErrInvalidArgument("Objects channel cannot be nil"), + } + return errorCh + } + + // Generate and call MultiDelete S3 requests based on entries received from objectsCh + go func(errorCh chan<- RemoveObjectError) { + maxEntries := 1000 + finish := false + urlValues := make(url.Values) + urlValues.Set("delete", "") + + // Close error channel when Multi delete finishes. + defer close(errorCh) + + // Loop over entries by 1000 and call MultiDelete requests + for { + if finish { + break + } + count := 0 + var batch []string + + // Try to gather 1000 entries + for object := range objectsCh { + batch = append(batch, object) + if count++; count >= maxEntries { + break + } + } + if count == 0 { + // Multi Objects Delete API doesn't accept empty object list, quit immediately + break + } + if count < maxEntries { + // We didn't have 1000 entries, so this is the last batch + finish = true + } + + // Generate remove multi objects XML request + removeBytes := generateRemoveMultiObjectsRequest(batch) + // Execute GET on bucket to list objects. + resp, err := c.executeMethod(context.Background(), "POST", requestMetadata{ + bucketName: bucketName, + queryValues: urlValues, + contentBody: bytes.NewReader(removeBytes), + contentLength: int64(len(removeBytes)), + contentMD5Base64: sumMD5Base64(removeBytes), + contentSHA256Hex: sum256Hex(removeBytes), + }) + if err != nil { + for _, b := range batch { + errorCh <- RemoveObjectError{ObjectName: b, Err: err} + } + continue + } + + // Process multiobjects remove xml response + processRemoveMultiObjectsResponse(resp.Body, batch, errorCh) + + closeResponse(resp) + } + }(errorCh) + return errorCh +} + +// RemoveIncompleteUpload aborts an partially uploaded object. +func (c Client) RemoveIncompleteUpload(bucketName, objectName string) error { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return err + } + // Find multipart upload id of the object to be aborted. + uploadID, err := c.findUploadID(bucketName, objectName) + if err != nil { + return err + } + if uploadID != "" { + // Upload id found, abort the incomplete multipart upload. + err := c.abortMultipartUpload(context.Background(), bucketName, objectName, uploadID) + if err != nil { + return err + } + } + return nil +} + +// abortMultipartUpload aborts a multipart upload for the given +// uploadID, all previously uploaded parts are deleted. +func (c Client) abortMultipartUpload(ctx context.Context, bucketName, objectName, uploadID string) error { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return err + } + + // Initialize url queries. + urlValues := make(url.Values) + urlValues.Set("uploadId", uploadID) + + // Execute DELETE on multipart upload. + resp, err := c.executeMethod(ctx, "DELETE", requestMetadata{ + bucketName: bucketName, + objectName: objectName, + queryValues: urlValues, + contentSHA256Hex: emptySHA256Hex, + }) + defer closeResponse(resp) + if err != nil { + return err + } + if resp != nil { + if resp.StatusCode != http.StatusNoContent { + // Abort has no response body, handle it for any errors. + var errorResponse ErrorResponse + switch resp.StatusCode { + case http.StatusNotFound: + // This is needed specifically for abort and it cannot + // be converged into default case. + errorResponse = ErrorResponse{ + Code: "NoSuchUpload", + Message: "The specified multipart upload does not exist.", + BucketName: bucketName, + Key: objectName, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + Region: resp.Header.Get("x-amz-bucket-region"), + } + default: + return httpRespToErrorResponse(resp, bucketName, objectName) + } + return errorResponse + } + } + return nil +} diff --git a/vendor/github.com/minio/minio-go/api-s3-datatypes.go b/vendor/github.com/minio/minio-go/api-s3-datatypes.go new file mode 100644 index 000000000..8d8880c05 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-s3-datatypes.go @@ -0,0 +1,245 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "encoding/xml" + "time" +) + +// listAllMyBucketsResult container for listBuckets response. +type listAllMyBucketsResult struct { + // Container for one or more buckets. + Buckets struct { + Bucket []BucketInfo + } + Owner owner +} + +// owner container for bucket owner information. +type owner struct { + DisplayName string + ID string +} + +// CommonPrefix container for prefix response. +type CommonPrefix struct { + Prefix string +} + +// ListBucketV2Result container for listObjects response version 2. +type ListBucketV2Result struct { + // A response can contain CommonPrefixes only if you have + // specified a delimiter. + CommonPrefixes []CommonPrefix + // Metadata about each object returned. + Contents []ObjectInfo + Delimiter string + + // Encoding type used to encode object keys in the response. + EncodingType string + + // A flag that indicates whether or not ListObjects returned all of the results + // that satisfied the search criteria. + IsTruncated bool + MaxKeys int64 + Name string + + // Hold the token that will be sent in the next request to fetch the next group of keys + NextContinuationToken string + + ContinuationToken string + Prefix string + + // FetchOwner and StartAfter are currently not used + FetchOwner string + StartAfter string +} + +// ListBucketResult container for listObjects response. +type ListBucketResult struct { + // A response can contain CommonPrefixes only if you have + // specified a delimiter. + CommonPrefixes []CommonPrefix + // Metadata about each object returned. + Contents []ObjectInfo + Delimiter string + + // Encoding type used to encode object keys in the response. + EncodingType string + + // A flag that indicates whether or not ListObjects returned all of the results + // that satisfied the search criteria. + IsTruncated bool + Marker string + MaxKeys int64 + Name string + + // When response is truncated (the IsTruncated element value in + // the response is true), you can use the key name in this field + // as marker in the subsequent request to get next set of objects. + // Object storage lists objects in alphabetical order Note: This + // element is returned only if you have delimiter request + // parameter specified. If response does not include the NextMaker + // and it is truncated, you can use the value of the last Key in + // the response as the marker in the subsequent request to get the + // next set of object keys. + NextMarker string + Prefix string +} + +// ListMultipartUploadsResult container for ListMultipartUploads response +type ListMultipartUploadsResult struct { + Bucket string + KeyMarker string + UploadIDMarker string `xml:"UploadIdMarker"` + NextKeyMarker string + NextUploadIDMarker string `xml:"NextUploadIdMarker"` + EncodingType string + MaxUploads int64 + IsTruncated bool + Uploads []ObjectMultipartInfo `xml:"Upload"` + Prefix string + Delimiter string + // A response can contain CommonPrefixes only if you specify a delimiter. + CommonPrefixes []CommonPrefix +} + +// initiator container for who initiated multipart upload. +type initiator struct { + ID string + DisplayName string +} + +// copyObjectResult container for copy object response. +type copyObjectResult struct { + ETag string + LastModified time.Time // time string format "2006-01-02T15:04:05.000Z" +} + +// ObjectPart container for particular part of an object. +type ObjectPart struct { + // Part number identifies the part. + PartNumber int + + // Date and time the part was uploaded. + LastModified time.Time + + // Entity tag returned when the part was uploaded, usually md5sum + // of the part. + ETag string + + // Size of the uploaded part data. + Size int64 +} + +// ListObjectPartsResult container for ListObjectParts response. +type ListObjectPartsResult struct { + Bucket string + Key string + UploadID string `xml:"UploadId"` + + Initiator initiator + Owner owner + + StorageClass string + PartNumberMarker int + NextPartNumberMarker int + MaxParts int + + // Indicates whether the returned list of parts is truncated. + IsTruncated bool + ObjectParts []ObjectPart `xml:"Part"` + + EncodingType string +} + +// initiateMultipartUploadResult container for InitiateMultiPartUpload +// response. +type initiateMultipartUploadResult struct { + Bucket string + Key string + UploadID string `xml:"UploadId"` +} + +// completeMultipartUploadResult container for completed multipart +// upload response. +type completeMultipartUploadResult struct { + Location string + Bucket string + Key string + ETag string +} + +// CompletePart sub container lists individual part numbers and their +// md5sum, part of completeMultipartUpload. +type CompletePart struct { + XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Part" json:"-"` + + // Part number identifies the part. + PartNumber int + ETag string +} + +// completeMultipartUpload container for completing multipart upload. +type completeMultipartUpload struct { + XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ CompleteMultipartUpload" json:"-"` + Parts []CompletePart `xml:"Part"` +} + +// createBucketConfiguration container for bucket configuration. +type createBucketConfiguration struct { + XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ CreateBucketConfiguration" json:"-"` + Location string `xml:"LocationConstraint"` +} + +// deleteObject container for Delete element in MultiObjects Delete XML request +type deleteObject struct { + Key string + VersionID string `xml:"VersionId,omitempty"` +} + +// deletedObject container for Deleted element in MultiObjects Delete XML response +type deletedObject struct { + Key string + VersionID string `xml:"VersionId,omitempty"` + // These fields are ignored. + DeleteMarker bool + DeleteMarkerVersionID string +} + +// nonDeletedObject container for Error element (failed deletion) in MultiObjects Delete XML response +type nonDeletedObject struct { + Key string + Code string + Message string +} + +// deletedMultiObjects container for MultiObjects Delete XML request +type deleteMultiObjects struct { + XMLName xml.Name `xml:"Delete"` + Quiet bool + Objects []deleteObject `xml:"Object"` +} + +// deletedMultiObjectsResult container for MultiObjects Delete XML response +type deleteMultiObjectsResult struct { + XMLName xml.Name `xml:"DeleteResult"` + DeletedObjects []deletedObject `xml:"Deleted"` + UnDeletedObjects []nonDeletedObject `xml:"Error"` +} diff --git a/vendor/github.com/minio/minio-go/api-stat.go b/vendor/github.com/minio/minio-go/api-stat.go new file mode 100644 index 000000000..8904dd678 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api-stat.go @@ -0,0 +1,178 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// BucketExists verify if bucket exists and you have permission to access it. +func (c Client) BucketExists(bucketName string) (bool, error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return false, err + } + + // Execute HEAD on bucketName. + resp, err := c.executeMethod(context.Background(), "HEAD", requestMetadata{ + bucketName: bucketName, + contentSHA256Hex: emptySHA256Hex, + }) + defer closeResponse(resp) + if err != nil { + if ToErrorResponse(err).Code == "NoSuchBucket" { + return false, nil + } + return false, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return false, httpRespToErrorResponse(resp, bucketName, "") + } + } + return true, nil +} + +// List of header keys to be filtered, usually +// from all S3 API http responses. +var defaultFilterKeys = []string{ + "Connection", + "Transfer-Encoding", + "Accept-Ranges", + "Date", + "Server", + "Vary", + "x-amz-bucket-region", + "x-amz-request-id", + "x-amz-id-2", + // Add new headers to be ignored. +} + +// Extract only necessary metadata header key/values by +// filtering them out with a list of custom header keys. +func extractObjMetadata(header http.Header) http.Header { + filterKeys := append([]string{ + "ETag", + "Content-Length", + "Last-Modified", + "Content-Type", + }, defaultFilterKeys...) + return filterHeader(header, filterKeys) +} + +// StatObject verifies if object exists and you have permission to access. +func (c Client) StatObject(bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return ObjectInfo{}, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return ObjectInfo{}, err + } + return c.statObject(context.Background(), bucketName, objectName, opts) +} + +// Lower level API for statObject supporting pre-conditions and range headers. +func (c Client) statObject(ctx context.Context, bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) { + // Input validation. + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return ObjectInfo{}, err + } + if err := s3utils.CheckValidObjectName(objectName); err != nil { + return ObjectInfo{}, err + } + + // Execute HEAD on objectName. + resp, err := c.executeMethod(ctx, "HEAD", requestMetadata{ + bucketName: bucketName, + objectName: objectName, + contentSHA256Hex: emptySHA256Hex, + customHeader: opts.Header(), + }) + defer closeResponse(resp) + if err != nil { + return ObjectInfo{}, err + } + if resp != nil { + if resp.StatusCode != http.StatusOK { + return ObjectInfo{}, httpRespToErrorResponse(resp, bucketName, objectName) + } + } + + // Trim off the odd double quotes from ETag in the beginning and end. + md5sum := strings.TrimPrefix(resp.Header.Get("ETag"), "\"") + md5sum = strings.TrimSuffix(md5sum, "\"") + + // Parse content length is exists + var size int64 = -1 + contentLengthStr := resp.Header.Get("Content-Length") + if contentLengthStr != "" { + size, err = strconv.ParseInt(contentLengthStr, 10, 64) + if err != nil { + // Content-Length is not valid + return ObjectInfo{}, ErrorResponse{ + Code: "InternalError", + Message: "Content-Length is invalid. " + reportIssue, + BucketName: bucketName, + Key: objectName, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + Region: resp.Header.Get("x-amz-bucket-region"), + } + } + } + + // Parse Last-Modified has http time format. + date, err := time.Parse(http.TimeFormat, resp.Header.Get("Last-Modified")) + if err != nil { + return ObjectInfo{}, ErrorResponse{ + Code: "InternalError", + Message: "Last-Modified time format is invalid. " + reportIssue, + BucketName: bucketName, + Key: objectName, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + Region: resp.Header.Get("x-amz-bucket-region"), + } + } + + // Fetch content type if any present. + contentType := strings.TrimSpace(resp.Header.Get("Content-Type")) + if contentType == "" { + contentType = "application/octet-stream" + } + + // Save object metadata info. + return ObjectInfo{ + ETag: md5sum, + Key: objectName, + Size: size, + LastModified: date, + ContentType: contentType, + // Extract only the relevant header keys describing the object. + // following function filters out a list of standard set of keys + // which are not part of object metadata. + Metadata: extractObjMetadata(resp.Header), + }, nil +} diff --git a/vendor/github.com/minio/minio-go/api.go b/vendor/github.com/minio/minio-go/api.go new file mode 100644 index 000000000..0cb007304 --- /dev/null +++ b/vendor/github.com/minio/minio-go/api.go @@ -0,0 +1,832 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "bytes" + "context" + "crypto/md5" + "crypto/sha256" + "errors" + "fmt" + "hash" + "io" + "io/ioutil" + "math/rand" + "net" + "net/http" + "net/http/httputil" + "net/url" + "os" + "runtime" + "strings" + "sync" + "time" + + "github.com/minio/minio-go/pkg/credentials" + "github.com/minio/minio-go/pkg/s3signer" + "github.com/minio/minio-go/pkg/s3utils" +) + +// Client implements Amazon S3 compatible methods. +type Client struct { + /// Standard options. + + // Parsed endpoint url provided by the user. + endpointURL url.URL + + // Holds various credential providers. + credsProvider *credentials.Credentials + + // Custom signerType value overrides all credentials. + overrideSignerType credentials.SignatureType + + // User supplied. + appInfo struct { + appName string + appVersion string + } + + // Indicate whether we are using https or not + secure bool + + // Needs allocation. + httpClient *http.Client + bucketLocCache *bucketLocationCache + + // Advanced functionality. + isTraceEnabled bool + traceOutput io.Writer + + // S3 specific accelerated endpoint. + s3AccelerateEndpoint string + + // Region endpoint + region string + + // Random seed. + random *rand.Rand +} + +// Global constants. +const ( + libraryName = "minio-go" + libraryVersion = "4.0.6" +) + +// User Agent should always following the below style. +// Please open an issue to discuss any new changes here. +// +// Minio (OS; ARCH) LIB/VER APP/VER +const ( + libraryUserAgentPrefix = "Minio (" + runtime.GOOS + "; " + runtime.GOARCH + ") " + libraryUserAgent = libraryUserAgentPrefix + libraryName + "/" + libraryVersion +) + +// NewV2 - instantiate minio client with Amazon S3 signature version +// '2' compatibility. +func NewV2(endpoint string, accessKeyID, secretAccessKey string, secure bool) (*Client, error) { + creds := credentials.NewStaticV2(accessKeyID, secretAccessKey, "") + clnt, err := privateNew(endpoint, creds, secure, "") + if err != nil { + return nil, err + } + clnt.overrideSignerType = credentials.SignatureV2 + return clnt, nil +} + +// NewV4 - instantiate minio client with Amazon S3 signature version +// '4' compatibility. +func NewV4(endpoint string, accessKeyID, secretAccessKey string, secure bool) (*Client, error) { + creds := credentials.NewStaticV4(accessKeyID, secretAccessKey, "") + clnt, err := privateNew(endpoint, creds, secure, "") + if err != nil { + return nil, err + } + clnt.overrideSignerType = credentials.SignatureV4 + return clnt, nil +} + +// New - instantiate minio client, adds automatic verification of signature. +func New(endpoint, accessKeyID, secretAccessKey string, secure bool) (*Client, error) { + creds := credentials.NewStaticV4(accessKeyID, secretAccessKey, "") + clnt, err := privateNew(endpoint, creds, secure, "") + if err != nil { + return nil, err + } + // Google cloud storage should be set to signature V2, force it if not. + if s3utils.IsGoogleEndpoint(clnt.endpointURL) { + clnt.overrideSignerType = credentials.SignatureV2 + } + // If Amazon S3 set to signature v4. + if s3utils.IsAmazonEndpoint(clnt.endpointURL) { + clnt.overrideSignerType = credentials.SignatureV4 + } + return clnt, nil +} + +// NewWithCredentials - instantiate minio client with credentials provider +// for retrieving credentials from various credentials provider such as +// IAM, File, Env etc. +func NewWithCredentials(endpoint string, creds *credentials.Credentials, secure bool, region string) (*Client, error) { + return privateNew(endpoint, creds, secure, region) +} + +// NewWithRegion - instantiate minio client, with region configured. Unlike New(), +// NewWithRegion avoids bucket-location lookup operations and it is slightly faster. +// Use this function when if your application deals with single region. +func NewWithRegion(endpoint, accessKeyID, secretAccessKey string, secure bool, region string) (*Client, error) { + creds := credentials.NewStaticV4(accessKeyID, secretAccessKey, "") + return privateNew(endpoint, creds, secure, region) +} + +// lockedRandSource provides protected rand source, implements rand.Source interface. +type lockedRandSource struct { + lk sync.Mutex + src rand.Source +} + +// Int63 returns a non-negative pseudo-random 63-bit integer as an int64. +func (r *lockedRandSource) Int63() (n int64) { + r.lk.Lock() + n = r.src.Int63() + r.lk.Unlock() + return +} + +// Seed uses the provided seed value to initialize the generator to a +// deterministic state. +func (r *lockedRandSource) Seed(seed int64) { + r.lk.Lock() + r.src.Seed(seed) + r.lk.Unlock() +} + +// getRegionFromURL - parse region from URL if present. +func getRegionFromURL(u url.URL) (region string) { + region = "" + if s3utils.IsGoogleEndpoint(u) { + return + } else if s3utils.IsAmazonChinaEndpoint(u) { + // For china specifically we need to set everything to + // cn-north-1 for now, there is no easier way until AWS S3 + // provides a cleaner compatible API across "us-east-1" and + // China region. + return "cn-north-1" + } else if s3utils.IsAmazonGovCloudEndpoint(u) { + // For us-gov specifically we need to set everything to + // us-gov-west-1 for now, there is no easier way until AWS S3 + // provides a cleaner compatible API across "us-east-1" and + // Gov cloud region. + return "us-gov-west-1" + } + parts := s3utils.AmazonS3Host.FindStringSubmatch(u.Host) + if len(parts) > 1 { + region = parts[1] + } + return region +} + +func privateNew(endpoint string, creds *credentials.Credentials, secure bool, region string) (*Client, error) { + // construct endpoint. + endpointURL, err := getEndpointURL(endpoint, secure) + if err != nil { + return nil, err + } + + // instantiate new Client. + clnt := new(Client) + + // Save the credentials. + clnt.credsProvider = creds + + // Remember whether we are using https or not + clnt.secure = secure + + // Save endpoint URL, user agent for future uses. + clnt.endpointURL = *endpointURL + + // Instantiate http client and bucket location cache. + clnt.httpClient = &http.Client{ + Transport: defaultMinioTransport, + } + + // Sets custom region, if region is empty bucket location cache is used automatically. + if region == "" { + region = getRegionFromURL(clnt.endpointURL) + } + clnt.region = region + + // Instantiate bucket location cache. + clnt.bucketLocCache = newBucketLocationCache() + + // Introduce a new locked random seed. + clnt.random = rand.New(&lockedRandSource{src: rand.NewSource(time.Now().UTC().UnixNano())}) + + // Return. + return clnt, nil +} + +// SetAppInfo - add application details to user agent. +func (c *Client) SetAppInfo(appName string, appVersion string) { + // if app name and version not set, we do not set a new user agent. + if appName != "" && appVersion != "" { + c.appInfo = struct { + appName string + appVersion string + }{} + c.appInfo.appName = appName + c.appInfo.appVersion = appVersion + } +} + +// SetCustomTransport - set new custom transport. +func (c *Client) SetCustomTransport(customHTTPTransport http.RoundTripper) { + // Set this to override default transport + // ``http.DefaultTransport``. + // + // This transport is usually needed for debugging OR to add your + // own custom TLS certificates on the client transport, for custom + // CA's and certs which are not part of standard certificate + // authority follow this example :- + // + // tr := &http.Transport{ + // TLSClientConfig: &tls.Config{RootCAs: pool}, + // DisableCompression: true, + // } + // api.SetTransport(tr) + // + if c.httpClient != nil { + c.httpClient.Transport = customHTTPTransport + } +} + +// TraceOn - enable HTTP tracing. +func (c *Client) TraceOn(outputStream io.Writer) { + // if outputStream is nil then default to os.Stdout. + if outputStream == nil { + outputStream = os.Stdout + } + // Sets a new output stream. + c.traceOutput = outputStream + + // Enable tracing. + c.isTraceEnabled = true +} + +// TraceOff - disable HTTP tracing. +func (c *Client) TraceOff() { + // Disable tracing. + c.isTraceEnabled = false +} + +// SetS3TransferAccelerate - turns s3 accelerated endpoint on or off for all your +// requests. This feature is only specific to S3 for all other endpoints this +// function does nothing. To read further details on s3 transfer acceleration +// please vist - +// http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html +func (c *Client) SetS3TransferAccelerate(accelerateEndpoint string) { + if s3utils.IsAmazonEndpoint(c.endpointURL) { + c.s3AccelerateEndpoint = accelerateEndpoint + } +} + +// Hash materials provides relevant initialized hash algo writers +// based on the expected signature type. +// +// - For signature v4 request if the connection is insecure compute only sha256. +// - For signature v4 request if the connection is secure compute only md5. +// - For anonymous request compute md5. +func (c *Client) hashMaterials() (hashAlgos map[string]hash.Hash, hashSums map[string][]byte) { + hashSums = make(map[string][]byte) + hashAlgos = make(map[string]hash.Hash) + if c.overrideSignerType.IsV4() { + if c.secure { + hashAlgos["md5"] = md5.New() + } else { + hashAlgos["sha256"] = sha256.New() + } + } else { + if c.overrideSignerType.IsAnonymous() { + hashAlgos["md5"] = md5.New() + } + } + return hashAlgos, hashSums +} + +// requestMetadata - is container for all the values to make a request. +type requestMetadata struct { + // If set newRequest presigns the URL. + presignURL bool + + // User supplied. + bucketName string + objectName string + queryValues url.Values + customHeader http.Header + expires int64 + + // Generated by our internal code. + bucketLocation string + contentBody io.Reader + contentLength int64 + contentMD5Base64 string // carries base64 encoded md5sum + contentSHA256Hex string // carries hex encoded sha256sum +} + +// dumpHTTP - dump HTTP request and response. +func (c Client) dumpHTTP(req *http.Request, resp *http.Response) error { + // Starts http dump. + _, err := fmt.Fprintln(c.traceOutput, "---------START-HTTP---------") + if err != nil { + return err + } + + // Filter out Signature field from Authorization header. + origAuth := req.Header.Get("Authorization") + if origAuth != "" { + req.Header.Set("Authorization", redactSignature(origAuth)) + } + + // Only display request header. + reqTrace, err := httputil.DumpRequestOut(req, false) + if err != nil { + return err + } + + // Write request to trace output. + _, err = fmt.Fprint(c.traceOutput, string(reqTrace)) + if err != nil { + return err + } + + // Only display response header. + var respTrace []byte + + // For errors we make sure to dump response body as well. + if resp.StatusCode != http.StatusOK && + resp.StatusCode != http.StatusPartialContent && + resp.StatusCode != http.StatusNoContent { + respTrace, err = httputil.DumpResponse(resp, true) + if err != nil { + return err + } + } else { + // WORKAROUND for https://github.com/golang/go/issues/13942. + // httputil.DumpResponse does not print response headers for + // all successful calls which have response ContentLength set + // to zero. Keep this workaround until the above bug is fixed. + if resp.ContentLength == 0 { + var buffer bytes.Buffer + if err = resp.Header.Write(&buffer); err != nil { + return err + } + respTrace = buffer.Bytes() + respTrace = append(respTrace, []byte("\r\n")...) + } else { + respTrace, err = httputil.DumpResponse(resp, false) + if err != nil { + return err + } + } + } + // Write response to trace output. + _, err = fmt.Fprint(c.traceOutput, strings.TrimSuffix(string(respTrace), "\r\n")) + if err != nil { + return err + } + + // Ends the http dump. + _, err = fmt.Fprintln(c.traceOutput, "---------END-HTTP---------") + if err != nil { + return err + } + + // Returns success. + return nil +} + +// do - execute http request. +func (c Client) do(req *http.Request) (*http.Response, error) { + var resp *http.Response + var err error + // Do the request in a loop in case of 307 http is met since golang still doesn't + // handle properly this situation (https://github.com/golang/go/issues/7912) + for { + resp, err = c.httpClient.Do(req) + if err != nil { + // Handle this specifically for now until future Golang + // versions fix this issue properly. + urlErr, ok := err.(*url.Error) + if ok && strings.Contains(urlErr.Err.Error(), "EOF") { + return nil, &url.Error{ + Op: urlErr.Op, + URL: urlErr.URL, + Err: errors.New("Connection closed by foreign host " + urlErr.URL + ". Retry again."), + } + } + return nil, err + } + // Redo the request with the new redirect url if http 307 is returned, quit the loop otherwise + if resp != nil && resp.StatusCode == http.StatusTemporaryRedirect { + newURL, err := url.Parse(resp.Header.Get("Location")) + if err != nil { + break + } + req.URL = newURL + } else { + break + } + } + + // Response cannot be non-nil, report if its the case. + if resp == nil { + msg := "Response is empty. " + reportIssue + return nil, ErrInvalidArgument(msg) + } + + // If trace is enabled, dump http request and response. + if c.isTraceEnabled { + err = c.dumpHTTP(req, resp) + if err != nil { + return nil, err + } + } + return resp, nil +} + +// List of success status. +var successStatus = []int{ + http.StatusOK, + http.StatusNoContent, + http.StatusPartialContent, +} + +// executeMethod - instantiates a given method, and retries the +// request upon any error up to maxRetries attempts in a binomially +// delayed manner using a standard back off algorithm. +func (c Client) executeMethod(ctx context.Context, method string, metadata requestMetadata) (res *http.Response, err error) { + var isRetryable bool // Indicates if request can be retried. + var bodySeeker io.Seeker // Extracted seeker from io.Reader. + var reqRetry = MaxRetry // Indicates how many times we can retry the request + + if metadata.contentBody != nil { + // Check if body is seekable then it is retryable. + bodySeeker, isRetryable = metadata.contentBody.(io.Seeker) + switch bodySeeker { + case os.Stdin, os.Stdout, os.Stderr: + isRetryable = false + } + // Retry only when reader is seekable + if !isRetryable { + reqRetry = 1 + } + + // Figure out if the body can be closed - if yes + // we will definitely close it upon the function + // return. + bodyCloser, ok := metadata.contentBody.(io.Closer) + if ok { + defer bodyCloser.Close() + } + } + + // Create a done channel to control 'newRetryTimer' go routine. + doneCh := make(chan struct{}, 1) + + // Indicate to our routine to exit cleanly upon return. + defer close(doneCh) + + // Blank indentifier is kept here on purpose since 'range' without + // blank identifiers is only supported since go1.4 + // https://golang.org/doc/go1.4#forrange. + for range c.newRetryTimer(reqRetry, DefaultRetryUnit, DefaultRetryCap, MaxJitter, doneCh) { + // Retry executes the following function body if request has an + // error until maxRetries have been exhausted, retry attempts are + // performed after waiting for a given period of time in a + // binomial fashion. + if isRetryable { + // Seek back to beginning for each attempt. + if _, err = bodySeeker.Seek(0, 0); err != nil { + // If seek failed, no need to retry. + return nil, err + } + } + + // Instantiate a new request. + var req *http.Request + req, err = c.newRequest(method, metadata) + if err != nil { + errResponse := ToErrorResponse(err) + if isS3CodeRetryable(errResponse.Code) { + continue // Retry. + } + return nil, err + } + // Add context to request + req = req.WithContext(ctx) + + // Initiate the request. + res, err = c.do(req) + if err != nil { + // For supported network errors verify. + if isNetErrorRetryable(err) { + continue // Retry. + } + // For other errors, return here no need to retry. + return nil, err + } + + // For any known successful http status, return quickly. + for _, httpStatus := range successStatus { + if httpStatus == res.StatusCode { + return res, nil + } + } + + // Read the body to be saved later. + errBodyBytes, err := ioutil.ReadAll(res.Body) + // res.Body should be closed + closeResponse(res) + if err != nil { + return nil, err + } + + // Save the body. + errBodySeeker := bytes.NewReader(errBodyBytes) + res.Body = ioutil.NopCloser(errBodySeeker) + + // For errors verify if its retryable otherwise fail quickly. + errResponse := ToErrorResponse(httpRespToErrorResponse(res, metadata.bucketName, metadata.objectName)) + + // Save the body back again. + errBodySeeker.Seek(0, 0) // Seek back to starting point. + res.Body = ioutil.NopCloser(errBodySeeker) + + // Bucket region if set in error response and the error + // code dictates invalid region, we can retry the request + // with the new region. + // + // Additionally we should only retry if bucketLocation and custom + // region is empty. + if metadata.bucketLocation == "" && c.region == "" { + if errResponse.Code == "AuthorizationHeaderMalformed" || errResponse.Code == "InvalidRegion" { + if metadata.bucketName != "" && errResponse.Region != "" { + // Gather Cached location only if bucketName is present. + if _, cachedLocationError := c.bucketLocCache.Get(metadata.bucketName); cachedLocationError != false { + c.bucketLocCache.Set(metadata.bucketName, errResponse.Region) + continue // Retry. + } + } + } + } + + // Verify if error response code is retryable. + if isS3CodeRetryable(errResponse.Code) { + continue // Retry. + } + + // Verify if http status code is retryable. + if isHTTPStatusRetryable(res.StatusCode) { + continue // Retry. + } + + // For all other cases break out of the retry loop. + break + } + return res, err +} + +// newRequest - instantiate a new HTTP request for a given method. +func (c Client) newRequest(method string, metadata requestMetadata) (req *http.Request, err error) { + // If no method is supplied default to 'POST'. + if method == "" { + method = "POST" + } + + location := metadata.bucketLocation + if location == "" { + if metadata.bucketName != "" { + // Gather location only if bucketName is present. + location, err = c.getBucketLocation(metadata.bucketName) + if err != nil { + if ToErrorResponse(err).Code != "AccessDenied" { + return nil, err + } + } + // Upon AccessDenied error on fetching bucket location, default + // to possible locations based on endpoint URL. This can usually + // happen when GetBucketLocation() is disabled using IAM policies. + } + if location == "" { + location = getDefaultLocation(c.endpointURL, c.region) + } + } + + // Construct a new target URL. + targetURL, err := c.makeTargetURL(metadata.bucketName, metadata.objectName, location, metadata.queryValues) + if err != nil { + return nil, err + } + + // Initialize a new HTTP request for the method. + req, err = http.NewRequest(method, targetURL.String(), nil) + if err != nil { + return nil, err + } + + // Get credentials from the configured credentials provider. + value, err := c.credsProvider.Get() + if err != nil { + return nil, err + } + + var ( + signerType = value.SignerType + accessKeyID = value.AccessKeyID + secretAccessKey = value.SecretAccessKey + sessionToken = value.SessionToken + ) + + // Custom signer set then override the behavior. + if c.overrideSignerType != credentials.SignatureDefault { + signerType = c.overrideSignerType + } + + // If signerType returned by credentials helper is anonymous, + // then do not sign regardless of signerType override. + if value.SignerType == credentials.SignatureAnonymous { + signerType = credentials.SignatureAnonymous + } + + // Generate presign url if needed, return right here. + if metadata.expires != 0 && metadata.presignURL { + if signerType.IsAnonymous() { + return nil, ErrInvalidArgument("Presigned URLs cannot be generated with anonymous credentials.") + } + if signerType.IsV2() { + // Presign URL with signature v2. + req = s3signer.PreSignV2(*req, accessKeyID, secretAccessKey, metadata.expires) + } else if signerType.IsV4() { + // Presign URL with signature v4. + req = s3signer.PreSignV4(*req, accessKeyID, secretAccessKey, sessionToken, location, metadata.expires) + } + return req, nil + } + + // Set 'User-Agent' header for the request. + c.setUserAgent(req) + + // Set all headers. + for k, v := range metadata.customHeader { + req.Header.Set(k, v[0]) + } + + // Go net/http notoriously closes the request body. + // - The request Body, if non-nil, will be closed by the underlying Transport, even on errors. + // This can cause underlying *os.File seekers to fail, avoid that + // by making sure to wrap the closer as a nop. + if metadata.contentLength == 0 { + req.Body = nil + } else { + req.Body = ioutil.NopCloser(metadata.contentBody) + } + + // Set incoming content-length. + req.ContentLength = metadata.contentLength + if req.ContentLength <= -1 { + // For unknown content length, we upload using transfer-encoding: chunked. + req.TransferEncoding = []string{"chunked"} + } + + // set md5Sum for content protection. + if len(metadata.contentMD5Base64) > 0 { + req.Header.Set("Content-Md5", metadata.contentMD5Base64) + } + + // For anonymous requests just return. + if signerType.IsAnonymous() { + return req, nil + } + + switch { + case signerType.IsV2(): + // Add signature version '2' authorization header. + req = s3signer.SignV2(*req, accessKeyID, secretAccessKey) + case metadata.objectName != "" && method == "PUT" && metadata.customHeader.Get("X-Amz-Copy-Source") == "" && !c.secure: + // Streaming signature is used by default for a PUT object request. Additionally we also + // look if the initialized client is secure, if yes then we don't need to perform + // streaming signature. + req = s3signer.StreamingSignV4(req, accessKeyID, + secretAccessKey, sessionToken, location, metadata.contentLength, time.Now().UTC()) + default: + // Set sha256 sum for signature calculation only with signature version '4'. + shaHeader := unsignedPayload + if metadata.contentSHA256Hex != "" { + shaHeader = metadata.contentSHA256Hex + } + req.Header.Set("X-Amz-Content-Sha256", shaHeader) + + // Add signature version '4' authorization header. + req = s3signer.SignV4(*req, accessKeyID, secretAccessKey, sessionToken, location) + } + + // Return request. + return req, nil +} + +// set User agent. +func (c Client) setUserAgent(req *http.Request) { + req.Header.Set("User-Agent", libraryUserAgent) + if c.appInfo.appName != "" && c.appInfo.appVersion != "" { + req.Header.Set("User-Agent", libraryUserAgent+" "+c.appInfo.appName+"/"+c.appInfo.appVersion) + } +} + +// makeTargetURL make a new target url. +func (c Client) makeTargetURL(bucketName, objectName, bucketLocation string, queryValues url.Values) (*url.URL, error) { + host := c.endpointURL.Host + // For Amazon S3 endpoint, try to fetch location based endpoint. + if s3utils.IsAmazonEndpoint(c.endpointURL) { + if c.s3AccelerateEndpoint != "" && bucketName != "" { + // http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html + // Disable transfer acceleration for non-compliant bucket names. + if strings.Contains(bucketName, ".") { + return nil, ErrTransferAccelerationBucket(bucketName) + } + // If transfer acceleration is requested set new host. + // For more details about enabling transfer acceleration read here. + // http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html + host = c.s3AccelerateEndpoint + } else { + // Do not change the host if the endpoint URL is a FIPS S3 endpoint. + if !s3utils.IsAmazonFIPSGovCloudEndpoint(c.endpointURL) { + // Fetch new host based on the bucket location. + host = getS3Endpoint(bucketLocation) + } + } + } + + // Save scheme. + scheme := c.endpointURL.Scheme + + // Strip port 80 and 443 so we won't send these ports in Host header. + // The reason is that browsers and curl automatically remove :80 and :443 + // with the generated presigned urls, then a signature mismatch error. + if h, p, err := net.SplitHostPort(host); err == nil { + if scheme == "http" && p == "80" || scheme == "https" && p == "443" { + host = h + } + } + + urlStr := scheme + "://" + host + "/" + // Make URL only if bucketName is available, otherwise use the + // endpoint URL. + if bucketName != "" { + // Save if target url will have buckets which suppport virtual host. + isVirtualHostStyle := s3utils.IsVirtualHostSupported(c.endpointURL, bucketName) + + // If endpoint supports virtual host style use that always. + // Currently only S3 and Google Cloud Storage would support + // virtual host style. + if isVirtualHostStyle { + urlStr = scheme + "://" + bucketName + "." + host + "/" + if objectName != "" { + urlStr = urlStr + s3utils.EncodePath(objectName) + } + } else { + // If not fall back to using path style. + urlStr = urlStr + bucketName + "/" + if objectName != "" { + urlStr = urlStr + s3utils.EncodePath(objectName) + } + } + } + + // If there are any query values, add them to the end. + if len(queryValues) > 0 { + urlStr = urlStr + "?" + s3utils.QueryEncode(queryValues) + } + + u, err := url.Parse(urlStr) + if err != nil { + return nil, err + } + + return u, nil +} diff --git a/vendor/github.com/minio/minio-go/bucket-cache.go b/vendor/github.com/minio/minio-go/bucket-cache.go new file mode 100644 index 000000000..5d56cdf42 --- /dev/null +++ b/vendor/github.com/minio/minio-go/bucket-cache.go @@ -0,0 +1,219 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "net/http" + "net/url" + "path" + "sync" + + "github.com/minio/minio-go/pkg/credentials" + "github.com/minio/minio-go/pkg/s3signer" + "github.com/minio/minio-go/pkg/s3utils" +) + +// bucketLocationCache - Provides simple mechanism to hold bucket +// locations in memory. +type bucketLocationCache struct { + // mutex is used for handling the concurrent + // read/write requests for cache. + sync.RWMutex + + // items holds the cached bucket locations. + items map[string]string +} + +// newBucketLocationCache - Provides a new bucket location cache to be +// used internally with the client object. +func newBucketLocationCache() *bucketLocationCache { + return &bucketLocationCache{ + items: make(map[string]string), + } +} + +// Get - Returns a value of a given key if it exists. +func (r *bucketLocationCache) Get(bucketName string) (location string, ok bool) { + r.RLock() + defer r.RUnlock() + location, ok = r.items[bucketName] + return +} + +// Set - Will persist a value into cache. +func (r *bucketLocationCache) Set(bucketName string, location string) { + r.Lock() + defer r.Unlock() + r.items[bucketName] = location +} + +// Delete - Deletes a bucket name from cache. +func (r *bucketLocationCache) Delete(bucketName string) { + r.Lock() + defer r.Unlock() + delete(r.items, bucketName) +} + +// GetBucketLocation - get location for the bucket name from location cache, if not +// fetch freshly by making a new request. +func (c Client) GetBucketLocation(bucketName string) (string, error) { + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return "", err + } + return c.getBucketLocation(bucketName) +} + +// getBucketLocation - Get location for the bucketName from location map cache, if not +// fetch freshly by making a new request. +func (c Client) getBucketLocation(bucketName string) (string, error) { + if err := s3utils.CheckValidBucketName(bucketName); err != nil { + return "", err + } + + // Region set then no need to fetch bucket location. + if c.region != "" { + return c.region, nil + } + + if location, ok := c.bucketLocCache.Get(bucketName); ok { + return location, nil + } + + // Initialize a new request. + req, err := c.getBucketLocationRequest(bucketName) + if err != nil { + return "", err + } + + // Initiate the request. + resp, err := c.do(req) + defer closeResponse(resp) + if err != nil { + return "", err + } + location, err := processBucketLocationResponse(resp, bucketName) + if err != nil { + return "", err + } + c.bucketLocCache.Set(bucketName, location) + return location, nil +} + +// processes the getBucketLocation http response from the server. +func processBucketLocationResponse(resp *http.Response, bucketName string) (bucketLocation string, err error) { + if resp != nil { + if resp.StatusCode != http.StatusOK { + err = httpRespToErrorResponse(resp, bucketName, "") + errResp := ToErrorResponse(err) + // For access denied error, it could be an anonymous + // request. Move forward and let the top level callers + // succeed if possible based on their policy. + if errResp.Code == "AccessDenied" { + return "us-east-1", nil + } + return "", err + } + } + + // Extract location. + var locationConstraint string + err = xmlDecoder(resp.Body, &locationConstraint) + if err != nil { + return "", err + } + + location := locationConstraint + // Location is empty will be 'us-east-1'. + if location == "" { + location = "us-east-1" + } + + // Location can be 'EU' convert it to meaningful 'eu-west-1'. + if location == "EU" { + location = "eu-west-1" + } + + // Save the location into cache. + + // Return. + return location, nil +} + +// getBucketLocationRequest - Wrapper creates a new getBucketLocation request. +func (c Client) getBucketLocationRequest(bucketName string) (*http.Request, error) { + // Set location query. + urlValues := make(url.Values) + urlValues.Set("location", "") + + // Set get bucket location always as path style. + targetURL := c.endpointURL + targetURL.Path = path.Join(bucketName, "") + "/" + targetURL.RawQuery = urlValues.Encode() + + // Get a new HTTP request for the method. + req, err := http.NewRequest("GET", targetURL.String(), nil) + if err != nil { + return nil, err + } + + // Set UserAgent for the request. + c.setUserAgent(req) + + // Get credentials from the configured credentials provider. + value, err := c.credsProvider.Get() + if err != nil { + return nil, err + } + + var ( + signerType = value.SignerType + accessKeyID = value.AccessKeyID + secretAccessKey = value.SecretAccessKey + sessionToken = value.SessionToken + ) + + // Custom signer set then override the behavior. + if c.overrideSignerType != credentials.SignatureDefault { + signerType = c.overrideSignerType + } + + // If signerType returned by credentials helper is anonymous, + // then do not sign regardless of signerType override. + if value.SignerType == credentials.SignatureAnonymous { + signerType = credentials.SignatureAnonymous + } + + if signerType.IsAnonymous() { + return req, nil + } + + if signerType.IsV2() { + req = s3signer.SignV2(*req, accessKeyID, secretAccessKey) + return req, nil + } + + // Set sha256 sum for signature calculation only with signature version '4'. + contentSha256 := emptySHA256Hex + if c.secure { + contentSha256 = unsignedPayload + } + + req.Header.Set("X-Amz-Content-Sha256", contentSha256) + req = s3signer.SignV4(*req, accessKeyID, secretAccessKey, sessionToken, "us-east-1") + return req, nil +} diff --git a/vendor/github.com/minio/minio-go/bucket-notification.go b/vendor/github.com/minio/minio-go/bucket-notification.go new file mode 100644 index 000000000..1b9d6a0c7 --- /dev/null +++ b/vendor/github.com/minio/minio-go/bucket-notification.go @@ -0,0 +1,232 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "encoding/xml" + "reflect" +) + +// NotificationEventType is a S3 notification event associated to the bucket notification configuration +type NotificationEventType string + +// The role of all event types are described in : +// http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#notification-how-to-event-types-and-destinations +const ( + ObjectCreatedAll NotificationEventType = "s3:ObjectCreated:*" + ObjectCreatedPut = "s3:ObjectCreated:Put" + ObjectCreatedPost = "s3:ObjectCreated:Post" + ObjectCreatedCopy = "s3:ObjectCreated:Copy" + ObjectCreatedCompleteMultipartUpload = "s3:ObjectCreated:CompleteMultipartUpload" + ObjectAccessedGet = "s3:ObjectAccessed:Get" + ObjectAccessedHead = "s3:ObjectAccessed:Head" + ObjectAccessedAll = "s3:ObjectAccessed:*" + ObjectRemovedAll = "s3:ObjectRemoved:*" + ObjectRemovedDelete = "s3:ObjectRemoved:Delete" + ObjectRemovedDeleteMarkerCreated = "s3:ObjectRemoved:DeleteMarkerCreated" + ObjectReducedRedundancyLostObject = "s3:ReducedRedundancyLostObject" +) + +// FilterRule - child of S3Key, a tag in the notification xml which +// carries suffix/prefix filters +type FilterRule struct { + Name string `xml:"Name"` + Value string `xml:"Value"` +} + +// S3Key - child of Filter, a tag in the notification xml which +// carries suffix/prefix filters +type S3Key struct { + FilterRules []FilterRule `xml:"FilterRule,omitempty"` +} + +// Filter - a tag in the notification xml structure which carries +// suffix/prefix filters +type Filter struct { + S3Key S3Key `xml:"S3Key,omitempty"` +} + +// Arn - holds ARN information that will be sent to the web service, +// ARN desciption can be found in http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html +type Arn struct { + Partition string + Service string + Region string + AccountID string + Resource string +} + +// NewArn creates new ARN based on the given partition, service, region, account id and resource +func NewArn(partition, service, region, accountID, resource string) Arn { + return Arn{Partition: partition, + Service: service, + Region: region, + AccountID: accountID, + Resource: resource} +} + +// Return the string format of the ARN +func (arn Arn) String() string { + return "arn:" + arn.Partition + ":" + arn.Service + ":" + arn.Region + ":" + arn.AccountID + ":" + arn.Resource +} + +// NotificationConfig - represents one single notification configuration +// such as topic, queue or lambda configuration. +type NotificationConfig struct { + ID string `xml:"Id,omitempty"` + Arn Arn `xml:"-"` + Events []NotificationEventType `xml:"Event"` + Filter *Filter `xml:"Filter,omitempty"` +} + +// NewNotificationConfig creates one notification config and sets the given ARN +func NewNotificationConfig(arn Arn) NotificationConfig { + return NotificationConfig{Arn: arn} +} + +// AddEvents adds one event to the current notification config +func (t *NotificationConfig) AddEvents(events ...NotificationEventType) { + t.Events = append(t.Events, events...) +} + +// AddFilterSuffix sets the suffix configuration to the current notification config +func (t *NotificationConfig) AddFilterSuffix(suffix string) { + if t.Filter == nil { + t.Filter = &Filter{} + } + newFilterRule := FilterRule{Name: "suffix", Value: suffix} + // Replace any suffix rule if existing and add to the list otherwise + for index := range t.Filter.S3Key.FilterRules { + if t.Filter.S3Key.FilterRules[index].Name == "suffix" { + t.Filter.S3Key.FilterRules[index] = newFilterRule + return + } + } + t.Filter.S3Key.FilterRules = append(t.Filter.S3Key.FilterRules, newFilterRule) +} + +// AddFilterPrefix sets the prefix configuration to the current notification config +func (t *NotificationConfig) AddFilterPrefix(prefix string) { + if t.Filter == nil { + t.Filter = &Filter{} + } + newFilterRule := FilterRule{Name: "prefix", Value: prefix} + // Replace any prefix rule if existing and add to the list otherwise + for index := range t.Filter.S3Key.FilterRules { + if t.Filter.S3Key.FilterRules[index].Name == "prefix" { + t.Filter.S3Key.FilterRules[index] = newFilterRule + return + } + } + t.Filter.S3Key.FilterRules = append(t.Filter.S3Key.FilterRules, newFilterRule) +} + +// TopicConfig carries one single topic notification configuration +type TopicConfig struct { + NotificationConfig + Topic string `xml:"Topic"` +} + +// QueueConfig carries one single queue notification configuration +type QueueConfig struct { + NotificationConfig + Queue string `xml:"Queue"` +} + +// LambdaConfig carries one single cloudfunction notification configuration +type LambdaConfig struct { + NotificationConfig + Lambda string `xml:"CloudFunction"` +} + +// BucketNotification - the struct that represents the whole XML to be sent to the web service +type BucketNotification struct { + XMLName xml.Name `xml:"NotificationConfiguration"` + LambdaConfigs []LambdaConfig `xml:"CloudFunctionConfiguration"` + TopicConfigs []TopicConfig `xml:"TopicConfiguration"` + QueueConfigs []QueueConfig `xml:"QueueConfiguration"` +} + +// AddTopic adds a given topic config to the general bucket notification config +func (b *BucketNotification) AddTopic(topicConfig NotificationConfig) { + newTopicConfig := TopicConfig{NotificationConfig: topicConfig, Topic: topicConfig.Arn.String()} + for _, n := range b.TopicConfigs { + if reflect.DeepEqual(n, newTopicConfig) { + // Avoid adding duplicated entry + return + } + } + b.TopicConfigs = append(b.TopicConfigs, newTopicConfig) +} + +// AddQueue adds a given queue config to the general bucket notification config +func (b *BucketNotification) AddQueue(queueConfig NotificationConfig) { + newQueueConfig := QueueConfig{NotificationConfig: queueConfig, Queue: queueConfig.Arn.String()} + for _, n := range b.QueueConfigs { + if reflect.DeepEqual(n, newQueueConfig) { + // Avoid adding duplicated entry + return + } + } + b.QueueConfigs = append(b.QueueConfigs, newQueueConfig) +} + +// AddLambda adds a given lambda config to the general bucket notification config +func (b *BucketNotification) AddLambda(lambdaConfig NotificationConfig) { + newLambdaConfig := LambdaConfig{NotificationConfig: lambdaConfig, Lambda: lambdaConfig.Arn.String()} + for _, n := range b.LambdaConfigs { + if reflect.DeepEqual(n, newLambdaConfig) { + // Avoid adding duplicated entry + return + } + } + b.LambdaConfigs = append(b.LambdaConfigs, newLambdaConfig) +} + +// RemoveTopicByArn removes all topic configurations that match the exact specified ARN +func (b *BucketNotification) RemoveTopicByArn(arn Arn) { + var topics []TopicConfig + for _, topic := range b.TopicConfigs { + if topic.Topic != arn.String() { + topics = append(topics, topic) + } + } + b.TopicConfigs = topics +} + +// RemoveQueueByArn removes all queue configurations that match the exact specified ARN +func (b *BucketNotification) RemoveQueueByArn(arn Arn) { + var queues []QueueConfig + for _, queue := range b.QueueConfigs { + if queue.Queue != arn.String() { + queues = append(queues, queue) + } + } + b.QueueConfigs = queues +} + +// RemoveLambdaByArn removes all lambda configurations that match the exact specified ARN +func (b *BucketNotification) RemoveLambdaByArn(arn Arn) { + var lambdas []LambdaConfig + for _, lambda := range b.LambdaConfigs { + if lambda.Lambda != arn.String() { + lambdas = append(lambdas, lambda) + } + } + b.LambdaConfigs = lambdas +} diff --git a/vendor/github.com/minio/minio-go/constants.go b/vendor/github.com/minio/minio-go/constants.go new file mode 100644 index 000000000..84b6cfdf3 --- /dev/null +++ b/vendor/github.com/minio/minio-go/constants.go @@ -0,0 +1,70 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +/// Multipart upload defaults. + +// absMinPartSize - absolute minimum part size (5 MiB) below which +// a part in a multipart upload may not be uploaded. +const absMinPartSize = 1024 * 1024 * 5 + +// minPartSize - minimum part size 64MiB per object after which +// putObject behaves internally as multipart. +const minPartSize = 1024 * 1024 * 64 + +// copyPartSize - default (and maximum) part size to copy in a +// copy-object request (5GiB) +const copyPartSize = 1024 * 1024 * 1024 * 5 + +// maxPartsCount - maximum number of parts for a single multipart session. +const maxPartsCount = 10000 + +// maxPartSize - maximum part size 5GiB for a single multipart upload +// operation. +const maxPartSize = 1024 * 1024 * 1024 * 5 + +// maxSinglePutObjectSize - maximum size 5GiB of object per PUT +// operation. +const maxSinglePutObjectSize = 1024 * 1024 * 1024 * 5 + +// maxMultipartPutObjectSize - maximum size 5TiB of object for +// Multipart operation. +const maxMultipartPutObjectSize = 1024 * 1024 * 1024 * 1024 * 5 + +// unsignedPayload - value to be set to X-Amz-Content-Sha256 header when +// we don't want to sign the request payload +const unsignedPayload = "UNSIGNED-PAYLOAD" + +// Total number of parallel workers used for multipart operation. +const totalWorkers = 4 + +// Signature related constants. +const ( + signV4Algorithm = "AWS4-HMAC-SHA256" + iso8601DateFormat = "20060102T150405Z" +) + +// Encryption headers stored along with the object. +const ( + amzHeaderIV = "X-Amz-Meta-X-Amz-Iv" + amzHeaderKey = "X-Amz-Meta-X-Amz-Key" + amzHeaderMatDesc = "X-Amz-Meta-X-Amz-Matdesc" +) + +// Storage class header constant. +const amzStorageClass = "X-Amz-Storage-Class" diff --git a/vendor/github.com/minio/minio-go/core.go b/vendor/github.com/minio/minio-go/core.go new file mode 100644 index 000000000..4245fc065 --- /dev/null +++ b/vendor/github.com/minio/minio-go/core.go @@ -0,0 +1,154 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "context" + "io" + "strings" + + "github.com/minio/minio-go/pkg/policy" +) + +// Core - Inherits Client and adds new methods to expose the low level S3 APIs. +type Core struct { + *Client +} + +// NewCore - Returns new initialized a Core client, this CoreClient should be +// only used under special conditions such as need to access lower primitives +// and being able to use them to write your own wrappers. +func NewCore(endpoint string, accessKeyID, secretAccessKey string, secure bool) (*Core, error) { + var s3Client Core + client, err := NewV4(endpoint, accessKeyID, secretAccessKey, secure) + if err != nil { + return nil, err + } + s3Client.Client = client + return &s3Client, nil +} + +// ListObjects - List all the objects at a prefix, optionally with marker and delimiter +// you can further filter the results. +func (c Core) ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (result ListBucketResult, err error) { + return c.listObjectsQuery(bucket, prefix, marker, delimiter, maxKeys) +} + +// ListObjectsV2 - Lists all the objects at a prefix, similar to ListObjects() but uses +// continuationToken instead of marker to further filter the results. +func (c Core) ListObjectsV2(bucketName, objectPrefix, continuationToken string, fetchOwner bool, delimiter string, maxkeys int) (ListBucketV2Result, error) { + return c.listObjectsV2Query(bucketName, objectPrefix, continuationToken, fetchOwner, delimiter, maxkeys) +} + +// CopyObject - copies an object from source object to destination object on server side. +func (c Core) CopyObject(sourceBucket, sourceObject, destBucket, destObject string, metadata map[string]string) (ObjectInfo, error) { + return c.copyObjectDo(context.Background(), sourceBucket, sourceObject, destBucket, destObject, metadata) +} + +// CopyObjectPart - creates a part in a multipart upload by copying (a +// part of) an existing object. +func (c Core) CopyObjectPart(srcBucket, srcObject, destBucket, destObject string, uploadID string, + partID int, startOffset, length int64, metadata map[string]string) (p CompletePart, err error) { + + return c.copyObjectPartDo(context.Background(), srcBucket, srcObject, destBucket, destObject, uploadID, + partID, startOffset, length, metadata) +} + +// PutObject - Upload object. Uploads using single PUT call. +func (c Core) PutObject(bucket, object string, data io.Reader, size int64, md5Base64, sha256Hex string, metadata map[string]string) (ObjectInfo, error) { + opts := PutObjectOptions{} + m := make(map[string]string) + for k, v := range metadata { + if strings.ToLower(k) == "content-encoding" { + opts.ContentEncoding = v + } else if strings.ToLower(k) == "content-disposition" { + opts.ContentDisposition = v + } else if strings.ToLower(k) == "content-type" { + opts.ContentType = v + } else if strings.ToLower(k) == "cache-control" { + opts.CacheControl = v + } else { + m[k] = metadata[k] + } + } + opts.UserMetadata = m + return c.putObjectDo(context.Background(), bucket, object, data, md5Base64, sha256Hex, size, opts) +} + +// NewMultipartUpload - Initiates new multipart upload and returns the new uploadID. +func (c Core) NewMultipartUpload(bucket, object string, opts PutObjectOptions) (uploadID string, err error) { + result, err := c.initiateMultipartUpload(context.Background(), bucket, object, opts) + return result.UploadID, err +} + +// ListMultipartUploads - List incomplete uploads. +func (c Core) ListMultipartUploads(bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (result ListMultipartUploadsResult, err error) { + return c.listMultipartUploadsQuery(bucket, keyMarker, uploadIDMarker, prefix, delimiter, maxUploads) +} + +// PutObjectPart - Upload an object part. +func (c Core) PutObjectPart(bucket, object, uploadID string, partID int, data io.Reader, size int64, md5Base64, sha256Hex string) (ObjectPart, error) { + return c.PutObjectPartWithMetadata(bucket, object, uploadID, partID, data, size, md5Base64, sha256Hex, nil) +} + +// PutObjectPartWithMetadata - upload an object part with additional request metadata. +func (c Core) PutObjectPartWithMetadata(bucket, object, uploadID string, partID int, data io.Reader, + size int64, md5Base64, sha256Hex string, metadata map[string]string) (ObjectPart, error) { + return c.uploadPart(context.Background(), bucket, object, uploadID, data, partID, md5Base64, sha256Hex, size, metadata) +} + +// ListObjectParts - List uploaded parts of an incomplete upload.x +func (c Core) ListObjectParts(bucket, object, uploadID string, partNumberMarker int, maxParts int) (result ListObjectPartsResult, err error) { + return c.listObjectPartsQuery(bucket, object, uploadID, partNumberMarker, maxParts) +} + +// CompleteMultipartUpload - Concatenate uploaded parts and commit to an object. +func (c Core) CompleteMultipartUpload(bucket, object, uploadID string, parts []CompletePart) error { + _, err := c.completeMultipartUpload(context.Background(), bucket, object, uploadID, completeMultipartUpload{ + Parts: parts, + }) + return err +} + +// AbortMultipartUpload - Abort an incomplete upload. +func (c Core) AbortMultipartUpload(bucket, object, uploadID string) error { + return c.abortMultipartUpload(context.Background(), bucket, object, uploadID) +} + +// GetBucketPolicy - fetches bucket access policy for a given bucket. +func (c Core) GetBucketPolicy(bucket string) (policy.BucketAccessPolicy, error) { + return c.getBucketPolicy(bucket) +} + +// PutBucketPolicy - applies a new bucket access policy for a given bucket. +func (c Core) PutBucketPolicy(bucket string, bucketPolicy policy.BucketAccessPolicy) error { + return c.putBucketPolicy(bucket, bucketPolicy) +} + +// GetObject is a lower level API implemented to support reading +// partial objects and also downloading objects with special conditions +// matching etag, modtime etc. +func (c Core) GetObject(bucketName, objectName string, opts GetObjectOptions) (io.ReadCloser, ObjectInfo, error) { + return c.getObject(context.Background(), bucketName, objectName, opts) +} + +// StatObject is a lower level API implemented to support special +// conditions matching etag, modtime on a request. +func (c Core) StatObject(bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) { + return c.statObject(context.Background(), bucketName, objectName, opts) +} diff --git a/vendor/github.com/minio/minio-go/docs/validator.go b/vendor/github.com/minio/minio-go/docs/validator.go new file mode 100644 index 000000000..7d5cbaaab --- /dev/null +++ b/vendor/github.com/minio/minio-go/docs/validator.go @@ -0,0 +1,227 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "strings" + "text/template" + + "github.com/a8m/mark" + "github.com/gernest/wow" + "github.com/gernest/wow/spin" + "github.com/minio/cli" +) + +func init() { + // Validate go binary. + if _, err := exec.LookPath("go"); err != nil { + panic(err) + } +} + +var globalFlags = []cli.Flag{ + cli.StringFlag{ + Name: "m", + Value: "API.md", + Usage: "Path to markdown api documentation.", + }, + cli.StringFlag{ + Name: "t", + Value: "checker.go.template", + Usage: "Template used for generating the programs.", + }, + cli.IntFlag{ + Name: "skip", + Value: 2, + Usage: "Skip entries before validating the code.", + }, +} + +func runGofmt(path string) (msg string, err error) { + cmdArgs := []string{"-s", "-w", "-l", path} + cmd := exec.Command("gofmt", cmdArgs...) + stdoutStderr, err := cmd.CombinedOutput() + if err != nil { + return "", err + } + return string(stdoutStderr), nil +} + +func runGoImports(path string) (msg string, err error) { + cmdArgs := []string{"-w", path} + cmd := exec.Command("goimports", cmdArgs...) + stdoutStderr, err := cmd.CombinedOutput() + if err != nil { + return string(stdoutStderr), err + } + return string(stdoutStderr), nil +} + +func runGoBuild(path string) (msg string, err error) { + // Go build the path. + cmdArgs := []string{"build", "-o", "/dev/null", path} + cmd := exec.Command("go", cmdArgs...) + stdoutStderr, err := cmd.CombinedOutput() + if err != nil { + return string(stdoutStderr), err + } + return string(stdoutStderr), nil +} + +func validatorAction(ctx *cli.Context) error { + if !ctx.IsSet("m") || !ctx.IsSet("t") { + return nil + } + docPath := ctx.String("m") + var err error + docPath, err = filepath.Abs(docPath) + if err != nil { + return err + } + data, err := ioutil.ReadFile(docPath) + if err != nil { + return err + } + + templatePath := ctx.String("t") + templatePath, err = filepath.Abs(templatePath) + if err != nil { + return err + } + + skipEntries := ctx.Int("skip") + m := mark.New(string(data), &mark.Options{ + Gfm: true, // Github markdown support is enabled by default. + }) + + t, err := template.ParseFiles(templatePath) + if err != nil { + return err + } + + tmpDir, err := ioutil.TempDir("", "md-verifier") + if err != nil { + return err + } + defer os.RemoveAll(tmpDir) + + entryN := 1 + for i := mark.NodeText; i < mark.NodeCheckbox; i++ { + if mark.NodeCode != mark.NodeType(i) { + m.AddRenderFn(mark.NodeType(i), func(node mark.Node) (s string) { + return "" + }) + continue + } + m.AddRenderFn(mark.NodeCode, func(node mark.Node) (s string) { + p, ok := node.(*mark.CodeNode) + if !ok { + return + } + p.Text = strings.NewReplacer("<", "<", ">", ">", """, `"`, "&", "&").Replace(p.Text) + if skipEntries > 0 { + skipEntries-- + return + } + + testFilePath := filepath.Join(tmpDir, "example.go") + w, werr := os.Create(testFilePath) + if werr != nil { + panic(werr) + } + t.Execute(w, p) + w.Sync() + w.Close() + entryN++ + + msg, err := runGofmt(testFilePath) + if err != nil { + fmt.Printf("Failed running gofmt on %s, with (%s):(%s)\n", testFilePath, msg, err) + os.Exit(-1) + } + + msg, err = runGoImports(testFilePath) + if err != nil { + fmt.Printf("Failed running gofmt on %s, with (%s):(%s)\n", testFilePath, msg, err) + os.Exit(-1) + } + + msg, err = runGoBuild(testFilePath) + if err != nil { + fmt.Printf("Failed running gobuild on %s, with (%s):(%s)\n", testFilePath, msg, err) + fmt.Printf("Code with possible issue in %s:\n%s", docPath, p.Text) + fmt.Printf("To test `go build %s`\n", testFilePath) + os.Exit(-1) + } + + // Once successfully built remove the test file + os.Remove(testFilePath) + return + }) + } + + w := wow.New(os.Stdout, spin.Get(spin.Moon), fmt.Sprintf(" Running validation tests in %s", tmpDir)) + + w.Start() + // Render markdown executes our checker on each code blocks. + _ = m.Render() + w.PersistWith(spin.Get(spin.Runner), " Successfully finished tests") + w.Stop() + + return nil +} + +func main() { + app := cli.NewApp() + app.Action = validatorAction + app.HideVersion = true + app.HideHelpCommand = true + app.Usage = "Validates code block sections inside API.md" + app.Author = "Minio.io" + app.Flags = globalFlags + // Help template for validator + app.CustomAppHelpTemplate = `NAME: + {{.Name}} - {{.Usage}} + +USAGE: + {{.Name}} {{if .VisibleFlags}}[FLAGS] {{end}}COMMAND{{if .VisibleFlags}} [COMMAND FLAGS | -h]{{end}} [ARGUMENTS...] + +COMMANDS: + {{range .VisibleCommands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} + {{end}}{{if .VisibleFlags}} +FLAGS: + {{range .VisibleFlags}}{{.}} + {{end}}{{end}} +TEMPLATE: + Validator uses Go's 'text/template' formatting so you need to ensure + your template is formatted correctly, check 'docs/checker.go.template' + +USAGE: + go run docs/validator.go -m docs/API.md -t /tmp/mycode.go.template + +` + app.Run(os.Args) + +} diff --git a/vendor/github.com/minio/minio-go/examples/minio/listenbucketnotification.go b/vendor/github.com/minio/minio-go/examples/minio/listenbucketnotification.go new file mode 100644 index 000000000..4c48510da --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/minio/listenbucketnotification.go @@ -0,0 +1,61 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + minioClient, err := minio.New("play.minio.io:9000", "YOUR-ACCESS", "YOUR-SECRET", true) + if err != nil { + log.Fatalln(err) + } + + // s3Client.TraceOn(os.Stderr) + + // Create a done channel to control 'ListenBucketNotification' go routine. + doneCh := make(chan struct{}) + + // Indicate to our routine to exit cleanly upon return. + defer close(doneCh) + + // Listen for bucket notifications on "mybucket" filtered by prefix, suffix and events. + for notificationInfo := range minioClient.ListenBucketNotification("YOUR-BUCKET", "PREFIX", "SUFFIX", []string{ + "s3:ObjectCreated:*", + "s3:ObjectAccessed:*", + "s3:ObjectRemoved:*", + }, doneCh) { + if notificationInfo.Err != nil { + log.Fatalln(notificationInfo.Err) + } + log.Println(notificationInfo) + } +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/bucketexists.go b/vendor/github.com/minio/minio-go/examples/s3/bucketexists.go new file mode 100644 index 000000000..20dea30a3 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/bucketexists.go @@ -0,0 +1,52 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + found, err := s3Client.BucketExists("my-bucketname") + if err != nil { + log.Fatalln(err) + } + + if found { + log.Println("Bucket found.") + } else { + log.Println("Bucket not found.") + } +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/composeobject.go b/vendor/github.com/minio/minio-go/examples/s3/composeobject.go new file mode 100644 index 000000000..2f76ff053 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/composeobject.go @@ -0,0 +1,78 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + minio "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // Enable trace. + // s3Client.TraceOn(os.Stderr) + + // Prepare source decryption key (here we assume same key to + // decrypt all source objects.) + decKey := minio.NewSSEInfo([]byte{1, 2, 3}, "") + + // Source objects to concatenate. We also specify decryption + // key for each + src1 := minio.NewSourceInfo("bucket1", "object1", &decKey) + src1.SetMatchETagCond("31624deb84149d2f8ef9c385918b653a") + + src2 := minio.NewSourceInfo("bucket2", "object2", &decKey) + src2.SetMatchETagCond("f8ef9c385918b653a31624deb84149d2") + + src3 := minio.NewSourceInfo("bucket3", "object3", &decKey) + src3.SetMatchETagCond("5918b653a31624deb84149d2f8ef9c38") + + // Create slice of sources. + srcs := []minio.SourceInfo{src1, src2, src3} + + // Prepare destination encryption key + encKey := minio.NewSSEInfo([]byte{8, 9, 0}, "") + + // Create destination info + dst, err := minio.NewDestinationInfo("bucket", "object", &encKey, nil) + if err != nil { + log.Fatalln(err) + } + + err = s3Client.ComposeObject(dst, srcs) + if err != nil { + log.Fatalln(err) + } + + log.Println("Composed object successfully.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/copyobject.go b/vendor/github.com/minio/minio-go/examples/s3/copyobject.go new file mode 100644 index 000000000..a7c3eca45 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/copyobject.go @@ -0,0 +1,75 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "time" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // Enable trace. + // s3Client.TraceOn(os.Stderr) + + // Source object + src := minio.NewSourceInfo("my-sourcebucketname", "my-sourceobjectname", nil) + + // All following conditions are allowed and can be combined together. + + // Set modified condition, copy object modified since 2014 April. + src.SetModifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC)) + + // Set unmodified condition, copy object unmodified since 2014 April. + // src.SetUnmodifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC)) + + // Set matching ETag condition, copy object which matches the following ETag. + // src.SetMatchETagCond("31624deb84149d2f8ef9c385918b653a") + + // Set matching ETag except condition, copy object which does not match the following ETag. + // src.SetMatchETagExceptCond("31624deb84149d2f8ef9c385918b653a") + + // Destination object + dst, err := minio.NewDestinationInfo("my-bucketname", "my-objectname", nil, nil) + if err != nil { + log.Fatalln(err) + } + + // Initiate copy object. + err = s3Client.CopyObject(dst, src) + if err != nil { + log.Fatalln(err) + } + log.Println("Copied source object /my-sourcebucketname/my-sourceobjectname to destination /my-bucketname/my-objectname Successfully.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/fgetobject-context.go b/vendor/github.com/minio/minio-go/examples/s3/fgetobject-context.go new file mode 100644 index 000000000..6004baa14 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/fgetobject-context.go @@ -0,0 +1,54 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "time" + + "context" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname + // and my-filename.csv are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) + defer cancel() + + if err := s3Client.FGetObjectWithContext(ctx, "my-bucketname", "my-objectname", "my-filename.csv", minio.GetObjectOptions{}); err != nil { + log.Fatalln(err) + } + log.Println("Successfully saved my-filename.csv") + +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/fgetobject.go b/vendor/github.com/minio/minio-go/examples/s3/fgetobject.go new file mode 100644 index 000000000..819a34f91 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/fgetobject.go @@ -0,0 +1,46 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname + // and my-filename.csv are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + if err := s3Client.FGetObject("my-bucketname", "my-objectname", "my-filename.csv", minio.GetObjectOptions{}); err != nil { + log.Fatalln(err) + } + log.Println("Successfully saved my-filename.csv") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/fputencrypted-object.go b/vendor/github.com/minio/minio-go/examples/s3/fputencrypted-object.go new file mode 100644 index 000000000..96eec7e8f --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/fputencrypted-object.go @@ -0,0 +1,80 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" + "github.com/minio/minio-go/pkg/encrypt" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // Specify a local file that we will upload + filePath := "my-testfile" + + //// Build an asymmetric key from private and public files + // + // privateKey, err := ioutil.ReadFile("private.key") + // if err != nil { + // t.Fatal(err) + // } + // + // publicKey, err := ioutil.ReadFile("public.key") + // if err != nil { + // t.Fatal(err) + // } + // + // asymmetricKey, err := NewAsymmetricKey(privateKey, publicKey) + // if err != nil { + // t.Fatal(err) + // } + //// + + // Build a symmetric key + symmetricKey := encrypt.NewSymmetricKey([]byte("my-secret-key-00")) + + // Build encryption materials which will encrypt uploaded data + cbcMaterials, err := encrypt.NewCBCSecureMaterials(symmetricKey) + if err != nil { + log.Fatalln(err) + } + + // Encrypt file content and upload to the server + n, err := s3Client.FPutEncryptedObject("my-bucketname", "my-objectname", filePath, cbcMaterials) + if err != nil { + log.Fatalln(err) + } + + log.Println("Uploaded", "my-objectname", " of size: ", n, "Successfully.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/fputobject-context.go b/vendor/github.com/minio/minio-go/examples/s3/fputobject-context.go new file mode 100644 index 000000000..d7c941c2b --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/fputobject-context.go @@ -0,0 +1,53 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "time" + + "context" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname + // and my-filename.csv are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) + defer cancel() + + if _, err := s3Client.FPutObjectWithContext(ctx, "my-bucketname", "my-objectname", "my-filename.csv", minio.PutObjectOptions{ContentType: "application/csv"}); err != nil { + log.Fatalln(err) + } + log.Println("Successfully uploaded my-filename.csv") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/fputobject.go b/vendor/github.com/minio/minio-go/examples/s3/fputobject.go new file mode 100644 index 000000000..34d876804 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/fputobject.go @@ -0,0 +1,48 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname + // and my-filename.csv are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + if _, err := s3Client.FPutObject("my-bucketname", "my-objectname", "my-filename.csv", minio.PutObjectOptions{ + ContentType: "application/csv", + }); err != nil { + log.Fatalln(err) + } + log.Println("Successfully uploaded my-filename.csv") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/get-encrypted-object.go b/vendor/github.com/minio/minio-go/examples/s3/get-encrypted-object.go new file mode 100644 index 000000000..9783bebe8 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/get-encrypted-object.go @@ -0,0 +1,89 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "io" + "log" + "os" + + "github.com/minio/minio-go" + "github.com/minio/minio-go/pkg/encrypt" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname and + // my-testfile are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESS-KEY-HERE", "YOUR-SECRET-KEY-HERE", true) + if err != nil { + log.Fatalln(err) + } + + //// Build an asymmetric key from private and public files + // + // privateKey, err := ioutil.ReadFile("private.key") + // if err != nil { + // t.Fatal(err) + // } + // + // publicKey, err := ioutil.ReadFile("public.key") + // if err != nil { + // t.Fatal(err) + // } + // + // asymmetricKey, err := NewAsymmetricKey(privateKey, publicKey) + // if err != nil { + // t.Fatal(err) + // } + //// + + // Build a symmetric key + symmetricKey := encrypt.NewSymmetricKey([]byte("my-secret-key-00")) + + // Build encryption materials which will encrypt uploaded data + cbcMaterials, err := encrypt.NewCBCSecureMaterials(symmetricKey) + if err != nil { + log.Fatalln(err) + } + + // Get a deciphered data from the server, deciphering is assured by cbcMaterials + reader, err := s3Client.GetEncryptedObject("my-bucketname", "my-objectname", cbcMaterials) + if err != nil { + log.Fatalln(err) + } + defer reader.Close() + + // Local file which holds plain data + localFile, err := os.Create("my-testfile") + if err != nil { + log.Fatalln(err) + } + defer localFile.Close() + + if _, err := io.Copy(localFile, reader); err != nil { + log.Fatalln(err) + } +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/getbucketnotification.go b/vendor/github.com/minio/minio-go/examples/s3/getbucketnotification.go new file mode 100644 index 000000000..19349baaf --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/getbucketnotification.go @@ -0,0 +1,56 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // s3Client.TraceOn(os.Stderr) + + notifications, err := s3Client.GetBucketNotification("my-bucketname") + if err != nil { + log.Fatalln(err) + } + + log.Println("Bucket notification are successfully retrieved.") + + for _, topicConfig := range notifications.TopicConfigs { + for _, e := range topicConfig.Events { + log.Println(e + " event is enabled.") + } + } +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/getbucketpolicy.go b/vendor/github.com/minio/minio-go/examples/s3/getbucketpolicy.go new file mode 100644 index 000000000..f9ac89b61 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/getbucketpolicy.go @@ -0,0 +1,56 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // s3Client.TraceOn(os.Stderr) + + // Fetch the policy at 'my-objectprefix'. + policy, err := s3Client.GetBucketPolicy("my-bucketname", "my-objectprefix") + if err != nil { + log.Fatalln(err) + } + + // Description of policy output. + // "none" - The specified bucket does not have a bucket policy. + // "readonly" - Read only operations are allowed. + // "writeonly" - Write only operations are allowed. + // "readwrite" - both read and write operations are allowed, the bucket is public. + log.Println("Success - ", policy) +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/getobject-context.go b/vendor/github.com/minio/minio-go/examples/s3/getobject-context.go new file mode 100644 index 000000000..c7d41707a --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/getobject-context.go @@ -0,0 +1,73 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "io" + "log" + "os" + "time" + + "context" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname and + // my-testfile are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESS-KEY-HERE", "YOUR-SECRET-KEY-HERE", true) + if err != nil { + log.Fatalln(err) + } + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) + defer cancel() + + opts := minio.GetObjectOptions{} + opts.SetModified(time.Now().Round(10 * time.Minute)) // get object if was modified within the last 10 minutes + reader, err := s3Client.GetObjectWithContext(ctx, "my-bucketname", "my-objectname", opts) + if err != nil { + log.Fatalln(err) + } + defer reader.Close() + + localFile, err := os.Create("my-testfile") + if err != nil { + log.Fatalln(err) + } + defer localFile.Close() + + stat, err := reader.Stat() + if err != nil { + log.Fatalln(err) + } + + if _, err := io.CopyN(localFile, reader, stat.Size); err != nil { + log.Fatalln(err) + } +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/getobject.go b/vendor/github.com/minio/minio-go/examples/s3/getobject.go new file mode 100644 index 000000000..e17ef8172 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/getobject.go @@ -0,0 +1,64 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "io" + "log" + "os" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname and + // my-testfile are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESS-KEY-HERE", "YOUR-SECRET-KEY-HERE", true) + if err != nil { + log.Fatalln(err) + } + + reader, err := s3Client.GetObject("my-bucketname", "my-objectname", minio.GetObjectOptions{}) + if err != nil { + log.Fatalln(err) + } + defer reader.Close() + + localFile, err := os.Create("my-testfile") + if err != nil { + log.Fatalln(err) + } + defer localFile.Close() + + stat, err := reader.Stat() + if err != nil { + log.Fatalln(err) + } + + if _, err := io.CopyN(localFile, reader, stat.Size); err != nil { + log.Fatalln(err) + } +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/listbucketpolicies.go b/vendor/github.com/minio/minio-go/examples/s3/listbucketpolicies.go new file mode 100644 index 000000000..43edd0c3d --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/listbucketpolicies.go @@ -0,0 +1,57 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // s3Client.TraceOn(os.Stderr) + + // Fetch the policy at 'my-objectprefix'. + policies, err := s3Client.ListBucketPolicies("my-bucketname", "my-objectprefix") + if err != nil { + log.Fatalln(err) + } + + // ListBucketPolicies returns a map of objects policy rules and their associated permissions + // e.g. mybucket/downloadfolder/* => readonly + // mybucket/shared/* => readwrite + + for resource, permission := range policies { + log.Println(resource, " => ", permission) + } +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/listbuckets.go b/vendor/github.com/minio/minio-go/examples/s3/listbuckets.go new file mode 100644 index 000000000..5eae587b4 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/listbuckets.go @@ -0,0 +1,49 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID and YOUR-SECRETACCESSKEY are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + buckets, err := s3Client.ListBuckets() + if err != nil { + log.Fatalln(err) + } + for _, bucket := range buckets { + log.Println(bucket) + } +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/listincompleteuploads.go b/vendor/github.com/minio/minio-go/examples/s3/listincompleteuploads.go new file mode 100644 index 000000000..a5a79b603 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/listincompleteuploads.go @@ -0,0 +1,58 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-prefixname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // Create a done channel to control 'ListObjects' go routine. + doneCh := make(chan struct{}) + + // Indicate to our routine to exit cleanly upon return. + defer close(doneCh) + + // List all multipart uploads from a bucket-name with a matching prefix. + for multipartObject := range s3Client.ListIncompleteUploads("my-bucketname", "my-prefixname", true, doneCh) { + if multipartObject.Err != nil { + fmt.Println(multipartObject.Err) + return + } + fmt.Println(multipartObject) + } + return +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/listobjects-N.go b/vendor/github.com/minio/minio-go/examples/s3/listobjects-N.go new file mode 100644 index 000000000..55bceb470 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/listobjects-N.go @@ -0,0 +1,77 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-prefixname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + fmt.Println(err) + return + } + + // List 'N' number of objects from a bucket-name with a matching prefix. + listObjectsN := func(bucket, prefix string, recursive bool, N int) (objsInfo []minio.ObjectInfo, err error) { + // Create a done channel to control 'ListObjects' go routine. + doneCh := make(chan struct{}, 1) + + // Free the channel upon return. + defer close(doneCh) + + i := 1 + for object := range s3Client.ListObjects(bucket, prefix, recursive, doneCh) { + if object.Err != nil { + return nil, object.Err + } + i++ + // Verify if we have printed N objects. + if i == N { + // Indicate ListObjects go-routine to exit and stop + // feeding the objectInfo channel. + doneCh <- struct{}{} + } + objsInfo = append(objsInfo, object) + } + return objsInfo, nil + } + + // List recursively first 100 entries for prefix 'my-prefixname'. + recursive := true + objsInfo, err := listObjectsN("my-bucketname", "my-prefixname", recursive, 100) + if err != nil { + fmt.Println(err) + } + + // Print all the entries. + fmt.Println(objsInfo) +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/listobjects.go b/vendor/github.com/minio/minio-go/examples/s3/listobjects.go new file mode 100644 index 000000000..1da2e3faa --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/listobjects.go @@ -0,0 +1,58 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-prefixname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + fmt.Println(err) + return + } + + // Create a done channel to control 'ListObjects' go routine. + doneCh := make(chan struct{}) + + // Indicate to our routine to exit cleanly upon return. + defer close(doneCh) + + // List all objects from a bucket-name with a matching prefix. + for object := range s3Client.ListObjects("my-bucketname", "my-prefixname", true, doneCh) { + if object.Err != nil { + fmt.Println(object.Err) + return + } + fmt.Println(object) + } + return +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/listobjectsV2.go b/vendor/github.com/minio/minio-go/examples/s3/listobjectsV2.go new file mode 100644 index 000000000..190aec36b --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/listobjectsV2.go @@ -0,0 +1,58 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-prefixname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + fmt.Println(err) + return + } + + // Create a done channel to control 'ListObjects' go routine. + doneCh := make(chan struct{}) + + // Indicate to our routine to exit cleanly upon return. + defer close(doneCh) + + // List all objects from a bucket-name with a matching prefix. + for object := range s3Client.ListObjectsV2("my-bucketname", "my-prefixname", true, doneCh) { + if object.Err != nil { + fmt.Println(object.Err) + return + } + fmt.Println(object) + } + return +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/makebucket.go b/vendor/github.com/minio/minio-go/examples/s3/makebucket.go new file mode 100644 index 000000000..419c96cf2 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/makebucket.go @@ -0,0 +1,47 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + err = s3Client.MakeBucket("my-bucketname", "us-east-1") + if err != nil { + log.Fatalln(err) + } + log.Println("Success") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/presignedgetobject.go b/vendor/github.com/minio/minio-go/examples/s3/presignedgetobject.go new file mode 100644 index 000000000..fd7fb9e8d --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/presignedgetobject.go @@ -0,0 +1,54 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "net/url" + "time" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // Set request parameters + reqParams := make(url.Values) + reqParams.Set("response-content-disposition", "attachment; filename=\"your-filename.txt\"") + + // Gernerate presigned get object url. + presignedURL, err := s3Client.PresignedGetObject("my-bucketname", "my-objectname", time.Duration(1000)*time.Second, reqParams) + if err != nil { + log.Fatalln(err) + } + log.Println(presignedURL) +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/presignedheadobject.go b/vendor/github.com/minio/minio-go/examples/s3/presignedheadobject.go new file mode 100644 index 000000000..8dbc0a4b7 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/presignedheadobject.go @@ -0,0 +1,54 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "net/url" + "time" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // Set request parameters + reqParams := make(url.Values) + reqParams.Set("response-content-disposition", "attachment; filename=\"your-filename.txt\"") + + // Gernerate presigned get object url. + presignedURL, err := s3Client.PresignedHeadObject("my-bucketname", "my-objectname", time.Duration(1000)*time.Second, reqParams) + if err != nil { + log.Fatalln(err) + } + log.Println(presignedURL) +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/presignedpostpolicy.go b/vendor/github.com/minio/minio-go/examples/s3/presignedpostpolicy.go new file mode 100644 index 000000000..205ac95a3 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/presignedpostpolicy.go @@ -0,0 +1,60 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "log" + "time" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + policy := minio.NewPostPolicy() + policy.SetBucket("my-bucketname") + policy.SetKey("my-objectname") + // Expires in 10 days. + policy.SetExpires(time.Now().UTC().AddDate(0, 0, 10)) + // Returns form data for POST form request. + url, formData, err := s3Client.PresignedPostPolicy(policy) + if err != nil { + log.Fatalln(err) + } + fmt.Printf("curl ") + for k, v := range formData { + fmt.Printf("-F %s=%s ", k, v) + } + fmt.Printf("-F file=@/etc/bash.bashrc ") + fmt.Printf("%s\n", url) +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/presignedputobject.go b/vendor/github.com/minio/minio-go/examples/s3/presignedputobject.go new file mode 100644 index 000000000..b2f8b4f82 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/presignedputobject.go @@ -0,0 +1,48 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "time" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + presignedURL, err := s3Client.PresignedPutObject("my-bucketname", "my-objectname", time.Duration(1000)*time.Second) + if err != nil { + log.Fatalln(err) + } + log.Println(presignedURL) +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/put-encrypted-object.go b/vendor/github.com/minio/minio-go/examples/s3/put-encrypted-object.go new file mode 100644 index 000000000..cdf09ac53 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/put-encrypted-object.go @@ -0,0 +1,85 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "os" + + "github.com/minio/minio-go" + "github.com/minio/minio-go/pkg/encrypt" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // Open a local file that we will upload + file, err := os.Open("my-testfile") + if err != nil { + log.Fatalln(err) + } + defer file.Close() + + //// Build an asymmetric key from private and public files + // + // privateKey, err := ioutil.ReadFile("private.key") + // if err != nil { + // t.Fatal(err) + // } + // + // publicKey, err := ioutil.ReadFile("public.key") + // if err != nil { + // t.Fatal(err) + // } + // + // asymmetricKey, err := NewAsymmetricKey(privateKey, publicKey) + // if err != nil { + // t.Fatal(err) + // } + //// + + // Build a symmetric key + symmetricKey := encrypt.NewSymmetricKey([]byte("my-secret-key-00")) + + // Build encryption materials which will encrypt uploaded data + cbcMaterials, err := encrypt.NewCBCSecureMaterials(symmetricKey) + if err != nil { + log.Fatalln(err) + } + + // Encrypt file content and upload to the server + n, err := s3Client.PutEncryptedObject("my-bucketname", "my-objectname", file, cbcMaterials) + if err != nil { + log.Fatalln(err) + } + + log.Println("Uploaded", "my-objectname", " of size: ", n, "Successfully.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/putobject-context.go b/vendor/github.com/minio/minio-go/examples/s3/putobject-context.go new file mode 100644 index 000000000..acc923f7e --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/putobject-context.go @@ -0,0 +1,68 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "os" + "time" + + "context" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) + defer cancel() + + object, err := os.Open("my-testfile") + if err != nil { + log.Fatalln(err) + } + defer object.Close() + + objectStat, err := object.Stat() + if err != nil { + log.Fatalln(err) + } + + n, err := s3Client.PutObjectWithContext(ctx, "my-bucketname", "my-objectname", object, objectStat.Size(), minio.PutObjectOptions{ + ContentType: "application/octet-stream", + }) + if err != nil { + log.Fatalln(err) + } + log.Println("Uploaded", "my-objectname", " of size: ", n, "Successfully.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/putobject-getobject-sse.go b/vendor/github.com/minio/minio-go/examples/s3/putobject-getobject-sse.go new file mode 100644 index 000000000..3d3b2fd2d --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/putobject-getobject-sse.go @@ -0,0 +1,87 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "bytes" + "crypto/md5" + "encoding/base64" + "io/ioutil" + "log" + + minio "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + minioClient, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + content := bytes.NewReader([]byte("Hello again")) + key := []byte("32byteslongsecretkeymustprovided") + h := md5.New() + h.Write(key) + encryptionKey := base64.StdEncoding.EncodeToString(key) + encryptionKeyMD5 := base64.StdEncoding.EncodeToString(h.Sum(nil)) + + // Amazon S3 does not store the encryption key you provide. + // Instead S3 stores a randomly salted HMAC value of the + // encryption key in order to validate future requests. + // The salted HMAC value cannot be used to derive the value + // of the encryption key or to decrypt the contents of the + // encrypted object. That means, if you lose the encryption + // key, you lose the object. + var metadata = map[string]string{ + "x-amz-server-side-encryption-customer-algorithm": "AES256", + "x-amz-server-side-encryption-customer-key": encryptionKey, + "x-amz-server-side-encryption-customer-key-MD5": encryptionKeyMD5, + } + + // minioClient.TraceOn(os.Stderr) // Enable to debug. + _, err = minioClient.PutObject("mybucket", "my-encrypted-object.txt", content, 11, minio.PutObjectOptions{UserMetadata: metadata}) + if err != nil { + log.Fatalln(err) + } + + opts := minio.GetObjectOptions{} + for k, v := range metadata { + opts.Set(k, v) + } + coreClient := minio.Core{minioClient} + reader, _, err := coreClient.GetObject("mybucket", "my-encrypted-object.txt", opts) + if err != nil { + log.Fatalln(err) + } + defer reader.Close() + + decBytes, err := ioutil.ReadAll(reader) + if err != nil { + log.Fatalln(err) + } + if !bytes.Equal(decBytes, []byte("Hello again")) { + log.Fatalln("Expected \"Hello, world\", got %s", string(decBytes)) + } +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/putobject-progress.go b/vendor/github.com/minio/minio-go/examples/s3/putobject-progress.go new file mode 100644 index 000000000..0e92dd65e --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/putobject-progress.go @@ -0,0 +1,64 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/cheggaaa/pb" + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + reader, err := s3Client.GetObject("my-bucketname", "my-objectname", minio.GetObjectOptions{}) + if err != nil { + log.Fatalln(err) + } + defer reader.Close() + + objectInfo, err := reader.Stat() + if err != nil { + log.Fatalln(err) + } + + // Progress reader is notified as PutObject makes progress with + // the Reads inside. + progress := pb.New64(objectInfo.Size) + progress.Start() + n, err := s3Client.PutObject("my-bucketname", "my-objectname-progress", reader, objectInfo.Size, minio.PutObjectOptions{ContentType: "application/octet-stream", Progress: progress}) + + if err != nil { + log.Fatalln(err) + } + log.Println("Uploaded", "my-objectname", " of size: ", n, "Successfully.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/putobject-s3-accelerate.go b/vendor/github.com/minio/minio-go/examples/s3/putobject-s3-accelerate.go new file mode 100644 index 000000000..06345cd87 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/putobject-s3-accelerate.go @@ -0,0 +1,62 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "os" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // Enable S3 transfer accelerate endpoint. + s3Client.SetS3TransferAccelerate("s3-accelerate.amazonaws.com") + + object, err := os.Open("my-testfile") + if err != nil { + log.Fatalln(err) + } + defer object.Close() + + objectStat, err := object.Stat() + if err != nil { + log.Fatalln(err) + } + + n, err := s3Client.PutObject("my-bucketname", "my-objectname", object, objectStat.Size(), minio.PutObjectOptions{ContentType: "application/octet-stream"}) + if err != nil { + log.Fatalln(err) + } + log.Println("Uploaded", "my-objectname", " of size: ", n, "Successfully.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/putobject-streaming.go b/vendor/github.com/minio/minio-go/examples/s3/putobject-streaming.go new file mode 100644 index 000000000..85b78dd45 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/putobject-streaming.go @@ -0,0 +1,55 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "os" + + minio "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + object, err := os.Open("my-testfile") + if err != nil { + log.Fatalln(err) + } + defer object.Close() + + n, err := s3Client.PutObject("my-bucketname", "my-objectname", object, -1, minio.PutObjectOptions{}) + if err != nil { + log.Fatalln(err) + } + + log.Println("Uploaded", "my-objectname", " of size: ", n, "Successfully.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/putobject.go b/vendor/github.com/minio/minio-go/examples/s3/putobject.go new file mode 100644 index 000000000..b9e4ff16c --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/putobject.go @@ -0,0 +1,58 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + "os" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and + // my-objectname are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + object, err := os.Open("my-testfile") + if err != nil { + log.Fatalln(err) + } + defer object.Close() + objectStat, err := object.Stat() + if err != nil { + log.Fatalln(err) + } + + n, err := s3Client.PutObject("my-bucketname", "my-objectname", object, objectStat.Size(), minio.PutObjectOptions{ContentType: "application/octet-stream"}) + if err != nil { + log.Fatalln(err) + } + log.Println("Uploaded", "my-objectname", " of size: ", n, "Successfully.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/removeallbucketnotification.go b/vendor/github.com/minio/minio-go/examples/s3/removeallbucketnotification.go new file mode 100644 index 000000000..1186afad8 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/removeallbucketnotification.go @@ -0,0 +1,50 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // s3Client.TraceOn(os.Stderr) + + err = s3Client.RemoveAllBucketNotification("my-bucketname") + if err != nil { + log.Fatalln(err) + } + + log.Println("Bucket notification are successfully removed.") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/removebucket.go b/vendor/github.com/minio/minio-go/examples/s3/removebucket.go new file mode 100644 index 000000000..7a7737ee0 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/removebucket.go @@ -0,0 +1,49 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // This operation will only work if your bucket is empty. + err = s3Client.RemoveBucket("my-bucketname") + if err != nil { + log.Fatalln(err) + } + log.Println("Success") + +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/removeincompleteupload.go b/vendor/github.com/minio/minio-go/examples/s3/removeincompleteupload.go new file mode 100644 index 000000000..31cc8790b --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/removeincompleteupload.go @@ -0,0 +1,47 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + err = s3Client.RemoveIncompleteUpload("my-bucketname", "my-objectname") + if err != nil { + log.Fatalln(err) + } + log.Println("Success") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/removeobject.go b/vendor/github.com/minio/minio-go/examples/s3/removeobject.go new file mode 100644 index 000000000..7e5848576 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/removeobject.go @@ -0,0 +1,46 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + err = s3Client.RemoveObject("my-bucketname", "my-objectname") + if err != nil { + log.Fatalln(err) + } + log.Println("Success") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/removeobjects.go b/vendor/github.com/minio/minio-go/examples/s3/removeobjects.go new file mode 100644 index 000000000..b912bc85d --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/removeobjects.go @@ -0,0 +1,65 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + objectsCh := make(chan string) + + // Send object names that are needed to be removed to objectsCh + go func() { + defer close(objectsCh) + // List all objects from a bucket-name with a matching prefix. + for object := range s3Client.ListObjects("my-bucketname", "my-prefixname", true, doneCh) { + if object.Err != nil { + log.Fatalln(object.Err) + } + objectsCh <- object.Key + } + }() + + // Call RemoveObjects API + errorCh := s3Client.RemoveObjects("my-bucketname", objectsCh) + + // Print errors received from RemoveObjects API + for e := range errorCh { + log.Fatalln("Failed to remove " + e.ObjectName + ", error: " + e.Err.Error()) + } + + log.Println("Success") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/setbucketnotification.go b/vendor/github.com/minio/minio-go/examples/s3/setbucketnotification.go new file mode 100644 index 000000000..b5af30f06 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/setbucketnotification.go @@ -0,0 +1,86 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // s3Client.TraceOn(os.Stderr) + + // ARN represents a notification channel that needs to be created in your S3 provider + // (e.g. http://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html) + + // An example of an ARN: + // arn:aws:sns:us-east-1:804064459714:UploadPhoto + // ^ ^ ^ ^ ^ + // Provider __| | | | | + // | Region Account ID |_ Notification Name + // Service _| + // + // You should replace YOUR-PROVIDER, YOUR-SERVICE, YOUR-REGION, YOUR-ACCOUNT-ID and YOUR-RESOURCE + // with actual values that you receive from the S3 provider + + // Here you create a new Topic notification + topicArn := minio.NewArn("YOUR-PROVIDER", "YOUR-SERVICE", "YOUR-REGION", "YOUR-ACCOUNT-ID", "YOUR-RESOURCE") + topicConfig := minio.NewNotificationConfig(topicArn) + topicConfig.AddEvents(minio.ObjectCreatedAll, minio.ObjectRemovedAll) + topicConfig.AddFilterPrefix("photos/") + topicConfig.AddFilterSuffix(".jpg") + + // Create a new Queue notification + queueArn := minio.NewArn("YOUR-PROVIDER", "YOUR-SERVICE", "YOUR-REGION", "YOUR-ACCOUNT-ID", "YOUR-RESOURCE") + queueConfig := minio.NewNotificationConfig(queueArn) + queueConfig.AddEvents(minio.ObjectRemovedAll) + + // Create a new Lambda (CloudFunction) + lambdaArn := minio.NewArn("YOUR-PROVIDER", "YOUR-SERVICE", "YOUR-REGION", "YOUR-ACCOUNT-ID", "YOUR-RESOURCE") + lambdaConfig := minio.NewNotificationConfig(lambdaArn) + lambdaConfig.AddEvents(minio.ObjectRemovedAll) + lambdaConfig.AddFilterSuffix(".swp") + + // Now, set all previously created notification configs + bucketNotification := minio.BucketNotification{} + bucketNotification.AddTopic(topicConfig) + bucketNotification.AddQueue(queueConfig) + bucketNotification.AddLambda(lambdaConfig) + + err = s3Client.SetBucketNotification("YOUR-BUCKET", bucketNotification) + if err != nil { + log.Fatalln("Error: " + err.Error()) + } + log.Println("Success") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/setbucketpolicy.go b/vendor/github.com/minio/minio-go/examples/s3/setbucketpolicy.go new file mode 100644 index 000000000..c81fb5050 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/setbucketpolicy.go @@ -0,0 +1,55 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" + "github.com/minio/minio-go/pkg/policy" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are + // dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + + // s3Client.TraceOn(os.Stderr) + + // Description of policy input. + // policy.BucketPolicyNone - Remove any previously applied bucket policy at a prefix. + // policy.BucketPolicyReadOnly - Set read-only operations at a prefix. + // policy.BucketPolicyWriteOnly - Set write-only operations at a prefix. + // policy.BucketPolicyReadWrite - Set read-write operations at a prefix. + err = s3Client.SetBucketPolicy("my-bucketname", "my-objectprefix", policy.BucketPolicyReadWrite) + if err != nil { + log.Fatalln(err) + } + log.Println("Success") +} diff --git a/vendor/github.com/minio/minio-go/examples/s3/statobject.go b/vendor/github.com/minio/minio-go/examples/s3/statobject.go new file mode 100644 index 000000000..0b27a83b3 --- /dev/null +++ b/vendor/github.com/minio/minio-go/examples/s3/statobject.go @@ -0,0 +1,46 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/minio/minio-go" +) + +func main() { + // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname + // are dummy values, please replace them with original values. + + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. + // This boolean value is the last argument for New(). + + // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically + // determined based on the Endpoint value. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) + if err != nil { + log.Fatalln(err) + } + stat, err := s3Client.StatObject("my-bucketname", "my-objectname", minio.StatObjectOptions{}) + if err != nil { + log.Fatalln(err) + } + log.Println(stat) +} diff --git a/vendor/github.com/minio/minio-go/functional_tests.go b/vendor/github.com/minio/minio-go/functional_tests.go new file mode 100644 index 000000000..93c463553 --- /dev/null +++ b/vendor/github.com/minio/minio-go/functional_tests.go @@ -0,0 +1,6939 @@ +// +build ignore + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "bytes" + "context" + "encoding/hex" + "encoding/json" + "errors" + "fmt" + "io" + "io/ioutil" + "math/rand" + "mime/multipart" + "net/http" + "net/url" + "os" + "path/filepath" + "reflect" + "runtime" + "strconv" + "strings" + "time" + + humanize "github.com/dustin/go-humanize" + minio "github.com/minio/minio-go" + log "github.com/sirupsen/logrus" + + "github.com/minio/minio-go/pkg/encrypt" + "github.com/minio/minio-go/pkg/policy" +) + +const letterBytes = "abcdefghijklmnopqrstuvwxyz01234569" +const ( + letterIdxBits = 6 // 6 bits to represent a letter index + letterIdxMask = 1<= 0; { + if remain == 0 { + cache, remain = src.Int63(), letterIdxMax + } + if idx := int(cache & letterIdxMask); idx < len(letterBytes) { + b[i] = letterBytes[idx] + i-- + } + cache >>= letterIdxBits + remain-- + } + return prefix + string(b[0:30-len(prefix)]) +} + +var dataFileMap = map[string]int{ + "datafile-1-b": 1, + "datafile-10-kB": 10 * humanize.KiByte, + "datafile-33-kB": 33 * humanize.KiByte, + "datafile-100-kB": 100 * humanize.KiByte, + "datafile-1.03-MB": 1056 * humanize.KiByte, + "datafile-1-MB": 1 * humanize.MiByte, + "datafile-5-MB": 5 * humanize.MiByte, + "datafile-6-MB": 6 * humanize.MiByte, + "datafile-11-MB": 11 * humanize.MiByte, + "datafile-65-MB": 65 * humanize.MiByte, +} + +func isQuickMode() bool { + return os.Getenv("MODE") == "quick" +} + +func getFuncName() string { + pc, _, _, _ := runtime.Caller(1) + return strings.TrimPrefix(runtime.FuncForPC(pc).Name(), "main.") +} + +// Tests bucket re-create errors. +func testMakeBucketError() { + region := "eu-central-1" + + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "MakeBucket(bucketName, region)" + // initialize logging params + args := map[string]interface{}{ + "bucketName": "", + "region": region, + } + + // skipping region functional tests for non s3 runs + if os.Getenv(serverEndpoint) != "s3.amazonaws.com" { + ignoredLog(testName, function, args, startTime, "Skipped region functional tests for non s3 runs").Info() + return + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket in 'eu-central-1'. + if err = c.MakeBucket(bucketName, region); err != nil { + logError(testName, function, args, startTime, "", "MakeBucket Failed", err) + return + } + if err = c.MakeBucket(bucketName, region); err == nil { + logError(testName, function, args, startTime, "", "Bucket already exists", err) + return + } + // Verify valid error response from server. + if minio.ToErrorResponse(err).Code != "BucketAlreadyExists" && + minio.ToErrorResponse(err).Code != "BucketAlreadyOwnedByYou" { + logError(testName, function, args, startTime, "", "Invalid error returned by server", err) + return + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + successLogger(testName, function, args, startTime).Info() +} + +func testMetadataSizeLimit() { + startTime := time.Now() + testName := getFuncName() + function := "PutObject(bucketName, objectName, reader, objectSize, opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "opts.UserMetadata": "", + } + rand.Seed(startTime.Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client creation failed", err) + return + } + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "Make bucket failed", err) + return + } + + const HeaderSizeLimit = 8 * 1024 + const UserMetadataLimit = 2 * 1024 + + // Meta-data greater than the 2 KB limit of AWS - PUT calls with this meta-data should fail + metadata := make(map[string]string) + metadata["X-Amz-Meta-Mint-Test"] = string(bytes.Repeat([]byte("m"), 1+UserMetadataLimit-len("X-Amz-Meta-Mint-Test"))) + args["metadata"] = fmt.Sprint(metadata) + + _, err = c.PutObject(bucketName, objectName, bytes.NewReader(nil), 0, minio.PutObjectOptions{UserMetadata: metadata}) + if err == nil { + logError(testName, function, args, startTime, "", "Created object with user-defined metadata exceeding metadata size limits", nil) + return + } + + // Meta-data (headers) greater than the 8 KB limit of AWS - PUT calls with this meta-data should fail + metadata = make(map[string]string) + metadata["X-Amz-Mint-Test"] = string(bytes.Repeat([]byte("m"), 1+HeaderSizeLimit-len("X-Amz-Mint-Test"))) + args["metadata"] = fmt.Sprint(metadata) + _, err = c.PutObject(bucketName, objectName, bytes.NewReader(nil), 0, minio.PutObjectOptions{UserMetadata: metadata}) + if err == nil { + logError(testName, function, args, startTime, "", "Created object with headers exceeding header size limits", nil) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests various bucket supported formats. +func testMakeBucketRegions() { + region := "eu-central-1" + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "MakeBucket(bucketName, region)" + // initialize logging params + args := map[string]interface{}{ + "bucketName": "", + "region": region, + } + + // skipping region functional tests for non s3 runs + if os.Getenv(serverEndpoint) != "s3.amazonaws.com" { + ignoredLog(testName, function, args, startTime, "Skipped region functional tests for non s3 runs").Info() + return + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket in 'eu-central-1'. + if err = c.MakeBucket(bucketName, region); err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + // Make a new bucket with '.' in its name, in 'us-west-2'. This + // request is internally staged into a path style instead of + // virtual host style. + region = "us-west-2" + args["region"] = region + if err = c.MakeBucket(bucketName+".withperiod", region); err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName+".withperiod", c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + successLogger(testName, function, args, startTime).Info() +} + +// Test PutObject using a large data to trigger multipart readat +func testPutObjectReadAt() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PutObject(bucketName, objectName, reader, opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "opts": "objectContentType", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "Make bucket failed", err) + return + } + + bufSize := dataFileMap["datafile-65-MB"] + var reader = getDataReader("datafile-65-MB") + defer reader.Close() + + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + // Object content type + objectContentType := "binary/octet-stream" + args["objectContentType"] = objectContentType + + n, err := c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: objectContentType}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes returned by PutObject does not match, expected "+string(bufSize)+" got "+string(n), err) + return + } + + // Read the data back + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "Get Object failed", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat Object failed", err) + return + } + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", fmt.Sprintf("Number of bytes in stat does not match, expected %d got %d", bufSize, st.Size), err) + return + } + if st.ContentType != objectContentType { + logError(testName, function, args, startTime, "", "Content types don't match", err) + return + } + if err := r.Close(); err != nil { + logError(testName, function, args, startTime, "", "Object Close failed", err) + return + } + if err := r.Close(); err == nil { + logError(testName, function, args, startTime, "", "Object is already closed, didn't return error on Close", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test PutObject using a large data to trigger multipart readat +func testPutObjectWithMetadata() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PutObject(bucketName, objectName, reader,size, opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "opts": "minio.PutObjectOptions{UserMetadata: metadata, Progress: progress}", + } + + if isQuickMode() { + ignoredLog(testName, function, args, startTime, "Skipping functional tests for short runs").Info() + return + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "Make bucket failed", err) + return + } + + bufSize := dataFileMap["datafile-65-MB"] + var reader = getDataReader("datafile-65-MB") + defer reader.Close() + + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + // Object custom metadata + customContentType := "custom/contenttype" + + args["metadata"] = map[string][]string{ + "Content-Type": {customContentType}, + } + + n, err := c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ + ContentType: customContentType}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes returned by PutObject does not match, expected "+string(bufSize)+" got "+string(n), err) + return + } + + // Read the data back + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes returned by PutObject does not match GetObject, expected "+string(bufSize)+" got "+string(st.Size), err) + return + } + if st.ContentType != customContentType { + logError(testName, function, args, startTime, "", "ContentType does not match, expected "+customContentType+" got "+st.ContentType, err) + return + } + if err := r.Close(); err != nil { + logError(testName, function, args, startTime, "", "Object Close failed", err) + return + } + if err := r.Close(); err == nil { + logError(testName, function, args, startTime, "", "Object already closed, should respond with error", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test put object with streaming signature. +func testPutObjectStreaming() { + // initialize logging params + objectName := "test-object" + startTime := time.Now() + testName := getFuncName() + function := "PutObject(bucketName, objectName, reader,size,opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": objectName, + "size": -1, + "opts": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Upload an object. + sizes := []int64{0, 64*1024 - 1, 64 * 1024} + + for _, size := range sizes { + data := bytes.Repeat([]byte("a"), int(size)) + n, err := c.PutObject(bucketName, objectName, bytes.NewReader(data), int64(size), minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObjectStreaming failed", err) + return + } + + if n != size { + logError(testName, function, args, startTime, "", "Expected upload object size doesn't match with PutObjectStreaming return value", err) + return + } + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test listing partially uploaded objects. +func testListPartiallyUploaded() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "ListIncompleteUploads(bucketName, objectName, isRecursive, doneCh)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "isRecursive": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Enable tracing, write to stdout. + // c.TraceOn(os.Stderr) + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + bufSize := dataFileMap["datafile-65-MB"] + r := bytes.NewReader(bytes.Repeat([]byte("0"), bufSize*2)) + + reader, writer := io.Pipe() + go func() { + i := 0 + for i < 25 { + _, cerr := io.CopyN(writer, r, (int64(bufSize)*2)/25) + if cerr != nil { + logError(testName, function, args, startTime, "", "Copy failed", err) + return + } + i++ + r.Seek(0, 0) + } + writer.CloseWithError(errors.New("proactively closed to be verified later")) + }() + + objectName := bucketName + "-resumable" + args["objectName"] = objectName + + _, err = c.PutObject(bucketName, objectName, reader, int64(bufSize*2), minio.PutObjectOptions{ContentType: "application/octet-stream"}) + if err == nil { + logError(testName, function, args, startTime, "", "PutObject should fail", err) + return + } + if !strings.Contains(err.Error(), "proactively closed to be verified later") { + logError(testName, function, args, startTime, "", "String not found in PutObject output", err) + return + } + + doneCh := make(chan struct{}) + defer close(doneCh) + isRecursive := true + args["isRecursive"] = isRecursive + + multiPartObjectCh := c.ListIncompleteUploads(bucketName, objectName, isRecursive, doneCh) + for multiPartObject := range multiPartObjectCh { + if multiPartObject.Err != nil { + logError(testName, function, args, startTime, "", "Multipart object error", multiPartObject.Err) + return + } + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test get object seeker from the end, using whence set to '2'. +func testGetObjectSeekEnd() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "GetObject(bucketName, objectName)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + buf, err := ioutil.ReadAll(reader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + + n, err := c.PutObject(bucketName, objectName, bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes read does not match, expected "+string(int64(bufSize))+" got "+string(n), err) + return + } + + // Read the data back + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes read does not match, expected "+string(int64(bufSize))+" got "+string(st.Size), err) + return + } + + pos, err := r.Seek(-100, 2) + if err != nil { + logError(testName, function, args, startTime, "", "Object Seek failed", err) + return + } + if pos != st.Size-100 { + logError(testName, function, args, startTime, "", "Incorrect position", err) + return + } + buf2 := make([]byte, 100) + m, err := io.ReadFull(r, buf2) + if err != nil { + logError(testName, function, args, startTime, "", "Error reading through io.ReadFull", err) + return + } + if m != len(buf2) { + logError(testName, function, args, startTime, "", "Number of bytes dont match, expected "+string(len(buf2))+" got "+string(m), err) + return + } + hexBuf1 := fmt.Sprintf("%02x", buf[len(buf)-100:]) + hexBuf2 := fmt.Sprintf("%02x", buf2[:m]) + if hexBuf1 != hexBuf2 { + logError(testName, function, args, startTime, "", "Values at same index dont match", err) + return + } + pos, err = r.Seek(-100, 2) + if err != nil { + logError(testName, function, args, startTime, "", "Object Seek failed", err) + return + } + if pos != st.Size-100 { + logError(testName, function, args, startTime, "", "Incorrect position", err) + return + } + if err = r.Close(); err != nil { + logError(testName, function, args, startTime, "", "ObjectClose failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test get object reader to not throw error on being closed twice. +func testGetObjectClosedTwice() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "GetObject(bucketName, objectName)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + n, err := c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "PutObject response doesn't match sent bytes, expected "+string(int64(bufSize))+" got "+string(n), err) + return + } + + // Read the data back + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes in stat does not match, expected "+string(int64(bufSize))+" got "+string(st.Size), err) + return + } + if err := r.Close(); err != nil { + logError(testName, function, args, startTime, "", "Object Close failed", err) + return + } + if err := r.Close(); err == nil { + logError(testName, function, args, startTime, "", "Already closed object. No error returned", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test removing multiple objects with Remove API +func testRemoveMultipleObjects() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "RemoveObjects(bucketName, objectsCh)" + args := map[string]interface{}{ + "bucketName": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Enable tracing, write to stdout. + // c.TraceOn(os.Stderr) + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + r := bytes.NewReader(bytes.Repeat([]byte("a"), 8)) + + // Multi remove of 1100 objects + nrObjects := 200 + + objectsCh := make(chan string) + + go func() { + defer close(objectsCh) + // Upload objects and send them to objectsCh + for i := 0; i < nrObjects; i++ { + objectName := "sample" + strconv.Itoa(i) + ".txt" + _, err = c.PutObject(bucketName, objectName, r, 8, minio.PutObjectOptions{ContentType: "application/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + continue + } + objectsCh <- objectName + } + }() + + // Call RemoveObjects API + errorCh := c.RemoveObjects(bucketName, objectsCh) + + // Check if errorCh doesn't receive any error + select { + case r, more := <-errorCh: + if more { + logError(testName, function, args, startTime, "", "Unexpected error", r.Err) + return + } + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests removing partially uploaded objects. +func testRemovePartiallyUploaded() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "RemoveIncompleteUpload(bucketName, objectName)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Enable tracing, write to stdout. + // c.TraceOn(os.Stderr) + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + r := bytes.NewReader(bytes.Repeat([]byte("a"), 128*1024)) + + reader, writer := io.Pipe() + go func() { + i := 0 + for i < 25 { + _, cerr := io.CopyN(writer, r, 128*1024) + if cerr != nil { + logError(testName, function, args, startTime, "", "Copy failed", err) + return + } + i++ + r.Seek(0, 0) + } + writer.CloseWithError(errors.New("proactively closed to be verified later")) + }() + + objectName := bucketName + "-resumable" + args["objectName"] = objectName + + _, err = c.PutObject(bucketName, objectName, reader, 128*1024, minio.PutObjectOptions{ContentType: "application/octet-stream"}) + if err == nil { + logError(testName, function, args, startTime, "", "PutObject should fail", err) + return + } + if !strings.Contains(err.Error(), "proactively closed to be verified later") { + logError(testName, function, args, startTime, "", "String not found", err) + return + } + err = c.RemoveIncompleteUpload(bucketName, objectName) + if err != nil { + logError(testName, function, args, startTime, "", "RemoveIncompleteUpload failed", err) + return + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests FPutObject of a big file to trigger multipart +func testFPutObjectMultipart() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "FPutObject(bucketName, objectName, fileName, opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "fileName": "", + "opts": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Upload 4 parts to utilize all 3 'workers' in multipart and still have a part to upload. + var fileName = getMintDataDirFilePath("datafile-65-MB") + if fileName == "" { + // Make a temp file with minPartSize bytes of data. + file, err := ioutil.TempFile(os.TempDir(), "FPutObjectTest") + if err != nil { + logError(testName, function, args, startTime, "", "TempFile creation failed", err) + return + } + // Upload 2 parts to utilize all 3 'workers' in multipart and still have a part to upload. + if _, err = io.Copy(file, getDataReader("datafile-65-MB")); err != nil { + logError(testName, function, args, startTime, "", "Copy failed", err) + return + } + if err = file.Close(); err != nil { + logError(testName, function, args, startTime, "", "File Close failed", err) + return + } + fileName = file.Name() + args["fileName"] = fileName + } + totalSize := dataFileMap["datafile-65-MB"] + // Set base object name + objectName := bucketName + "FPutObject" + "-standard" + args["objectName"] = objectName + + objectContentType := "testapplication/octet-stream" + args["objectContentType"] = objectContentType + + // Perform standard FPutObject with contentType provided (Expecting application/octet-stream) + n, err := c.FPutObject(bucketName, objectName, fileName, minio.PutObjectOptions{ContentType: objectContentType}) + if err != nil { + logError(testName, function, args, startTime, "", "FPutObject failed", err) + return + } + if n != int64(totalSize) { + logError(testName, function, args, startTime, "", "FPutObject failed", err) + return + } + + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + objInfo, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Unexpected error", err) + return + } + if objInfo.Size != int64(totalSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(totalSize))+" got "+string(objInfo.Size), err) + return + } + if objInfo.ContentType != objectContentType { + logError(testName, function, args, startTime, "", "ContentType doesn't match", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests FPutObject with null contentType (default = application/octet-stream) +func testFPutObject() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "FPutObject(bucketName, objectName, fileName, opts)" + + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "fileName": "", + "opts": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + location := "us-east-1" + + // Make a new bucket. + args["bucketName"] = bucketName + args["location"] = location + function = "MakeBucket()bucketName, location" + err = c.MakeBucket(bucketName, location) + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Upload 3 parts worth of data to use all 3 of multiparts 'workers' and have an extra part. + // Use different data in part for multipart tests to check parts are uploaded in correct order. + var fName = getMintDataDirFilePath("datafile-65-MB") + if fName == "" { + // Make a temp file with minPartSize bytes of data. + file, err := ioutil.TempFile(os.TempDir(), "FPutObjectTest") + if err != nil { + logError(testName, function, args, startTime, "", "TempFile creation failed", err) + return + } + + // Upload 3 parts to utilize all 3 'workers' in multipart and still have a part to upload. + if _, err = io.Copy(file, getDataReader("datafile-65-MB")); err != nil { + logError(testName, function, args, startTime, "", "File copy failed", err) + return + } + // Close the file pro-actively for windows. + if err = file.Close(); err != nil { + logError(testName, function, args, startTime, "", "File close failed", err) + return + } + defer os.Remove(file.Name()) + fName = file.Name() + } + totalSize := dataFileMap["datafile-65-MB"] + + // Set base object name + function = "FPutObject(bucketName, objectName, fileName, opts)" + objectName := bucketName + "FPutObject" + args["objectName"] = objectName + "-standard" + args["fileName"] = fName + args["opts"] = minio.PutObjectOptions{ContentType: "application/octet-stream"} + + // Perform standard FPutObject with contentType provided (Expecting application/octet-stream) + n, err := c.FPutObject(bucketName, objectName+"-standard", fName, minio.PutObjectOptions{ContentType: "application/octet-stream"}) + + if err != nil { + logError(testName, function, args, startTime, "", "FPutObject failed", err) + return + } + if n != int64(totalSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(totalSize)+", got "+string(n), err) + return + } + + // Perform FPutObject with no contentType provided (Expecting application/octet-stream) + args["objectName"] = objectName + "-Octet" + n, err = c.FPutObject(bucketName, objectName+"-Octet", fName, minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "File close failed", err) + return + } + if n != int64(totalSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(totalSize)+", got "+string(n), err) + return + } + srcFile, err := os.Open(fName) + if err != nil { + logError(testName, function, args, startTime, "", "File open failed", err) + return + } + defer srcFile.Close() + // Add extension to temp file name + tmpFile, err := os.Create(fName + ".gtar") + if err != nil { + logError(testName, function, args, startTime, "", "File create failed", err) + return + } + defer tmpFile.Close() + _, err = io.Copy(tmpFile, srcFile) + if err != nil { + logError(testName, function, args, startTime, "", "File copy failed", err) + return + } + + // Perform FPutObject with no contentType provided (Expecting application/x-gtar) + args["objectName"] = objectName + "-GTar" + n, err = c.FPutObject(bucketName, objectName+"-GTar", fName+".gtar", minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "FPutObject failed", err) + return + } + if n != int64(totalSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(totalSize)+", got "+string(n), err) + return + } + + // Check headers + function = "StatObject(bucketName, objectName, opts)" + args["objectName"] = objectName + "-standard" + rStandard, err := c.StatObject(bucketName, objectName+"-standard", minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "StatObject failed", err) + return + } + if rStandard.ContentType != "application/octet-stream" { + logError(testName, function, args, startTime, "", "ContentType does not match, expected application/octet-stream, got "+rStandard.ContentType, err) + return + } + + function = "StatObject(bucketName, objectName, opts)" + args["objectName"] = objectName + "-Octet" + rOctet, err := c.StatObject(bucketName, objectName+"-Octet", minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "StatObject failed", err) + return + } + if rOctet.ContentType != "application/octet-stream" { + logError(testName, function, args, startTime, "", "ContentType does not match, expected application/octet-stream, got "+rStandard.ContentType, err) + return + } + + function = "StatObject(bucketName, objectName, opts)" + args["objectName"] = objectName + "-GTar" + rGTar, err := c.StatObject(bucketName, objectName+"-GTar", minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "StatObject failed", err) + return + } + if rGTar.ContentType != "application/x-gtar" { + logError(testName, function, args, startTime, "", "ContentType does not match, expected application/x-gtar, got "+rStandard.ContentType, err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + if err = os.Remove(fName + ".gtar"); err != nil { + logError(testName, function, args, startTime, "", "File remove failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests FPutObjectWithContext request context cancels after timeout +func testFPutObjectWithContext() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "FPutObject(bucketName, objectName, fileName, opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "fileName": "", + "opts": "", + } + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Upload 1 parts worth of data to use multipart upload. + // Use different data in part for multipart tests to check parts are uploaded in correct order. + var fName = getMintDataDirFilePath("datafile-1-MB") + if fName == "" { + // Make a temp file with 1 MiB bytes of data. + file, err := ioutil.TempFile(os.TempDir(), "FPutObjectWithContextTest") + if err != nil { + logError(testName, function, args, startTime, "", "TempFile creation failed", err) + return + } + + // Upload 1 parts to trigger multipart upload + if _, err = io.Copy(file, getDataReader("datafile-1-MB")); err != nil { + logError(testName, function, args, startTime, "", "File copy failed", err) + return + } + // Close the file pro-actively for windows. + if err = file.Close(); err != nil { + logError(testName, function, args, startTime, "", "File close failed", err) + return + } + defer os.Remove(file.Name()) + fName = file.Name() + } + totalSize := dataFileMap["datafile-1-MB"] + + // Set base object name + objectName := bucketName + "FPutObjectWithContext" + args["objectName"] = objectName + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) + args["ctx"] = ctx + defer cancel() + + // Perform standard FPutObjectWithContext with contentType provided (Expecting application/octet-stream) + _, err = c.FPutObjectWithContext(ctx, bucketName, objectName+"-Shorttimeout", fName, minio.PutObjectOptions{ContentType: "application/octet-stream"}) + if err == nil { + logError(testName, function, args, startTime, "", "FPutObjectWithContext should fail on short timeout", err) + return + } + ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) + defer cancel() + // Perform FPutObjectWithContext with a long timeout. Expect the put object to succeed + n, err := c.FPutObjectWithContext(ctx, bucketName, objectName+"-Longtimeout", fName, minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "FPutObjectWithContext shouldn't fail on long timeout", err) + return + } + if n != int64(totalSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(totalSize)+", got "+string(n), err) + return + } + + _, err = c.StatObject(bucketName, objectName+"-Longtimeout", minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "StatObject failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() + +} + +// Tests FPutObjectWithContext request context cancels after timeout +func testFPutObjectWithContextV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "FPutObjectWithContext(ctx, bucketName, objectName, fileName, opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "opts": "minio.PutObjectOptions{ContentType:objectContentType}", + } + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Upload 1 parts worth of data to use multipart upload. + // Use different data in part for multipart tests to check parts are uploaded in correct order. + var fName = getMintDataDirFilePath("datafile-1-MB") + if fName == "" { + // Make a temp file with 1 MiB bytes of data. + file, err := ioutil.TempFile(os.TempDir(), "FPutObjectWithContextTest") + if err != nil { + logError(testName, function, args, startTime, "", "Temp file creation failed", err) + return + } + + // Upload 1 parts to trigger multipart upload + if _, err = io.Copy(file, getDataReader("datafile-1-MB")); err != nil { + logError(testName, function, args, startTime, "", "File copy failed", err) + return + } + + // Close the file pro-actively for windows. + if err = file.Close(); err != nil { + logError(testName, function, args, startTime, "", "File close failed", err) + return + } + defer os.Remove(file.Name()) + fName = file.Name() + } + totalSize := dataFileMap["datafile-1-MB"] + + // Set base object name + objectName := bucketName + "FPutObjectWithContext" + args["objectName"] = objectName + + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) + args["ctx"] = ctx + defer cancel() + + // Perform standard FPutObjectWithContext with contentType provided (Expecting application/octet-stream) + _, err = c.FPutObjectWithContext(ctx, bucketName, objectName+"-Shorttimeout", fName, minio.PutObjectOptions{ContentType: "application/octet-stream"}) + if err == nil { + logError(testName, function, args, startTime, "", "FPutObjectWithContext should fail on short timeout", err) + return + } + ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) + defer cancel() + // Perform FPutObjectWithContext with a long timeout. Expect the put object to succeed + n, err := c.FPutObjectWithContext(ctx, bucketName, objectName+"-Longtimeout", fName, minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "FPutObjectWithContext shouldn't fail on longer timeout", err) + return + } + if n != int64(totalSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match:wanted"+string(totalSize)+" got "+string(n), err) + return + } + + _, err = c.StatObject(bucketName, objectName+"-Longtimeout", minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "StatObject failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() + +} + +// Test validates putObject with context to see if request cancellation is honored. +func testPutObjectWithContext() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PutObjectWithContext(ctx, bucketName, objectName, fileName, opts)" + args := map[string]interface{}{ + "ctx": "", + "bucketName": "", + "objectName": "", + "opts": "", + } + // Instantiate new minio client object. + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Make a new bucket. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket call failed", err) + return + } + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + objectName := fmt.Sprintf("test-file-%v", rand.Uint32()) + args["objectName"] = objectName + + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) + args["ctx"] = ctx + args["opts"] = minio.PutObjectOptions{ContentType: "binary/octet-stream"} + defer cancel() + + _, err = c.PutObjectWithContext(ctx, bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err == nil { + logError(testName, function, args, startTime, "", "PutObjectWithContext should fail on short timeout", err) + return + } + + ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) + args["ctx"] = ctx + + defer cancel() + reader = getDataReader("datafile-33-kB") + defer reader.Close() + _, err = c.PutObjectWithContext(ctx, bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObjectWithContext with long timeout failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() + +} + +// Tests get object ReaderSeeker interface methods. +func testGetObjectReadSeekFunctional() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "GetObject(bucketName, objectName)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + buf, err := ioutil.ReadAll(reader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + + // Save the data + n, err := c.PutObject(bucketName, objectName, bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(bufSize))+", got "+string(n), err) + return + } + + defer func() { + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + }() + + // Read the data back + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat object failed", err) + return + } + + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(bufSize))+", got "+string(st.Size), err) + return + } + + // This following function helps us to compare data from the reader after seek + // with the data from the original buffer + cmpData := func(r io.Reader, start, end int) { + if end-start == 0 { + return + } + buffer := bytes.NewBuffer([]byte{}) + if _, err := io.CopyN(buffer, r, int64(bufSize)); err != nil { + if err != io.EOF { + logError(testName, function, args, startTime, "", "CopyN failed", err) + return + } + } + if !bytes.Equal(buf[start:end], buffer.Bytes()) { + logError(testName, function, args, startTime, "", "Incorrect read bytes v/s original buffer", err) + return + } + } + + // Generic seek error for errors other than io.EOF + seekErr := errors.New("seek error") + + testCases := []struct { + offset int64 + whence int + pos int64 + err error + shouldCmp bool + start int + end int + }{ + // Start from offset 0, fetch data and compare + {0, 0, 0, nil, true, 0, 0}, + // Start from offset 2048, fetch data and compare + {2048, 0, 2048, nil, true, 2048, bufSize}, + // Start from offset larger than possible + {int64(bufSize) + 1024, 0, 0, seekErr, false, 0, 0}, + // Move to offset 0 without comparing + {0, 0, 0, nil, false, 0, 0}, + // Move one step forward and compare + {1, 1, 1, nil, true, 1, bufSize}, + // Move larger than possible + {int64(bufSize), 1, 0, seekErr, false, 0, 0}, + // Provide negative offset with CUR_SEEK + {int64(-1), 1, 0, seekErr, false, 0, 0}, + // Test with whence SEEK_END and with positive offset + {1024, 2, int64(bufSize) - 1024, io.EOF, true, 0, 0}, + // Test with whence SEEK_END and with negative offset + {-1024, 2, int64(bufSize) - 1024, nil, true, bufSize - 1024, bufSize}, + // Test with whence SEEK_END and with large negative offset + {-int64(bufSize) * 2, 2, 0, seekErr, true, 0, 0}, + } + + for i, testCase := range testCases { + // Perform seek operation + n, err := r.Seek(testCase.offset, testCase.whence) + // We expect an error + if testCase.err == seekErr && err == nil { + logError(testName, function, args, startTime, "", "Test "+string(i+1)+", unexpected err value: expected: "+testCase.err.Error()+", found: "+err.Error(), err) + return + } + // We expect a specific error + if testCase.err != seekErr && testCase.err != err { + logError(testName, function, args, startTime, "", "Test "+string(i+1)+", unexpected err value: expected: "+testCase.err.Error()+", found: "+err.Error(), err) + return + } + // If we expect an error go to the next loop + if testCase.err != nil { + continue + } + // Check the returned seek pos + if n != testCase.pos { + logError(testName, function, args, startTime, "", "Test "+string(i+1)+", number of bytes seeked does not match, expected "+string(testCase.pos)+", got "+string(n), err) + return + } + // Compare only if shouldCmp is activated + if testCase.shouldCmp { + cmpData(r, testCase.start, testCase.end) + } + } + successLogger(testName, function, args, startTime).Info() +} + +// Tests get object ReaderAt interface methods. +func testGetObjectReadAtFunctional() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "GetObject(bucketName, objectName)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + buf, err := ioutil.ReadAll(reader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + + // Save the data + n, err := c.PutObject(bucketName, objectName, bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(bufSize))+", got "+string(n), err) + return + } + + // read the data back + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + offset := int64(2048) + + // read directly + buf1 := make([]byte, 512) + buf2 := make([]byte, 512) + buf3 := make([]byte, 512) + buf4 := make([]byte, 512) + + // Test readAt before stat is called. + m, err := r.ReadAt(buf1, offset) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + if m != len(buf1) { + logError(testName, function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, expected "+string(len(buf1))+", got "+string(m), err) + return + } + if !bytes.Equal(buf1, buf[offset:offset+512]) { + logError(testName, function, args, startTime, "", "Incorrect read between two ReadAt from same offset", err) + return + } + offset += 512 + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes in stat does not match, expected "+string(int64(bufSize))+", got "+string(st.Size), err) + return + } + + m, err = r.ReadAt(buf2, offset) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + if m != len(buf2) { + logError(testName, function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, expected "+string(len(buf2))+", got "+string(m), err) + return + } + if !bytes.Equal(buf2, buf[offset:offset+512]) { + logError(testName, function, args, startTime, "", "Incorrect read between two ReadAt from same offset", err) + return + } + offset += 512 + m, err = r.ReadAt(buf3, offset) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + if m != len(buf3) { + logError(testName, function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, expected "+string(len(buf3))+", got "+string(m), err) + return + } + if !bytes.Equal(buf3, buf[offset:offset+512]) { + logError(testName, function, args, startTime, "", "Incorrect read between two ReadAt from same offset", err) + return + } + offset += 512 + m, err = r.ReadAt(buf4, offset) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + if m != len(buf4) { + logError(testName, function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, expected "+string(len(buf4))+", got "+string(m), err) + return + } + if !bytes.Equal(buf4, buf[offset:offset+512]) { + logError(testName, function, args, startTime, "", "Incorrect read between two ReadAt from same offset", err) + return + } + + buf5 := make([]byte, n) + // Read the whole object. + m, err = r.ReadAt(buf5, 0) + if err != nil { + if err != io.EOF { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + } + if m != len(buf5) { + logError(testName, function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, expected "+string(len(buf5))+", got "+string(m), err) + return + } + if !bytes.Equal(buf, buf5) { + logError(testName, function, args, startTime, "", "Incorrect data read in GetObject, than what was previously uploaded", err) + return + } + + buf6 := make([]byte, n+1) + // Read the whole object and beyond. + _, err = r.ReadAt(buf6, 0) + if err != nil { + if err != io.EOF { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + successLogger(testName, function, args, startTime).Info() +} + +// Test Presigned Post Policy +func testPresignedPostPolicy() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PresignedPostPolicy(policy)" + args := map[string]interface{}{ + "policy": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + + // Make a new bucket in 'us-east-1' (source bucket). + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + metadataKey := randString(60, rand.NewSource(time.Now().UnixNano()), "") + metadataValue := randString(60, rand.NewSource(time.Now().UnixNano()), "") + + buf, err := ioutil.ReadAll(reader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + + // Save the data + n, err := c.PutObject(bucketName, objectName, bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(bufSize))+" got "+string(n), err) + return + } + + policy := minio.NewPostPolicy() + + if err := policy.SetBucket(""); err == nil { + logError(testName, function, args, startTime, "", "SetBucket did not fail for invalid conditions", err) + return + } + if err := policy.SetKey(""); err == nil { + logError(testName, function, args, startTime, "", "SetKey did not fail for invalid conditions", err) + return + } + if err := policy.SetKeyStartsWith(""); err == nil { + logError(testName, function, args, startTime, "", "SetKeyStartsWith did not fail for invalid conditions", err) + return + } + if err := policy.SetExpires(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)); err == nil { + logError(testName, function, args, startTime, "", "SetExpires did not fail for invalid conditions", err) + return + } + if err := policy.SetContentType(""); err == nil { + logError(testName, function, args, startTime, "", "SetContentType did not fail for invalid conditions", err) + return + } + if err := policy.SetContentLengthRange(1024*1024, 1024); err == nil { + logError(testName, function, args, startTime, "", "SetContentLengthRange did not fail for invalid conditions", err) + return + } + if err := policy.SetUserMetadata("", ""); err == nil { + logError(testName, function, args, startTime, "", "SetUserMetadata did not fail for invalid conditions", err) + return + } + + policy.SetBucket(bucketName) + policy.SetKey(objectName) + policy.SetExpires(time.Now().UTC().AddDate(0, 0, 10)) // expires in 10 days + policy.SetContentType("binary/octet-stream") + policy.SetContentLengthRange(10, 1024*1024) + policy.SetUserMetadata(metadataKey, metadataValue) + args["policy"] = policy.String() + + presignedPostPolicyURL, formData, err := c.PresignedPostPolicy(policy) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedPostPolicy failed", err) + return + } + + var formBuf bytes.Buffer + writer := multipart.NewWriter(&formBuf) + for k, v := range formData { + writer.WriteField(k, v) + } + + // Get a 33KB file to upload and test if set post policy works + var filePath = getMintDataDirFilePath("datafile-33-kB") + if filePath == "" { + // Make a temp file with 33 KB data. + file, err := ioutil.TempFile(os.TempDir(), "PresignedPostPolicyTest") + if err != nil { + logError(testName, function, args, startTime, "", "TempFile creation failed", err) + return + } + if _, err = io.Copy(file, getDataReader("datafile-33-kB")); err != nil { + logError(testName, function, args, startTime, "", "Copy failed", err) + return + } + if err = file.Close(); err != nil { + logError(testName, function, args, startTime, "", "File Close failed", err) + return + } + filePath = file.Name() + } + + // add file to post request + f, err := os.Open(filePath) + defer f.Close() + if err != nil { + logError(testName, function, args, startTime, "", "File open failed", err) + return + } + w, err := writer.CreateFormFile("file", filePath) + if err != nil { + logError(testName, function, args, startTime, "", "CreateFormFile failed", err) + return + } + + _, err = io.Copy(w, f) + if err != nil { + logError(testName, function, args, startTime, "", "Copy failed", err) + return + } + writer.Close() + + // make post request with correct form data + res, err := http.Post(presignedPostPolicyURL.String(), writer.FormDataContentType(), bytes.NewReader(formBuf.Bytes())) + if err != nil { + logError(testName, function, args, startTime, "", "Http request failed", err) + return + } + defer res.Body.Close() + if res.StatusCode != http.StatusNoContent { + logError(testName, function, args, startTime, "", "Http request failed", errors.New(res.Status)) + return + } + + // expected path should be absolute path of the object + var scheme string + if mustParseBool(os.Getenv(enableHTTPS)) { + scheme = "https://" + } else { + scheme = "http://" + } + + expectedLocation := scheme + os.Getenv(serverEndpoint) + "/" + bucketName + "/" + objectName + + if val, ok := res.Header["Location"]; ok { + if val[0] != expectedLocation { + logError(testName, function, args, startTime, "", "Location in header response is incorrect", err) + return + } + } else { + logError(testName, function, args, startTime, "", "Location not found in header response", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests copy object +func testCopyObject() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "CopyObject(dst, src)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + + // Make a new bucket in 'us-east-1' (source bucket). + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Make a new bucket in 'us-east-1' (destination bucket). + err = c.MakeBucket(bucketName+"-copy", "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + n, err := c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(bufSize))+", got "+string(n), err) + return + } + + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + // Check the various fields of source object against destination object. + objInfo, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + + // Copy Source + src := minio.NewSourceInfo(bucketName, objectName, nil) + args["src"] = src + + // Set copy conditions. + + // All invalid conditions first. + err = src.SetModifiedSinceCond(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)) + if err == nil { + logError(testName, function, args, startTime, "", "SetModifiedSinceCond did not fail for invalid conditions", err) + return + } + err = src.SetUnmodifiedSinceCond(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)) + if err == nil { + logError(testName, function, args, startTime, "", "SetUnmodifiedSinceCond did not fail for invalid conditions", err) + return + } + err = src.SetMatchETagCond("") + if err == nil { + logError(testName, function, args, startTime, "", "SetMatchETagCond did not fail for invalid conditions", err) + return + } + err = src.SetMatchETagExceptCond("") + if err == nil { + logError(testName, function, args, startTime, "", "SetMatchETagExceptCond did not fail for invalid conditions", err) + return + } + + err = src.SetModifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC)) + if err != nil { + logError(testName, function, args, startTime, "", "SetModifiedSinceCond failed", err) + return + } + err = src.SetMatchETagCond(objInfo.ETag) + if err != nil { + logError(testName, function, args, startTime, "", "SetMatchETagCond failed", err) + return + } + + dst, err := minio.NewDestinationInfo(bucketName+"-copy", objectName+"-copy", nil, nil) + args["dst"] = dst + if err != nil { + logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err) + return + } + + // Perform the Copy + err = c.CopyObject(dst, src) + if err != nil { + logError(testName, function, args, startTime, "", "CopyObject failed", err) + return + } + + // Source object + r, err = c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + // Destination object + readerCopy, err := c.GetObject(bucketName+"-copy", objectName+"-copy", minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + // Check the various fields of source object against destination object. + objInfo, err = r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + objInfoCopy, err := readerCopy.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + if objInfo.Size != objInfoCopy.Size { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(objInfoCopy.Size)+", got "+string(objInfo.Size), err) + return + } + + // CopyObject again but with wrong conditions + src = minio.NewSourceInfo(bucketName, objectName, nil) + err = src.SetUnmodifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC)) + if err != nil { + logError(testName, function, args, startTime, "", "SetUnmodifiedSinceCond failed", err) + return + } + err = src.SetMatchETagExceptCond(objInfo.ETag) + if err != nil { + logError(testName, function, args, startTime, "", "SetMatchETagExceptCond failed", err) + return + } + + // Perform the Copy which should fail + err = c.CopyObject(dst, src) + if err == nil { + logError(testName, function, args, startTime, "", "CopyObject did not fail for invalid conditions", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + if err = cleanupBucket(bucketName+"-copy", c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + successLogger(testName, function, args, startTime).Info() +} + +// TestEncryptionPutGet tests client side encryption +func testEncryptionPutGet() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PutEncryptedObject(bucketName, objectName, reader, cbcMaterials, metadata, progress)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "cbcMaterials": "", + "metadata": "", + } + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate a symmetric key + symKey := encrypt.NewSymmetricKey([]byte("my-secret-key-00")) + + // Generate an assymmetric key from predefine public and private certificates + privateKey, err := hex.DecodeString( + "30820277020100300d06092a864886f70d0101010500048202613082025d" + + "0201000281810087b42ea73243a3576dc4c0b6fa245d339582dfdbddc20c" + + "bb8ab666385034d997210c54ba79275c51162a1221c3fb1a4c7c61131ca6" + + "5563b319d83474ef5e803fbfa7e52b889e1893b02586b724250de7ac6351" + + "cc0b7c638c980acec0a07020a78eed7eaa471eca4b92071394e061346c06" + + "15ccce2f465dee2080a89e43f29b5702030100010281801dd5770c3af8b3" + + "c85cd18cacad81a11bde1acfac3eac92b00866e142301fee565365aa9af4" + + "57baebf8bb7711054d071319a51dd6869aef3848ce477a0dc5f0dbc0c336" + + "5814b24c820491ae2bb3c707229a654427e03307fec683e6b27856688f08" + + "bdaa88054c5eeeb773793ff7543ee0fb0e2ad716856f2777f809ef7e6fa4" + + "41024100ca6b1edf89e8a8f93cce4b98c76c6990a09eb0d32ad9d3d04fbf" + + "0b026fa935c44f0a1c05dd96df192143b7bda8b110ec8ace28927181fd8c" + + "d2f17330b9b63535024100aba0260afb41489451baaeba423bee39bcbd1e" + + "f63dd44ee2d466d2453e683bf46d019a8baead3a2c7fca987988eb4d565e" + + "27d6be34605953f5034e4faeec9bdb0241009db2cb00b8be8c36710aff96" + + "6d77a6dec86419baca9d9e09a2b761ea69f7d82db2ae5b9aae4246599bb2" + + "d849684d5ab40e8802cfe4a2b358ad56f2b939561d2902404e0ead9ecafd" + + "bb33f22414fa13cbcc22a86bdf9c212ce1a01af894e3f76952f36d6c904c" + + "bd6a7e0de52550c9ddf31f1e8bfe5495f79e66a25fca5c20b3af5b870241" + + "0083456232aa58a8c45e5b110494599bda8dbe6a094683a0539ddd24e19d" + + "47684263bbe285ad953d725942d670b8f290d50c0bca3d1dc9688569f1d5" + + "9945cb5c7d") + + if err != nil { + logError(testName, function, args, startTime, "", "DecodeString for symmetric Key generation failed", err) + return + } + + publicKey, err := hex.DecodeString("30819f300d06092a864886f70d010101050003818d003081890281810087" + + "b42ea73243a3576dc4c0b6fa245d339582dfdbddc20cbb8ab666385034d9" + + "97210c54ba79275c51162a1221c3fb1a4c7c61131ca65563b319d83474ef" + + "5e803fbfa7e52b889e1893b02586b724250de7ac6351cc0b7c638c980ace" + + "c0a07020a78eed7eaa471eca4b92071394e061346c0615ccce2f465dee20" + + "80a89e43f29b570203010001") + if err != nil { + logError(testName, function, args, startTime, "", "DecodeString for symmetric Key generation failed", err) + return + } + + // Generate an asymmetric key + asymKey, err := encrypt.NewAsymmetricKey(privateKey, publicKey) + if err != nil { + logError(testName, function, args, startTime, "", "NewAsymmetricKey for symmetric Key generation failed", err) + return + } + + testCases := []struct { + buf []byte + encKey encrypt.Key + }{ + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 0)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 1)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 15)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 16)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 17)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 31)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 32)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 33)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 1024)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 1024*2)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 1024*1024)}, + + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 0)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 1)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 16)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 32)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 1024)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 1024*1024)}, + } + + for i, testCase := range testCases { + // Generate a random object name + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + // Secured object + cbcMaterials, err := encrypt.NewCBCSecureMaterials(testCase.encKey) + args["cbcMaterials"] = cbcMaterials + + if err != nil { + logError(testName, function, args, startTime, "", "NewCBCSecureMaterials failed", err) + return + } + + // Put encrypted data + _, err = c.PutEncryptedObject(bucketName, objectName, bytes.NewReader(testCase.buf), cbcMaterials) + if err != nil { + logError(testName, function, args, startTime, "", "PutEncryptedObject failed", err) + return + } + + // Read the data back + r, err := c.GetEncryptedObject(bucketName, objectName, cbcMaterials) + if err != nil { + logError(testName, function, args, startTime, "", "GetEncryptedObject failed", err) + return + } + defer r.Close() + + // Compare the sent object with the received one + recvBuffer := bytes.NewBuffer([]byte{}) + if _, err = io.Copy(recvBuffer, r); err != nil { + logError(testName, function, args, startTime, "", "Test "+string(i+1)+", error: "+err.Error(), err) + return + } + if recvBuffer.Len() != len(testCase.buf) { + logError(testName, function, args, startTime, "", "Test "+string(i+1)+", Number of bytes of received object does not match, expected "+string(len(testCase.buf))+", got "+string(recvBuffer.Len()), err) + return + } + if !bytes.Equal(testCase.buf, recvBuffer.Bytes()) { + logError(testName, function, args, startTime, "", "Test "+string(i+1)+", Encrypted sent is not equal to decrypted, expected "+string(testCase.buf)+", got "+string(recvBuffer.Bytes()), err) + return + } + + successLogger(testName, function, args, startTime).Info() + + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// TestEncryptionFPut tests client side encryption +func testEncryptionFPut() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "FPutEncryptedObject(bucketName, objectName, filePath, contentType, cbcMaterials)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "filePath": "", + "contentType": "", + "cbcMaterials": "", + } + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate a symmetric key + symKey := encrypt.NewSymmetricKey([]byte("my-secret-key-00")) + + // Generate an assymmetric key from predefine public and private certificates + privateKey, err := hex.DecodeString( + "30820277020100300d06092a864886f70d0101010500048202613082025d" + + "0201000281810087b42ea73243a3576dc4c0b6fa245d339582dfdbddc20c" + + "bb8ab666385034d997210c54ba79275c51162a1221c3fb1a4c7c61131ca6" + + "5563b319d83474ef5e803fbfa7e52b889e1893b02586b724250de7ac6351" + + "cc0b7c638c980acec0a07020a78eed7eaa471eca4b92071394e061346c06" + + "15ccce2f465dee2080a89e43f29b5702030100010281801dd5770c3af8b3" + + "c85cd18cacad81a11bde1acfac3eac92b00866e142301fee565365aa9af4" + + "57baebf8bb7711054d071319a51dd6869aef3848ce477a0dc5f0dbc0c336" + + "5814b24c820491ae2bb3c707229a654427e03307fec683e6b27856688f08" + + "bdaa88054c5eeeb773793ff7543ee0fb0e2ad716856f2777f809ef7e6fa4" + + "41024100ca6b1edf89e8a8f93cce4b98c76c6990a09eb0d32ad9d3d04fbf" + + "0b026fa935c44f0a1c05dd96df192143b7bda8b110ec8ace28927181fd8c" + + "d2f17330b9b63535024100aba0260afb41489451baaeba423bee39bcbd1e" + + "f63dd44ee2d466d2453e683bf46d019a8baead3a2c7fca987988eb4d565e" + + "27d6be34605953f5034e4faeec9bdb0241009db2cb00b8be8c36710aff96" + + "6d77a6dec86419baca9d9e09a2b761ea69f7d82db2ae5b9aae4246599bb2" + + "d849684d5ab40e8802cfe4a2b358ad56f2b939561d2902404e0ead9ecafd" + + "bb33f22414fa13cbcc22a86bdf9c212ce1a01af894e3f76952f36d6c904c" + + "bd6a7e0de52550c9ddf31f1e8bfe5495f79e66a25fca5c20b3af5b870241" + + "0083456232aa58a8c45e5b110494599bda8dbe6a094683a0539ddd24e19d" + + "47684263bbe285ad953d725942d670b8f290d50c0bca3d1dc9688569f1d5" + + "9945cb5c7d") + + if err != nil { + logError(testName, function, args, startTime, "", "DecodeString for symmetric Key generation failed", err) + return + } + + publicKey, err := hex.DecodeString("30819f300d06092a864886f70d010101050003818d003081890281810087" + + "b42ea73243a3576dc4c0b6fa245d339582dfdbddc20cbb8ab666385034d9" + + "97210c54ba79275c51162a1221c3fb1a4c7c61131ca65563b319d83474ef" + + "5e803fbfa7e52b889e1893b02586b724250de7ac6351cc0b7c638c980ace" + + "c0a07020a78eed7eaa471eca4b92071394e061346c0615ccce2f465dee20" + + "80a89e43f29b570203010001") + if err != nil { + logError(testName, function, args, startTime, "", "DecodeString for symmetric Key generation failed", err) + return + } + + // Generate an asymmetric key + asymKey, err := encrypt.NewAsymmetricKey(privateKey, publicKey) + if err != nil { + logError(testName, function, args, startTime, "", "NewAsymmetricKey for symmetric Key generation failed", err) + return + } + + // Object custom metadata + customContentType := "custom/contenttype" + args["metadata"] = customContentType + + testCases := []struct { + buf []byte + encKey encrypt.Key + }{ + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 0)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 1)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 15)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 16)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 17)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 31)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 32)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 33)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 1024)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 1024*2)}, + {encKey: symKey, buf: bytes.Repeat([]byte("F"), 1024*1024)}, + + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 0)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 1)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 16)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 32)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 1024)}, + {encKey: asymKey, buf: bytes.Repeat([]byte("F"), 1024*1024)}, + } + + for i, testCase := range testCases { + // Generate a random object name + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + // Secured object + cbcMaterials, err := encrypt.NewCBCSecureMaterials(testCase.encKey) + args["cbcMaterials"] = cbcMaterials + + if err != nil { + logError(testName, function, args, startTime, "", "NewCBCSecureMaterials failed", err) + return + } + // Generate a random file name. + fileName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + file, err := os.Create(fileName) + if err != nil { + logError(testName, function, args, startTime, "", "file create failed", err) + return + } + _, err = file.Write(testCase.buf) + if err != nil { + logError(testName, function, args, startTime, "", "file write failed", err) + return + } + file.Close() + // Put encrypted data + if _, err = c.FPutEncryptedObject(bucketName, objectName, fileName, cbcMaterials); err != nil { + logError(testName, function, args, startTime, "", "FPutEncryptedObject failed", err) + return + } + + // Read the data back + r, err := c.GetEncryptedObject(bucketName, objectName, cbcMaterials) + if err != nil { + logError(testName, function, args, startTime, "", "GetEncryptedObject failed", err) + return + } + defer r.Close() + + // Compare the sent object with the received one + recvBuffer := bytes.NewBuffer([]byte{}) + if _, err = io.Copy(recvBuffer, r); err != nil { + logError(testName, function, args, startTime, "", "Test "+string(i+1)+", error: "+err.Error(), err) + return + } + if recvBuffer.Len() != len(testCase.buf) { + logError(testName, function, args, startTime, "", "Test "+string(i+1)+", Number of bytes of received object does not match, expected "+string(len(testCase.buf))+", got "+string(recvBuffer.Len()), err) + return + } + if !bytes.Equal(testCase.buf, recvBuffer.Bytes()) { + logError(testName, function, args, startTime, "", "Test "+string(i+1)+", Encrypted sent is not equal to decrypted, expected "+string(testCase.buf)+", got "+string(recvBuffer.Bytes()), err) + return + } + + if err = os.Remove(fileName); err != nil { + logError(testName, function, args, startTime, "", "File remove failed", err) + return + } + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +func testBucketNotification() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "SetBucketNotification(bucketName)" + args := map[string]interface{}{ + "bucketName": "", + } + + if os.Getenv("NOTIFY_BUCKET") == "" || + os.Getenv("NOTIFY_SERVICE") == "" || + os.Getenv("NOTIFY_REGION") == "" || + os.Getenv("NOTIFY_ACCOUNTID") == "" || + os.Getenv("NOTIFY_RESOURCE") == "" { + ignoredLog(testName, function, args, startTime, "Skipped notification test as it is not configured").Info() + return + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable to debug + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + bucketName := os.Getenv("NOTIFY_BUCKET") + args["bucketName"] = bucketName + + topicArn := minio.NewArn("aws", os.Getenv("NOTIFY_SERVICE"), os.Getenv("NOTIFY_REGION"), os.Getenv("NOTIFY_ACCOUNTID"), os.Getenv("NOTIFY_RESOURCE")) + queueArn := minio.NewArn("aws", "dummy-service", "dummy-region", "dummy-accountid", "dummy-resource") + + topicConfig := minio.NewNotificationConfig(topicArn) + + topicConfig.AddEvents(minio.ObjectCreatedAll, minio.ObjectRemovedAll) + topicConfig.AddFilterSuffix("jpg") + + queueConfig := minio.NewNotificationConfig(queueArn) + queueConfig.AddEvents(minio.ObjectCreatedAll) + queueConfig.AddFilterPrefix("photos/") + + bNotification := minio.BucketNotification{} + bNotification.AddTopic(topicConfig) + + // Add the same topicConfig again, should have no effect + // because it is duplicated + bNotification.AddTopic(topicConfig) + if len(bNotification.TopicConfigs) != 1 { + logError(testName, function, args, startTime, "", "Duplicate entry added", err) + return + } + + // Add and remove a queue config + bNotification.AddQueue(queueConfig) + bNotification.RemoveQueueByArn(queueArn) + + err = c.SetBucketNotification(bucketName, bNotification) + if err != nil { + logError(testName, function, args, startTime, "", "SetBucketNotification failed", err) + return + } + + bNotification, err = c.GetBucketNotification(bucketName) + if err != nil { + logError(testName, function, args, startTime, "", "GetBucketNotification failed", err) + return + } + + if len(bNotification.TopicConfigs) != 1 { + logError(testName, function, args, startTime, "", "Topic config is empty", err) + return + } + + if bNotification.TopicConfigs[0].Filter.S3Key.FilterRules[0].Value != "jpg" { + logError(testName, function, args, startTime, "", "Couldn't get the suffix", err) + return + } + + err = c.RemoveAllBucketNotification(bucketName) + if err != nil { + logError(testName, function, args, startTime, "", "RemoveAllBucketNotification failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests comprehensive list of all methods. +func testFunctional() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "testFunctional()" + function_all := "" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + c, err := minio.New( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, nil, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable to debug + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + + // Make a new bucket. + function = "MakeBucket(bucketName, region)" + function_all = "MakeBucket(bucketName, region)" + args["bucketName"] = bucketName + err = c.MakeBucket(bucketName, "us-east-1") + + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate a random file name. + fileName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + file, err := os.Create(fileName) + if err != nil { + logError(testName, function, args, startTime, "", "File creation failed", err) + return + } + for i := 0; i < 3; i++ { + buf := make([]byte, rand.Intn(1<<19)) + _, err = file.Write(buf) + if err != nil { + logError(testName, function, args, startTime, "", "File write failed", err) + return + } + } + file.Close() + + // Verify if bucket exits and you have access. + var exists bool + function = "BucketExists(bucketName)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + } + exists, err = c.BucketExists(bucketName) + + if err != nil { + logError(testName, function, args, startTime, "", "BucketExists failed", err) + return + } + if !exists { + logError(testName, function, args, startTime, "", "Could not find the bucket", err) + return + } + + // Asserting the default bucket policy. + function = "GetBucketPolicy(bucketName, objectPrefix)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectPrefix": "", + } + policyAccess, err := c.GetBucketPolicy(bucketName, "") + + if err != nil { + logError(testName, function, args, startTime, "", "GetBucketPolicy failed", err) + return + } + if policyAccess != "none" { + logError(testName, function, args, startTime, "", "policy should be set to none", err) + return + } + + // Set the bucket policy to 'public readonly'. + function = "SetBucketPolicy(bucketName, objectPrefix, bucketPolicy)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectPrefix": "", + "bucketPolicy": policy.BucketPolicyReadOnly, + } + err = c.SetBucketPolicy(bucketName, "", policy.BucketPolicyReadOnly) + + if err != nil { + logError(testName, function, args, startTime, "", "SetBucketPolicy failed", err) + return + } + // should return policy `readonly`. + function = "GetBucketPolicy(bucketName, objectPrefix)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectPrefix": "", + } + policyAccess, err = c.GetBucketPolicy(bucketName, "") + + if err != nil { + logError(testName, function, args, startTime, "", "GetBucketPolicy failed", err) + return + } + if policyAccess != "readonly" { + logError(testName, function, args, startTime, "", "policy should be set to readonly", err) + return + } + + // Make the bucket 'public writeonly'. + function = "SetBucketPolicy(bucketName, objectPrefix, bucketPolicy)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectPrefix": "", + "bucketPolicy": policy.BucketPolicyWriteOnly, + } + err = c.SetBucketPolicy(bucketName, "", policy.BucketPolicyWriteOnly) + + if err != nil { + logError(testName, function, args, startTime, "", "SetBucketPolicy failed", err) + return + } + // should return policy `writeonly`. + function = "GetBucketPolicy(bucketName, objectPrefix)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectPrefix": "", + } + policyAccess, err = c.GetBucketPolicy(bucketName, "") + + if err != nil { + logError(testName, function, args, startTime, "", "GetBucketPolicy failed", err) + return + } + if policyAccess != "writeonly" { + logError(testName, function, args, startTime, "", "policy should be set to writeonly", err) + return + } + // Make the bucket 'public read/write'. + function = "SetBucketPolicy(bucketName, objectPrefix, bucketPolicy)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectPrefix": "", + "bucketPolicy": policy.BucketPolicyReadWrite, + } + err = c.SetBucketPolicy(bucketName, "", policy.BucketPolicyReadWrite) + + if err != nil { + logError(testName, function, args, startTime, "", "SetBucketPolicy failed", err) + return + } + // should return policy `readwrite`. + function = "GetBucketPolicy(bucketName, objectPrefix)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectPrefix": "", + } + policyAccess, err = c.GetBucketPolicy(bucketName, "") + + if err != nil { + logError(testName, function, args, startTime, "", "GetBucketPolicy failed", err) + return + } + if policyAccess != "readwrite" { + logError(testName, function, args, startTime, "", "policy should be set to readwrite", err) + return + } + // List all buckets. + function = "ListBuckets()" + function_all += ", " + function + args = nil + buckets, err := c.ListBuckets() + + if len(buckets) == 0 { + logError(testName, function, args, startTime, "", "Found bucket list to be empty", err) + return + } + if err != nil { + logError(testName, function, args, startTime, "", "ListBuckets failed", err) + return + } + + // Verify if previously created bucket is listed in list buckets. + bucketFound := false + for _, bucket := range buckets { + if bucket.Name == bucketName { + bucketFound = true + } + } + + // If bucket not found error out. + if !bucketFound { + logError(testName, function, args, startTime, "", "Bucket: "+bucketName+" not found", err) + return + } + + objectName := bucketName + "unique" + + // Generate data + buf := bytes.Repeat([]byte("f"), 1<<19) + + function = "PutObject(bucketName, objectName, reader, contentType)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "contentType": "", + } + + n, err := c.PutObject(bucketName, objectName, bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(len(buf)) { + logError(testName, function, args, startTime, "", "Length doesn't match, expected "+string(int64(len(buf)))+" got "+string(n), err) + return + } + + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName + "-nolength", + "contentType": "binary/octet-stream", + } + + n, err = c.PutObject(bucketName, objectName+"-nolength", bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(len(buf)) { + logError(testName, function, args, startTime, "", "Length doesn't match, expected "+string(int64(len(buf)))+" got "+string(n), err) + return + } + + // Instantiate a done channel to close all listing. + doneCh := make(chan struct{}) + defer close(doneCh) + + objFound := false + isRecursive := true // Recursive is true. + + function = "ListObjects(bucketName, objectName, isRecursive, doneCh)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "isRecursive": isRecursive, + } + + for obj := range c.ListObjects(bucketName, objectName, isRecursive, doneCh) { + if obj.Key == objectName { + objFound = true + break + } + } + if !objFound { + logError(testName, function, args, startTime, "", "Object "+objectName+" not found", err) + return + } + + objFound = false + isRecursive = true // Recursive is true. + function = "ListObjectsV2(bucketName, objectName, isRecursive, doneCh)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "isRecursive": isRecursive, + } + + for obj := range c.ListObjectsV2(bucketName, objectName, isRecursive, doneCh) { + if obj.Key == objectName { + objFound = true + break + } + } + if !objFound { + logError(testName, function, args, startTime, "", "Object "+objectName+" not found", err) + return + } + + incompObjNotFound := true + + function = "ListIncompleteUploads(bucketName, objectName, isRecursive, doneCh)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "isRecursive": isRecursive, + } + + for objIncompl := range c.ListIncompleteUploads(bucketName, objectName, isRecursive, doneCh) { + if objIncompl.Key != "" { + incompObjNotFound = false + break + } + } + if !incompObjNotFound { + logError(testName, function, args, startTime, "", "Unexpected dangling incomplete upload found", err) + return + } + + function = "GetObject(bucketName, objectName)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + } + newReader, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + newReadBytes, err := ioutil.ReadAll(newReader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + + if !bytes.Equal(newReadBytes, buf) { + logError(testName, function, args, startTime, "", "GetObject bytes mismatch", err) + return + } + + function = "FGetObject(bucketName, objectName, fileName)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "fileName": fileName + "-f", + } + err = c.FGetObject(bucketName, objectName, fileName+"-f", minio.GetObjectOptions{}) + + if err != nil { + logError(testName, function, args, startTime, "", "FGetObject failed", err) + return + } + + function = "PresignedHeadObject(bucketName, objectName, expires, reqParams)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": "", + "expires": 3600 * time.Second, + } + if _, err = c.PresignedHeadObject(bucketName, "", 3600*time.Second, nil); err == nil { + logError(testName, function, args, startTime, "", "PresignedHeadObject success", err) + return + } + + // Generate presigned HEAD object url. + function = "PresignedHeadObject(bucketName, objectName, expires, reqParams)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "expires": 3600 * time.Second, + } + presignedHeadURL, err := c.PresignedHeadObject(bucketName, objectName, 3600*time.Second, nil) + + if err != nil { + logError(testName, function, args, startTime, "", "PresignedHeadObject failed", err) + return + } + // Verify if presigned url works. + resp, err := http.Head(presignedHeadURL.String()) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedHeadObject response incorrect", err) + return + } + if resp.StatusCode != http.StatusOK { + logError(testName, function, args, startTime, "", "PresignedHeadObject response incorrect, status "+string(resp.StatusCode), err) + return + } + if resp.Header.Get("ETag") == "" { + logError(testName, function, args, startTime, "", "PresignedHeadObject response incorrect", err) + return + } + resp.Body.Close() + + function = "PresignedGetObject(bucketName, objectName, expires, reqParams)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": "", + "expires": 3600 * time.Second, + } + _, err = c.PresignedGetObject(bucketName, "", 3600*time.Second, nil) + if err == nil { + logError(testName, function, args, startTime, "", "PresignedGetObject success", err) + return + } + + // Generate presigned GET object url. + function = "PresignedGetObject(bucketName, objectName, expires, reqParams)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "expires": 3600 * time.Second, + } + presignedGetURL, err := c.PresignedGetObject(bucketName, objectName, 3600*time.Second, nil) + + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject failed", err) + return + } + + // Verify if presigned url works. + resp, err = http.Get(presignedGetURL.String()) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject response incorrect", err) + return + } + if resp.StatusCode != http.StatusOK { + logError(testName, function, args, startTime, "", "PresignedGetObject response incorrect, status "+string(resp.StatusCode), err) + return + } + newPresignedBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject response incorrect", err) + return + } + resp.Body.Close() + if !bytes.Equal(newPresignedBytes, buf) { + logError(testName, function, args, startTime, "", "PresignedGetObject response incorrect", err) + return + } + + // Set request parameters. + reqParams := make(url.Values) + reqParams.Set("response-content-disposition", "attachment; filename=\"test.txt\"") + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "expires": 3600 * time.Second, + "reqParams": reqParams, + } + presignedGetURL, err = c.PresignedGetObject(bucketName, objectName, 3600*time.Second, reqParams) + + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject failed", err) + return + } + // Verify if presigned url works. + resp, err = http.Get(presignedGetURL.String()) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject response incorrect", err) + return + } + if resp.StatusCode != http.StatusOK { + logError(testName, function, args, startTime, "", "PresignedGetObject response incorrect, status "+string(resp.StatusCode), err) + return + } + newPresignedBytes, err = ioutil.ReadAll(resp.Body) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject response incorrect", err) + return + } + if !bytes.Equal(newPresignedBytes, buf) { + logError(testName, function, args, startTime, "", "Bytes mismatch for presigned GET URL", err) + return + } + if resp.Header.Get("Content-Disposition") != "attachment; filename=\"test.txt\"" { + logError(testName, function, args, startTime, "", "wrong Content-Disposition received "+string(resp.Header.Get("Content-Disposition")), err) + return + } + + function = "PresignedPutObject(bucketName, objectName, expires)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": "", + "expires": 3600 * time.Second, + } + _, err = c.PresignedPutObject(bucketName, "", 3600*time.Second) + if err == nil { + logError(testName, function, args, startTime, "", "PresignedPutObject success", err) + return + } + + function = "PresignedPutObject(bucketName, objectName, expires)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName + "-presigned", + "expires": 3600 * time.Second, + } + presignedPutURL, err := c.PresignedPutObject(bucketName, objectName+"-presigned", 3600*time.Second) + + if err != nil { + logError(testName, function, args, startTime, "", "PresignedPutObject failed", err) + return + } + + buf = bytes.Repeat([]byte("g"), 1<<19) + + req, err := http.NewRequest("PUT", presignedPutURL.String(), bytes.NewReader(buf)) + if err != nil { + logError(testName, function, args, startTime, "", "Couldn't make HTTP request with PresignedPutObject URL", err) + return + } + httpClient := &http.Client{ + // Setting a sensible time out of 30secs to wait for response + // headers. Request is pro-actively cancelled after 30secs + // with no response. + Timeout: 30 * time.Second, + Transport: http.DefaultTransport, + } + resp, err = httpClient.Do(req) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedPutObject failed", err) + return + } + + newReader, err = c.GetObject(bucketName, objectName+"-presigned", minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject after PresignedPutObject failed", err) + return + } + + newReadBytes, err = ioutil.ReadAll(newReader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll after GetObject failed", err) + return + } + + if !bytes.Equal(newReadBytes, buf) { + logError(testName, function, args, startTime, "", "Bytes mismatch", err) + return + } + + function = "RemoveObject(bucketName, objectName)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + } + err = c.RemoveObject(bucketName, objectName) + + if err != nil { + logError(testName, function, args, startTime, "", "RemoveObject failed", err) + return + } + args["objectName"] = objectName + "-f" + err = c.RemoveObject(bucketName, objectName+"-f") + + if err != nil { + logError(testName, function, args, startTime, "", "RemoveObject failed", err) + return + } + + args["objectName"] = objectName + "-nolength" + err = c.RemoveObject(bucketName, objectName+"-nolength") + + if err != nil { + logError(testName, function, args, startTime, "", "RemoveObject failed", err) + return + } + + args["objectName"] = objectName + "-presigned" + err = c.RemoveObject(bucketName, objectName+"-presigned") + + if err != nil { + logError(testName, function, args, startTime, "", "RemoveObject failed", err) + return + } + + function = "RemoveBucket(bucketName)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + } + err = c.RemoveBucket(bucketName) + + if err != nil { + logError(testName, function, args, startTime, "", "RemoveBucket failed", err) + return + } + err = c.RemoveBucket(bucketName) + if err == nil { + logError(testName, function, args, startTime, "", "RemoveBucket did not fail for invalid bucket name", err) + return + } + if err.Error() != "The specified bucket does not exist" { + logError(testName, function, args, startTime, "", "RemoveBucket failed", err) + return + } + + if err = os.Remove(fileName); err != nil { + logError(testName, function, args, startTime, "", "File Remove failed", err) + return + } + if err = os.Remove(fileName + "-f"); err != nil { + logError(testName, function, args, startTime, "", "File Remove failed", err) + return + } + successLogger(testName, function_all, args, startTime).Info() +} + +// Test for validating GetObject Reader* methods functioning when the +// object is modified in the object store. +func testGetObjectModified() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "GetObject(bucketName, objectName)" + args := map[string]interface{}{} + + // Instantiate new minio client object. + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Make a new bucket. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + defer c.RemoveBucket(bucketName) + + // Upload an object. + objectName := "myobject" + args["objectName"] = objectName + content := "helloworld" + _, err = c.PutObject(bucketName, objectName, strings.NewReader(content), int64(len(content)), minio.PutObjectOptions{ContentType: "application/text"}) + if err != nil { + logError(testName, function, args, startTime, "", "Failed to upload "+objectName+", to bucket "+bucketName, err) + return + } + + defer c.RemoveObject(bucketName, objectName) + + reader, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "Failed to GetObject "+objectName+", from bucket "+bucketName, err) + return + } + defer reader.Close() + + // Read a few bytes of the object. + b := make([]byte, 5) + n, err := reader.ReadAt(b, 0) + if err != nil { + logError(testName, function, args, startTime, "", "Failed to read object "+objectName+", from bucket "+bucketName+" at an offset", err) + return + } + + // Upload different contents to the same object while object is being read. + newContent := "goodbyeworld" + _, err = c.PutObject(bucketName, objectName, strings.NewReader(newContent), int64(len(newContent)), minio.PutObjectOptions{ContentType: "application/text"}) + if err != nil { + logError(testName, function, args, startTime, "", "Failed to upload "+objectName+", to bucket "+bucketName, err) + return + } + + // Confirm that a Stat() call in between doesn't change the Object's cached etag. + _, err = reader.Stat() + expectedError := "At least one of the pre-conditions you specified did not hold" + if err.Error() != expectedError { + logError(testName, function, args, startTime, "", "Expected Stat to fail with error "+expectedError+", but received "+err.Error(), err) + return + } + + // Read again only to find object contents have been modified since last read. + _, err = reader.ReadAt(b, int64(n)) + if err.Error() != expectedError { + logError(testName, function, args, startTime, "", "Expected ReadAt to fail with error "+expectedError+", but received "+err.Error(), err) + return + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test validates putObject to upload a file seeked at a given offset. +func testPutObjectUploadSeekedObject() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PutObject(bucketName, objectName, fileToUpload, contentType)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "fileToUpload": "", + "contentType": "binary/octet-stream", + } + + // Instantiate new minio client object. + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Make a new bucket. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + defer c.RemoveBucket(bucketName) + + var tempfile *os.File + + if fileName := getMintDataDirFilePath("datafile-100-kB"); fileName != "" { + tempfile, err = os.Open(fileName) + if err != nil { + logError(testName, function, args, startTime, "", "File open failed", err) + return + } + args["fileToUpload"] = fileName + } else { + tempfile, err = ioutil.TempFile("", "minio-go-upload-test-") + if err != nil { + logError(testName, function, args, startTime, "", "TempFile create failed", err) + return + } + args["fileToUpload"] = tempfile.Name() + + // Generate 100kB data + if _, err = io.Copy(tempfile, getDataReader("datafile-100-kB")); err != nil { + logError(testName, function, args, startTime, "", "File copy failed", err) + return + } + + defer os.Remove(tempfile.Name()) + + // Seek back to the beginning of the file. + tempfile.Seek(0, 0) + } + var length = 100 * humanize.KiByte + objectName := fmt.Sprintf("test-file-%v", rand.Uint32()) + args["objectName"] = objectName + + offset := length / 2 + if _, err = tempfile.Seek(int64(offset), 0); err != nil { + logError(testName, function, args, startTime, "", "TempFile seek failed", err) + return + } + + n, err := c.PutObject(bucketName, objectName, tempfile, int64(length-offset), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + if n != int64(length-offset) { + logError(testName, function, args, startTime, "", fmt.Sprintf("Invalid length returned, expected %d got %d", int64(length-offset), n), err) + return + } + tempfile.Close() + + obj, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + n, err = obj.Seek(int64(offset), 0) + if err != nil { + logError(testName, function, args, startTime, "", "Seek failed", err) + return + } + if n != int64(offset) { + logError(testName, function, args, startTime, "", fmt.Sprintf("Invalid offset returned, expected %d got %d", int64(offset), n), err) + return + } + + n, err = c.PutObject(bucketName, objectName+"getobject", obj, int64(length-offset), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + if n != int64(length-offset) { + logError(testName, function, args, startTime, "", fmt.Sprintf("Invalid offset returned, expected %d got %d", int64(length-offset), n), err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests bucket re-create errors. +func testMakeBucketErrorV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "MakeBucket(bucketName, region)" + args := map[string]interface{}{ + "bucketName": "", + "region": "eu-west-1", + } + + if os.Getenv(serverEndpoint) != "s3.amazonaws.com" { + ignoredLog(testName, function, args, startTime, "Skipped region functional tests for non s3 runs").Info() + return + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + region := "eu-west-1" + args["bucketName"] = bucketName + args["region"] = region + + // Make a new bucket in 'eu-west-1'. + if err = c.MakeBucket(bucketName, region); err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + if err = c.MakeBucket(bucketName, region); err == nil { + logError(testName, function, args, startTime, "", "MakeBucket did not fail for existing bucket name", err) + return + } + // Verify valid error response from server. + if minio.ToErrorResponse(err).Code != "BucketAlreadyExists" && + minio.ToErrorResponse(err).Code != "BucketAlreadyOwnedByYou" { + logError(testName, function, args, startTime, "", "Invalid error returned by server", err) + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test get object reader to not throw error on being closed twice. +func testGetObjectClosedTwiceV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "MakeBucket(bucketName, region)" + args := map[string]interface{}{ + "bucketName": "", + "region": "eu-west-1", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + n, err := c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(bufSize)+" got "+string(n), err) + return + } + + // Read the data back + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(bufSize)+" got "+string(st.Size), err) + return + } + if err := r.Close(); err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + if err := r.Close(); err == nil { + logError(testName, function, args, startTime, "", "Object is already closed, should return error", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests removing partially uploaded objects. +func testRemovePartiallyUploadedV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "RemoveIncompleteUpload(bucketName, objectName)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Enable tracing, write to stdout. + // c.TraceOn(os.Stderr) + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + r := bytes.NewReader(bytes.Repeat([]byte("a"), 128*1024)) + + reader, writer := io.Pipe() + go func() { + i := 0 + for i < 25 { + _, cerr := io.CopyN(writer, r, 128*1024) + if cerr != nil { + logError(testName, function, args, startTime, "", "Copy failed", cerr) + return + } + i++ + r.Seek(0, 0) + } + writer.CloseWithError(errors.New("proactively closed to be verified later")) + }() + + objectName := bucketName + "-resumable" + args["objectName"] = objectName + + _, err = c.PutObject(bucketName, objectName, reader, -1, minio.PutObjectOptions{ContentType: "application/octet-stream"}) + if err == nil { + logError(testName, function, args, startTime, "", "PutObject should fail", err) + return + } + if err.Error() != "proactively closed to be verified later" { + logError(testName, function, args, startTime, "", "Unexpected error, expected : proactively closed to be verified later", err) + return + } + err = c.RemoveIncompleteUpload(bucketName, objectName) + if err != nil { + logError(testName, function, args, startTime, "", "RemoveIncompleteUpload failed", err) + return + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests FPutObject hidden contentType setting +func testFPutObjectV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "FPutObject(bucketName, objectName, fileName, opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "fileName": "", + "opts": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Make a temp file with 11*1024*1024 bytes of data. + file, err := ioutil.TempFile(os.TempDir(), "FPutObjectTest") + if err != nil { + logError(testName, function, args, startTime, "", "TempFile creation failed", err) + return + } + + r := bytes.NewReader(bytes.Repeat([]byte("b"), 11*1024*1024)) + n, err := io.CopyN(file, r, 11*1024*1024) + if err != nil { + logError(testName, function, args, startTime, "", "Copy failed", err) + return + } + if n != int64(11*1024*1024) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(11*1024*1024))+" got "+string(n), err) + return + } + + // Close the file pro-actively for windows. + err = file.Close() + if err != nil { + logError(testName, function, args, startTime, "", "File close failed", err) + return + } + + // Set base object name + objectName := bucketName + "FPutObject" + args["objectName"] = objectName + args["fileName"] = file.Name() + + // Perform standard FPutObject with contentType provided (Expecting application/octet-stream) + n, err = c.FPutObject(bucketName, objectName+"-standard", file.Name(), minio.PutObjectOptions{ContentType: "application/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "FPutObject failed", err) + return + } + if n != int64(11*1024*1024) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(11*1024*1024))+" got "+string(n), err) + return + } + + // Perform FPutObject with no contentType provided (Expecting application/octet-stream) + args["objectName"] = objectName + "-Octet" + args["contentType"] = "" + + n, err = c.FPutObject(bucketName, objectName+"-Octet", file.Name(), minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "FPutObject failed", err) + return + } + if n != int64(11*1024*1024) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(11*1024*1024))+" got "+string(n), err) + return + } + + // Add extension to temp file name + fileName := file.Name() + err = os.Rename(file.Name(), fileName+".gtar") + if err != nil { + logError(testName, function, args, startTime, "", "Rename failed", err) + return + } + + // Perform FPutObject with no contentType provided (Expecting application/x-gtar) + args["objectName"] = objectName + "-Octet" + args["contentType"] = "" + args["fileName"] = fileName + ".gtar" + + n, err = c.FPutObject(bucketName, objectName+"-GTar", fileName+".gtar", minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "FPutObject failed", err) + return + } + if n != int64(11*1024*1024) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(11*1024*1024))+" got "+string(n), err) + return + } + + // Check headers + rStandard, err := c.StatObject(bucketName, objectName+"-standard", minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "StatObject failed", err) + return + } + if rStandard.ContentType != "application/octet-stream" { + logError(testName, function, args, startTime, "", "Content-Type headers mismatched, expected: application/octet-stream , got "+rStandard.ContentType, err) + return + } + + rOctet, err := c.StatObject(bucketName, objectName+"-Octet", minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "StatObject failed", err) + return + } + if rOctet.ContentType != "application/octet-stream" { + logError(testName, function, args, startTime, "", "Content-Type headers mismatched, expected: application/octet-stream , got "+rOctet.ContentType, err) + return + } + + rGTar, err := c.StatObject(bucketName, objectName+"-GTar", minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "StatObject failed", err) + return + } + if rGTar.ContentType != "application/x-gtar" { + logError(testName, function, args, startTime, "", "Content-Type headers mismatched, expected: application/x-gtar , got "+rGTar.ContentType, err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + err = os.Remove(fileName + ".gtar") + if err != nil { + logError(testName, function, args, startTime, "", "File remove failed", err) + return + } + successLogger(testName, function, args, startTime).Info() +} + +// Tests various bucket supported formats. +func testMakeBucketRegionsV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "MakeBucket(bucketName, region)" + args := map[string]interface{}{ + "bucketName": "", + "region": "eu-west-1", + } + + if os.Getenv(serverEndpoint) != "s3.amazonaws.com" { + ignoredLog(testName, function, args, startTime, "Skipped region functional tests for non s3 runs").Info() + return + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket in 'eu-central-1'. + if err = c.MakeBucket(bucketName, "eu-west-1"); err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + // Make a new bucket with '.' in its name, in 'us-west-2'. This + // request is internally staged into a path style instead of + // virtual host style. + if err = c.MakeBucket(bucketName+".withperiod", "us-west-2"); err != nil { + args["bucketName"] = bucketName + ".withperiod" + args["region"] = "us-west-2" + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName+".withperiod", c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests get object ReaderSeeker interface methods. +func testGetObjectReadSeekFunctionalV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "GetObject(bucketName, objectName)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + buf, err := ioutil.ReadAll(reader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + + // Save the data. + n, err := c.PutObject(bucketName, objectName, bytes.NewReader(buf), int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(bufSize))+" got "+string(n), err) + return + } + + // Read the data back + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes in stat does not match, expected "+string(int64(bufSize))+" got "+string(st.Size), err) + return + } + + offset := int64(2048) + n, err = r.Seek(offset, 0) + if err != nil { + logError(testName, function, args, startTime, "", "Seek failed", err) + return + } + if n != offset { + logError(testName, function, args, startTime, "", "Number of seeked bytes does not match, expected "+string(offset)+" got "+string(n), err) + return + } + n, err = r.Seek(0, 1) + if err != nil { + logError(testName, function, args, startTime, "", "Seek failed", err) + return + } + if n != offset { + logError(testName, function, args, startTime, "", "Number of seeked bytes does not match, expected "+string(offset)+" got "+string(n), err) + return + } + _, err = r.Seek(offset, 2) + if err == nil { + logError(testName, function, args, startTime, "", "Seek on positive offset for whence '2' should error out", err) + return + } + n, err = r.Seek(-offset, 2) + if err != nil { + logError(testName, function, args, startTime, "", "Seek failed", err) + return + } + if n != st.Size-offset { + logError(testName, function, args, startTime, "", "Number of seeked bytes does not match, expected "+string(st.Size-offset)+" got "+string(n), err) + return + } + + var buffer1 bytes.Buffer + if _, err = io.CopyN(&buffer1, r, st.Size); err != nil { + if err != io.EOF { + logError(testName, function, args, startTime, "", "Copy failed", err) + return + } + } + if !bytes.Equal(buf[len(buf)-int(offset):], buffer1.Bytes()) { + logError(testName, function, args, startTime, "", "Incorrect read bytes v/s original buffer", err) + return + } + + // Seek again and read again. + n, err = r.Seek(offset-1, 0) + if err != nil { + logError(testName, function, args, startTime, "", "Seek failed", err) + return + } + if n != (offset - 1) { + logError(testName, function, args, startTime, "", "Number of seeked bytes does not match, expected "+string(offset-1)+" got "+string(n), err) + return + } + + var buffer2 bytes.Buffer + if _, err = io.CopyN(&buffer2, r, st.Size); err != nil { + if err != io.EOF { + logError(testName, function, args, startTime, "", "Copy failed", err) + return + } + } + // Verify now lesser bytes. + if !bytes.Equal(buf[2047:], buffer2.Bytes()) { + logError(testName, function, args, startTime, "", "Incorrect read bytes v/s original buffer", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests get object ReaderAt interface methods. +func testGetObjectReadAtFunctionalV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "GetObject(bucketName, objectName)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + buf, err := ioutil.ReadAll(reader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + + // Save the data + n, err := c.PutObject(bucketName, objectName, bytes.NewReader(buf), int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(bufSize)+" got "+string(n), err) + return + } + + // Read the data back + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(bufSize)+" got "+string(st.Size), err) + return + } + + offset := int64(2048) + + // Read directly + buf2 := make([]byte, 512) + buf3 := make([]byte, 512) + buf4 := make([]byte, 512) + + m, err := r.ReadAt(buf2, offset) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + if m != len(buf2) { + logError(testName, function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, expected "+string(len(buf2))+" got "+string(m), err) + return + } + if !bytes.Equal(buf2, buf[offset:offset+512]) { + logError(testName, function, args, startTime, "", "Incorrect read between two ReadAt from same offset", err) + return + } + offset += 512 + m, err = r.ReadAt(buf3, offset) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + if m != len(buf3) { + logError(testName, function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, expected "+string(len(buf3))+" got "+string(m), err) + return + } + if !bytes.Equal(buf3, buf[offset:offset+512]) { + logError(testName, function, args, startTime, "", "Incorrect read between two ReadAt from same offset", err) + return + } + offset += 512 + m, err = r.ReadAt(buf4, offset) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + if m != len(buf4) { + logError(testName, function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, expected "+string(len(buf4))+" got "+string(m), err) + return + } + if !bytes.Equal(buf4, buf[offset:offset+512]) { + logError(testName, function, args, startTime, "", "Incorrect read between two ReadAt from same offset", err) + return + } + + buf5 := make([]byte, n) + // Read the whole object. + m, err = r.ReadAt(buf5, 0) + if err != nil { + if err != io.EOF { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + } + if m != len(buf5) { + logError(testName, function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, expected "+string(len(buf5))+" got "+string(m), err) + return + } + if !bytes.Equal(buf, buf5) { + logError(testName, function, args, startTime, "", "Incorrect data read in GetObject, than what was previously uploaded", err) + return + } + + buf6 := make([]byte, n+1) + // Read the whole object and beyond. + _, err = r.ReadAt(buf6, 0) + if err != nil { + if err != io.EOF { + logError(testName, function, args, startTime, "", "ReadAt failed", err) + return + } + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Tests copy object +func testCopyObjectV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "CopyObject(destination, source)" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + + // Make a new bucket in 'us-east-1' (source bucket). + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Make a new bucket in 'us-east-1' (destination bucket). + err = c.MakeBucket(bucketName+"-copy", "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate 33K of data. + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + n, err := c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(int64(bufSize))+" got "+string(n), err) + return + } + + r, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + // Check the various fields of source object against destination object. + objInfo, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + + // Copy Source + src := minio.NewSourceInfo(bucketName, objectName, nil) + args["source"] = src + + // Set copy conditions. + + // All invalid conditions first. + err = src.SetModifiedSinceCond(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)) + if err == nil { + logError(testName, function, args, startTime, "", "SetModifiedSinceCond did not fail for invalid conditions", err) + return + } + err = src.SetUnmodifiedSinceCond(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)) + if err == nil { + logError(testName, function, args, startTime, "", "SetUnmodifiedSinceCond did not fail for invalid conditions", err) + return + } + err = src.SetMatchETagCond("") + if err == nil { + logError(testName, function, args, startTime, "", "SetMatchETagCond did not fail for invalid conditions", err) + return + } + err = src.SetMatchETagExceptCond("") + if err == nil { + logError(testName, function, args, startTime, "", "SetMatchETagExceptCond did not fail for invalid conditions", err) + return + } + + err = src.SetModifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC)) + if err != nil { + logError(testName, function, args, startTime, "", "SetModifiedSinceCond failed", err) + return + } + err = src.SetMatchETagCond(objInfo.ETag) + if err != nil { + logError(testName, function, args, startTime, "", "SetMatchETagCond failed", err) + return + } + + dst, err := minio.NewDestinationInfo(bucketName+"-copy", objectName+"-copy", nil, nil) + args["destination"] = dst + if err != nil { + logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err) + return + } + + // Perform the Copy + err = c.CopyObject(dst, src) + if err != nil { + logError(testName, function, args, startTime, "", "CopyObject failed", err) + return + } + + // Source object + r, err = c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + // Destination object + readerCopy, err := c.GetObject(bucketName+"-copy", objectName+"-copy", minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + // Check the various fields of source object against destination object. + objInfo, err = r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + objInfoCopy, err := readerCopy.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + if objInfo.Size != objInfoCopy.Size { + logError(testName, function, args, startTime, "", "Number of bytes does not match, expected "+string(objInfoCopy.Size)+" got "+string(objInfo.Size), err) + return + } + + // CopyObject again but with wrong conditions + src = minio.NewSourceInfo(bucketName, objectName, nil) + err = src.SetUnmodifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC)) + if err != nil { + logError(testName, function, args, startTime, "", "SetUnmodifiedSinceCond failed", err) + return + } + err = src.SetMatchETagExceptCond(objInfo.ETag) + if err != nil { + logError(testName, function, args, startTime, "", "SetMatchETagExceptCond failed", err) + return + } + + // Perform the Copy which should fail + err = c.CopyObject(dst, src) + if err == nil { + logError(testName, function, args, startTime, "", "CopyObject did not fail for invalid conditions", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + if err = cleanupBucket(bucketName+"-copy", c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + successLogger(testName, function, args, startTime).Info() +} + +func testComposeObjectErrorCasesWrapper(c *minio.Client) { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "ComposeObject(destination, sourceList)" + args := map[string]interface{}{} + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + + // Make a new bucket in 'us-east-1' (source bucket). + err := c.MakeBucket(bucketName, "us-east-1") + + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Test that more than 10K source objects cannot be + // concatenated. + srcArr := [10001]minio.SourceInfo{} + srcSlice := srcArr[:] + dst, err := minio.NewDestinationInfo(bucketName, "object", nil, nil) + if err != nil { + logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err) + return + } + + args["destination"] = dst + // Just explain about srcArr in args["sourceList"] + // to stop having 10,001 null headers logged + args["sourceList"] = "source array of 10,001 elements" + if err := c.ComposeObject(dst, srcSlice); err == nil { + logError(testName, function, args, startTime, "", "Expected error in ComposeObject", err) + return + } else if err.Error() != "There must be as least one and up to 10000 source objects." { + logError(testName, function, args, startTime, "", "Got unexpected error", err) + return + } + + // Create a source with invalid offset spec and check that + // error is returned: + // 1. Create the source object. + const badSrcSize = 5 * 1024 * 1024 + buf := bytes.Repeat([]byte("1"), badSrcSize) + _, err = c.PutObject(bucketName, "badObject", bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + // 2. Set invalid range spec on the object (going beyond + // object size) + badSrc := minio.NewSourceInfo(bucketName, "badObject", nil) + err = badSrc.SetRange(1, badSrcSize) + if err != nil { + logError(testName, function, args, startTime, "", "Setting NewSourceInfo failed", err) + return + } + // 3. ComposeObject call should fail. + if err := c.ComposeObject(dst, []minio.SourceInfo{badSrc}); err == nil { + logError(testName, function, args, startTime, "", "ComposeObject expected to fail", err) + return + } else if !strings.Contains(err.Error(), "has invalid segment-to-copy") { + logError(testName, function, args, startTime, "", "Got invalid error", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test expected error cases +func testComposeObjectErrorCasesV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "ComposeObject(destination, sourceList)" + args := map[string]interface{}{} + + // Instantiate new minio client object + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + testComposeObjectErrorCasesWrapper(c) +} + +func testComposeMultipleSources(c *minio.Client) { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "ComposeObject(destination, sourceList)" + args := map[string]interface{}{ + "destination": "", + "sourceList": "", + } + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + // Make a new bucket in 'us-east-1' (source bucket). + err := c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Upload a small source object + const srcSize = 1024 * 1024 * 5 + buf := bytes.Repeat([]byte("1"), srcSize) + _, err = c.PutObject(bucketName, "srcObject", bytes.NewReader(buf), int64(srcSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + // We will append 10 copies of the object. + srcs := []minio.SourceInfo{} + for i := 0; i < 10; i++ { + srcs = append(srcs, minio.NewSourceInfo(bucketName, "srcObject", nil)) + } + // make the last part very small + err = srcs[9].SetRange(0, 0) + if err != nil { + logError(testName, function, args, startTime, "", "SetRange failed", err) + return + } + args["sourceList"] = srcs + + dst, err := minio.NewDestinationInfo(bucketName, "dstObject", nil, nil) + args["destination"] = dst + + if err != nil { + logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err) + return + } + err = c.ComposeObject(dst, srcs) + if err != nil { + logError(testName, function, args, startTime, "", "ComposeObject failed", err) + return + } + + objProps, err := c.StatObject(bucketName, "dstObject", minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "StatObject failed", err) + return + } + + if objProps.Size != 9*srcSize+1 { + logError(testName, function, args, startTime, "", "Size mismatched! Expected "+string(10000*srcSize)+" got "+string(objProps.Size), err) + return + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + successLogger(testName, function, args, startTime).Info() +} + +// Test concatenating multiple objects objects +func testCompose10KSourcesV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "ComposeObject(destination, sourceList)" + args := map[string]interface{}{} + + // Instantiate new minio client object + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + testComposeMultipleSources(c) +} + +func testEncryptedCopyObjectWrapper(c *minio.Client) { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "CopyObject(destination, source)" + args := map[string]interface{}{} + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + // Make a new bucket in 'us-east-1' (source bucket). + err := c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + key1 := minio.NewSSEInfo([]byte("32byteslongsecretkeymustbegiven1"), "AES256") + key2 := minio.NewSSEInfo([]byte("32byteslongsecretkeymustbegiven2"), "AES256") + + // 1. create an sse-c encrypted object to copy by uploading + const srcSize = 1024 * 1024 + buf := bytes.Repeat([]byte("abcde"), srcSize) // gives a buffer of 5MiB + metadata := make(map[string]string) + for k, v := range key1.GetSSEHeaders() { + metadata[k] = v + } + _, err = c.PutObject(bucketName, "srcObject", bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{UserMetadata: metadata, Progress: nil}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject call failed", err) + return + } + + // 2. copy object and change encryption key + src := minio.NewSourceInfo(bucketName, "srcObject", &key1) + args["source"] = src + dst, err := minio.NewDestinationInfo(bucketName, "dstObject", &key2, nil) + if err != nil { + logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err) + return + } + args["destination"] = dst + + err = c.CopyObject(dst, src) + if err != nil { + logError(testName, function, args, startTime, "", "CopyObject failed", err) + return + } + + // 3. get copied object and check if content is equal + opts := minio.GetObjectOptions{} + for k, v := range key2.GetSSEHeaders() { + opts.Set(k, v) + } + coreClient := minio.Core{c} + reader, _, err := coreClient.GetObject(bucketName, "dstObject", opts) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + defer reader.Close() + + decBytes, err := ioutil.ReadAll(reader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + if !bytes.Equal(decBytes, buf) { + logError(testName, function, args, startTime, "", "Downloaded object mismatched for encrypted object", err) + return + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test encrypted copy object +func testEncryptedCopyObject() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "CopyObject(destination, source)" + args := map[string]interface{}{} + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + // c.TraceOn(os.Stderr) + testEncryptedCopyObjectWrapper(c) +} + +// Test encrypted copy object +func testEncryptedCopyObjectV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "CopyObject(destination, source)" + args := map[string]interface{}{} + + // Instantiate new minio client object + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v2 client object creation failed", err) + return + } + + testEncryptedCopyObjectWrapper(c) +} + +func testUserMetadataCopying() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "CopyObject(destination, source)" + args := map[string]interface{}{} + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + // c.TraceOn(os.Stderr) + testUserMetadataCopyingWrapper(c) +} + +func testUserMetadataCopyingWrapper(c *minio.Client) { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "CopyObject(destination, source)" + args := map[string]interface{}{} + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + // Make a new bucket in 'us-east-1' (source bucket). + err := c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + fetchMeta := func(object string) (h http.Header) { + objInfo, err := c.StatObject(bucketName, object, minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + h = make(http.Header) + for k, vs := range objInfo.Metadata { + if strings.HasPrefix(strings.ToLower(k), "x-amz-meta-") { + for _, v := range vs { + h.Add(k, v) + } + } + } + return h + } + + // 1. create a client encrypted object to copy by uploading + const srcSize = 1024 * 1024 + buf := bytes.Repeat([]byte("abcde"), srcSize) // gives a buffer of 5MiB + metadata := make(http.Header) + metadata.Set("x-amz-meta-myheader", "myvalue") + m := make(map[string]string) + m["x-amz-meta-myheader"] = "myvalue" + _, err = c.PutObject(bucketName, "srcObject", + bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{UserMetadata: m}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObjectWithMetadata failed", err) + return + } + if !reflect.DeepEqual(metadata, fetchMeta("srcObject")) { + logError(testName, function, args, startTime, "", "Metadata match failed", err) + return + } + + // 2. create source + src := minio.NewSourceInfo(bucketName, "srcObject", nil) + // 2.1 create destination with metadata set + dst1, err := minio.NewDestinationInfo(bucketName, "dstObject-1", nil, map[string]string{"notmyheader": "notmyvalue"}) + if err != nil { + logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err) + return + } + + // 3. Check that copying to an object with metadata set resets + // the headers on the copy. + args["source"] = src + args["destination"] = dst1 + err = c.CopyObject(dst1, src) + if err != nil { + logError(testName, function, args, startTime, "", "CopyObject failed", err) + return + } + + expectedHeaders := make(http.Header) + expectedHeaders.Set("x-amz-meta-notmyheader", "notmyvalue") + if !reflect.DeepEqual(expectedHeaders, fetchMeta("dstObject-1")) { + logError(testName, function, args, startTime, "", "Metadata match failed", err) + return + } + + // 4. create destination with no metadata set and same source + dst2, err := minio.NewDestinationInfo(bucketName, "dstObject-2", nil, nil) + if err != nil { + logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err) + return + } + src = minio.NewSourceInfo(bucketName, "srcObject", nil) + + // 5. Check that copying to an object with no metadata set, + // copies metadata. + args["source"] = src + args["destination"] = dst2 + err = c.CopyObject(dst2, src) + if err != nil { + logError(testName, function, args, startTime, "", "CopyObject failed", err) + return + } + + expectedHeaders = metadata + if !reflect.DeepEqual(expectedHeaders, fetchMeta("dstObject-2")) { + logError(testName, function, args, startTime, "", "Metadata match failed", err) + return + } + + // 6. Compose a pair of sources. + srcs := []minio.SourceInfo{ + minio.NewSourceInfo(bucketName, "srcObject", nil), + minio.NewSourceInfo(bucketName, "srcObject", nil), + } + dst3, err := minio.NewDestinationInfo(bucketName, "dstObject-3", nil, nil) + if err != nil { + logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err) + return + } + + function = "ComposeObject(destination, sources)" + args["source"] = srcs + args["destination"] = dst3 + err = c.ComposeObject(dst3, srcs) + if err != nil { + logError(testName, function, args, startTime, "", "ComposeObject failed", err) + return + } + + // Check that no headers are copied in this case + if !reflect.DeepEqual(make(http.Header), fetchMeta("dstObject-3")) { + logError(testName, function, args, startTime, "", "Metadata match failed", err) + return + } + + // 7. Compose a pair of sources with dest user metadata set. + srcs = []minio.SourceInfo{ + minio.NewSourceInfo(bucketName, "srcObject", nil), + minio.NewSourceInfo(bucketName, "srcObject", nil), + } + dst4, err := minio.NewDestinationInfo(bucketName, "dstObject-4", nil, map[string]string{"notmyheader": "notmyvalue"}) + if err != nil { + logError(testName, function, args, startTime, "", "NewDestinationInfo failed", err) + return + } + + function = "ComposeObject(destination, sources)" + args["source"] = srcs + args["destination"] = dst4 + err = c.ComposeObject(dst4, srcs) + if err != nil { + logError(testName, function, args, startTime, "", "ComposeObject failed", err) + return + } + + // Check that no headers are copied in this case + expectedHeaders = make(http.Header) + expectedHeaders.Set("x-amz-meta-notmyheader", "notmyvalue") + if !reflect.DeepEqual(expectedHeaders, fetchMeta("dstObject-4")) { + logError(testName, function, args, startTime, "", "Metadata match failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +func testUserMetadataCopyingV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "CopyObject(destination, source)" + args := map[string]interface{}{} + + // Instantiate new minio client object + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v2 object creation failed", err) + return + } + + // c.TraceOn(os.Stderr) + testUserMetadataCopyingWrapper(c) +} + +func testStorageClassMetadataPutObject() { + // initialize logging params + startTime := time.Now() + function := "testStorageClassMetadataPutObject()" + args := map[string]interface{}{} + testName := getFuncName() + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v4 client object creation failed", err) + return + } + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test") + // Make a new bucket in 'us-east-1' (source bucket). + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + fetchMeta := func(object string) (h http.Header) { + objInfo, err := c.StatObject(bucketName, object, minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + h = make(http.Header) + for k, vs := range objInfo.Metadata { + if strings.HasPrefix(strings.ToLower(k), "x-amz-storage-class") { + for _, v := range vs { + h.Add(k, v) + } + } + } + return h + } + + metadata := make(http.Header) + metadata.Set("x-amz-storage-class", "REDUCED_REDUNDANCY") + + const srcSize = 1024 * 1024 + buf := bytes.Repeat([]byte("abcde"), srcSize) // gives a buffer of 1MiB + + _, err = c.PutObject(bucketName, "srcObjectRRSClass", + bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{StorageClass: "REDUCED_REDUNDANCY"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + if !reflect.DeepEqual(metadata, fetchMeta("srcObjectRRSClass")) { + logError(testName, function, args, startTime, "", "Metadata match failed", err) + return + } + + metadata = make(http.Header) + metadata.Set("x-amz-storage-class", "STANDARD") + + _, err = c.PutObject(bucketName, "srcObjectSSClass", + bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{StorageClass: "STANDARD"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + if !reflect.DeepEqual(metadata, fetchMeta("srcObjectSSClass")) { + logError(testName, function, args, startTime, "", "Metadata match failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +func testStorageClassInvalidMetadataPutObject() { + // initialize logging params + startTime := time.Now() + function := "testStorageClassInvalidMetadataPutObject()" + args := map[string]interface{}{} + testName := getFuncName() + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v4 client object creation failed", err) + return + } + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test") + // Make a new bucket in 'us-east-1' (source bucket). + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + const srcSize = 1024 * 1024 + buf := bytes.Repeat([]byte("abcde"), srcSize) // gives a buffer of 1MiB + + _, err = c.PutObject(bucketName, "srcObjectRRSClass", + bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{StorageClass: "INVALID_STORAGE_CLASS"}) + if err == nil { + logError(testName, function, args, startTime, "", "PutObject with invalid storage class passed, was expected to fail", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +func testStorageClassMetadataCopyObject() { + // initialize logging params + startTime := time.Now() + function := "testStorageClassMetadataCopyObject()" + args := map[string]interface{}{} + testName := getFuncName() + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio v4 client object creation failed", err) + return + } + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test") + // Make a new bucket in 'us-east-1' (source bucket). + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + fetchMeta := func(object string) (h http.Header) { + objInfo, err := c.StatObject(bucketName, object, minio.StatObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "Stat failed", err) + return + } + h = make(http.Header) + for k, vs := range objInfo.Metadata { + if strings.HasPrefix(strings.ToLower(k), "x-amz-storage-class") { + for _, v := range vs { + h.Add(k, v) + } + } + } + return h + } + + metadata := make(http.Header) + metadata.Set("x-amz-storage-class", "REDUCED_REDUNDANCY") + + const srcSize = 1024 * 1024 + buf := bytes.Repeat([]byte("abcde"), srcSize) + + // Put an object with RRS Storage class + _, err = c.PutObject(bucketName, "srcObjectRRSClass", + bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{StorageClass: "REDUCED_REDUNDANCY"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + // Make server side copy of object uploaded in previous step + src := minio.NewSourceInfo(bucketName, "srcObjectRRSClass", nil) + dst, err := minio.NewDestinationInfo(bucketName, "srcObjectRRSClassCopy", nil, nil) + c.CopyObject(dst, src) + + // Fetch the meta data of copied object + if !reflect.DeepEqual(metadata, fetchMeta("srcObjectRRSClassCopy")) { + logError(testName, function, args, startTime, "", "Metadata match failed", err) + return + } + + metadata = make(http.Header) + metadata.Set("x-amz-storage-class", "STANDARD") + + // Put an object with Standard Storage class + _, err = c.PutObject(bucketName, "srcObjectSSClass", + bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{StorageClass: "STANDARD"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + // Make server side copy of object uploaded in previous step + src = minio.NewSourceInfo(bucketName, "srcObjectSSClass", nil) + dst, err = minio.NewDestinationInfo(bucketName, "srcObjectSSClassCopy", nil, nil) + c.CopyObject(dst, src) + + // Fetch the meta data of copied object + if !reflect.DeepEqual(metadata, fetchMeta("srcObjectSSClassCopy")) { + logError(testName, function, args, startTime, "", "Metadata match failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test put object with size -1 byte object. +func testPutObjectNoLengthV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PutObject(bucketName, objectName, reader, size, opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "size": -1, + "opts": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v2 object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + objectName := bucketName + "unique" + args["objectName"] = objectName + + bufSize := dataFileMap["datafile-65-MB"] + var reader = getDataReader("datafile-65-MB") + defer reader.Close() + args["size"] = bufSize + + // Upload an object. + n, err := c.PutObject(bucketName, objectName, reader, -1, minio.PutObjectOptions{}) + + if err != nil { + logError(testName, function, args, startTime, "", "PutObjectWithSize failed", err) + return + } + if n != int64(bufSize) { + logError(testName, function, args, startTime, "", "Expected upload object size "+string(bufSize)+" got "+string(n), err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test put objects of unknown size. +func testPutObjectsUnknownV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PutObject(bucketName, objectName, reader,size,opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "size": "", + "opts": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v2 object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Issues are revealed by trying to upload multiple files of unknown size + // sequentially (on 4GB machines) + for i := 1; i <= 4; i++ { + // Simulate that we could be receiving byte slices of data that we want + // to upload as a file + rpipe, wpipe := io.Pipe() + defer rpipe.Close() + go func() { + b := []byte("test") + wpipe.Write(b) + wpipe.Close() + }() + + // Upload the object. + objectName := fmt.Sprintf("%sunique%d", bucketName, i) + args["objectName"] = objectName + + n, err := c.PutObject(bucketName, objectName, rpipe, -1, minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObjectStreaming failed", err) + return + } + args["size"] = n + if n != int64(4) { + logError(testName, function, args, startTime, "", "Expected upload object size "+string(4)+" got "+string(n), err) + return + } + + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test put object with 0 byte object. +func testPutObject0ByteV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PutObject(bucketName, objectName, reader, size, opts)" + args := map[string]interface{}{ + "bucketName": "", + "objectName": "", + "size": 0, + "opts": "", + } + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v2 object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + objectName := bucketName + "unique" + args["objectName"] = objectName + args["opts"] = minio.PutObjectOptions{} + + // Upload an object. + n, err := c.PutObject(bucketName, objectName, bytes.NewReader([]byte("")), 0, minio.PutObjectOptions{}) + + if err != nil { + logError(testName, function, args, startTime, "", "PutObjectWithSize failed", err) + return + } + if n != 0 { + logError(testName, function, args, startTime, "", "Expected upload object size 0 but got "+string(n), err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() +} + +// Test expected error cases +func testComposeObjectErrorCases() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "ComposeObject(destination, sourceList)" + args := map[string]interface{}{} + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + testComposeObjectErrorCasesWrapper(c) +} + +// Test concatenating 10K objects +func testCompose10KSources() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "ComposeObject(destination, sourceList)" + args := map[string]interface{}{} + + // Instantiate new minio client object + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client object creation failed", err) + return + } + + testComposeMultipleSources(c) +} + +// Tests comprehensive list of all methods. +func testFunctionalV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "testFunctionalV2()" + function_all := "" + args := map[string]interface{}{} + + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v2 object creation failed", err) + return + } + + // Enable to debug + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + location := "us-east-1" + // Make a new bucket. + function = "MakeBucket(bucketName, location)" + function_all = "MakeBucket(bucketName, location)" + args = map[string]interface{}{ + "bucketName": bucketName, + "location": location, + } + err = c.MakeBucket(bucketName, location) + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + // Generate a random file name. + fileName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + file, err := os.Create(fileName) + if err != nil { + logError(testName, function, args, startTime, "", "file create failed", err) + return + } + for i := 0; i < 3; i++ { + buf := make([]byte, rand.Intn(1<<19)) + _, err = file.Write(buf) + if err != nil { + logError(testName, function, args, startTime, "", "file write failed", err) + return + } + } + file.Close() + + // Verify if bucket exits and you have access. + var exists bool + function = "BucketExists(bucketName)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + } + exists, err = c.BucketExists(bucketName) + if err != nil { + logError(testName, function, args, startTime, "", "BucketExists failed", err) + return + } + if !exists { + logError(testName, function, args, startTime, "", "Could not find existing bucket "+bucketName, err) + return + } + + // Make the bucket 'public read/write'. + function = "SetBucketPolicy(bucketName, objectPrefix, bucketPolicy)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectPrefix": "", + "bucketPolicy": policy.BucketPolicyReadWrite, + } + err = c.SetBucketPolicy(bucketName, "", policy.BucketPolicyReadWrite) + if err != nil { + logError(testName, function, args, startTime, "", "SetBucketPolicy failed", err) + return + } + + // List all buckets. + function = "ListBuckets()" + function_all += ", " + function + args = nil + buckets, err := c.ListBuckets() + if len(buckets) == 0 { + logError(testName, function, args, startTime, "", "List buckets cannot be empty", err) + return + } + if err != nil { + logError(testName, function, args, startTime, "", "ListBuckets failed", err) + return + } + + // Verify if previously created bucket is listed in list buckets. + bucketFound := false + for _, bucket := range buckets { + if bucket.Name == bucketName { + bucketFound = true + } + } + + // If bucket not found error out. + if !bucketFound { + logError(testName, function, args, startTime, "", "Bucket "+bucketName+"not found", err) + return + } + + objectName := bucketName + "unique" + + // Generate data + buf := bytes.Repeat([]byte("n"), rand.Intn(1<<19)) + + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "contentType": "", + } + n, err := c.PutObject(bucketName, objectName, bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + if n != int64(len(buf)) { + logError(testName, function, args, startTime, "", "Expected uploaded object length "+string(len(buf))+" got "+string(n), err) + return + } + + objectName_noLength := objectName + "-nolength" + args["objectName"] = objectName_noLength + n, err = c.PutObject(bucketName, objectName_noLength, bytes.NewReader(buf), int64(len(buf)), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + if n != int64(len(buf)) { + logError(testName, function, args, startTime, "", "Expected uploaded object length "+string(len(buf))+" got "+string(n), err) + return + } + + // Instantiate a done channel to close all listing. + doneCh := make(chan struct{}) + defer close(doneCh) + + objFound := false + isRecursive := true // Recursive is true. + function = "ListObjects(bucketName, objectName, isRecursive, doneCh)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "isRecursive": isRecursive, + } + for obj := range c.ListObjects(bucketName, objectName, isRecursive, doneCh) { + if obj.Key == objectName { + objFound = true + break + } + } + if !objFound { + logError(testName, function, args, startTime, "", "Could not find existing object "+objectName, err) + return + } + + incompObjNotFound := true + function = "ListIncompleteUploads(bucketName, objectName, isRecursive, doneCh)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "isRecursive": isRecursive, + } + for objIncompl := range c.ListIncompleteUploads(bucketName, objectName, isRecursive, doneCh) { + if objIncompl.Key != "" { + incompObjNotFound = false + break + } + } + if !incompObjNotFound { + logError(testName, function, args, startTime, "", "Unexpected dangling incomplete upload found", err) + return + } + + function = "GetObject(bucketName, objectName)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + } + newReader, err := c.GetObject(bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + newReadBytes, err := ioutil.ReadAll(newReader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + + if !bytes.Equal(newReadBytes, buf) { + logError(testName, function, args, startTime, "", "Bytes mismatch", err) + return + } + + function = "FGetObject(bucketName, objectName, fileName)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "fileName": fileName + "-f", + } + err = c.FGetObject(bucketName, objectName, fileName+"-f", minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "FgetObject failed", err) + return + } + + // Generate presigned HEAD object url. + function = "PresignedHeadObject(bucketName, objectName, expires, reqParams)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "expires": 3600 * time.Second, + } + presignedHeadURL, err := c.PresignedHeadObject(bucketName, objectName, 3600*time.Second, nil) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedHeadObject failed", err) + return + } + // Verify if presigned url works. + resp, err := http.Head(presignedHeadURL.String()) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedHeadObject URL head request failed", err) + return + } + if resp.StatusCode != http.StatusOK { + logError(testName, function, args, startTime, "", "PresignedHeadObject URL returns status "+string(resp.StatusCode), err) + return + } + if resp.Header.Get("ETag") == "" { + logError(testName, function, args, startTime, "", "Got empty ETag", err) + return + } + resp.Body.Close() + + // Generate presigned GET object url. + function = "PresignedGetObject(bucketName, objectName, expires, reqParams)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName, + "expires": 3600 * time.Second, + } + presignedGetURL, err := c.PresignedGetObject(bucketName, objectName, 3600*time.Second, nil) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject failed", err) + return + } + // Verify if presigned url works. + resp, err = http.Get(presignedGetURL.String()) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject URL GET request failed", err) + return + } + if resp.StatusCode != http.StatusOK { + logError(testName, function, args, startTime, "", "PresignedGetObject URL returns status "+string(resp.StatusCode), err) + return + } + newPresignedBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + resp.Body.Close() + if !bytes.Equal(newPresignedBytes, buf) { + logError(testName, function, args, startTime, "", "Bytes mismatch", err) + return + } + + // Set request parameters. + reqParams := make(url.Values) + reqParams.Set("response-content-disposition", "attachment; filename=\"test.txt\"") + // Generate presigned GET object url. + args["reqParams"] = reqParams + presignedGetURL, err = c.PresignedGetObject(bucketName, objectName, 3600*time.Second, reqParams) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject failed", err) + return + } + // Verify if presigned url works. + resp, err = http.Get(presignedGetURL.String()) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedGetObject URL GET request failed", err) + return + } + if resp.StatusCode != http.StatusOK { + logError(testName, function, args, startTime, "", "PresignedGetObject URL returns status "+string(resp.StatusCode), err) + return + } + newPresignedBytes, err = ioutil.ReadAll(resp.Body) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + if !bytes.Equal(newPresignedBytes, buf) { + logError(testName, function, args, startTime, "", "Bytes mismatch", err) + return + } + // Verify content disposition. + if resp.Header.Get("Content-Disposition") != "attachment; filename=\"test.txt\"" { + logError(testName, function, args, startTime, "", "wrong Content-Disposition received ", err) + return + } + + function = "PresignedPutObject(bucketName, objectName, expires)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName + "-presigned", + "expires": 3600 * time.Second, + } + presignedPutURL, err := c.PresignedPutObject(bucketName, objectName+"-presigned", 3600*time.Second) + if err != nil { + logError(testName, function, args, startTime, "", "PresignedPutObject failed", err) + return + } + + // Generate data more than 32K + buf = bytes.Repeat([]byte("1"), rand.Intn(1<<10)+32*1024) + + req, err := http.NewRequest("PUT", presignedPutURL.String(), bytes.NewReader(buf)) + if err != nil { + logError(testName, function, args, startTime, "", "HTTP request to PresignedPutObject URL failed", err) + return + } + httpClient := &http.Client{ + // Setting a sensible time out of 30secs to wait for response + // headers. Request is pro-actively cancelled after 30secs + // with no response. + Timeout: 30 * time.Second, + Transport: http.DefaultTransport, + } + resp, err = httpClient.Do(req) + if err != nil { + logError(testName, function, args, startTime, "", "HTTP request to PresignedPutObject URL failed", err) + return + } + + function = "GetObject(bucketName, objectName)" + function_all += ", " + function + args = map[string]interface{}{ + "bucketName": bucketName, + "objectName": objectName + "-presigned", + } + newReader, err = c.GetObject(bucketName, objectName+"-presigned", minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObject failed", err) + return + } + + newReadBytes, err = ioutil.ReadAll(newReader) + if err != nil { + logError(testName, function, args, startTime, "", "ReadAll failed", err) + return + } + + if !bytes.Equal(newReadBytes, buf) { + logError(testName, function, args, startTime, "", "Bytes mismatch", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + if err = os.Remove(fileName); err != nil { + logError(testName, function, args, startTime, "", "File remove failed", err) + return + } + if err = os.Remove(fileName + "-f"); err != nil { + logError(testName, function, args, startTime, "", "File removes failed", err) + return + } + successLogger(testName, function_all, args, startTime).Info() +} + +// Test get object with GetObjectWithContext +func testGetObjectWithContext() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "GetObjectWithContext(ctx, bucketName, objectName)" + args := map[string]interface{}{ + "ctx": "", + "bucketName": "", + "objectName": "", + } + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v4 object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + _, err = c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) + args["ctx"] = ctx + defer cancel() + + r, err := c.GetObjectWithContext(ctx, bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObjectWithContext failed unexpectedly", err) + return + } + if _, err = r.Stat(); err == nil { + logError(testName, function, args, startTime, "", "GetObjectWithContext should fail on short timeout", err) + return + } + + ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) + args["ctx"] = ctx + defer cancel() + + // Read the data back + r, err = c.GetObjectWithContext(ctx, bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObjectWithContext failed", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "object Stat call failed", err) + return + } + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes in stat does not match: want "+string(bufSize)+", got"+string(st.Size), err) + return + } + if err := r.Close(); err != nil { + logError(testName, function, args, startTime, "", "object Close() call failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() + +} + +// Test get object with FGetObjectWithContext +func testFGetObjectWithContext() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "FGetObjectWithContext(ctx, bucketName, objectName, fileName)" + args := map[string]interface{}{ + "ctx": "", + "bucketName": "", + "objectName": "", + "fileName": "", + } + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV4( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v4 object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + bufSize := dataFileMap["datafile-1-MB"] + var reader = getDataReader("datafile-1-MB") + defer reader.Close() + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + _, err = c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject failed", err) + return + } + + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) + args["ctx"] = ctx + defer cancel() + + fileName := "tempfile-context" + args["fileName"] = fileName + // Read the data back + err = c.FGetObjectWithContext(ctx, bucketName, objectName, fileName+"-f", minio.GetObjectOptions{}) + if err == nil { + logError(testName, function, args, startTime, "", "FGetObjectWithContext should fail on short timeout", err) + return + } + ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) + defer cancel() + + // Read the data back + err = c.FGetObjectWithContext(ctx, bucketName, objectName, fileName+"-fcontext", minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "FGetObjectWithContext with long timeout failed", err) + return + } + if err = os.Remove(fileName + "-fcontext"); err != nil { + logError(testName, function, args, startTime, "", "Remove file failed", err) + return + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() + +} + +// Test validates putObject with context to see if request cancellation is honored for V2. +func testPutObjectWithContextV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "PutObjectWithContext(ctx, bucketName, objectName, reader, size, opts)" + args := map[string]interface{}{ + "ctx": "", + "bucketName": "", + "objectName": "", + "size": "", + "opts": "", + } + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v2 object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Make a new bucket. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + defer c.RemoveBucket(bucketName) + bufSize := dataFileMap["datatfile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + + objectName := fmt.Sprintf("test-file-%v", rand.Uint32()) + args["objectName"] = objectName + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + args["ctx"] = ctx + args["size"] = bufSize + defer cancel() + + _, err = c.PutObjectWithContext(ctx, bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObjectWithContext with short timeout failed", err) + return + } + + ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) + args["ctx"] = ctx + + defer cancel() + reader = getDataReader("datafile-33-kB") + defer reader.Close() + _, err = c.PutObjectWithContext(ctx, bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObjectWithContext with long timeout failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() + +} + +// Test get object with GetObjectWithContext +func testGetObjectWithContextV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "GetObjectWithContext(ctx, bucketName, objectName)" + args := map[string]interface{}{ + "ctx": "", + "bucketName": "", + "objectName": "", + } + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v2 object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket failed", err) + return + } + + bufSize := dataFileMap["datafile-33-kB"] + var reader = getDataReader("datafile-33-kB") + defer reader.Close() + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + _, err = c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject call failed", err) + return + } + + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) + args["ctx"] = ctx + defer cancel() + + r, err := c.GetObjectWithContext(ctx, bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObjectWithContext failed unexpectedly", err) + return + } + if _, err = r.Stat(); err == nil { + logError(testName, function, args, startTime, "", "GetObjectWithContext should fail on short timeout", err) + return + } + + ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) + defer cancel() + + // Read the data back + r, err = c.GetObjectWithContext(ctx, bucketName, objectName, minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "GetObjectWithContext shouldn't fail on longer timeout", err) + return + } + + st, err := r.Stat() + if err != nil { + logError(testName, function, args, startTime, "", "object Stat call failed", err) + return + } + if st.Size != int64(bufSize) { + logError(testName, function, args, startTime, "", "Number of bytes in stat does not match, expected "+string(bufSize)+" got "+string(st.Size), err) + return + } + if err := r.Close(); err != nil { + logError(testName, function, args, startTime, "", " object Close() call failed", err) + return + } + + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() + +} + +// Test get object with FGetObjectWithContext +func testFGetObjectWithContextV2() { + // initialize logging params + startTime := time.Now() + testName := getFuncName() + function := "FGetObjectWithContext(ctx, bucketName, objectName,fileName)" + args := map[string]interface{}{ + "ctx": "", + "bucketName": "", + "objectName": "", + "fileName": "", + } + // Seed random based on current time. + rand.Seed(time.Now().Unix()) + + // Instantiate new minio client object. + c, err := minio.NewV2( + os.Getenv(serverEndpoint), + os.Getenv(accessKey), + os.Getenv(secretKey), + mustParseBool(os.Getenv(enableHTTPS)), + ) + if err != nil { + logError(testName, function, args, startTime, "", "Minio client v2 object creation failed", err) + return + } + + // Enable tracing, write to stderr. + // c.TraceOn(os.Stderr) + + // Set user agent. + c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0") + + // Generate a new random bucket name. + bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") + args["bucketName"] = bucketName + + // Make a new bucket. + err = c.MakeBucket(bucketName, "us-east-1") + if err != nil { + logError(testName, function, args, startTime, "", "MakeBucket call failed", err) + return + } + + bufSize := dataFileMap["datatfile-1-MB"] + var reader = getDataReader("datafile-1-MB") + defer reader.Close() + // Save the data + objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") + args["objectName"] = objectName + + _, err = c.PutObject(bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) + if err != nil { + logError(testName, function, args, startTime, "", "PutObject call failed", err) + return + } + + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) + args["ctx"] = ctx + defer cancel() + + fileName := "tempfile-context" + args["fileName"] = fileName + + // Read the data back + err = c.FGetObjectWithContext(ctx, bucketName, objectName, fileName+"-f", minio.GetObjectOptions{}) + if err == nil { + logError(testName, function, args, startTime, "", "FGetObjectWithContext should fail on short timeout", err) + return + } + ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) + defer cancel() + + // Read the data back + err = c.FGetObjectWithContext(ctx, bucketName, objectName, fileName+"-fcontext", minio.GetObjectOptions{}) + if err != nil { + logError(testName, function, args, startTime, "", "FGetObjectWithContext call shouldn't fail on long timeout", err) + return + } + + if err = os.Remove(fileName + "-fcontext"); err != nil { + logError(testName, function, args, startTime, "", "Remove file failed", err) + return + } + // Delete all objects and buckets + if err = cleanupBucket(bucketName, c); err != nil { + logError(testName, function, args, startTime, "", "Cleanup failed", err) + return + } + + successLogger(testName, function, args, startTime).Info() + +} + +// Convert string to bool and always return false if any error +func mustParseBool(str string) bool { + b, err := strconv.ParseBool(str) + if err != nil { + return false + } + return b +} + +func main() { + // Output to stdout instead of the default stderr + log.SetOutput(os.Stdout) + // create custom formatter + mintFormatter := mintJSONFormatter{} + // set custom formatter + log.SetFormatter(&mintFormatter) + // log Info or above -- success cases are Info level, failures are Fatal level + log.SetLevel(log.InfoLevel) + + tls := mustParseBool(os.Getenv(enableHTTPS)) + // execute tests + if !isQuickMode() { + testMakeBucketErrorV2() + testGetObjectClosedTwiceV2() + testRemovePartiallyUploadedV2() + testFPutObjectV2() + testMakeBucketRegionsV2() + testGetObjectReadSeekFunctionalV2() + testGetObjectReadAtFunctionalV2() + testCopyObjectV2() + testFunctionalV2() + testComposeObjectErrorCasesV2() + testCompose10KSourcesV2() + testUserMetadataCopyingV2() + testPutObject0ByteV2() + testPutObjectNoLengthV2() + testPutObjectsUnknownV2() + testGetObjectWithContextV2() + testFPutObjectWithContextV2() + testFGetObjectWithContextV2() + testPutObjectWithContextV2() + testMakeBucketError() + testMakeBucketRegions() + testPutObjectWithMetadata() + testPutObjectReadAt() + testPutObjectStreaming() + testListPartiallyUploaded() + testGetObjectSeekEnd() + testGetObjectClosedTwice() + testRemoveMultipleObjects() + testRemovePartiallyUploaded() + testFPutObjectMultipart() + testFPutObject() + testGetObjectReadSeekFunctional() + testGetObjectReadAtFunctional() + testPresignedPostPolicy() + testCopyObject() + testEncryptionPutGet() + testEncryptionFPut() + testComposeObjectErrorCases() + testCompose10KSources() + testUserMetadataCopying() + testBucketNotification() + testFunctional() + testGetObjectModified() + testPutObjectUploadSeekedObject() + testGetObjectWithContext() + testFPutObjectWithContext() + testFGetObjectWithContext() + testPutObjectWithContext() + testStorageClassMetadataPutObject() + testStorageClassInvalidMetadataPutObject() + testStorageClassMetadataCopyObject() + + // SSE-C tests will only work over TLS connection. + if tls { + testEncryptedCopyObjectV2() + testEncryptedCopyObject() + } + } else { + testFunctional() + testFunctionalV2() + } +} diff --git a/vendor/github.com/minio/minio-go/hook-reader.go b/vendor/github.com/minio/minio-go/hook-reader.go new file mode 100644 index 000000000..8f32291d4 --- /dev/null +++ b/vendor/github.com/minio/minio-go/hook-reader.go @@ -0,0 +1,71 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import "io" + +// hookReader hooks additional reader in the source stream. It is +// useful for making progress bars. Second reader is appropriately +// notified about the exact number of bytes read from the primary +// source on each Read operation. +type hookReader struct { + source io.Reader + hook io.Reader +} + +// Seek implements io.Seeker. Seeks source first, and if necessary +// seeks hook if Seek method is appropriately found. +func (hr *hookReader) Seek(offset int64, whence int) (n int64, err error) { + // Verify for source has embedded Seeker, use it. + sourceSeeker, ok := hr.source.(io.Seeker) + if ok { + return sourceSeeker.Seek(offset, whence) + } + // Verify if hook has embedded Seeker, use it. + hookSeeker, ok := hr.hook.(io.Seeker) + if ok { + return hookSeeker.Seek(offset, whence) + } + return n, nil +} + +// Read implements io.Reader. Always reads from the source, the return +// value 'n' number of bytes are reported through the hook. Returns +// error for all non io.EOF conditions. +func (hr *hookReader) Read(b []byte) (n int, err error) { + n, err = hr.source.Read(b) + if err != nil && err != io.EOF { + return n, err + } + // Progress the hook with the total read bytes from the source. + if _, herr := hr.hook.Read(b[:n]); herr != nil { + if herr != io.EOF { + return n, herr + } + } + return n, err +} + +// newHook returns a io.ReadSeeker which implements hookReader that +// reports the data read from the source to the hook. +func newHook(source, hook io.Reader) io.Reader { + if hook == nil { + return source + } + return &hookReader{source, hook} +} diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/chain.go b/vendor/github.com/minio/minio-go/pkg/credentials/chain.go new file mode 100644 index 000000000..e29826f48 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/chain.go @@ -0,0 +1,89 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package credentials + +// A Chain will search for a provider which returns credentials +// and cache that provider until Retrieve is called again. +// +// The Chain provides a way of chaining multiple providers together +// which will pick the first available using priority order of the +// Providers in the list. +// +// If none of the Providers retrieve valid credentials Value, ChainProvider's +// Retrieve() will return the no credentials value. +// +// If a Provider is found which returns valid credentials Value ChainProvider +// will cache that Provider for all calls to IsExpired(), until Retrieve is +// called again after IsExpired() is true. +// +// creds := credentials.NewChainCredentials( +// []credentials.Provider{ +// &credentials.EnvAWSS3{}, +// &credentials.EnvMinio{}, +// }) +// +// // Usage of ChainCredentials. +// mc, err := minio.NewWithCredentials(endpoint, creds, secure, "us-east-1") +// if err != nil { +// log.Fatalln(err) +// } +// +type Chain struct { + Providers []Provider + curr Provider +} + +// NewChainCredentials returns a pointer to a new Credentials object +// wrapping a chain of providers. +func NewChainCredentials(providers []Provider) *Credentials { + return New(&Chain{ + Providers: append([]Provider{}, providers...), + }) +} + +// Retrieve returns the credentials value, returns no credentials(anonymous) +// if no credentials provider returned any value. +// +// If a provider is found with credentials, it will be cached and any calls +// to IsExpired() will return the expired state of the cached provider. +func (c *Chain) Retrieve() (Value, error) { + for _, p := range c.Providers { + creds, _ := p.Retrieve() + // Always prioritize non-anonymous providers, if any. + if creds.AccessKeyID == "" && creds.SecretAccessKey == "" { + continue + } + c.curr = p + return creds, nil + } + // At this point we have exhausted all the providers and + // are left without any credentials return anonymous. + return Value{ + SignerType: SignatureAnonymous, + }, nil +} + +// IsExpired will returned the expired state of the currently cached provider +// if there is one. If there is no current provider, true will be returned. +func (c *Chain) IsExpired() bool { + if c.curr != nil { + return c.curr.IsExpired() + } + + return true +} diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/credentials.go b/vendor/github.com/minio/minio-go/pkg/credentials/credentials.go new file mode 100644 index 000000000..4bfdad413 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/credentials.go @@ -0,0 +1,175 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package credentials + +import ( + "sync" + "time" +) + +// A Value is the AWS credentials value for individual credential fields. +type Value struct { + // AWS Access key ID + AccessKeyID string + + // AWS Secret Access Key + SecretAccessKey string + + // AWS Session Token + SessionToken string + + // Signature Type. + SignerType SignatureType +} + +// A Provider is the interface for any component which will provide credentials +// Value. A provider is required to manage its own Expired state, and what to +// be expired means. +type Provider interface { + // Retrieve returns nil if it successfully retrieved the value. + // Error is returned if the value were not obtainable, or empty. + Retrieve() (Value, error) + + // IsExpired returns if the credentials are no longer valid, and need + // to be retrieved. + IsExpired() bool +} + +// A Expiry provides shared expiration logic to be used by credentials +// providers to implement expiry functionality. +// +// The best method to use this struct is as an anonymous field within the +// provider's struct. +// +// Example: +// type IAMCredentialProvider struct { +// Expiry +// ... +// } +type Expiry struct { + // The date/time when to expire on + expiration time.Time + + // If set will be used by IsExpired to determine the current time. + // Defaults to time.Now if CurrentTime is not set. + CurrentTime func() time.Time +} + +// SetExpiration sets the expiration IsExpired will check when called. +// +// If window is greater than 0 the expiration time will be reduced by the +// window value. +// +// Using a window is helpful to trigger credentials to expire sooner than +// the expiration time given to ensure no requests are made with expired +// tokens. +func (e *Expiry) SetExpiration(expiration time.Time, window time.Duration) { + e.expiration = expiration + if window > 0 { + e.expiration = e.expiration.Add(-window) + } +} + +// IsExpired returns if the credentials are expired. +func (e *Expiry) IsExpired() bool { + if e.CurrentTime == nil { + e.CurrentTime = time.Now + } + return e.expiration.Before(e.CurrentTime()) +} + +// Credentials - A container for synchronous safe retrieval of credentials Value. +// Credentials will cache the credentials value until they expire. Once the value +// expires the next Get will attempt to retrieve valid credentials. +// +// Credentials is safe to use across multiple goroutines and will manage the +// synchronous state so the Providers do not need to implement their own +// synchronization. +// +// The first Credentials.Get() will always call Provider.Retrieve() to get the +// first instance of the credentials Value. All calls to Get() after that +// will return the cached credentials Value until IsExpired() returns true. +type Credentials struct { + sync.Mutex + + creds Value + forceRefresh bool + provider Provider +} + +// New returns a pointer to a new Credentials with the provider set. +func New(provider Provider) *Credentials { + return &Credentials{ + provider: provider, + forceRefresh: true, + } +} + +// Get returns the credentials value, or error if the credentials Value failed +// to be retrieved. +// +// Will return the cached credentials Value if it has not expired. If the +// credentials Value has expired the Provider's Retrieve() will be called +// to refresh the credentials. +// +// If Credentials.Expire() was called the credentials Value will be force +// expired, and the next call to Get() will cause them to be refreshed. +func (c *Credentials) Get() (Value, error) { + c.Lock() + defer c.Unlock() + + if c.isExpired() { + creds, err := c.provider.Retrieve() + if err != nil { + return Value{}, err + } + c.creds = creds + c.forceRefresh = false + } + + return c.creds, nil +} + +// Expire expires the credentials and forces them to be retrieved on the +// next call to Get(). +// +// This will override the Provider's expired state, and force Credentials +// to call the Provider's Retrieve(). +func (c *Credentials) Expire() { + c.Lock() + defer c.Unlock() + + c.forceRefresh = true +} + +// IsExpired returns if the credentials are no longer valid, and need +// to be refreshed. +// +// If the Credentials were forced to be expired with Expire() this will +// reflect that override. +func (c *Credentials) IsExpired() bool { + c.Lock() + defer c.Unlock() + + return c.isExpired() +} + +// isExpired helper method wrapping the definition of expired credentials. +func (c *Credentials) isExpired() bool { + return c.forceRefresh || c.provider.IsExpired() +} diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/doc.go b/vendor/github.com/minio/minio-go/pkg/credentials/doc.go new file mode 100644 index 000000000..c48784ba8 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/doc.go @@ -0,0 +1,62 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Package credentials provides credential retrieval and management +// for S3 compatible object storage. +// +// By default the Credentials.Get() will cache the successful result of a +// Provider's Retrieve() until Provider.IsExpired() returns true. At which +// point Credentials will call Provider's Retrieve() to get new credential Value. +// +// The Provider is responsible for determining when credentials have expired. +// It is also important to note that Credentials will always call Retrieve the +// first time Credentials.Get() is called. +// +// Example of using the environment variable credentials. +// +// creds := NewFromEnv() +// // Retrieve the credentials value +// credValue, err := creds.Get() +// if err != nil { +// // handle error +// } +// +// Example of forcing credentials to expire and be refreshed on the next Get(). +// This may be helpful to proactively expire credentials and refresh them sooner +// than they would naturally expire on their own. +// +// creds := NewFromIAM("") +// creds.Expire() +// credsValue, err := creds.Get() +// // New credentials will be retrieved instead of from cache. +// +// +// Custom Provider +// +// Each Provider built into this package also provides a helper method to generate +// a Credentials pointer setup with the provider. To use a custom Provider just +// create a type which satisfies the Provider interface and pass it to the +// NewCredentials method. +// +// type MyProvider struct{} +// func (m *MyProvider) Retrieve() (Value, error) {...} +// func (m *MyProvider) IsExpired() bool {...} +// +// creds := NewCredentials(&MyProvider{}) +// credValue, err := creds.Get() +// +package credentials diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/env_aws.go b/vendor/github.com/minio/minio-go/pkg/credentials/env_aws.go new file mode 100644 index 000000000..f9b2cc33a --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/env_aws.go @@ -0,0 +1,71 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package credentials + +import "os" + +// A EnvAWS retrieves credentials from the environment variables of the +// running process. EnvAWSironment credentials never expire. +// +// EnvAWSironment variables used: +// +// * Access Key ID: AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY. +// * Secret Access Key: AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY. +// * Secret Token: AWS_SESSION_TOKEN. +type EnvAWS struct { + retrieved bool +} + +// NewEnvAWS returns a pointer to a new Credentials object +// wrapping the environment variable provider. +func NewEnvAWS() *Credentials { + return New(&EnvAWS{}) +} + +// Retrieve retrieves the keys from the environment. +func (e *EnvAWS) Retrieve() (Value, error) { + e.retrieved = false + + id := os.Getenv("AWS_ACCESS_KEY_ID") + if id == "" { + id = os.Getenv("AWS_ACCESS_KEY") + } + + secret := os.Getenv("AWS_SECRET_ACCESS_KEY") + if secret == "" { + secret = os.Getenv("AWS_SECRET_KEY") + } + + signerType := SignatureV4 + if id == "" || secret == "" { + signerType = SignatureAnonymous + } + + e.retrieved = true + return Value{ + AccessKeyID: id, + SecretAccessKey: secret, + SessionToken: os.Getenv("AWS_SESSION_TOKEN"), + SignerType: signerType, + }, nil +} + +// IsExpired returns if the credentials have been retrieved. +func (e *EnvAWS) IsExpired() bool { + return !e.retrieved +} diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/env_minio.go b/vendor/github.com/minio/minio-go/pkg/credentials/env_minio.go new file mode 100644 index 000000000..d72e77185 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/env_minio.go @@ -0,0 +1,62 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package credentials + +import "os" + +// A EnvMinio retrieves credentials from the environment variables of the +// running process. EnvMinioironment credentials never expire. +// +// EnvMinioironment variables used: +// +// * Access Key ID: MINIO_ACCESS_KEY. +// * Secret Access Key: MINIO_SECRET_KEY. +type EnvMinio struct { + retrieved bool +} + +// NewEnvMinio returns a pointer to a new Credentials object +// wrapping the environment variable provider. +func NewEnvMinio() *Credentials { + return New(&EnvMinio{}) +} + +// Retrieve retrieves the keys from the environment. +func (e *EnvMinio) Retrieve() (Value, error) { + e.retrieved = false + + id := os.Getenv("MINIO_ACCESS_KEY") + secret := os.Getenv("MINIO_SECRET_KEY") + + signerType := SignatureV4 + if id == "" || secret == "" { + signerType = SignatureAnonymous + } + + e.retrieved = true + return Value{ + AccessKeyID: id, + SecretAccessKey: secret, + SignerType: signerType, + }, nil +} + +// IsExpired returns if the credentials have been retrieved. +func (e *EnvMinio) IsExpired() bool { + return !e.retrieved +} diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/file_aws_credentials.go b/vendor/github.com/minio/minio-go/pkg/credentials/file_aws_credentials.go new file mode 100644 index 000000000..5ad68303a --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/file_aws_credentials.go @@ -0,0 +1,120 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package credentials + +import ( + "os" + "path/filepath" + + "github.com/go-ini/ini" + homedir "github.com/mitchellh/go-homedir" +) + +// A FileAWSCredentials retrieves credentials from the current user's home +// directory, and keeps track if those credentials are expired. +// +// Profile ini file example: $HOME/.aws/credentials +type FileAWSCredentials struct { + // Path to the shared credentials file. + // + // If empty will look for "AWS_SHARED_CREDENTIALS_FILE" env variable. If the + // env value is empty will default to current user's home directory. + // Linux/OSX: "$HOME/.aws/credentials" + // Windows: "%USERPROFILE%\.aws\credentials" + filename string + + // AWS Profile to extract credentials from the shared credentials file. If empty + // will default to environment variable "AWS_PROFILE" or "default" if + // environment variable is also not set. + profile string + + // retrieved states if the credentials have been successfully retrieved. + retrieved bool +} + +// NewFileAWSCredentials returns a pointer to a new Credentials object +// wrapping the Profile file provider. +func NewFileAWSCredentials(filename string, profile string) *Credentials { + return New(&FileAWSCredentials{ + filename: filename, + profile: profile, + }) +} + +// Retrieve reads and extracts the shared credentials from the current +// users home directory. +func (p *FileAWSCredentials) Retrieve() (Value, error) { + if p.filename == "" { + p.filename = os.Getenv("AWS_SHARED_CREDENTIALS_FILE") + if p.filename == "" { + homeDir, err := homedir.Dir() + if err != nil { + return Value{}, err + } + p.filename = filepath.Join(homeDir, ".aws", "credentials") + } + } + if p.profile == "" { + p.profile = os.Getenv("AWS_PROFILE") + if p.profile == "" { + p.profile = "default" + } + } + + p.retrieved = false + + iniProfile, err := loadProfile(p.filename, p.profile) + if err != nil { + return Value{}, err + } + + // Default to empty string if not found. + id := iniProfile.Key("aws_access_key_id") + // Default to empty string if not found. + secret := iniProfile.Key("aws_secret_access_key") + // Default to empty string if not found. + token := iniProfile.Key("aws_session_token") + + p.retrieved = true + return Value{ + AccessKeyID: id.String(), + SecretAccessKey: secret.String(), + SessionToken: token.String(), + SignerType: SignatureV4, + }, nil +} + +// IsExpired returns if the shared credentials have expired. +func (p *FileAWSCredentials) IsExpired() bool { + return !p.retrieved +} + +// loadProfiles loads from the file pointed to by shared credentials filename for profile. +// The credentials retrieved from the profile will be returned or error. Error will be +// returned if it fails to read from the file, or the data is invalid. +func loadProfile(filename, profile string) (*ini.Section, error) { + config, err := ini.Load(filename) + if err != nil { + return nil, err + } + iniProfile, err := config.GetSection(profile) + if err != nil { + return nil, err + } + return iniProfile, nil +} diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/file_minio_client.go b/vendor/github.com/minio/minio-go/pkg/credentials/file_minio_client.go new file mode 100644 index 000000000..c282c2a2c --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/file_minio_client.go @@ -0,0 +1,129 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package credentials + +import ( + "encoding/json" + "io/ioutil" + "os" + "path/filepath" + "runtime" + + homedir "github.com/mitchellh/go-homedir" +) + +// A FileMinioClient retrieves credentials from the current user's home +// directory, and keeps track if those credentials are expired. +// +// Configuration file example: $HOME/.mc/config.json +type FileMinioClient struct { + // Path to the shared credentials file. + // + // If empty will look for "MINIO_SHARED_CREDENTIALS_FILE" env variable. If the + // env value is empty will default to current user's home directory. + // Linux/OSX: "$HOME/.mc/config.json" + // Windows: "%USERALIAS%\mc\config.json" + filename string + + // Minio Alias to extract credentials from the shared credentials file. If empty + // will default to environment variable "MINIO_ALIAS" or "default" if + // environment variable is also not set. + alias string + + // retrieved states if the credentials have been successfully retrieved. + retrieved bool +} + +// NewFileMinioClient returns a pointer to a new Credentials object +// wrapping the Alias file provider. +func NewFileMinioClient(filename string, alias string) *Credentials { + return New(&FileMinioClient{ + filename: filename, + alias: alias, + }) +} + +// Retrieve reads and extracts the shared credentials from the current +// users home directory. +func (p *FileMinioClient) Retrieve() (Value, error) { + if p.filename == "" { + homeDir, err := homedir.Dir() + if err != nil { + return Value{}, err + } + p.filename = filepath.Join(homeDir, ".mc", "config.json") + if runtime.GOOS == "windows" { + p.filename = filepath.Join(homeDir, "mc", "config.json") + } + } + + if p.alias == "" { + p.alias = os.Getenv("MINIO_ALIAS") + if p.alias == "" { + p.alias = "s3" + } + } + + p.retrieved = false + + hostCfg, err := loadAlias(p.filename, p.alias) + if err != nil { + return Value{}, err + } + + p.retrieved = true + return Value{ + AccessKeyID: hostCfg.AccessKey, + SecretAccessKey: hostCfg.SecretKey, + SignerType: parseSignatureType(hostCfg.API), + }, nil +} + +// IsExpired returns if the shared credentials have expired. +func (p *FileMinioClient) IsExpired() bool { + return !p.retrieved +} + +// hostConfig configuration of a host. +type hostConfig struct { + URL string `json:"url"` + AccessKey string `json:"accessKey"` + SecretKey string `json:"secretKey"` + API string `json:"api"` +} + +// config config version. +type config struct { + Version string `json:"version"` + Hosts map[string]hostConfig `json:"hosts"` +} + +// loadAliass loads from the file pointed to by shared credentials filename for alias. +// The credentials retrieved from the alias will be returned or error. Error will be +// returned if it fails to read from the file. +func loadAlias(filename, alias string) (hostConfig, error) { + cfg := &config{} + configBytes, err := ioutil.ReadFile(filename) + if err != nil { + return hostConfig{}, err + } + if err = json.Unmarshal(configBytes, cfg); err != nil { + return hostConfig{}, err + } + return cfg.Hosts[alias], nil +} diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/iam_aws.go b/vendor/github.com/minio/minio-go/pkg/credentials/iam_aws.go new file mode 100644 index 000000000..637df7466 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/iam_aws.go @@ -0,0 +1,214 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package credentials + +import ( + "bufio" + "encoding/json" + "errors" + "net/http" + "net/url" + "path" + "time" +) + +// DefaultExpiryWindow - Default expiry window. +// ExpiryWindow will allow the credentials to trigger refreshing +// prior to the credentials actually expiring. This is beneficial +// so race conditions with expiring credentials do not cause +// request to fail unexpectedly due to ExpiredTokenException exceptions. +const DefaultExpiryWindow = time.Second * 10 // 10 secs + +// A IAM retrieves credentials from the EC2 service, and keeps track if +// those credentials are expired. +type IAM struct { + Expiry + + // Required http Client to use when connecting to IAM metadata service. + Client *http.Client + + // Custom endpoint to fetch IAM role credentials. + endpoint string +} + +// IAM Roles for Amazon EC2 +// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html +const ( + defaultIAMRoleEndpoint = "http://169.254.169.254" + defaultIAMSecurityCredsPath = "/latest/meta-data/iam/security-credentials" +) + +// NewIAM returns a pointer to a new Credentials object wrapping +// the IAM. Takes a ConfigProvider to create a EC2Metadata client. +// The ConfigProvider is satisfied by the session.Session type. +func NewIAM(endpoint string) *Credentials { + if endpoint == "" { + endpoint = defaultIAMRoleEndpoint + } + p := &IAM{ + Client: &http.Client{ + Transport: http.DefaultTransport, + }, + endpoint: endpoint, + } + return New(p) +} + +// Retrieve retrieves credentials from the EC2 service. +// Error will be returned if the request fails, or unable to extract +// the desired +func (m *IAM) Retrieve() (Value, error) { + roleCreds, err := getCredentials(m.Client, m.endpoint) + if err != nil { + return Value{}, err + } + + // Expiry window is set to 10secs. + m.SetExpiration(roleCreds.Expiration, DefaultExpiryWindow) + + return Value{ + AccessKeyID: roleCreds.AccessKeyID, + SecretAccessKey: roleCreds.SecretAccessKey, + SessionToken: roleCreds.Token, + SignerType: SignatureV4, + }, nil +} + +// A ec2RoleCredRespBody provides the shape for unmarshaling credential +// request responses. +type ec2RoleCredRespBody struct { + // Success State + Expiration time.Time + AccessKeyID string + SecretAccessKey string + Token string + + // Error state + Code string + Message string + + // Unused params. + LastUpdated time.Time + Type string +} + +// Get the final IAM role URL where the request will +// be sent to fetch the rolling access credentials. +// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html +func getIAMRoleURL(endpoint string) (*url.URL, error) { + if endpoint == "" { + endpoint = defaultIAMRoleEndpoint + } + u, err := url.Parse(endpoint) + if err != nil { + return nil, err + } + u.Path = defaultIAMSecurityCredsPath + return u, nil +} + +// listRoleNames lists of credential role names associated +// with the current EC2 service. If there are no credentials, +// or there is an error making or receiving the request. +// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html +func listRoleNames(client *http.Client, u *url.URL) ([]string, error) { + req, err := http.NewRequest("GET", u.String(), nil) + if err != nil { + return nil, err + } + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return nil, errors.New(resp.Status) + } + + credsList := []string{} + s := bufio.NewScanner(resp.Body) + for s.Scan() { + credsList = append(credsList, s.Text()) + } + + if err := s.Err(); err != nil { + return nil, err + } + + return credsList, nil +} + +// getCredentials - obtains the credentials from the IAM role name associated with +// the current EC2 service. +// +// If the credentials cannot be found, or there is an error +// reading the response an error will be returned. +func getCredentials(client *http.Client, endpoint string) (ec2RoleCredRespBody, error) { + // http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html + u, err := getIAMRoleURL(endpoint) + if err != nil { + return ec2RoleCredRespBody{}, err + } + + // http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html + roleNames, err := listRoleNames(client, u) + if err != nil { + return ec2RoleCredRespBody{}, err + } + + if len(roleNames) == 0 { + return ec2RoleCredRespBody{}, errors.New("No IAM roles attached to this EC2 service") + } + + // http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html + // - An instance profile can contain only one IAM role. This limit cannot be increased. + roleName := roleNames[0] + + // http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html + // The following command retrieves the security credentials for an + // IAM role named `s3access`. + // + // $ curl http://169.254.169.254/latest/meta-data/iam/security-credentials/s3access + // + u.Path = path.Join(u.Path, roleName) + req, err := http.NewRequest("GET", u.String(), nil) + if err != nil { + return ec2RoleCredRespBody{}, err + } + + resp, err := client.Do(req) + if err != nil { + return ec2RoleCredRespBody{}, err + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return ec2RoleCredRespBody{}, errors.New(resp.Status) + } + + respCreds := ec2RoleCredRespBody{} + if err := json.NewDecoder(resp.Body).Decode(&respCreds); err != nil { + return ec2RoleCredRespBody{}, err + } + + if respCreds.Code != "Success" { + // If an error code was returned something failed requesting the role. + return ec2RoleCredRespBody{}, errors.New(respCreds.Message) + } + + return respCreds, nil +} diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/signature-type.go b/vendor/github.com/minio/minio-go/pkg/credentials/signature-type.go new file mode 100644 index 000000000..1b768e8c3 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/signature-type.go @@ -0,0 +1,77 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package credentials + +import "strings" + +// SignatureType is type of Authorization requested for a given HTTP request. +type SignatureType int + +// Different types of supported signatures - default is SignatureV4 or SignatureDefault. +const ( + // SignatureDefault is always set to v4. + SignatureDefault SignatureType = iota + SignatureV4 + SignatureV2 + SignatureV4Streaming + SignatureAnonymous // Anonymous signature signifies, no signature. +) + +// IsV2 - is signature SignatureV2? +func (s SignatureType) IsV2() bool { + return s == SignatureV2 +} + +// IsV4 - is signature SignatureV4? +func (s SignatureType) IsV4() bool { + return s == SignatureV4 || s == SignatureDefault +} + +// IsStreamingV4 - is signature SignatureV4Streaming? +func (s SignatureType) IsStreamingV4() bool { + return s == SignatureV4Streaming +} + +// IsAnonymous - is signature empty? +func (s SignatureType) IsAnonymous() bool { + return s == SignatureAnonymous +} + +// Stringer humanized version of signature type, +// strings returned here are case insensitive. +func (s SignatureType) String() string { + if s.IsV2() { + return "S3v2" + } else if s.IsV4() { + return "S3v4" + } else if s.IsStreamingV4() { + return "S3v4Streaming" + } + return "Anonymous" +} + +func parseSignatureType(str string) SignatureType { + if strings.EqualFold(str, "S3v4") { + return SignatureV4 + } else if strings.EqualFold(str, "S3v2") { + return SignatureV2 + } else if strings.EqualFold(str, "S3v4Streaming") { + return SignatureV4Streaming + } + return SignatureAnonymous +} diff --git a/vendor/github.com/minio/minio-go/pkg/credentials/static.go b/vendor/github.com/minio/minio-go/pkg/credentials/static.go new file mode 100644 index 000000000..8b0ba711c --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/credentials/static.go @@ -0,0 +1,67 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package credentials + +// A Static is a set of credentials which are set programmatically, +// and will never expire. +type Static struct { + Value +} + +// NewStaticV2 returns a pointer to a new Credentials object +// wrapping a static credentials value provider, signature is +// set to v2. If access and secret are not specified then +// regardless of signature type set it Value will return +// as anonymous. +func NewStaticV2(id, secret, token string) *Credentials { + return NewStatic(id, secret, token, SignatureV2) +} + +// NewStaticV4 is similar to NewStaticV2 with similar considerations. +func NewStaticV4(id, secret, token string) *Credentials { + return NewStatic(id, secret, token, SignatureV4) +} + +// NewStatic returns a pointer to a new Credentials object +// wrapping a static credentials value provider. +func NewStatic(id, secret, token string, signerType SignatureType) *Credentials { + return New(&Static{ + Value: Value{ + AccessKeyID: id, + SecretAccessKey: secret, + SessionToken: token, + SignerType: signerType, + }, + }) +} + +// Retrieve returns the static credentials. +func (s *Static) Retrieve() (Value, error) { + if s.AccessKeyID == "" || s.SecretAccessKey == "" { + // Anonymous is not an error + return Value{SignerType: SignatureAnonymous}, nil + } + return s.Value, nil +} + +// IsExpired returns if the credentials are expired. +// +// For Static, the credentials never expired. +func (s *Static) IsExpired() bool { + return false +} diff --git a/vendor/github.com/minio/minio-go/pkg/encrypt/cbc.go b/vendor/github.com/minio/minio-go/pkg/encrypt/cbc.go new file mode 100644 index 000000000..b0f2d6e08 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/encrypt/cbc.go @@ -0,0 +1,294 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package encrypt + +import ( + "bytes" + "crypto/aes" + "crypto/cipher" + "crypto/rand" + "encoding/base64" + "errors" + "io" +) + +// Crypt mode - encryption or decryption +type cryptMode int + +const ( + encryptMode cryptMode = iota + decryptMode +) + +// CBCSecureMaterials encrypts/decrypts data using AES CBC algorithm +type CBCSecureMaterials struct { + + // Data stream to encrypt/decrypt + stream io.Reader + + // Last internal error + err error + + // End of file reached + eof bool + + // Holds initial data + srcBuf *bytes.Buffer + + // Holds transformed data (encrypted or decrypted) + dstBuf *bytes.Buffer + + // Encryption algorithm + encryptionKey Key + + // Key to encrypts/decrypts data + contentKey []byte + + // Encrypted form of contentKey + cryptedKey []byte + + // Initialization vector + iv []byte + + // matDesc - currently unused + matDesc []byte + + // Indicate if we are going to encrypt or decrypt + cryptMode cryptMode + + // Helper that encrypts/decrypts data + blockMode cipher.BlockMode +} + +// NewCBCSecureMaterials builds new CBC crypter module with +// the specified encryption key (symmetric or asymmetric) +func NewCBCSecureMaterials(key Key) (*CBCSecureMaterials, error) { + if key == nil { + return nil, errors.New("Unable to recognize empty encryption properties") + } + return &CBCSecureMaterials{ + srcBuf: bytes.NewBuffer([]byte{}), + dstBuf: bytes.NewBuffer([]byte{}), + encryptionKey: key, + matDesc: []byte("{}"), + }, nil + +} + +// Close implements closes the internal stream. +func (s *CBCSecureMaterials) Close() error { + closer, ok := s.stream.(io.Closer) + if ok { + return closer.Close() + } + return nil +} + +// SetupEncryptMode - tells CBC that we are going to encrypt data +func (s *CBCSecureMaterials) SetupEncryptMode(stream io.Reader) error { + // Set mode to encrypt + s.cryptMode = encryptMode + + // Set underlying reader + s.stream = stream + + s.eof = false + s.srcBuf.Reset() + s.dstBuf.Reset() + + var err error + + // Generate random content key + s.contentKey = make([]byte, aes.BlockSize*2) + if _, err := rand.Read(s.contentKey); err != nil { + return err + } + // Encrypt content key + s.cryptedKey, err = s.encryptionKey.Encrypt(s.contentKey) + if err != nil { + return err + } + // Generate random IV + s.iv = make([]byte, aes.BlockSize) + if _, err = rand.Read(s.iv); err != nil { + return err + } + // New cipher + encryptContentBlock, err := aes.NewCipher(s.contentKey) + if err != nil { + return err + } + + s.blockMode = cipher.NewCBCEncrypter(encryptContentBlock, s.iv) + + return nil +} + +// SetupDecryptMode - tells CBC that we are going to decrypt data +func (s *CBCSecureMaterials) SetupDecryptMode(stream io.Reader, iv string, key string) error { + // Set mode to decrypt + s.cryptMode = decryptMode + + // Set underlying reader + s.stream = stream + + // Reset + s.eof = false + s.srcBuf.Reset() + s.dstBuf.Reset() + + var err error + + // Get IV + s.iv, err = base64.StdEncoding.DecodeString(iv) + if err != nil { + return err + } + + // Get encrypted content key + s.cryptedKey, err = base64.StdEncoding.DecodeString(key) + if err != nil { + return err + } + + // Decrypt content key + s.contentKey, err = s.encryptionKey.Decrypt(s.cryptedKey) + if err != nil { + return err + } + + // New cipher + decryptContentBlock, err := aes.NewCipher(s.contentKey) + if err != nil { + return err + } + + s.blockMode = cipher.NewCBCDecrypter(decryptContentBlock, s.iv) + return nil +} + +// GetIV - return randomly generated IV (per S3 object), base64 encoded. +func (s *CBCSecureMaterials) GetIV() string { + return base64.StdEncoding.EncodeToString(s.iv) +} + +// GetKey - return content encrypting key (cek) in encrypted form, base64 encoded. +func (s *CBCSecureMaterials) GetKey() string { + return base64.StdEncoding.EncodeToString(s.cryptedKey) +} + +// GetDesc - user provided encryption material description in JSON (UTF8) format. +func (s *CBCSecureMaterials) GetDesc() string { + return string(s.matDesc) +} + +// Fill buf with encrypted/decrypted data +func (s *CBCSecureMaterials) Read(buf []byte) (n int, err error) { + // Always fill buf from bufChunk at the end of this function + defer func() { + if s.err != nil { + n, err = 0, s.err + } else { + n, err = s.dstBuf.Read(buf) + } + }() + + // Return + if s.eof { + return + } + + // Fill dest buffer if its length is less than buf + for !s.eof && s.dstBuf.Len() < len(buf) { + + srcPart := make([]byte, aes.BlockSize) + dstPart := make([]byte, aes.BlockSize) + + // Fill src buffer + for s.srcBuf.Len() < aes.BlockSize*2 { + _, err = io.CopyN(s.srcBuf, s.stream, aes.BlockSize) + if err != nil { + break + } + } + + // Quit immediately for errors other than io.EOF + if err != nil && err != io.EOF { + s.err = err + return + } + + // Mark current encrypting/decrypting as finished + s.eof = (err == io.EOF) + + if s.eof && s.cryptMode == encryptMode { + if srcPart, err = pkcs5Pad(s.srcBuf.Bytes(), aes.BlockSize); err != nil { + s.err = err + return + } + } else { + _, _ = s.srcBuf.Read(srcPart) + } + + // Crypt srcPart content + for len(srcPart) > 0 { + + // Crypt current part + s.blockMode.CryptBlocks(dstPart, srcPart[:aes.BlockSize]) + + // Unpad when this is the last part and we are decrypting + if s.eof && s.cryptMode == decryptMode { + dstPart, err = pkcs5Unpad(dstPart, aes.BlockSize) + if err != nil { + s.err = err + return + } + } + + // Send crypted data to dstBuf + if _, wErr := s.dstBuf.Write(dstPart); wErr != nil { + s.err = wErr + return + } + // Move to the next part + srcPart = srcPart[aes.BlockSize:] + } + } + return +} + +// Unpad a set of bytes following PKCS5 algorithm +func pkcs5Unpad(buf []byte, blockSize int) ([]byte, error) { + len := len(buf) + if len == 0 { + return nil, errors.New("buffer is empty") + } + pad := int(buf[len-1]) + if pad > len || pad > blockSize { + return nil, errors.New("invalid padding size") + } + return buf[:len-pad], nil +} + +// Pad a set of bytes following PKCS5 algorithm +func pkcs5Pad(buf []byte, blockSize int) ([]byte, error) { + len := len(buf) + pad := blockSize - (len % blockSize) + padText := bytes.Repeat([]byte{byte(pad)}, pad) + return append(buf, padText...), nil +} diff --git a/vendor/github.com/minio/minio-go/pkg/encrypt/interface.go b/vendor/github.com/minio/minio-go/pkg/encrypt/interface.go new file mode 100644 index 000000000..482922ab7 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/encrypt/interface.go @@ -0,0 +1,54 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Package encrypt implements a generic interface to encrypt any stream of data. +// currently this package implements two types of encryption +// - Symmetric encryption using AES. +// - Asymmetric encrytion using RSA. +package encrypt + +import "io" + +// Materials - provides generic interface to encrypt any stream of data. +type Materials interface { + + // Closes the wrapped stream properly, initiated by the caller. + Close() error + + // Returns encrypted/decrypted data, io.Reader compatible. + Read(b []byte) (int, error) + + // Get randomly generated IV, base64 encoded. + GetIV() (iv string) + + // Get content encrypting key (cek) in encrypted form, base64 encoded. + GetKey() (key string) + + // Get user provided encryption material description in + // JSON (UTF8) format. This is not used, kept for future. + GetDesc() (desc string) + + // Setup encrypt mode, further calls of Read() function + // will return the encrypted form of data streamed + // by the passed reader + SetupEncryptMode(stream io.Reader) error + + // Setup decrypted mode, further calls of Read() function + // will return the decrypted form of data streamed + // by the passed reader + SetupDecryptMode(stream io.Reader, iv string, key string) error +} diff --git a/vendor/github.com/minio/minio-go/pkg/encrypt/keys.go b/vendor/github.com/minio/minio-go/pkg/encrypt/keys.go new file mode 100644 index 000000000..0ed95f5ff --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/encrypt/keys.go @@ -0,0 +1,166 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package encrypt + +import ( + "crypto/aes" + "crypto/rand" + "crypto/rsa" + "crypto/x509" + "errors" +) + +// Key - generic interface to encrypt/decrypt a key. +// We use it to encrypt/decrypt content key which is the key +// that encrypt/decrypt object data. +type Key interface { + // Encrypt data using to the set encryption key + Encrypt([]byte) ([]byte, error) + // Decrypt data using to the set encryption key + Decrypt([]byte) ([]byte, error) +} + +// SymmetricKey - encrypts data with a symmetric master key +type SymmetricKey struct { + masterKey []byte +} + +// Encrypt passed bytes +func (s *SymmetricKey) Encrypt(plain []byte) ([]byte, error) { + // Initialize an AES encryptor using a master key + keyBlock, err := aes.NewCipher(s.masterKey) + if err != nil { + return []byte{}, err + } + + // Pad the key before encryption + plain, _ = pkcs5Pad(plain, aes.BlockSize) + + encKey := []byte{} + encPart := make([]byte, aes.BlockSize) + + // Encrypt the passed key by block + for { + if len(plain) < aes.BlockSize { + break + } + // Encrypt the passed key + keyBlock.Encrypt(encPart, plain[:aes.BlockSize]) + // Add the encrypted block to the total encrypted key + encKey = append(encKey, encPart...) + // Pass to the next plain block + plain = plain[aes.BlockSize:] + } + return encKey, nil +} + +// Decrypt passed bytes +func (s *SymmetricKey) Decrypt(cipher []byte) ([]byte, error) { + // Initialize AES decrypter + keyBlock, err := aes.NewCipher(s.masterKey) + if err != nil { + return nil, err + } + + var plain []byte + plainPart := make([]byte, aes.BlockSize) + + // Decrypt the encrypted data block by block + for { + if len(cipher) < aes.BlockSize { + break + } + keyBlock.Decrypt(plainPart, cipher[:aes.BlockSize]) + // Add the decrypted block to the total result + plain = append(plain, plainPart...) + // Pass to the next cipher block + cipher = cipher[aes.BlockSize:] + } + + // Unpad the resulted plain data + plain, err = pkcs5Unpad(plain, aes.BlockSize) + if err != nil { + return nil, err + } + + return plain, nil +} + +// NewSymmetricKey generates a new encrypt/decrypt crypto using +// an AES master key password +func NewSymmetricKey(b []byte) *SymmetricKey { + return &SymmetricKey{masterKey: b} +} + +// AsymmetricKey - struct which encrypts/decrypts data +// using RSA public/private certificates +type AsymmetricKey struct { + publicKey *rsa.PublicKey + privateKey *rsa.PrivateKey +} + +// Encrypt data using public key +func (a *AsymmetricKey) Encrypt(plain []byte) ([]byte, error) { + cipher, err := rsa.EncryptPKCS1v15(rand.Reader, a.publicKey, plain) + if err != nil { + return nil, err + } + return cipher, nil +} + +// Decrypt data using public key +func (a *AsymmetricKey) Decrypt(cipher []byte) ([]byte, error) { + cipher, err := rsa.DecryptPKCS1v15(rand.Reader, a.privateKey, cipher) + if err != nil { + return nil, err + } + return cipher, nil +} + +// NewAsymmetricKey - generates a crypto module able to encrypt/decrypt +// data using a pair for private and public key +func NewAsymmetricKey(privData []byte, pubData []byte) (*AsymmetricKey, error) { + // Parse private key from passed data + priv, err := x509.ParsePKCS8PrivateKey(privData) + if err != nil { + return nil, err + } + privKey, ok := priv.(*rsa.PrivateKey) + if !ok { + return nil, errors.New("not a valid private key") + } + + // Parse public key from passed data + pub, err := x509.ParsePKIXPublicKey(pubData) + if err != nil { + return nil, err + } + + pubKey, ok := pub.(*rsa.PublicKey) + if !ok { + return nil, errors.New("not a valid public key") + } + + // Associate the private key with the passed public key + privKey.PublicKey = *pubKey + + return &AsymmetricKey{ + publicKey: pubKey, + privateKey: privKey, + }, nil +} diff --git a/vendor/github.com/minio/minio-go/pkg/policy/bucket-policy-condition.go b/vendor/github.com/minio/minio-go/pkg/policy/bucket-policy-condition.go new file mode 100644 index 000000000..737b810ac --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/policy/bucket-policy-condition.go @@ -0,0 +1,116 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package policy + +import "github.com/minio/minio-go/pkg/set" + +// ConditionKeyMap - map of policy condition key and value. +type ConditionKeyMap map[string]set.StringSet + +// Add - adds key and value. The value is appended If key already exists. +func (ckm ConditionKeyMap) Add(key string, value set.StringSet) { + if v, ok := ckm[key]; ok { + ckm[key] = v.Union(value) + } else { + ckm[key] = set.CopyStringSet(value) + } +} + +// Remove - removes value of given key. If key has empty after removal, the key is also removed. +func (ckm ConditionKeyMap) Remove(key string, value set.StringSet) { + if v, ok := ckm[key]; ok { + if value != nil { + ckm[key] = v.Difference(value) + } + + if ckm[key].IsEmpty() { + delete(ckm, key) + } + } +} + +// RemoveKey - removes key and its value. +func (ckm ConditionKeyMap) RemoveKey(key string) { + if _, ok := ckm[key]; ok { + delete(ckm, key) + } +} + +// CopyConditionKeyMap - returns new copy of given ConditionKeyMap. +func CopyConditionKeyMap(condKeyMap ConditionKeyMap) ConditionKeyMap { + out := make(ConditionKeyMap) + + for k, v := range condKeyMap { + out[k] = set.CopyStringSet(v) + } + + return out +} + +// mergeConditionKeyMap - returns a new ConditionKeyMap which contains merged key/value of given two ConditionKeyMap. +func mergeConditionKeyMap(condKeyMap1 ConditionKeyMap, condKeyMap2 ConditionKeyMap) ConditionKeyMap { + out := CopyConditionKeyMap(condKeyMap1) + + for k, v := range condKeyMap2 { + if ev, ok := out[k]; ok { + out[k] = ev.Union(v) + } else { + out[k] = set.CopyStringSet(v) + } + } + + return out +} + +// ConditionMap - map of condition and conditional values. +type ConditionMap map[string]ConditionKeyMap + +// Add - adds condition key and condition value. The value is appended if key already exists. +func (cond ConditionMap) Add(condKey string, condKeyMap ConditionKeyMap) { + if v, ok := cond[condKey]; ok { + cond[condKey] = mergeConditionKeyMap(v, condKeyMap) + } else { + cond[condKey] = CopyConditionKeyMap(condKeyMap) + } +} + +// Remove - removes condition key and its value. +func (cond ConditionMap) Remove(condKey string) { + if _, ok := cond[condKey]; ok { + delete(cond, condKey) + } +} + +// mergeConditionMap - returns new ConditionMap which contains merged key/value of two ConditionMap. +func mergeConditionMap(condMap1 ConditionMap, condMap2 ConditionMap) ConditionMap { + out := make(ConditionMap) + + for k, v := range condMap1 { + out[k] = CopyConditionKeyMap(v) + } + + for k, v := range condMap2 { + if ev, ok := out[k]; ok { + out[k] = mergeConditionKeyMap(ev, v) + } else { + out[k] = CopyConditionKeyMap(v) + } + } + + return out +} diff --git a/vendor/github.com/minio/minio-go/pkg/policy/bucket-policy.go b/vendor/github.com/minio/minio-go/pkg/policy/bucket-policy.go new file mode 100644 index 000000000..9dda99efc --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/policy/bucket-policy.go @@ -0,0 +1,635 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package policy + +import ( + "reflect" + "strings" + + "github.com/minio/minio-go/pkg/set" +) + +// BucketPolicy - Bucket level policy. +type BucketPolicy string + +// Different types of Policies currently supported for buckets. +const ( + BucketPolicyNone BucketPolicy = "none" + BucketPolicyReadOnly = "readonly" + BucketPolicyReadWrite = "readwrite" + BucketPolicyWriteOnly = "writeonly" +) + +// IsValidBucketPolicy - returns true if policy is valid and supported, false otherwise. +func (p BucketPolicy) IsValidBucketPolicy() bool { + switch p { + case BucketPolicyNone, BucketPolicyReadOnly, BucketPolicyReadWrite, BucketPolicyWriteOnly: + return true + } + return false +} + +// Resource prefix for all aws resources. +const awsResourcePrefix = "arn:aws:s3:::" + +// Common bucket actions for both read and write policies. +var commonBucketActions = set.CreateStringSet("s3:GetBucketLocation") + +// Read only bucket actions. +var readOnlyBucketActions = set.CreateStringSet("s3:ListBucket") + +// Write only bucket actions. +var writeOnlyBucketActions = set.CreateStringSet("s3:ListBucketMultipartUploads") + +// Read only object actions. +var readOnlyObjectActions = set.CreateStringSet("s3:GetObject") + +// Write only object actions. +var writeOnlyObjectActions = set.CreateStringSet("s3:AbortMultipartUpload", "s3:DeleteObject", "s3:ListMultipartUploadParts", "s3:PutObject") + +// Read and write object actions. +var readWriteObjectActions = readOnlyObjectActions.Union(writeOnlyObjectActions) + +// All valid bucket and object actions. +var validActions = commonBucketActions. + Union(readOnlyBucketActions). + Union(writeOnlyBucketActions). + Union(readOnlyObjectActions). + Union(writeOnlyObjectActions) + +var startsWithFunc = func(resource string, resourcePrefix string) bool { + return strings.HasPrefix(resource, resourcePrefix) +} + +// User - canonical users list. +type User struct { + AWS set.StringSet `json:"AWS,omitempty"` + CanonicalUser set.StringSet `json:"CanonicalUser,omitempty"` +} + +// Statement - minio policy statement +type Statement struct { + Actions set.StringSet `json:"Action"` + Conditions ConditionMap `json:"Condition,omitempty"` + Effect string + Principal User `json:"Principal"` + Resources set.StringSet `json:"Resource"` + Sid string +} + +// BucketAccessPolicy - minio policy collection +type BucketAccessPolicy struct { + Version string // date in YYYY-MM-DD format + Statements []Statement `json:"Statement"` +} + +// isValidStatement - returns whether given statement is valid to process for given bucket name. +func isValidStatement(statement Statement, bucketName string) bool { + if statement.Actions.Intersection(validActions).IsEmpty() { + return false + } + + if statement.Effect != "Allow" { + return false + } + + if statement.Principal.AWS == nil || !statement.Principal.AWS.Contains("*") { + return false + } + + bucketResource := awsResourcePrefix + bucketName + if statement.Resources.Contains(bucketResource) { + return true + } + + if statement.Resources.FuncMatch(startsWithFunc, bucketResource+"/").IsEmpty() { + return false + } + + return true +} + +// Returns new statements with bucket actions for given policy. +func newBucketStatement(policy BucketPolicy, bucketName string, prefix string) (statements []Statement) { + statements = []Statement{} + if policy == BucketPolicyNone || bucketName == "" { + return statements + } + + bucketResource := set.CreateStringSet(awsResourcePrefix + bucketName) + + statement := Statement{ + Actions: commonBucketActions, + Effect: "Allow", + Principal: User{AWS: set.CreateStringSet("*")}, + Resources: bucketResource, + Sid: "", + } + statements = append(statements, statement) + + if policy == BucketPolicyReadOnly || policy == BucketPolicyReadWrite { + statement = Statement{ + Actions: readOnlyBucketActions, + Effect: "Allow", + Principal: User{AWS: set.CreateStringSet("*")}, + Resources: bucketResource, + Sid: "", + } + if prefix != "" { + condKeyMap := make(ConditionKeyMap) + condKeyMap.Add("s3:prefix", set.CreateStringSet(prefix)) + condMap := make(ConditionMap) + condMap.Add("StringEquals", condKeyMap) + statement.Conditions = condMap + } + statements = append(statements, statement) + } + + if policy == BucketPolicyWriteOnly || policy == BucketPolicyReadWrite { + statement = Statement{ + Actions: writeOnlyBucketActions, + Effect: "Allow", + Principal: User{AWS: set.CreateStringSet("*")}, + Resources: bucketResource, + Sid: "", + } + statements = append(statements, statement) + } + + return statements +} + +// Returns new statements contains object actions for given policy. +func newObjectStatement(policy BucketPolicy, bucketName string, prefix string) (statements []Statement) { + statements = []Statement{} + if policy == BucketPolicyNone || bucketName == "" { + return statements + } + + statement := Statement{ + Effect: "Allow", + Principal: User{AWS: set.CreateStringSet("*")}, + Resources: set.CreateStringSet(awsResourcePrefix + bucketName + "/" + prefix + "*"), + Sid: "", + } + + if policy == BucketPolicyReadOnly { + statement.Actions = readOnlyObjectActions + } else if policy == BucketPolicyWriteOnly { + statement.Actions = writeOnlyObjectActions + } else if policy == BucketPolicyReadWrite { + statement.Actions = readWriteObjectActions + } + + statements = append(statements, statement) + return statements +} + +// Returns new statements for given policy, bucket and prefix. +func newStatements(policy BucketPolicy, bucketName string, prefix string) (statements []Statement) { + statements = []Statement{} + ns := newBucketStatement(policy, bucketName, prefix) + statements = append(statements, ns...) + + ns = newObjectStatement(policy, bucketName, prefix) + statements = append(statements, ns...) + + return statements +} + +// Returns whether given bucket statements are used by other than given prefix statements. +func getInUsePolicy(statements []Statement, bucketName string, prefix string) (readOnlyInUse, writeOnlyInUse bool) { + resourcePrefix := awsResourcePrefix + bucketName + "/" + objectResource := awsResourcePrefix + bucketName + "/" + prefix + "*" + + for _, s := range statements { + if !s.Resources.Contains(objectResource) && !s.Resources.FuncMatch(startsWithFunc, resourcePrefix).IsEmpty() { + if s.Actions.Intersection(readOnlyObjectActions).Equals(readOnlyObjectActions) { + readOnlyInUse = true + } + + if s.Actions.Intersection(writeOnlyObjectActions).Equals(writeOnlyObjectActions) { + writeOnlyInUse = true + } + } + if readOnlyInUse && writeOnlyInUse { + break + } + } + + return readOnlyInUse, writeOnlyInUse +} + +// Removes object actions in given statement. +func removeObjectActions(statement Statement, objectResource string) Statement { + if statement.Conditions == nil { + if len(statement.Resources) > 1 { + statement.Resources.Remove(objectResource) + } else { + statement.Actions = statement.Actions.Difference(readOnlyObjectActions) + statement.Actions = statement.Actions.Difference(writeOnlyObjectActions) + } + } + + return statement +} + +// Removes bucket actions for given policy in given statement. +func removeBucketActions(statement Statement, prefix string, bucketResource string, readOnlyInUse, writeOnlyInUse bool) Statement { + removeReadOnly := func() { + if !statement.Actions.Intersection(readOnlyBucketActions).Equals(readOnlyBucketActions) { + return + } + + if statement.Conditions == nil { + statement.Actions = statement.Actions.Difference(readOnlyBucketActions) + return + } + + if prefix != "" { + stringEqualsValue := statement.Conditions["StringEquals"] + values := set.NewStringSet() + if stringEqualsValue != nil { + values = stringEqualsValue["s3:prefix"] + if values == nil { + values = set.NewStringSet() + } + } + + values.Remove(prefix) + + if stringEqualsValue != nil { + if values.IsEmpty() { + delete(stringEqualsValue, "s3:prefix") + } + if len(stringEqualsValue) == 0 { + delete(statement.Conditions, "StringEquals") + } + } + + if len(statement.Conditions) == 0 { + statement.Conditions = nil + statement.Actions = statement.Actions.Difference(readOnlyBucketActions) + } + } + } + + removeWriteOnly := func() { + if statement.Conditions == nil { + statement.Actions = statement.Actions.Difference(writeOnlyBucketActions) + } + } + + if len(statement.Resources) > 1 { + statement.Resources.Remove(bucketResource) + } else { + if !readOnlyInUse { + removeReadOnly() + } + + if !writeOnlyInUse { + removeWriteOnly() + } + } + + return statement +} + +// Returns statements containing removed actions/statements for given +// policy, bucket name and prefix. +func removeStatements(statements []Statement, bucketName string, prefix string) []Statement { + bucketResource := awsResourcePrefix + bucketName + objectResource := awsResourcePrefix + bucketName + "/" + prefix + "*" + readOnlyInUse, writeOnlyInUse := getInUsePolicy(statements, bucketName, prefix) + + out := []Statement{} + readOnlyBucketStatements := []Statement{} + s3PrefixValues := set.NewStringSet() + + for _, statement := range statements { + if !isValidStatement(statement, bucketName) { + out = append(out, statement) + continue + } + + if statement.Resources.Contains(bucketResource) { + if statement.Conditions != nil { + statement = removeBucketActions(statement, prefix, bucketResource, false, false) + } else { + statement = removeBucketActions(statement, prefix, bucketResource, readOnlyInUse, writeOnlyInUse) + } + } else if statement.Resources.Contains(objectResource) { + statement = removeObjectActions(statement, objectResource) + } + + if !statement.Actions.IsEmpty() { + if statement.Resources.Contains(bucketResource) && + statement.Actions.Intersection(readOnlyBucketActions).Equals(readOnlyBucketActions) && + statement.Effect == "Allow" && + statement.Principal.AWS.Contains("*") { + + if statement.Conditions != nil { + stringEqualsValue := statement.Conditions["StringEquals"] + values := set.NewStringSet() + if stringEqualsValue != nil { + values = stringEqualsValue["s3:prefix"] + if values == nil { + values = set.NewStringSet() + } + } + s3PrefixValues = s3PrefixValues.Union(values.ApplyFunc(func(v string) string { + return bucketResource + "/" + v + "*" + })) + } else if !s3PrefixValues.IsEmpty() { + readOnlyBucketStatements = append(readOnlyBucketStatements, statement) + continue + } + } + out = append(out, statement) + } + } + + skipBucketStatement := true + resourcePrefix := awsResourcePrefix + bucketName + "/" + for _, statement := range out { + if !statement.Resources.FuncMatch(startsWithFunc, resourcePrefix).IsEmpty() && + s3PrefixValues.Intersection(statement.Resources).IsEmpty() { + skipBucketStatement = false + break + } + } + + for _, statement := range readOnlyBucketStatements { + if skipBucketStatement && + statement.Resources.Contains(bucketResource) && + statement.Effect == "Allow" && + statement.Principal.AWS.Contains("*") && + statement.Conditions == nil { + continue + } + + out = append(out, statement) + } + + if len(out) == 1 { + statement := out[0] + if statement.Resources.Contains(bucketResource) && + statement.Actions.Intersection(commonBucketActions).Equals(commonBucketActions) && + statement.Effect == "Allow" && + statement.Principal.AWS.Contains("*") && + statement.Conditions == nil { + out = []Statement{} + } + } + + return out +} + +// Appends given statement into statement list to have unique statements. +// - If statement already exists in statement list, it ignores. +// - If statement exists with different conditions, they are merged. +// - Else the statement is appended to statement list. +func appendStatement(statements []Statement, statement Statement) []Statement { + for i, s := range statements { + if s.Actions.Equals(statement.Actions) && + s.Effect == statement.Effect && + s.Principal.AWS.Equals(statement.Principal.AWS) && + reflect.DeepEqual(s.Conditions, statement.Conditions) { + statements[i].Resources = s.Resources.Union(statement.Resources) + return statements + } else if s.Resources.Equals(statement.Resources) && + s.Effect == statement.Effect && + s.Principal.AWS.Equals(statement.Principal.AWS) && + reflect.DeepEqual(s.Conditions, statement.Conditions) { + statements[i].Actions = s.Actions.Union(statement.Actions) + return statements + } + + if s.Resources.Intersection(statement.Resources).Equals(statement.Resources) && + s.Actions.Intersection(statement.Actions).Equals(statement.Actions) && + s.Effect == statement.Effect && + s.Principal.AWS.Intersection(statement.Principal.AWS).Equals(statement.Principal.AWS) { + if reflect.DeepEqual(s.Conditions, statement.Conditions) { + return statements + } + if s.Conditions != nil && statement.Conditions != nil { + if s.Resources.Equals(statement.Resources) { + statements[i].Conditions = mergeConditionMap(s.Conditions, statement.Conditions) + return statements + } + } + } + } + + if !(statement.Actions.IsEmpty() && statement.Resources.IsEmpty()) { + return append(statements, statement) + } + + return statements +} + +// Appends two statement lists. +func appendStatements(statements []Statement, appendStatements []Statement) []Statement { + for _, s := range appendStatements { + statements = appendStatement(statements, s) + } + + return statements +} + +// Returns policy of given bucket statement. +func getBucketPolicy(statement Statement, prefix string) (commonFound, readOnly, writeOnly bool) { + if !(statement.Effect == "Allow" && statement.Principal.AWS.Contains("*")) { + return commonFound, readOnly, writeOnly + } + + if statement.Actions.Intersection(commonBucketActions).Equals(commonBucketActions) && + statement.Conditions == nil { + commonFound = true + } + + if statement.Actions.Intersection(writeOnlyBucketActions).Equals(writeOnlyBucketActions) && + statement.Conditions == nil { + writeOnly = true + } + + if statement.Actions.Intersection(readOnlyBucketActions).Equals(readOnlyBucketActions) { + if prefix != "" && statement.Conditions != nil { + if stringEqualsValue, ok := statement.Conditions["StringEquals"]; ok { + if s3PrefixValues, ok := stringEqualsValue["s3:prefix"]; ok { + if s3PrefixValues.Contains(prefix) { + readOnly = true + } + } + } else if stringNotEqualsValue, ok := statement.Conditions["StringNotEquals"]; ok { + if s3PrefixValues, ok := stringNotEqualsValue["s3:prefix"]; ok { + if !s3PrefixValues.Contains(prefix) { + readOnly = true + } + } + } + } else if prefix == "" && statement.Conditions == nil { + readOnly = true + } else if prefix != "" && statement.Conditions == nil { + readOnly = true + } + } + + return commonFound, readOnly, writeOnly +} + +// Returns policy of given object statement. +func getObjectPolicy(statement Statement) (readOnly bool, writeOnly bool) { + if statement.Effect == "Allow" && + statement.Principal.AWS.Contains("*") && + statement.Conditions == nil { + if statement.Actions.Intersection(readOnlyObjectActions).Equals(readOnlyObjectActions) { + readOnly = true + } + if statement.Actions.Intersection(writeOnlyObjectActions).Equals(writeOnlyObjectActions) { + writeOnly = true + } + } + + return readOnly, writeOnly +} + +// GetPolicy - Returns policy of given bucket name, prefix in given statements. +func GetPolicy(statements []Statement, bucketName string, prefix string) BucketPolicy { + bucketResource := awsResourcePrefix + bucketName + objectResource := awsResourcePrefix + bucketName + "/" + prefix + "*" + + bucketCommonFound := false + bucketReadOnly := false + bucketWriteOnly := false + matchedResource := "" + objReadOnly := false + objWriteOnly := false + + for _, s := range statements { + matchedObjResources := set.NewStringSet() + if s.Resources.Contains(objectResource) { + matchedObjResources.Add(objectResource) + } else { + matchedObjResources = s.Resources.FuncMatch(resourceMatch, objectResource) + } + + if !matchedObjResources.IsEmpty() { + readOnly, writeOnly := getObjectPolicy(s) + for resource := range matchedObjResources { + if len(matchedResource) < len(resource) { + objReadOnly = readOnly + objWriteOnly = writeOnly + matchedResource = resource + } else if len(matchedResource) == len(resource) { + objReadOnly = objReadOnly || readOnly + objWriteOnly = objWriteOnly || writeOnly + matchedResource = resource + } + } + } else if s.Resources.Contains(bucketResource) { + commonFound, readOnly, writeOnly := getBucketPolicy(s, prefix) + bucketCommonFound = bucketCommonFound || commonFound + bucketReadOnly = bucketReadOnly || readOnly + bucketWriteOnly = bucketWriteOnly || writeOnly + } + } + + policy := BucketPolicyNone + if bucketCommonFound { + if bucketReadOnly && bucketWriteOnly && objReadOnly && objWriteOnly { + policy = BucketPolicyReadWrite + } else if bucketReadOnly && objReadOnly { + policy = BucketPolicyReadOnly + } else if bucketWriteOnly && objWriteOnly { + policy = BucketPolicyWriteOnly + } + } + + return policy +} + +// GetPolicies - returns a map of policies rules of given bucket name, prefix in given statements. +func GetPolicies(statements []Statement, bucketName string) map[string]BucketPolicy { + policyRules := map[string]BucketPolicy{} + objResources := set.NewStringSet() + // Search all resources related to objects policy + for _, s := range statements { + for r := range s.Resources { + if strings.HasPrefix(r, awsResourcePrefix+bucketName+"/") { + objResources.Add(r) + } + } + } + // Pretend that policy resource as an actual object and fetch its policy + for r := range objResources { + // Put trailing * if exists in asterisk + asterisk := "" + if strings.HasSuffix(r, "*") { + r = r[:len(r)-1] + asterisk = "*" + } + objectPath := r[len(awsResourcePrefix+bucketName)+1:] + p := GetPolicy(statements, bucketName, objectPath) + policyRules[bucketName+"/"+objectPath+asterisk] = p + } + return policyRules +} + +// SetPolicy - Returns new statements containing policy of given bucket name and prefix are appended. +func SetPolicy(statements []Statement, policy BucketPolicy, bucketName string, prefix string) []Statement { + out := removeStatements(statements, bucketName, prefix) + // fmt.Println("out = ") + // printstatement(out) + ns := newStatements(policy, bucketName, prefix) + // fmt.Println("ns = ") + // printstatement(ns) + + rv := appendStatements(out, ns) + // fmt.Println("rv = ") + // printstatement(rv) + + return rv +} + +// Match function matches wild cards in 'pattern' for resource. +func resourceMatch(pattern, resource string) bool { + if pattern == "" { + return resource == pattern + } + if pattern == "*" { + return true + } + parts := strings.Split(pattern, "*") + if len(parts) == 1 { + return resource == pattern + } + tGlob := strings.HasSuffix(pattern, "*") + end := len(parts) - 1 + if !strings.HasPrefix(resource, parts[0]) { + return false + } + for i := 1; i < end; i++ { + if !strings.Contains(resource, parts[i]) { + return false + } + idx := strings.Index(resource, parts[i]) + len(parts[i]) + resource = resource[idx:] + } + return tGlob || strings.HasSuffix(resource, parts[end]) +} diff --git a/vendor/github.com/minio/minio-go/pkg/s3signer/request-signature-streaming.go b/vendor/github.com/minio/minio-go/pkg/s3signer/request-signature-streaming.go new file mode 100644 index 000000000..156a6d63a --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/s3signer/request-signature-streaming.go @@ -0,0 +1,306 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package s3signer + +import ( + "bytes" + "encoding/hex" + "fmt" + "io" + "io/ioutil" + "net/http" + "strconv" + "strings" + "time" +) + +// Reference for constants used below - +// http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html#example-signature-calculations-streaming +const ( + streamingSignAlgorithm = "STREAMING-AWS4-HMAC-SHA256-PAYLOAD" + streamingPayloadHdr = "AWS4-HMAC-SHA256-PAYLOAD" + emptySHA256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + payloadChunkSize = 64 * 1024 + chunkSigConstLen = 17 // ";chunk-signature=" + signatureStrLen = 64 // e.g. "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2" + crlfLen = 2 // CRLF +) + +// Request headers to be ignored while calculating seed signature for +// a request. +var ignoredStreamingHeaders = map[string]bool{ + "Authorization": true, + "User-Agent": true, + "Content-Type": true, +} + +// getSignedChunkLength - calculates the length of chunk metadata +func getSignedChunkLength(chunkDataSize int64) int64 { + return int64(len(fmt.Sprintf("%x", chunkDataSize))) + + chunkSigConstLen + + signatureStrLen + + crlfLen + + chunkDataSize + + crlfLen +} + +// getStreamLength - calculates the length of the overall stream (data + metadata) +func getStreamLength(dataLen, chunkSize int64) int64 { + if dataLen <= 0 { + return 0 + } + + chunksCount := int64(dataLen / chunkSize) + remainingBytes := int64(dataLen % chunkSize) + streamLen := int64(0) + streamLen += chunksCount * getSignedChunkLength(chunkSize) + if remainingBytes > 0 { + streamLen += getSignedChunkLength(remainingBytes) + } + streamLen += getSignedChunkLength(0) + return streamLen +} + +// buildChunkStringToSign - returns the string to sign given chunk data +// and previous signature. +func buildChunkStringToSign(t time.Time, region, previousSig string, chunkData []byte) string { + stringToSignParts := []string{ + streamingPayloadHdr, + t.Format(iso8601DateFormat), + getScope(region, t), + previousSig, + emptySHA256, + hex.EncodeToString(sum256(chunkData)), + } + + return strings.Join(stringToSignParts, "\n") +} + +// prepareStreamingRequest - prepares a request with appropriate +// headers before computing the seed signature. +func prepareStreamingRequest(req *http.Request, sessionToken string, dataLen int64, timestamp time.Time) { + // Set x-amz-content-sha256 header. + req.Header.Set("X-Amz-Content-Sha256", streamingSignAlgorithm) + if sessionToken != "" { + req.Header.Set("X-Amz-Security-Token", sessionToken) + } + + req.Header.Set("X-Amz-Date", timestamp.Format(iso8601DateFormat)) + // Set content length with streaming signature for each chunk included. + req.ContentLength = getStreamLength(dataLen, int64(payloadChunkSize)) + req.Header.Set("x-amz-decoded-content-length", strconv.FormatInt(dataLen, 10)) +} + +// buildChunkHeader - returns the chunk header. +// e.g string(IntHexBase(chunk-size)) + ";chunk-signature=" + signature + \r\n + chunk-data + \r\n +func buildChunkHeader(chunkLen int64, signature string) []byte { + return []byte(strconv.FormatInt(chunkLen, 16) + ";chunk-signature=" + signature + "\r\n") +} + +// buildChunkSignature - returns chunk signature for a given chunk and previous signature. +func buildChunkSignature(chunkData []byte, reqTime time.Time, region, + previousSignature, secretAccessKey string) string { + + chunkStringToSign := buildChunkStringToSign(reqTime, region, + previousSignature, chunkData) + signingKey := getSigningKey(secretAccessKey, region, reqTime) + return getSignature(signingKey, chunkStringToSign) +} + +// getSeedSignature - returns the seed signature for a given request. +func (s *StreamingReader) setSeedSignature(req *http.Request) { + // Get canonical request + canonicalRequest := getCanonicalRequest(*req, ignoredStreamingHeaders) + + // Get string to sign from canonical request. + stringToSign := getStringToSignV4(s.reqTime, s.region, canonicalRequest) + + signingKey := getSigningKey(s.secretAccessKey, s.region, s.reqTime) + + // Calculate signature. + s.seedSignature = getSignature(signingKey, stringToSign) +} + +// StreamingReader implements chunked upload signature as a reader on +// top of req.Body's ReaderCloser chunk header;data;... repeat +type StreamingReader struct { + accessKeyID string + secretAccessKey string + sessionToken string + region string + prevSignature string + seedSignature string + contentLen int64 // Content-Length from req header + baseReadCloser io.ReadCloser // underlying io.Reader + bytesRead int64 // bytes read from underlying io.Reader + buf bytes.Buffer // holds signed chunk + chunkBuf []byte // holds raw data read from req Body + chunkBufLen int // no. of bytes read so far into chunkBuf + done bool // done reading the underlying reader to EOF + reqTime time.Time + chunkNum int + totalChunks int + lastChunkSize int +} + +// signChunk - signs a chunk read from s.baseReader of chunkLen size. +func (s *StreamingReader) signChunk(chunkLen int) { + // Compute chunk signature for next header + signature := buildChunkSignature(s.chunkBuf[:chunkLen], s.reqTime, + s.region, s.prevSignature, s.secretAccessKey) + + // For next chunk signature computation + s.prevSignature = signature + + // Write chunk header into streaming buffer + chunkHdr := buildChunkHeader(int64(chunkLen), signature) + s.buf.Write(chunkHdr) + + // Write chunk data into streaming buffer + s.buf.Write(s.chunkBuf[:chunkLen]) + + // Write the chunk trailer. + s.buf.Write([]byte("\r\n")) + + // Reset chunkBufLen for next chunk read. + s.chunkBufLen = 0 + s.chunkNum++ +} + +// setStreamingAuthHeader - builds and sets authorization header value +// for streaming signature. +func (s *StreamingReader) setStreamingAuthHeader(req *http.Request) { + credential := GetCredential(s.accessKeyID, s.region, s.reqTime) + authParts := []string{ + signV4Algorithm + " Credential=" + credential, + "SignedHeaders=" + getSignedHeaders(*req, ignoredStreamingHeaders), + "Signature=" + s.seedSignature, + } + + // Set authorization header. + auth := strings.Join(authParts, ",") + req.Header.Set("Authorization", auth) +} + +// StreamingSignV4 - provides chunked upload signatureV4 support by +// implementing io.Reader. +func StreamingSignV4(req *http.Request, accessKeyID, secretAccessKey, sessionToken, + region string, dataLen int64, reqTime time.Time) *http.Request { + + // Set headers needed for streaming signature. + prepareStreamingRequest(req, sessionToken, dataLen, reqTime) + + if req.Body == nil { + req.Body = ioutil.NopCloser(bytes.NewReader([]byte(""))) + } + + stReader := &StreamingReader{ + baseReadCloser: req.Body, + accessKeyID: accessKeyID, + secretAccessKey: secretAccessKey, + sessionToken: sessionToken, + region: region, + reqTime: reqTime, + chunkBuf: make([]byte, payloadChunkSize), + contentLen: dataLen, + chunkNum: 1, + totalChunks: int((dataLen+payloadChunkSize-1)/payloadChunkSize) + 1, + lastChunkSize: int(dataLen % payloadChunkSize), + } + + // Add the request headers required for chunk upload signing. + + // Compute the seed signature. + stReader.setSeedSignature(req) + + // Set the authorization header with the seed signature. + stReader.setStreamingAuthHeader(req) + + // Set seed signature as prevSignature for subsequent + // streaming signing process. + stReader.prevSignature = stReader.seedSignature + req.Body = stReader + + return req +} + +// Read - this method performs chunk upload signature providing a +// io.Reader interface. +func (s *StreamingReader) Read(buf []byte) (int, error) { + switch { + // After the last chunk is read from underlying reader, we + // never re-fill s.buf. + case s.done: + + // s.buf will be (re-)filled with next chunk when has lesser + // bytes than asked for. + case s.buf.Len() < len(buf): + s.chunkBufLen = 0 + for { + n1, err := s.baseReadCloser.Read(s.chunkBuf[s.chunkBufLen:]) + // Usually we validate `err` first, but in this case + // we are validating n > 0 for the following reasons. + // + // 1. n > 0, err is one of io.EOF, nil (near end of stream) + // A Reader returning a non-zero number of bytes at the end + // of the input stream may return either err == EOF or err == nil + // + // 2. n == 0, err is io.EOF (actual end of stream) + // + // Callers should always process the n > 0 bytes returned + // before considering the error err. + if n1 > 0 { + s.chunkBufLen += n1 + s.bytesRead += int64(n1) + + if s.chunkBufLen == payloadChunkSize || + (s.chunkNum == s.totalChunks-1 && + s.chunkBufLen == s.lastChunkSize) { + // Sign the chunk and write it to s.buf. + s.signChunk(s.chunkBufLen) + break + } + } + if err != nil { + if err == io.EOF { + // No more data left in baseReader - last chunk. + // Done reading the last chunk from baseReader. + s.done = true + + // bytes read from baseReader different than + // content length provided. + if s.bytesRead != s.contentLen { + return 0, io.ErrUnexpectedEOF + } + + // Sign the chunk and write it to s.buf. + s.signChunk(0) + break + } + return 0, err + } + + } + } + return s.buf.Read(buf) +} + +// Close - this method makes underlying io.ReadCloser's Close method available. +func (s *StreamingReader) Close() error { + return s.baseReadCloser.Close() +} diff --git a/vendor/github.com/minio/minio-go/pkg/s3signer/request-signature-v2.go b/vendor/github.com/minio/minio-go/pkg/s3signer/request-signature-v2.go new file mode 100644 index 000000000..620af1c59 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/s3signer/request-signature-v2.go @@ -0,0 +1,320 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package s3signer + +import ( + "bytes" + "crypto/hmac" + "crypto/sha1" + "encoding/base64" + "fmt" + "net/http" + "net/url" + "path/filepath" + "sort" + "strconv" + "strings" + "time" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// Signature and API related constants. +const ( + signV2Algorithm = "AWS" +) + +// Encode input URL path to URL encoded path. +func encodeURL2Path(u *url.URL) (path string) { + // Encode URL path. + if isS3, _ := filepath.Match("*.s3*.amazonaws.com", u.Host); isS3 { + bucketName := u.Host[:strings.LastIndex(u.Host, ".s3")] + path = "/" + bucketName + path += u.Path + path = s3utils.EncodePath(path) + return + } + if strings.HasSuffix(u.Host, ".storage.googleapis.com") { + path = "/" + strings.TrimSuffix(u.Host, ".storage.googleapis.com") + path += u.Path + path = s3utils.EncodePath(path) + return + } + path = s3utils.EncodePath(u.Path) + return +} + +// PreSignV2 - presign the request in following style. +// https://${S3_BUCKET}.s3.amazonaws.com/${S3_OBJECT}?AWSAccessKeyId=${S3_ACCESS_KEY}&Expires=${TIMESTAMP}&Signature=${SIGNATURE}. +func PreSignV2(req http.Request, accessKeyID, secretAccessKey string, expires int64) *http.Request { + // Presign is not needed for anonymous credentials. + if accessKeyID == "" || secretAccessKey == "" { + return &req + } + + d := time.Now().UTC() + // Find epoch expires when the request will expire. + epochExpires := d.Unix() + expires + + // Add expires header if not present. + if expiresStr := req.Header.Get("Expires"); expiresStr == "" { + req.Header.Set("Expires", strconv.FormatInt(epochExpires, 10)) + } + + // Get presigned string to sign. + stringToSign := preStringToSignV2(req) + hm := hmac.New(sha1.New, []byte(secretAccessKey)) + hm.Write([]byte(stringToSign)) + + // Calculate signature. + signature := base64.StdEncoding.EncodeToString(hm.Sum(nil)) + + query := req.URL.Query() + // Handle specially for Google Cloud Storage. + if strings.Contains(req.URL.Host, ".storage.googleapis.com") { + query.Set("GoogleAccessId", accessKeyID) + } else { + query.Set("AWSAccessKeyId", accessKeyID) + } + + // Fill in Expires for presigned query. + query.Set("Expires", strconv.FormatInt(epochExpires, 10)) + + // Encode query and save. + req.URL.RawQuery = s3utils.QueryEncode(query) + + // Save signature finally. + req.URL.RawQuery += "&Signature=" + s3utils.EncodePath(signature) + + // Return. + return &req +} + +// PostPresignSignatureV2 - presigned signature for PostPolicy +// request. +func PostPresignSignatureV2(policyBase64, secretAccessKey string) string { + hm := hmac.New(sha1.New, []byte(secretAccessKey)) + hm.Write([]byte(policyBase64)) + signature := base64.StdEncoding.EncodeToString(hm.Sum(nil)) + return signature +} + +// Authorization = "AWS" + " " + AWSAccessKeyId + ":" + Signature; +// Signature = Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) ); +// +// StringToSign = HTTP-Verb + "\n" + +// Content-Md5 + "\n" + +// Content-Type + "\n" + +// Date + "\n" + +// CanonicalizedProtocolHeaders + +// CanonicalizedResource; +// +// CanonicalizedResource = [ "/" + Bucket ] + +// + +// [ subresource, if present. For example "?acl", "?location", "?logging", or "?torrent"]; +// +// CanonicalizedProtocolHeaders = + +// SignV2 sign the request before Do() (AWS Signature Version 2). +func SignV2(req http.Request, accessKeyID, secretAccessKey string) *http.Request { + // Signature calculation is not needed for anonymous credentials. + if accessKeyID == "" || secretAccessKey == "" { + return &req + } + + // Initial time. + d := time.Now().UTC() + + // Add date if not present. + if date := req.Header.Get("Date"); date == "" { + req.Header.Set("Date", d.Format(http.TimeFormat)) + } + + // Calculate HMAC for secretAccessKey. + stringToSign := stringToSignV2(req) + hm := hmac.New(sha1.New, []byte(secretAccessKey)) + hm.Write([]byte(stringToSign)) + + // Prepare auth header. + authHeader := new(bytes.Buffer) + authHeader.WriteString(fmt.Sprintf("%s %s:", signV2Algorithm, accessKeyID)) + encoder := base64.NewEncoder(base64.StdEncoding, authHeader) + encoder.Write(hm.Sum(nil)) + encoder.Close() + + // Set Authorization header. + req.Header.Set("Authorization", authHeader.String()) + + return &req +} + +// From the Amazon docs: +// +// StringToSign = HTTP-Verb + "\n" + +// Content-Md5 + "\n" + +// Content-Type + "\n" + +// Expires + "\n" + +// CanonicalizedProtocolHeaders + +// CanonicalizedResource; +func preStringToSignV2(req http.Request) string { + buf := new(bytes.Buffer) + // Write standard headers. + writePreSignV2Headers(buf, req) + // Write canonicalized protocol headers if any. + writeCanonicalizedHeaders(buf, req) + // Write canonicalized Query resources if any. + writeCanonicalizedResource(buf, req) + return buf.String() +} + +// writePreSignV2Headers - write preSign v2 required headers. +func writePreSignV2Headers(buf *bytes.Buffer, req http.Request) { + buf.WriteString(req.Method + "\n") + buf.WriteString(req.Header.Get("Content-Md5") + "\n") + buf.WriteString(req.Header.Get("Content-Type") + "\n") + buf.WriteString(req.Header.Get("Expires") + "\n") +} + +// From the Amazon docs: +// +// StringToSign = HTTP-Verb + "\n" + +// Content-Md5 + "\n" + +// Content-Type + "\n" + +// Date + "\n" + +// CanonicalizedProtocolHeaders + +// CanonicalizedResource; +func stringToSignV2(req http.Request) string { + buf := new(bytes.Buffer) + // Write standard headers. + writeSignV2Headers(buf, req) + // Write canonicalized protocol headers if any. + writeCanonicalizedHeaders(buf, req) + // Write canonicalized Query resources if any. + writeCanonicalizedResource(buf, req) + return buf.String() +} + +// writeSignV2Headers - write signV2 required headers. +func writeSignV2Headers(buf *bytes.Buffer, req http.Request) { + buf.WriteString(req.Method + "\n") + buf.WriteString(req.Header.Get("Content-Md5") + "\n") + buf.WriteString(req.Header.Get("Content-Type") + "\n") + buf.WriteString(req.Header.Get("Date") + "\n") +} + +// writeCanonicalizedHeaders - write canonicalized headers. +func writeCanonicalizedHeaders(buf *bytes.Buffer, req http.Request) { + var protoHeaders []string + vals := make(map[string][]string) + for k, vv := range req.Header { + // All the AMZ headers should be lowercase + lk := strings.ToLower(k) + if strings.HasPrefix(lk, "x-amz") { + protoHeaders = append(protoHeaders, lk) + vals[lk] = vv + } + } + sort.Strings(protoHeaders) + for _, k := range protoHeaders { + buf.WriteString(k) + buf.WriteByte(':') + for idx, v := range vals[k] { + if idx > 0 { + buf.WriteByte(',') + } + if strings.Contains(v, "\n") { + // TODO: "Unfold" long headers that + // span multiple lines (as allowed by + // RFC 2616, section 4.2) by replacing + // the folding white-space (including + // new-line) by a single space. + buf.WriteString(v) + } else { + buf.WriteString(v) + } + } + buf.WriteByte('\n') + } +} + +// AWS S3 Signature V2 calculation rule is give here: +// http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationStringToSign + +// Whitelist resource list that will be used in query string for signature-V2 calculation. +// The list should be alphabetically sorted +var resourceList = []string{ + "acl", + "delete", + "lifecycle", + "location", + "logging", + "notification", + "partNumber", + "policy", + "requestPayment", + "response-cache-control", + "response-content-disposition", + "response-content-encoding", + "response-content-language", + "response-content-type", + "response-expires", + "torrent", + "uploadId", + "uploads", + "versionId", + "versioning", + "versions", + "website", +} + +// From the Amazon docs: +// +// CanonicalizedResource = [ "/" + Bucket ] + +// + +// [ sub-resource, if present. For example "?acl", "?location", "?logging", or "?torrent"]; +func writeCanonicalizedResource(buf *bytes.Buffer, req http.Request) { + // Save request URL. + requestURL := req.URL + // Get encoded URL path. + buf.WriteString(encodeURL2Path(requestURL)) + if requestURL.RawQuery != "" { + var n int + vals, _ := url.ParseQuery(requestURL.RawQuery) + // Verify if any sub resource queries are present, if yes + // canonicallize them. + for _, resource := range resourceList { + if vv, ok := vals[resource]; ok && len(vv) > 0 { + n++ + // First element + switch n { + case 1: + buf.WriteByte('?') + // The rest + default: + buf.WriteByte('&') + } + buf.WriteString(resource) + // Request parameters + if len(vv[0]) > 0 { + buf.WriteByte('=') + buf.WriteString(vv[0]) + } + } + } + } +} diff --git a/vendor/github.com/minio/minio-go/pkg/s3signer/request-signature-v4.go b/vendor/github.com/minio/minio-go/pkg/s3signer/request-signature-v4.go new file mode 100644 index 000000000..d5721ac4b --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/s3signer/request-signature-v4.go @@ -0,0 +1,315 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package s3signer + +import ( + "bytes" + "encoding/hex" + "net/http" + "sort" + "strconv" + "strings" + "time" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// Signature and API related constants. +const ( + signV4Algorithm = "AWS4-HMAC-SHA256" + iso8601DateFormat = "20060102T150405Z" + yyyymmdd = "20060102" +) + +/// +/// Excerpts from @lsegal - +/// https://github.com/aws/aws-sdk-js/issues/659#issuecomment-120477258. +/// +/// User-Agent: +/// +/// This is ignored from signing because signing this causes +/// problems with generating pre-signed URLs (that are executed +/// by other agents) or when customers pass requests through +/// proxies, which may modify the user-agent. +/// +/// Content-Length: +/// +/// This is ignored from signing because generating a pre-signed +/// URL should not provide a content-length constraint, +/// specifically when vending a S3 pre-signed PUT URL. The +/// corollary to this is that when sending regular requests +/// (non-pre-signed), the signature contains a checksum of the +/// body, which implicitly validates the payload length (since +/// changing the number of bytes would change the checksum) +/// and therefore this header is not valuable in the signature. +/// +/// Content-Type: +/// +/// Signing this header causes quite a number of problems in +/// browser environments, where browsers like to modify and +/// normalize the content-type header in different ways. There is +/// more information on this in https://goo.gl/2E9gyy. Avoiding +/// this field simplifies logic and reduces the possibility of +/// future bugs. +/// +/// Authorization: +/// +/// Is skipped for obvious reasons +/// +var v4IgnoredHeaders = map[string]bool{ + "Authorization": true, + "Content-Type": true, + "Content-Length": true, + "User-Agent": true, +} + +// getSigningKey hmac seed to calculate final signature. +func getSigningKey(secret, loc string, t time.Time) []byte { + date := sumHMAC([]byte("AWS4"+secret), []byte(t.Format(yyyymmdd))) + location := sumHMAC(date, []byte(loc)) + service := sumHMAC(location, []byte("s3")) + signingKey := sumHMAC(service, []byte("aws4_request")) + return signingKey +} + +// getSignature final signature in hexadecimal form. +func getSignature(signingKey []byte, stringToSign string) string { + return hex.EncodeToString(sumHMAC(signingKey, []byte(stringToSign))) +} + +// getScope generate a string of a specific date, an AWS region, and a +// service. +func getScope(location string, t time.Time) string { + scope := strings.Join([]string{ + t.Format(yyyymmdd), + location, + "s3", + "aws4_request", + }, "/") + return scope +} + +// GetCredential generate a credential string. +func GetCredential(accessKeyID, location string, t time.Time) string { + scope := getScope(location, t) + return accessKeyID + "/" + scope +} + +// getHashedPayload get the hexadecimal value of the SHA256 hash of +// the request payload. +func getHashedPayload(req http.Request) string { + hashedPayload := req.Header.Get("X-Amz-Content-Sha256") + if hashedPayload == "" { + // Presign does not have a payload, use S3 recommended value. + hashedPayload = unsignedPayload + } + return hashedPayload +} + +// getCanonicalHeaders generate a list of request headers for +// signature. +func getCanonicalHeaders(req http.Request, ignoredHeaders map[string]bool) string { + var headers []string + vals := make(map[string][]string) + for k, vv := range req.Header { + if _, ok := ignoredHeaders[http.CanonicalHeaderKey(k)]; ok { + continue // ignored header + } + headers = append(headers, strings.ToLower(k)) + vals[strings.ToLower(k)] = vv + } + headers = append(headers, "host") + sort.Strings(headers) + + var buf bytes.Buffer + // Save all the headers in canonical form
: newline + // separated for each header. + for _, k := range headers { + buf.WriteString(k) + buf.WriteByte(':') + switch { + case k == "host": + buf.WriteString(req.URL.Host) + fallthrough + default: + for idx, v := range vals[k] { + if idx > 0 { + buf.WriteByte(',') + } + buf.WriteString(v) + } + buf.WriteByte('\n') + } + } + return buf.String() +} + +// getSignedHeaders generate all signed request headers. +// i.e lexically sorted, semicolon-separated list of lowercase +// request header names. +func getSignedHeaders(req http.Request, ignoredHeaders map[string]bool) string { + var headers []string + for k := range req.Header { + if _, ok := ignoredHeaders[http.CanonicalHeaderKey(k)]; ok { + continue // Ignored header found continue. + } + headers = append(headers, strings.ToLower(k)) + } + headers = append(headers, "host") + sort.Strings(headers) + return strings.Join(headers, ";") +} + +// getCanonicalRequest generate a canonical request of style. +// +// canonicalRequest = +// \n +// \n +// \n +// \n +// \n +// +func getCanonicalRequest(req http.Request, ignoredHeaders map[string]bool) string { + req.URL.RawQuery = strings.Replace(req.URL.Query().Encode(), "+", "%20", -1) + canonicalRequest := strings.Join([]string{ + req.Method, + s3utils.EncodePath(req.URL.Path), + req.URL.RawQuery, + getCanonicalHeaders(req, ignoredHeaders), + getSignedHeaders(req, ignoredHeaders), + getHashedPayload(req), + }, "\n") + return canonicalRequest +} + +// getStringToSign a string based on selected query values. +func getStringToSignV4(t time.Time, location, canonicalRequest string) string { + stringToSign := signV4Algorithm + "\n" + t.Format(iso8601DateFormat) + "\n" + stringToSign = stringToSign + getScope(location, t) + "\n" + stringToSign = stringToSign + hex.EncodeToString(sum256([]byte(canonicalRequest))) + return stringToSign +} + +// PreSignV4 presign the request, in accordance with +// http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html. +func PreSignV4(req http.Request, accessKeyID, secretAccessKey, sessionToken, location string, expires int64) *http.Request { + // Presign is not needed for anonymous credentials. + if accessKeyID == "" || secretAccessKey == "" { + return &req + } + + // Initial time. + t := time.Now().UTC() + + // Get credential string. + credential := GetCredential(accessKeyID, location, t) + + // Get all signed headers. + signedHeaders := getSignedHeaders(req, v4IgnoredHeaders) + + // Set URL query. + query := req.URL.Query() + query.Set("X-Amz-Algorithm", signV4Algorithm) + query.Set("X-Amz-Date", t.Format(iso8601DateFormat)) + query.Set("X-Amz-Expires", strconv.FormatInt(expires, 10)) + query.Set("X-Amz-SignedHeaders", signedHeaders) + query.Set("X-Amz-Credential", credential) + // Set session token if available. + if sessionToken != "" { + query.Set("X-Amz-Security-Token", sessionToken) + } + req.URL.RawQuery = query.Encode() + + // Get canonical request. + canonicalRequest := getCanonicalRequest(req, v4IgnoredHeaders) + + // Get string to sign from canonical request. + stringToSign := getStringToSignV4(t, location, canonicalRequest) + + // Gext hmac signing key. + signingKey := getSigningKey(secretAccessKey, location, t) + + // Calculate signature. + signature := getSignature(signingKey, stringToSign) + + // Add signature header to RawQuery. + req.URL.RawQuery += "&X-Amz-Signature=" + signature + + return &req +} + +// PostPresignSignatureV4 - presigned signature for PostPolicy +// requests. +func PostPresignSignatureV4(policyBase64 string, t time.Time, secretAccessKey, location string) string { + // Get signining key. + signingkey := getSigningKey(secretAccessKey, location, t) + // Calculate signature. + signature := getSignature(signingkey, policyBase64) + return signature +} + +// SignV4 sign the request before Do(), in accordance with +// http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html. +func SignV4(req http.Request, accessKeyID, secretAccessKey, sessionToken, location string) *http.Request { + // Signature calculation is not needed for anonymous credentials. + if accessKeyID == "" || secretAccessKey == "" { + return &req + } + + // Initial time. + t := time.Now().UTC() + + // Set x-amz-date. + req.Header.Set("X-Amz-Date", t.Format(iso8601DateFormat)) + + // Set session token if available. + if sessionToken != "" { + req.Header.Set("X-Amz-Security-Token", sessionToken) + } + + // Get canonical request. + canonicalRequest := getCanonicalRequest(req, v4IgnoredHeaders) + + // Get string to sign from canonical request. + stringToSign := getStringToSignV4(t, location, canonicalRequest) + + // Get hmac signing key. + signingKey := getSigningKey(secretAccessKey, location, t) + + // Get credential string. + credential := GetCredential(accessKeyID, location, t) + + // Get all signed headers. + signedHeaders := getSignedHeaders(req, v4IgnoredHeaders) + + // Calculate signature. + signature := getSignature(signingKey, stringToSign) + + // If regular request, construct the final authorization header. + parts := []string{ + signV4Algorithm + " Credential=" + credential, + "SignedHeaders=" + signedHeaders, + "Signature=" + signature, + } + + // Set authorization header. + auth := strings.Join(parts, ", ") + req.Header.Set("Authorization", auth) + + return &req +} diff --git a/vendor/github.com/minio/minio-go/pkg/s3signer/utils.go b/vendor/github.com/minio/minio-go/pkg/s3signer/utils.go new file mode 100644 index 000000000..29243635a --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/s3signer/utils.go @@ -0,0 +1,40 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package s3signer + +import ( + "crypto/hmac" + "crypto/sha256" +) + +// unsignedPayload - value to be set to X-Amz-Content-Sha256 header when +const unsignedPayload = "UNSIGNED-PAYLOAD" + +// sum256 calculate sha256 sum for an input byte array. +func sum256(data []byte) []byte { + hash := sha256.New() + hash.Write(data) + return hash.Sum(nil) +} + +// sumHMAC calculate hmac between two input byte array. +func sumHMAC(key []byte, data []byte) []byte { + hash := hmac.New(sha256.New, key) + hash.Write(data) + return hash.Sum(nil) +} diff --git a/vendor/github.com/minio/minio-go/pkg/s3utils/utils.go b/vendor/github.com/minio/minio-go/pkg/s3utils/utils.go new file mode 100644 index 000000000..258390f63 --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/s3utils/utils.go @@ -0,0 +1,277 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package s3utils + +import ( + "bytes" + "encoding/hex" + "errors" + "net" + "net/url" + "regexp" + "sort" + "strings" + "unicode/utf8" +) + +// Sentinel URL is the default url value which is invalid. +var sentinelURL = url.URL{} + +// IsValidDomain validates if input string is a valid domain name. +func IsValidDomain(host string) bool { + // See RFC 1035, RFC 3696. + host = strings.TrimSpace(host) + if len(host) == 0 || len(host) > 255 { + return false + } + // host cannot start or end with "-" + if host[len(host)-1:] == "-" || host[:1] == "-" { + return false + } + // host cannot start or end with "_" + if host[len(host)-1:] == "_" || host[:1] == "_" { + return false + } + // host cannot start or end with a "." + if host[len(host)-1:] == "." || host[:1] == "." { + return false + } + // All non alphanumeric characters are invalid. + if strings.ContainsAny(host, "`~!@#$%^&*()+={}[]|\\\"';:> 0 { + buf.WriteByte('&') + } + buf.WriteString(prefix) + buf.WriteString(percentEncodeSlash(EncodePath(v))) + } + } + return buf.String() +} + +// if object matches reserved string, no need to encode them +var reservedObjectNames = regexp.MustCompile("^[a-zA-Z0-9-_.~/]+$") + +// EncodePath encode the strings from UTF-8 byte representations to HTML hex escape sequences +// +// This is necessary since regular url.Parse() and url.Encode() functions do not support UTF-8 +// non english characters cannot be parsed due to the nature in which url.Encode() is written +// +// This function on the other hand is a direct replacement for url.Encode() technique to support +// pretty much every UTF-8 character. +func EncodePath(pathName string) string { + if reservedObjectNames.MatchString(pathName) { + return pathName + } + var encodedPathname string + for _, s := range pathName { + if 'A' <= s && s <= 'Z' || 'a' <= s && s <= 'z' || '0' <= s && s <= '9' { // §2.3 Unreserved characters (mark) + encodedPathname = encodedPathname + string(s) + continue + } + switch s { + case '-', '_', '.', '~', '/': // §2.3 Unreserved characters (mark) + encodedPathname = encodedPathname + string(s) + continue + default: + len := utf8.RuneLen(s) + if len < 0 { + // if utf8 cannot convert return the same string as is + return pathName + } + u := make([]byte, len) + utf8.EncodeRune(u, s) + for _, r := range u { + hex := hex.EncodeToString([]byte{r}) + encodedPathname = encodedPathname + "%" + strings.ToUpper(hex) + } + } + } + return encodedPathname +} + +// We support '.' with bucket names but we fallback to using path +// style requests instead for such buckets. +var ( + validBucketName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9\.\-\_\:]{1,61}[A-Za-z0-9]$`) + validBucketNameStrict = regexp.MustCompile(`^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$`) + ipAddress = regexp.MustCompile(`^(\d+\.){3}\d+$`) +) + +// Common checker for both stricter and basic validation. +func checkBucketNameCommon(bucketName string, strict bool) (err error) { + if strings.TrimSpace(bucketName) == "" { + return errors.New("Bucket name cannot be empty") + } + if len(bucketName) < 3 { + return errors.New("Bucket name cannot be smaller than 3 characters") + } + if len(bucketName) > 63 { + return errors.New("Bucket name cannot be greater than 63 characters") + } + if ipAddress.MatchString(bucketName) { + return errors.New("Bucket name cannot be an ip address") + } + if strings.Contains(bucketName, "..") { + return errors.New("Bucket name contains invalid characters") + } + if strict { + if !validBucketNameStrict.MatchString(bucketName) { + err = errors.New("Bucket name contains invalid characters") + } + return err + } + if !validBucketName.MatchString(bucketName) { + err = errors.New("Bucket name contains invalid characters") + } + return err +} + +// CheckValidBucketName - checks if we have a valid input bucket name. +func CheckValidBucketName(bucketName string) (err error) { + return checkBucketNameCommon(bucketName, false) +} + +// CheckValidBucketNameStrict - checks if we have a valid input bucket name. +// This is a stricter version. +// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html +func CheckValidBucketNameStrict(bucketName string) (err error) { + return checkBucketNameCommon(bucketName, true) +} + +// CheckValidObjectNamePrefix - checks if we have a valid input object name prefix. +// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html +func CheckValidObjectNamePrefix(objectName string) error { + if len(objectName) > 1024 { + return errors.New("Object name cannot be greater than 1024 characters") + } + if !utf8.ValidString(objectName) { + return errors.New("Object name with non UTF-8 strings are not supported") + } + return nil +} + +// CheckValidObjectName - checks if we have a valid input object name. +// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html +func CheckValidObjectName(objectName string) error { + if strings.TrimSpace(objectName) == "" { + return errors.New("Object name cannot be empty") + } + return CheckValidObjectNamePrefix(objectName) +} diff --git a/vendor/github.com/minio/minio-go/pkg/set/stringset.go b/vendor/github.com/minio/minio-go/pkg/set/stringset.go new file mode 100644 index 000000000..efd02629b --- /dev/null +++ b/vendor/github.com/minio/minio-go/pkg/set/stringset.go @@ -0,0 +1,197 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package set + +import ( + "encoding/json" + "fmt" + "sort" +) + +// StringSet - uses map as set of strings. +type StringSet map[string]struct{} + +// ToSlice - returns StringSet as string slice. +func (set StringSet) ToSlice() []string { + keys := make([]string, 0, len(set)) + for k := range set { + keys = append(keys, k) + } + sort.Strings(keys) + return keys +} + +// IsEmpty - returns whether the set is empty or not. +func (set StringSet) IsEmpty() bool { + return len(set) == 0 +} + +// Add - adds string to the set. +func (set StringSet) Add(s string) { + set[s] = struct{}{} +} + +// Remove - removes string in the set. It does nothing if string does not exist in the set. +func (set StringSet) Remove(s string) { + delete(set, s) +} + +// Contains - checks if string is in the set. +func (set StringSet) Contains(s string) bool { + _, ok := set[s] + return ok +} + +// FuncMatch - returns new set containing each value who passes match function. +// A 'matchFn' should accept element in a set as first argument and +// 'matchString' as second argument. The function can do any logic to +// compare both the arguments and should return true to accept element in +// a set to include in output set else the element is ignored. +func (set StringSet) FuncMatch(matchFn func(string, string) bool, matchString string) StringSet { + nset := NewStringSet() + for k := range set { + if matchFn(k, matchString) { + nset.Add(k) + } + } + return nset +} + +// ApplyFunc - returns new set containing each value processed by 'applyFn'. +// A 'applyFn' should accept element in a set as a argument and return +// a processed string. The function can do any logic to return a processed +// string. +func (set StringSet) ApplyFunc(applyFn func(string) string) StringSet { + nset := NewStringSet() + for k := range set { + nset.Add(applyFn(k)) + } + return nset +} + +// Equals - checks whether given set is equal to current set or not. +func (set StringSet) Equals(sset StringSet) bool { + // If length of set is not equal to length of given set, the + // set is not equal to given set. + if len(set) != len(sset) { + return false + } + + // As both sets are equal in length, check each elements are equal. + for k := range set { + if _, ok := sset[k]; !ok { + return false + } + } + + return true +} + +// Intersection - returns the intersection with given set as new set. +func (set StringSet) Intersection(sset StringSet) StringSet { + nset := NewStringSet() + for k := range set { + if _, ok := sset[k]; ok { + nset.Add(k) + } + } + + return nset +} + +// Difference - returns the difference with given set as new set. +func (set StringSet) Difference(sset StringSet) StringSet { + nset := NewStringSet() + for k := range set { + if _, ok := sset[k]; !ok { + nset.Add(k) + } + } + + return nset +} + +// Union - returns the union with given set as new set. +func (set StringSet) Union(sset StringSet) StringSet { + nset := NewStringSet() + for k := range set { + nset.Add(k) + } + + for k := range sset { + nset.Add(k) + } + + return nset +} + +// MarshalJSON - converts to JSON data. +func (set StringSet) MarshalJSON() ([]byte, error) { + return json.Marshal(set.ToSlice()) +} + +// UnmarshalJSON - parses JSON data and creates new set with it. +// If 'data' contains JSON string array, the set contains each string. +// If 'data' contains JSON string, the set contains the string as one element. +// If 'data' contains Other JSON types, JSON parse error is returned. +func (set *StringSet) UnmarshalJSON(data []byte) error { + sl := []string{} + var err error + if err = json.Unmarshal(data, &sl); err == nil { + *set = make(StringSet) + for _, s := range sl { + set.Add(s) + } + } else { + var s string + if err = json.Unmarshal(data, &s); err == nil { + *set = make(StringSet) + set.Add(s) + } + } + + return err +} + +// String - returns printable string of the set. +func (set StringSet) String() string { + return fmt.Sprintf("%s", set.ToSlice()) +} + +// NewStringSet - creates new string set. +func NewStringSet() StringSet { + return make(StringSet) +} + +// CreateStringSet - creates new string set with given string values. +func CreateStringSet(sl ...string) StringSet { + set := make(StringSet) + for _, k := range sl { + set.Add(k) + } + return set +} + +// CopyStringSet - returns copy of given set. +func CopyStringSet(set StringSet) StringSet { + nset := NewStringSet() + for k, v := range set { + nset[k] = v + } + return nset +} diff --git a/vendor/github.com/minio/minio-go/post-policy.go b/vendor/github.com/minio/minio-go/post-policy.go new file mode 100644 index 000000000..b3ae7050a --- /dev/null +++ b/vendor/github.com/minio/minio-go/post-policy.go @@ -0,0 +1,248 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "encoding/base64" + "fmt" + "strings" + "time" +) + +// expirationDateFormat date format for expiration key in json policy. +const expirationDateFormat = "2006-01-02T15:04:05.999Z" + +// policyCondition explanation: +// http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html +// +// Example: +// +// policyCondition { +// matchType: "$eq", +// key: "$Content-Type", +// value: "image/png", +// } +// +type policyCondition struct { + matchType string + condition string + value string +} + +// PostPolicy - Provides strict static type conversion and validation +// for Amazon S3's POST policy JSON string. +type PostPolicy struct { + // Expiration date and time of the POST policy. + expiration time.Time + // Collection of different policy conditions. + conditions []policyCondition + // ContentLengthRange minimum and maximum allowable size for the + // uploaded content. + contentLengthRange struct { + min int64 + max int64 + } + + // Post form data. + formData map[string]string +} + +// NewPostPolicy - Instantiate new post policy. +func NewPostPolicy() *PostPolicy { + p := &PostPolicy{} + p.conditions = make([]policyCondition, 0) + p.formData = make(map[string]string) + return p +} + +// SetExpires - Sets expiration time for the new policy. +func (p *PostPolicy) SetExpires(t time.Time) error { + if t.IsZero() { + return ErrInvalidArgument("No expiry time set.") + } + p.expiration = t + return nil +} + +// SetKey - Sets an object name for the policy based upload. +func (p *PostPolicy) SetKey(key string) error { + if strings.TrimSpace(key) == "" || key == "" { + return ErrInvalidArgument("Object name is empty.") + } + policyCond := policyCondition{ + matchType: "eq", + condition: "$key", + value: key, + } + if err := p.addNewPolicy(policyCond); err != nil { + return err + } + p.formData["key"] = key + return nil +} + +// SetKeyStartsWith - Sets an object name that an policy based upload +// can start with. +func (p *PostPolicy) SetKeyStartsWith(keyStartsWith string) error { + if strings.TrimSpace(keyStartsWith) == "" || keyStartsWith == "" { + return ErrInvalidArgument("Object prefix is empty.") + } + policyCond := policyCondition{ + matchType: "starts-with", + condition: "$key", + value: keyStartsWith, + } + if err := p.addNewPolicy(policyCond); err != nil { + return err + } + p.formData["key"] = keyStartsWith + return nil +} + +// SetBucket - Sets bucket at which objects will be uploaded to. +func (p *PostPolicy) SetBucket(bucketName string) error { + if strings.TrimSpace(bucketName) == "" || bucketName == "" { + return ErrInvalidArgument("Bucket name is empty.") + } + policyCond := policyCondition{ + matchType: "eq", + condition: "$bucket", + value: bucketName, + } + if err := p.addNewPolicy(policyCond); err != nil { + return err + } + p.formData["bucket"] = bucketName + return nil +} + +// SetContentType - Sets content-type of the object for this policy +// based upload. +func (p *PostPolicy) SetContentType(contentType string) error { + if strings.TrimSpace(contentType) == "" || contentType == "" { + return ErrInvalidArgument("No content type specified.") + } + policyCond := policyCondition{ + matchType: "eq", + condition: "$Content-Type", + value: contentType, + } + if err := p.addNewPolicy(policyCond); err != nil { + return err + } + p.formData["Content-Type"] = contentType + return nil +} + +// SetContentLengthRange - Set new min and max content length +// condition for all incoming uploads. +func (p *PostPolicy) SetContentLengthRange(min, max int64) error { + if min > max { + return ErrInvalidArgument("Minimum limit is larger than maximum limit.") + } + if min < 0 { + return ErrInvalidArgument("Minimum limit cannot be negative.") + } + if max < 0 { + return ErrInvalidArgument("Maximum limit cannot be negative.") + } + p.contentLengthRange.min = min + p.contentLengthRange.max = max + return nil +} + +// SetSuccessStatusAction - Sets the status success code of the object for this policy +// based upload. +func (p *PostPolicy) SetSuccessStatusAction(status string) error { + if strings.TrimSpace(status) == "" || status == "" { + return ErrInvalidArgument("Status is empty") + } + policyCond := policyCondition{ + matchType: "eq", + condition: "$success_action_status", + value: status, + } + if err := p.addNewPolicy(policyCond); err != nil { + return err + } + p.formData["success_action_status"] = status + return nil +} + +// SetUserMetadata - Set user metadata as a key/value couple. +// Can be retrieved through a HEAD request or an event. +func (p *PostPolicy) SetUserMetadata(key string, value string) error { + if strings.TrimSpace(key) == "" || key == "" { + return ErrInvalidArgument("Key is empty") + } + if strings.TrimSpace(value) == "" || value == "" { + return ErrInvalidArgument("Value is empty") + } + headerName := fmt.Sprintf("x-amz-meta-%s", key) + policyCond := policyCondition{ + matchType: "eq", + condition: fmt.Sprintf("$%s", headerName), + value: value, + } + if err := p.addNewPolicy(policyCond); err != nil { + return err + } + p.formData[headerName] = value + return nil +} + +// addNewPolicy - internal helper to validate adding new policies. +func (p *PostPolicy) addNewPolicy(policyCond policyCondition) error { + if policyCond.matchType == "" || policyCond.condition == "" || policyCond.value == "" { + return ErrInvalidArgument("Policy fields are empty.") + } + p.conditions = append(p.conditions, policyCond) + return nil +} + +// Stringer interface for printing policy in json formatted string. +func (p PostPolicy) String() string { + return string(p.marshalJSON()) +} + +// marshalJSON - Provides Marshalled JSON in bytes. +func (p PostPolicy) marshalJSON() []byte { + expirationStr := `"expiration":"` + p.expiration.Format(expirationDateFormat) + `"` + var conditionsStr string + conditions := []string{} + for _, po := range p.conditions { + conditions = append(conditions, fmt.Sprintf("[\"%s\",\"%s\",\"%s\"]", po.matchType, po.condition, po.value)) + } + if p.contentLengthRange.min != 0 || p.contentLengthRange.max != 0 { + conditions = append(conditions, fmt.Sprintf("[\"content-length-range\", %d, %d]", + p.contentLengthRange.min, p.contentLengthRange.max)) + } + if len(conditions) > 0 { + conditionsStr = `"conditions":[` + strings.Join(conditions, ",") + "]" + } + retStr := "{" + retStr = retStr + expirationStr + "," + retStr = retStr + conditionsStr + retStr = retStr + "}" + return []byte(retStr) +} + +// base64 - Produces base64 of PostPolicy's Marshalled json. +func (p PostPolicy) base64() string { + return base64.StdEncoding.EncodeToString(p.marshalJSON()) +} diff --git a/vendor/github.com/minio/minio-go/retry-continous.go b/vendor/github.com/minio/minio-go/retry-continous.go new file mode 100644 index 000000000..f31dfa6f2 --- /dev/null +++ b/vendor/github.com/minio/minio-go/retry-continous.go @@ -0,0 +1,69 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import "time" + +// newRetryTimerContinous creates a timer with exponentially increasing delays forever. +func (c Client) newRetryTimerContinous(unit time.Duration, cap time.Duration, jitter float64, doneCh chan struct{}) <-chan int { + attemptCh := make(chan int) + + // normalize jitter to the range [0, 1.0] + if jitter < NoJitter { + jitter = NoJitter + } + if jitter > MaxJitter { + jitter = MaxJitter + } + + // computes the exponential backoff duration according to + // https://www.awsarchitectureblog.com/2015/03/backoff.html + exponentialBackoffWait := func(attempt int) time.Duration { + // 1< maxAttempt { + attempt = maxAttempt + } + //sleep = random_between(0, min(cap, base * 2 ** attempt)) + sleep := unit * time.Duration(1< cap { + sleep = cap + } + if jitter != NoJitter { + sleep -= time.Duration(c.random.Float64() * float64(sleep) * jitter) + } + return sleep + } + + go func() { + defer close(attemptCh) + var nextBackoff int + for { + select { + // Attempts starts. + case attemptCh <- nextBackoff: + nextBackoff++ + case <-doneCh: + // Stop the routine. + return + } + time.Sleep(exponentialBackoffWait(nextBackoff)) + } + }() + return attemptCh +} diff --git a/vendor/github.com/minio/minio-go/retry.go b/vendor/github.com/minio/minio-go/retry.go new file mode 100644 index 000000000..2c8ceda6b --- /dev/null +++ b/vendor/github.com/minio/minio-go/retry.go @@ -0,0 +1,153 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "net" + "net/http" + "net/url" + "strings" + "time" +) + +// MaxRetry is the maximum number of retries before stopping. +var MaxRetry = 5 + +// MaxJitter will randomize over the full exponential backoff time +const MaxJitter = 1.0 + +// NoJitter disables the use of jitter for randomizing the exponential backoff time +const NoJitter = 0.0 + +// DefaultRetryUnit - default unit multiplicative per retry. +// defaults to 1 second. +const DefaultRetryUnit = time.Second + +// DefaultRetryCap - Each retry attempt never waits no longer than +// this maximum time duration. +const DefaultRetryCap = time.Second * 30 + +// newRetryTimer creates a timer with exponentially increasing +// delays until the maximum retry attempts are reached. +func (c Client) newRetryTimer(maxRetry int, unit time.Duration, cap time.Duration, jitter float64, doneCh chan struct{}) <-chan int { + attemptCh := make(chan int) + + // computes the exponential backoff duration according to + // https://www.awsarchitectureblog.com/2015/03/backoff.html + exponentialBackoffWait := func(attempt int) time.Duration { + // normalize jitter to the range [0, 1.0] + if jitter < NoJitter { + jitter = NoJitter + } + if jitter > MaxJitter { + jitter = MaxJitter + } + + //sleep = random_between(0, min(cap, base * 2 ** attempt)) + sleep := unit * time.Duration(1< cap { + sleep = cap + } + if jitter != NoJitter { + sleep -= time.Duration(c.random.Float64() * float64(sleep) * jitter) + } + return sleep + } + + go func() { + defer close(attemptCh) + for i := 0; i < maxRetry; i++ { + select { + // Attempts start from 1. + case attemptCh <- i + 1: + case <-doneCh: + // Stop the routine. + return + } + time.Sleep(exponentialBackoffWait(i)) + } + }() + return attemptCh +} + +// isNetErrorRetryable - is network error retryable. +func isNetErrorRetryable(err error) bool { + if err == nil { + return false + } + switch err.(type) { + case net.Error: + switch err.(type) { + case *net.DNSError, *net.OpError, net.UnknownNetworkError: + return true + case *url.Error: + // For a URL error, where it replies back "connection closed" + // retry again. + if strings.Contains(err.Error(), "Connection closed by foreign host") { + return true + } + default: + if strings.Contains(err.Error(), "net/http: TLS handshake timeout") { + // If error is - tlsHandshakeTimeoutError, retry. + return true + } else if strings.Contains(err.Error(), "i/o timeout") { + // If error is - tcp timeoutError, retry. + return true + } else if strings.Contains(err.Error(), "connection timed out") { + // If err is a net.Dial timeout, retry. + return true + } + } + } + return false +} + +// List of AWS S3 error codes which are retryable. +var retryableS3Codes = map[string]struct{}{ + "RequestError": {}, + "RequestTimeout": {}, + "Throttling": {}, + "ThrottlingException": {}, + "RequestLimitExceeded": {}, + "RequestThrottled": {}, + "InternalError": {}, + "ExpiredToken": {}, + "ExpiredTokenException": {}, + // Add more AWS S3 codes here. +} + +// isS3CodeRetryable - is s3 error code retryable. +func isS3CodeRetryable(s3Code string) (ok bool) { + _, ok = retryableS3Codes[s3Code] + return ok +} + +// List of HTTP status codes which are retryable. +var retryableHTTPStatusCodes = map[int]struct{}{ + 429: {}, // http.StatusTooManyRequests is not part of the Go 1.5 library, yet + http.StatusInternalServerError: {}, + http.StatusBadGateway: {}, + http.StatusServiceUnavailable: {}, + // Add more HTTP status codes here. +} + +// isHTTPStatusRetryable - is HTTP error code retryable. +func isHTTPStatusRetryable(httpStatusCode int) (ok bool) { + _, ok = retryableHTTPStatusCodes[httpStatusCode] + return ok +} diff --git a/vendor/github.com/minio/minio-go/s3-endpoints.go b/vendor/github.com/minio/minio-go/s3-endpoints.go new file mode 100644 index 000000000..2a86eaab0 --- /dev/null +++ b/vendor/github.com/minio/minio-go/s3-endpoints.go @@ -0,0 +1,49 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +// awsS3EndpointMap Amazon S3 endpoint map. +// "cn-north-1" adds support for AWS China. +var awsS3EndpointMap = map[string]string{ + "us-east-1": "s3.amazonaws.com", + "us-east-2": "s3-us-east-2.amazonaws.com", + "us-west-2": "s3-us-west-2.amazonaws.com", + "us-west-1": "s3-us-west-1.amazonaws.com", + "ca-central-1": "s3.ca-central-1.amazonaws.com", + "eu-west-1": "s3-eu-west-1.amazonaws.com", + "eu-west-2": "s3-eu-west-2.amazonaws.com", + "eu-central-1": "s3-eu-central-1.amazonaws.com", + "ap-south-1": "s3-ap-south-1.amazonaws.com", + "ap-southeast-1": "s3-ap-southeast-1.amazonaws.com", + "ap-southeast-2": "s3-ap-southeast-2.amazonaws.com", + "ap-northeast-1": "s3-ap-northeast-1.amazonaws.com", + "ap-northeast-2": "s3-ap-northeast-2.amazonaws.com", + "sa-east-1": "s3-sa-east-1.amazonaws.com", + "us-gov-west-1": "s3-us-gov-west-1.amazonaws.com", + "cn-north-1": "s3.cn-north-1.amazonaws.com.cn", +} + +// getS3Endpoint get Amazon S3 endpoint based on the bucket location. +func getS3Endpoint(bucketLocation string) (s3Endpoint string) { + s3Endpoint, ok := awsS3EndpointMap[bucketLocation] + if !ok { + // Default to 's3.amazonaws.com' endpoint. + s3Endpoint = "s3.amazonaws.com" + } + return s3Endpoint +} diff --git a/vendor/github.com/minio/minio-go/s3-error.go b/vendor/github.com/minio/minio-go/s3-error.go new file mode 100644 index 000000000..f9e82334a --- /dev/null +++ b/vendor/github.com/minio/minio-go/s3-error.go @@ -0,0 +1,61 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +// Non exhaustive list of AWS S3 standard error responses - +// http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html +var s3ErrorResponseMap = map[string]string{ + "AccessDenied": "Access Denied.", + "BadDigest": "The Content-Md5 you specified did not match what we received.", + "EntityTooSmall": "Your proposed upload is smaller than the minimum allowed object size.", + "EntityTooLarge": "Your proposed upload exceeds the maximum allowed object size.", + "IncompleteBody": "You did not provide the number of bytes specified by the Content-Length HTTP header.", + "InternalError": "We encountered an internal error, please try again.", + "InvalidAccessKeyId": "The access key ID you provided does not exist in our records.", + "InvalidBucketName": "The specified bucket is not valid.", + "InvalidDigest": "The Content-Md5 you specified is not valid.", + "InvalidRange": "The requested range is not satisfiable", + "MalformedXML": "The XML you provided was not well-formed or did not validate against our published schema.", + "MissingContentLength": "You must provide the Content-Length HTTP header.", + "MissingContentMD5": "Missing required header for this request: Content-Md5.", + "MissingRequestBodyError": "Request body is empty.", + "NoSuchBucket": "The specified bucket does not exist", + "NoSuchBucketPolicy": "The bucket policy does not exist", + "NoSuchKey": "The specified key does not exist.", + "NoSuchUpload": "The specified multipart upload does not exist. The upload ID may be invalid, or the upload may have been aborted or completed.", + "NotImplemented": "A header you provided implies functionality that is not implemented", + "PreconditionFailed": "At least one of the pre-conditions you specified did not hold", + "RequestTimeTooSkewed": "The difference between the request time and the server's time is too large.", + "SignatureDoesNotMatch": "The request signature we calculated does not match the signature you provided. Check your key and signing method.", + "MethodNotAllowed": "The specified method is not allowed against this resource.", + "InvalidPart": "One or more of the specified parts could not be found.", + "InvalidPartOrder": "The list of parts was not in ascending order. The parts list must be specified in order by part number.", + "InvalidObjectState": "The operation is not valid for the current state of the object.", + "AuthorizationHeaderMalformed": "The authorization header is malformed; the region is wrong.", + "MalformedPOSTRequest": "The body of your POST request is not well-formed multipart/form-data.", + "BucketNotEmpty": "The bucket you tried to delete is not empty", + "AllAccessDisabled": "All access to this bucket has been disabled.", + "MalformedPolicy": "Policy has invalid resource.", + "MissingFields": "Missing fields in request.", + "AuthorizationQueryParametersError": "Error parsing the X-Amz-Credential parameter; the Credential is mal-formed; expecting \"/YYYYMMDD/REGION/SERVICE/aws4_request\".", + "MalformedDate": "Invalid date format header, expected to be in ISO8601, RFC1123 or RFC1123Z time format.", + "BucketAlreadyOwnedByYou": "Your previous request to create the named bucket succeeded and you already own it.", + "InvalidDuration": "Duration provided in the request is invalid.", + "XAmzContentSHA256Mismatch": "The provided 'x-amz-content-sha256' header does not match what was computed.", + // Add new API errors here. +} diff --git a/vendor/github.com/minio/minio-go/transport.go b/vendor/github.com/minio/minio-go/transport.go new file mode 100644 index 000000000..e2dafe172 --- /dev/null +++ b/vendor/github.com/minio/minio-go/transport.go @@ -0,0 +1,48 @@ +// +build go1.7 go1.8 + +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "net" + "net/http" + "time" +) + +// This default transport is similar to http.DefaultTransport +// but with additional DisableCompression: +var defaultMinioTransport http.RoundTripper = &http.Transport{ + Proxy: http.ProxyFromEnvironment, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + DualStack: true, + }).DialContext, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + // Set this value so that the underlying transport round-tripper + // doesn't try to auto decode the body of objects with + // content-encoding set to `gzip`. + // + // Refer: + // https://golang.org/src/net/http/transport.go?h=roundTrip#L1843 + DisableCompression: true, +} diff --git a/vendor/github.com/minio/minio-go/utils.go b/vendor/github.com/minio/minio-go/utils.go new file mode 100644 index 000000000..6120dc833 --- /dev/null +++ b/vendor/github.com/minio/minio-go/utils.go @@ -0,0 +1,292 @@ +/* + * Minio Go Library for Amazon S3 Compatible Cloud Storage + * Copyright 2015-2017 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "crypto/md5" + "crypto/sha256" + "encoding/base64" + "encoding/hex" + "encoding/xml" + "io" + "io/ioutil" + "net" + "net/http" + "net/url" + "regexp" + "strings" + "time" + + "github.com/minio/minio-go/pkg/s3utils" +) + +// xmlDecoder provide decoded value in xml. +func xmlDecoder(body io.Reader, v interface{}) error { + d := xml.NewDecoder(body) + return d.Decode(v) +} + +// sum256 calculate sha256sum for an input byte array, returns hex encoded. +func sum256Hex(data []byte) string { + hash := sha256.New() + hash.Write(data) + return hex.EncodeToString(hash.Sum(nil)) +} + +// sumMD5Base64 calculate md5sum for an input byte array, returns base64 encoded. +func sumMD5Base64(data []byte) string { + hash := md5.New() + hash.Write(data) + return base64.StdEncoding.EncodeToString(hash.Sum(nil)) +} + +// getEndpointURL - construct a new endpoint. +func getEndpointURL(endpoint string, secure bool) (*url.URL, error) { + if strings.Contains(endpoint, ":") { + host, _, err := net.SplitHostPort(endpoint) + if err != nil { + return nil, err + } + if !s3utils.IsValidIP(host) && !s3utils.IsValidDomain(host) { + msg := "Endpoint: " + endpoint + " does not follow ip address or domain name standards." + return nil, ErrInvalidArgument(msg) + } + } else { + if !s3utils.IsValidIP(endpoint) && !s3utils.IsValidDomain(endpoint) { + msg := "Endpoint: " + endpoint + " does not follow ip address or domain name standards." + return nil, ErrInvalidArgument(msg) + } + } + // If secure is false, use 'http' scheme. + scheme := "https" + if !secure { + scheme = "http" + } + + // Construct a secured endpoint URL. + endpointURLStr := scheme + "://" + endpoint + endpointURL, err := url.Parse(endpointURLStr) + if err != nil { + return nil, err + } + + // Validate incoming endpoint URL. + if err := isValidEndpointURL(*endpointURL); err != nil { + return nil, err + } + return endpointURL, nil +} + +// closeResponse close non nil response with any response Body. +// convenient wrapper to drain any remaining data on response body. +// +// Subsequently this allows golang http RoundTripper +// to re-use the same connection for future requests. +func closeResponse(resp *http.Response) { + // Callers should close resp.Body when done reading from it. + // If resp.Body is not closed, the Client's underlying RoundTripper + // (typically Transport) may not be able to re-use a persistent TCP + // connection to the server for a subsequent "keep-alive" request. + if resp != nil && resp.Body != nil { + // Drain any remaining Body and then close the connection. + // Without this closing connection would disallow re-using + // the same connection for future uses. + // - http://stackoverflow.com/a/17961593/4465767 + io.Copy(ioutil.Discard, resp.Body) + resp.Body.Close() + } +} + +var ( + // Hex encoded string of nil sha256sum bytes. + emptySHA256Hex = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + + // Sentinel URL is the default url value which is invalid. + sentinelURL = url.URL{} +) + +// Verify if input endpoint URL is valid. +func isValidEndpointURL(endpointURL url.URL) error { + if endpointURL == sentinelURL { + return ErrInvalidArgument("Endpoint url cannot be empty.") + } + if endpointURL.Path != "/" && endpointURL.Path != "" { + return ErrInvalidArgument("Endpoint url cannot have fully qualified paths.") + } + if strings.Contains(endpointURL.Host, ".s3.amazonaws.com") { + if !s3utils.IsAmazonEndpoint(endpointURL) { + return ErrInvalidArgument("Amazon S3 endpoint should be 's3.amazonaws.com'.") + } + } + if strings.Contains(endpointURL.Host, ".googleapis.com") { + if !s3utils.IsGoogleEndpoint(endpointURL) { + return ErrInvalidArgument("Google Cloud Storage endpoint should be 'storage.googleapis.com'.") + } + } + return nil +} + +// Verify if input expires value is valid. +func isValidExpiry(expires time.Duration) error { + expireSeconds := int64(expires / time.Second) + if expireSeconds < 1 { + return ErrInvalidArgument("Expires cannot be lesser than 1 second.") + } + if expireSeconds > 604800 { + return ErrInvalidArgument("Expires cannot be greater than 7 days.") + } + return nil +} + +// make a copy of http.Header +func cloneHeader(h http.Header) http.Header { + h2 := make(http.Header, len(h)) + for k, vv := range h { + vv2 := make([]string, len(vv)) + copy(vv2, vv) + h2[k] = vv2 + } + return h2 +} + +// Filter relevant response headers from +// the HEAD, GET http response. The function takes +// a list of headers which are filtered out and +// returned as a new http header. +func filterHeader(header http.Header, filterKeys []string) (filteredHeader http.Header) { + filteredHeader = cloneHeader(header) + for _, key := range filterKeys { + filteredHeader.Del(key) + } + return filteredHeader +} + +// regCred matches credential string in HTTP header +var regCred = regexp.MustCompile("Credential=([A-Z0-9]+)/") + +// regCred matches signature string in HTTP header +var regSign = regexp.MustCompile("Signature=([[0-9a-f]+)") + +// Redact out signature value from authorization string. +func redactSignature(origAuth string) string { + if !strings.HasPrefix(origAuth, signV4Algorithm) { + // Set a temporary redacted auth + return "AWS **REDACTED**:**REDACTED**" + } + + /// Signature V4 authorization header. + + // Strip out accessKeyID from: + // Credential=////aws4_request + newAuth := regCred.ReplaceAllString(origAuth, "Credential=**REDACTED**/") + + // Strip out 256-bit signature from: Signature=<256-bit signature> + return regSign.ReplaceAllString(newAuth, "Signature=**REDACTED**") +} + +// Get default location returns the location based on the input +// URL `u`, if region override is provided then all location +// defaults to regionOverride. +// +// If no other cases match then the location is set to `us-east-1` +// as a last resort. +func getDefaultLocation(u url.URL, regionOverride string) (location string) { + if regionOverride != "" { + return regionOverride + } + if s3utils.IsAmazonChinaEndpoint(u) { + return "cn-north-1" + } + if s3utils.IsAmazonGovCloudEndpoint(u) { + return "us-gov-west-1" + } + // Default to location to 'us-east-1'. + return "us-east-1" +} + +var supportedHeaders = []string{ + "content-type", + "cache-control", + "content-encoding", + "content-disposition", + // Add more supported headers here. +} + +// cseHeaders is list of client side encryption headers +var cseHeaders = []string{ + "X-Amz-Iv", + "X-Amz-Key", + "X-Amz-Matdesc", +} + +// isStorageClassHeader returns true if the header is a supported storage class header +func isStorageClassHeader(headerKey string) bool { + return strings.ToLower(amzStorageClass) == strings.ToLower(headerKey) +} + +// isStandardHeader returns true if header is a supported header and not a custom header +func isStandardHeader(headerKey string) bool { + key := strings.ToLower(headerKey) + for _, header := range supportedHeaders { + if strings.ToLower(header) == key { + return true + } + } + return false +} + +// isCSEHeader returns true if header is a client side encryption header. +func isCSEHeader(headerKey string) bool { + key := strings.ToLower(headerKey) + for _, h := range cseHeaders { + header := strings.ToLower(h) + if (header == key) || + (("x-amz-meta-" + header) == key) { + return true + } + } + return false +} + +// sseHeaders is list of server side encryption headers +var sseHeaders = []string{ + "x-amz-server-side-encryption", + "x-amz-server-side-encryption-aws-kms-key-id", + "x-amz-server-side-encryption-context", + "x-amz-server-side-encryption-customer-algorithm", + "x-amz-server-side-encryption-customer-key", + "x-amz-server-side-encryption-customer-key-MD5", +} + +// isSSEHeader returns true if header is a server side encryption header. +func isSSEHeader(headerKey string) bool { + key := strings.ToLower(headerKey) + for _, h := range sseHeaders { + if strings.ToLower(h) == key { + return true + } + } + return false +} + +// isAmzHeader returns true if header is a x-amz-meta-* or x-amz-acl header. +func isAmzHeader(headerKey string) bool { + key := strings.ToLower(headerKey) + + return strings.HasPrefix(key, "x-amz-meta-") || key == "x-amz-acl" +} diff --git a/vendor/github.com/mitchellh/go-homedir/LICENSE b/vendor/github.com/mitchellh/go-homedir/LICENSE new file mode 100644 index 000000000..f9c841a51 --- /dev/null +++ b/vendor/github.com/mitchellh/go-homedir/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013 Mitchell Hashimoto + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/github.com/mitchellh/go-homedir/homedir.go b/vendor/github.com/mitchellh/go-homedir/homedir.go new file mode 100644 index 000000000..47e1f9ef8 --- /dev/null +++ b/vendor/github.com/mitchellh/go-homedir/homedir.go @@ -0,0 +1,137 @@ +package homedir + +import ( + "bytes" + "errors" + "os" + "os/exec" + "path/filepath" + "runtime" + "strconv" + "strings" + "sync" +) + +// DisableCache will disable caching of the home directory. Caching is enabled +// by default. +var DisableCache bool + +var homedirCache string +var cacheLock sync.RWMutex + +// Dir returns the home directory for the executing user. +// +// This uses an OS-specific method for discovering the home directory. +// An error is returned if a home directory cannot be detected. +func Dir() (string, error) { + if !DisableCache { + cacheLock.RLock() + cached := homedirCache + cacheLock.RUnlock() + if cached != "" { + return cached, nil + } + } + + cacheLock.Lock() + defer cacheLock.Unlock() + + var result string + var err error + if runtime.GOOS == "windows" { + result, err = dirWindows() + } else { + // Unix-like system, so just assume Unix + result, err = dirUnix() + } + + if err != nil { + return "", err + } + homedirCache = result + return result, nil +} + +// Expand expands the path to include the home directory if the path +// is prefixed with `~`. If it isn't prefixed with `~`, the path is +// returned as-is. +func Expand(path string) (string, error) { + if len(path) == 0 { + return path, nil + } + + if path[0] != '~' { + return path, nil + } + + if len(path) > 1 && path[1] != '/' && path[1] != '\\' { + return "", errors.New("cannot expand user-specific home dir") + } + + dir, err := Dir() + if err != nil { + return "", err + } + + return filepath.Join(dir, path[1:]), nil +} + +func dirUnix() (string, error) { + // First prefer the HOME environmental variable + if home := os.Getenv("HOME"); home != "" { + return home, nil + } + + // If that fails, try getent + var stdout bytes.Buffer + cmd := exec.Command("getent", "passwd", strconv.Itoa(os.Getuid())) + cmd.Stdout = &stdout + if err := cmd.Run(); err != nil { + // If the error is ErrNotFound, we ignore it. Otherwise, return it. + if err != exec.ErrNotFound { + return "", err + } + } else { + if passwd := strings.TrimSpace(stdout.String()); passwd != "" { + // username:password:uid:gid:gecos:home:shell + passwdParts := strings.SplitN(passwd, ":", 7) + if len(passwdParts) > 5 { + return passwdParts[5], nil + } + } + } + + // If all else fails, try the shell + stdout.Reset() + cmd = exec.Command("sh", "-c", "cd && pwd") + cmd.Stdout = &stdout + if err := cmd.Run(); err != nil { + return "", err + } + + result := strings.TrimSpace(stdout.String()) + if result == "" { + return "", errors.New("blank output when reading home directory") + } + + return result, nil +} + +func dirWindows() (string, error) { + // First prefer the HOME environmental variable + if home := os.Getenv("HOME"); home != "" { + return home, nil + } + + drive := os.Getenv("HOMEDRIVE") + path := os.Getenv("HOMEPATH") + home := drive + path + if drive == "" || path == "" { + home = os.Getenv("USERPROFILE") + } + if home == "" { + return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank") + } + + return home, nil +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/LICENSE b/vendor/github.com/prometheus/client_golang/prometheus/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/prometheus/client_golang/prometheus/collector.go b/vendor/github.com/prometheus/client_golang/prometheus/collector.go new file mode 100644 index 000000000..623d3d83f --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/collector.go @@ -0,0 +1,75 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +// Collector is the interface implemented by anything that can be used by +// Prometheus to collect metrics. A Collector has to be registered for +// collection. See Registerer.Register. +// +// The stock metrics provided by this package (Gauge, Counter, Summary, +// Histogram, Untyped) are also Collectors (which only ever collect one metric, +// namely itself). An implementer of Collector may, however, collect multiple +// metrics in a coordinated fashion and/or create metrics on the fly. Examples +// for collectors already implemented in this library are the metric vectors +// (i.e. collection of multiple instances of the same Metric but with different +// label values) like GaugeVec or SummaryVec, and the ExpvarCollector. +type Collector interface { + // Describe sends the super-set of all possible descriptors of metrics + // collected by this Collector to the provided channel and returns once + // the last descriptor has been sent. The sent descriptors fulfill the + // consistency and uniqueness requirements described in the Desc + // documentation. (It is valid if one and the same Collector sends + // duplicate descriptors. Those duplicates are simply ignored. However, + // two different Collectors must not send duplicate descriptors.) This + // method idempotently sends the same descriptors throughout the + // lifetime of the Collector. If a Collector encounters an error while + // executing this method, it must send an invalid descriptor (created + // with NewInvalidDesc) to signal the error to the registry. + Describe(chan<- *Desc) + // Collect is called by the Prometheus registry when collecting + // metrics. The implementation sends each collected metric via the + // provided channel and returns once the last metric has been sent. The + // descriptor of each sent metric is one of those returned by + // Describe. Returned metrics that share the same descriptor must differ + // in their variable label values. This method may be called + // concurrently and must therefore be implemented in a concurrency safe + // way. Blocking occurs at the expense of total performance of rendering + // all registered metrics. Ideally, Collector implementations support + // concurrent readers. + Collect(chan<- Metric) +} + +// selfCollector implements Collector for a single Metric so that the Metric +// collects itself. Add it as an anonymous field to a struct that implements +// Metric, and call init with the Metric itself as an argument. +type selfCollector struct { + self Metric +} + +// init provides the selfCollector with a reference to the metric it is supposed +// to collect. It is usually called within the factory function to create a +// metric. See example. +func (c *selfCollector) init(self Metric) { + c.self = self +} + +// Describe implements Collector. +func (c *selfCollector) Describe(ch chan<- *Desc) { + ch <- c.self.Desc() +} + +// Collect implements Collector. +func (c *selfCollector) Collect(ch chan<- Metric) { + ch <- c.self +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/counter.go b/vendor/github.com/prometheus/client_golang/prometheus/counter.go new file mode 100644 index 000000000..02ea9a639 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/counter.go @@ -0,0 +1,228 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "errors" +) + +// Counter is a Metric that represents a single numerical value that only ever +// goes up. That implies that it cannot be used to count items whose number can +// also go down, e.g. the number of currently running goroutines. Those +// "counters" are represented by Gauges. +// +// A Counter is typically used to count requests served, tasks completed, errors +// occurred, etc. +// +// To create Counter instances, use NewCounter. +type Counter interface { + Metric + Collector + + // Inc increments the counter by 1. Use Add to increment it by arbitrary + // non-negative values. + Inc() + // Add adds the given value to the counter. It panics if the value is < + // 0. + Add(float64) +} + +// CounterOpts is an alias for Opts. See there for doc comments. +type CounterOpts Opts + +// NewCounter creates a new Counter based on the provided CounterOpts. +func NewCounter(opts CounterOpts) Counter { + desc := NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + nil, + opts.ConstLabels, + ) + result := &counter{value: value{desc: desc, valType: CounterValue, labelPairs: desc.constLabelPairs}} + result.init(result) // Init self-collection. + return result +} + +type counter struct { + value +} + +func (c *counter) Add(v float64) { + if v < 0 { + panic(errors.New("counter cannot decrease in value")) + } + c.value.Add(v) +} + +// CounterVec is a Collector that bundles a set of Counters that all share the +// same Desc, but have different values for their variable labels. This is used +// if you want to count the same thing partitioned by various dimensions +// (e.g. number of HTTP requests, partitioned by response code and +// method). Create instances with NewCounterVec. +type CounterVec struct { + *metricVec +} + +// NewCounterVec creates a new CounterVec based on the provided CounterOpts and +// partitioned by the given label names. +func NewCounterVec(opts CounterOpts, labelNames []string) *CounterVec { + desc := NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + labelNames, + opts.ConstLabels, + ) + return &CounterVec{ + metricVec: newMetricVec(desc, func(lvs ...string) Metric { + result := &counter{value: value{ + desc: desc, + valType: CounterValue, + labelPairs: makeLabelPairs(desc, lvs), + }} + result.init(result) // Init self-collection. + return result + }), + } +} + +// GetMetricWithLabelValues returns the Counter for the given slice of label +// values (same order as the VariableLabels in Desc). If that combination of +// label values is accessed for the first time, a new Counter is created. +// +// It is possible to call this method without using the returned Counter to only +// create the new Counter but leave it at its starting value 0. See also the +// SummaryVec example. +// +// Keeping the Counter for later use is possible (and should be considered if +// performance is critical), but keep in mind that Reset, DeleteLabelValues and +// Delete can be used to delete the Counter from the CounterVec. In that case, +// the Counter will still exist, but it will not be exported anymore, even if a +// Counter with the same label values is created later. +// +// An error is returned if the number of label values is not the same as the +// number of VariableLabels in Desc (minus any curried labels). +// +// Note that for more than one label value, this method is prone to mistakes +// caused by an incorrect order of arguments. Consider GetMetricWith(Labels) as +// an alternative to avoid that type of mistake. For higher label numbers, the +// latter has a much more readable (albeit more verbose) syntax, but it comes +// with a performance overhead (for creating and processing the Labels map). +// See also the GaugeVec example. +func (v *CounterVec) GetMetricWithLabelValues(lvs ...string) (Counter, error) { + metric, err := v.metricVec.getMetricWithLabelValues(lvs...) + if metric != nil { + return metric.(Counter), err + } + return nil, err +} + +// GetMetricWith returns the Counter for the given Labels map (the label names +// must match those of the VariableLabels in Desc). If that label map is +// accessed for the first time, a new Counter is created. Implications of +// creating a Counter without using it and keeping the Counter for later use are +// the same as for GetMetricWithLabelValues. +// +// An error is returned if the number and names of the Labels are inconsistent +// with those of the VariableLabels in Desc (minus any curried labels). +// +// This method is used for the same purpose as +// GetMetricWithLabelValues(...string). See there for pros and cons of the two +// methods. +func (v *CounterVec) GetMetricWith(labels Labels) (Counter, error) { + metric, err := v.metricVec.getMetricWith(labels) + if metric != nil { + return metric.(Counter), err + } + return nil, err +} + +// WithLabelValues works as GetMetricWithLabelValues, but panics where +// GetMetricWithLabelValues would have returned an error. Not returning an +// error allows shortcuts like +// myVec.WithLabelValues("404", "GET").Add(42) +func (v *CounterVec) WithLabelValues(lvs ...string) Counter { + c, err := v.GetMetricWithLabelValues(lvs...) + if err != nil { + panic(err) + } + return c +} + +// With works as GetMetricWith, but panics where GetMetricWithLabels would have +// returned an error. Not returning an error allows shortcuts like +// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42) +func (v *CounterVec) With(labels Labels) Counter { + c, err := v.GetMetricWith(labels) + if err != nil { + panic(err) + } + return c +} + +// CurryWith returns a vector curried with the provided labels, i.e. the +// returned vector has those labels pre-set for all labeled operations performed +// on it. The cardinality of the curried vector is reduced accordingly. The +// order of the remaining labels stays the same (just with the curried labels +// taken out of the sequence – which is relevant for the +// (GetMetric)WithLabelValues methods). It is possible to curry a curried +// vector, but only with labels not yet used for currying before. +// +// The metrics contained in the CounterVec are shared between the curried and +// uncurried vectors. They are just accessed differently. Curried and uncurried +// vectors behave identically in terms of collection. Only one must be +// registered with a given registry (usually the uncurried version). The Reset +// method deletes all metrics, even if called on a curried vector. +func (v *CounterVec) CurryWith(labels Labels) (*CounterVec, error) { + vec, err := v.curryWith(labels) + if vec != nil { + return &CounterVec{vec}, err + } + return nil, err +} + +// MustCurryWith works as CurryWith but panics where CurryWith would have +// returned an error. +func (v *CounterVec) MustCurryWith(labels Labels) *CounterVec { + vec, err := v.CurryWith(labels) + if err != nil { + panic(err) + } + return vec +} + +// CounterFunc is a Counter whose value is determined at collect time by calling a +// provided function. +// +// To create CounterFunc instances, use NewCounterFunc. +type CounterFunc interface { + Metric + Collector +} + +// NewCounterFunc creates a new CounterFunc based on the provided +// CounterOpts. The value reported is determined by calling the given function +// from within the Write method. Take into account that metric collection may +// happen concurrently. If that results in concurrent calls to Write, like in +// the case where a CounterFunc is directly registered with Prometheus, the +// provided function must be concurrency-safe. The function should also honor +// the contract for a Counter (values only go up, not down), but compliance will +// not be checked. +func NewCounterFunc(opts CounterOpts, function func() float64) CounterFunc { + return newValueFunc(NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + nil, + opts.ConstLabels, + ), CounterValue, function) +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/desc.go b/vendor/github.com/prometheus/client_golang/prometheus/desc.go new file mode 100644 index 000000000..4a755b0fa --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/desc.go @@ -0,0 +1,188 @@ +// Copyright 2016 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "errors" + "fmt" + "sort" + "strings" + + "github.com/golang/protobuf/proto" + "github.com/prometheus/common/model" + + dto "github.com/prometheus/client_model/go" +) + +// Desc is the descriptor used by every Prometheus Metric. It is essentially +// the immutable meta-data of a Metric. The normal Metric implementations +// included in this package manage their Desc under the hood. Users only have to +// deal with Desc if they use advanced features like the ExpvarCollector or +// custom Collectors and Metrics. +// +// Descriptors registered with the same registry have to fulfill certain +// consistency and uniqueness criteria if they share the same fully-qualified +// name: They must have the same help string and the same label names (aka label +// dimensions) in each, constLabels and variableLabels, but they must differ in +// the values of the constLabels. +// +// Descriptors that share the same fully-qualified names and the same label +// values of their constLabels are considered equal. +// +// Use NewDesc to create new Desc instances. +type Desc struct { + // fqName has been built from Namespace, Subsystem, and Name. + fqName string + // help provides some helpful information about this metric. + help string + // constLabelPairs contains precalculated DTO label pairs based on + // the constant labels. + constLabelPairs []*dto.LabelPair + // VariableLabels contains names of labels for which the metric + // maintains variable values. + variableLabels []string + // id is a hash of the values of the ConstLabels and fqName. This + // must be unique among all registered descriptors and can therefore be + // used as an identifier of the descriptor. + id uint64 + // dimHash is a hash of the label names (preset and variable) and the + // Help string. Each Desc with the same fqName must have the same + // dimHash. + dimHash uint64 + // err is an error that occurred during construction. It is reported on + // registration time. + err error +} + +// NewDesc allocates and initializes a new Desc. Errors are recorded in the Desc +// and will be reported on registration time. variableLabels and constLabels can +// be nil if no such labels should be set. fqName and help must not be empty. +// +// variableLabels only contain the label names. Their label values are variable +// and therefore not part of the Desc. (They are managed within the Metric.) +// +// For constLabels, the label values are constant. Therefore, they are fully +// specified in the Desc. See the Collector example for a usage pattern. +func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) *Desc { + d := &Desc{ + fqName: fqName, + help: help, + variableLabels: variableLabels, + } + if help == "" { + d.err = errors.New("empty help string") + return d + } + if !model.IsValidMetricName(model.LabelValue(fqName)) { + d.err = fmt.Errorf("%q is not a valid metric name", fqName) + return d + } + // labelValues contains the label values of const labels (in order of + // their sorted label names) plus the fqName (at position 0). + labelValues := make([]string, 1, len(constLabels)+1) + labelValues[0] = fqName + labelNames := make([]string, 0, len(constLabels)+len(variableLabels)) + labelNameSet := map[string]struct{}{} + // First add only the const label names and sort them... + for labelName := range constLabels { + if !checkLabelName(labelName) { + d.err = fmt.Errorf("%q is not a valid label name", labelName) + return d + } + labelNames = append(labelNames, labelName) + labelNameSet[labelName] = struct{}{} + } + sort.Strings(labelNames) + // ... so that we can now add const label values in the order of their names. + for _, labelName := range labelNames { + labelValues = append(labelValues, constLabels[labelName]) + } + // Validate the const label values. They can't have a wrong cardinality, so + // use in len(labelValues) as expectedNumberOfValues. + if err := validateLabelValues(labelValues, len(labelValues)); err != nil { + d.err = err + return d + } + // Now add the variable label names, but prefix them with something that + // cannot be in a regular label name. That prevents matching the label + // dimension with a different mix between preset and variable labels. + for _, labelName := range variableLabels { + if !checkLabelName(labelName) { + d.err = fmt.Errorf("%q is not a valid label name", labelName) + return d + } + labelNames = append(labelNames, "$"+labelName) + labelNameSet[labelName] = struct{}{} + } + if len(labelNames) != len(labelNameSet) { + d.err = errors.New("duplicate label names") + return d + } + + vh := hashNew() + for _, val := range labelValues { + vh = hashAdd(vh, val) + vh = hashAddByte(vh, separatorByte) + } + d.id = vh + // Sort labelNames so that order doesn't matter for the hash. + sort.Strings(labelNames) + // Now hash together (in this order) the help string and the sorted + // label names. + lh := hashNew() + lh = hashAdd(lh, help) + lh = hashAddByte(lh, separatorByte) + for _, labelName := range labelNames { + lh = hashAdd(lh, labelName) + lh = hashAddByte(lh, separatorByte) + } + d.dimHash = lh + + d.constLabelPairs = make([]*dto.LabelPair, 0, len(constLabels)) + for n, v := range constLabels { + d.constLabelPairs = append(d.constLabelPairs, &dto.LabelPair{ + Name: proto.String(n), + Value: proto.String(v), + }) + } + sort.Sort(LabelPairSorter(d.constLabelPairs)) + return d +} + +// NewInvalidDesc returns an invalid descriptor, i.e. a descriptor with the +// provided error set. If a collector returning such a descriptor is registered, +// registration will fail with the provided error. NewInvalidDesc can be used by +// a Collector to signal inability to describe itself. +func NewInvalidDesc(err error) *Desc { + return &Desc{ + err: err, + } +} + +func (d *Desc) String() string { + lpStrings := make([]string, 0, len(d.constLabelPairs)) + for _, lp := range d.constLabelPairs { + lpStrings = append( + lpStrings, + fmt.Sprintf("%s=%q", lp.GetName(), lp.GetValue()), + ) + } + return fmt.Sprintf( + "Desc{fqName: %q, help: %q, constLabels: {%s}, variableLabels: %v}", + d.fqName, + d.help, + strings.Join(lpStrings, ","), + d.variableLabels, + ) +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/doc.go b/vendor/github.com/prometheus/client_golang/prometheus/doc.go new file mode 100644 index 000000000..36ef15567 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/doc.go @@ -0,0 +1,186 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package prometheus provides metrics primitives to instrument code for +// monitoring. It also offers a registry for metrics. Sub-packages allow to +// expose the registered metrics via HTTP (package promhttp) or push them to a +// Pushgateway (package push). +// +// All exported functions and methods are safe to be used concurrently unless +// specified otherwise. +// +// A Basic Example +// +// As a starting point, a very basic usage example: +// +// package main +// +// import ( +// "log" +// "net/http" +// +// "github.com/prometheus/client_golang/prometheus" +// "github.com/prometheus/client_golang/prometheus/promhttp" +// ) +// +// var ( +// cpuTemp = prometheus.NewGauge(prometheus.GaugeOpts{ +// Name: "cpu_temperature_celsius", +// Help: "Current temperature of the CPU.", +// }) +// hdFailures = prometheus.NewCounterVec( +// prometheus.CounterOpts{ +// Name: "hd_errors_total", +// Help: "Number of hard-disk errors.", +// }, +// []string{"device"}, +// ) +// ) +// +// func init() { +// // Metrics have to be registered to be exposed: +// prometheus.MustRegister(cpuTemp) +// prometheus.MustRegister(hdFailures) +// } +// +// func main() { +// cpuTemp.Set(65.3) +// hdFailures.With(prometheus.Labels{"device":"/dev/sda"}).Inc() +// +// // The Handler function provides a default handler to expose metrics +// // via an HTTP server. "/metrics" is the usual endpoint for that. +// http.Handle("/metrics", promhttp.Handler()) +// log.Fatal(http.ListenAndServe(":8080", nil)) +// } +// +// +// This is a complete program that exports two metrics, a Gauge and a Counter, +// the latter with a label attached to turn it into a (one-dimensional) vector. +// +// Metrics +// +// The number of exported identifiers in this package might appear a bit +// overwhelming. However, in addition to the basic plumbing shown in the example +// above, you only need to understand the different metric types and their +// vector versions for basic usage. +// +// Above, you have already touched the Counter and the Gauge. There are two more +// advanced metric types: the Summary and Histogram. A more thorough description +// of those four metric types can be found in the Prometheus docs: +// https://prometheus.io/docs/concepts/metric_types/ +// +// A fifth "type" of metric is Untyped. It behaves like a Gauge, but signals the +// Prometheus server not to assume anything about its type. +// +// In addition to the fundamental metric types Gauge, Counter, Summary, +// Histogram, and Untyped, a very important part of the Prometheus data model is +// the partitioning of samples along dimensions called labels, which results in +// metric vectors. The fundamental types are GaugeVec, CounterVec, SummaryVec, +// HistogramVec, and UntypedVec. +// +// While only the fundamental metric types implement the Metric interface, both +// the metrics and their vector versions implement the Collector interface. A +// Collector manages the collection of a number of Metrics, but for convenience, +// a Metric can also “collect itself”. Note that Gauge, Counter, Summary, +// Histogram, and Untyped are interfaces themselves while GaugeVec, CounterVec, +// SummaryVec, HistogramVec, and UntypedVec are not. +// +// To create instances of Metrics and their vector versions, you need a suitable +// …Opts struct, i.e. GaugeOpts, CounterOpts, SummaryOpts, HistogramOpts, or +// UntypedOpts. +// +// Custom Collectors and constant Metrics +// +// While you could create your own implementations of Metric, most likely you +// will only ever implement the Collector interface on your own. At a first +// glance, a custom Collector seems handy to bundle Metrics for common +// registration (with the prime example of the different metric vectors above, +// which bundle all the metrics of the same name but with different labels). +// +// There is a more involved use case, too: If you already have metrics +// available, created outside of the Prometheus context, you don't need the +// interface of the various Metric types. You essentially want to mirror the +// existing numbers into Prometheus Metrics during collection. An own +// implementation of the Collector interface is perfect for that. You can create +// Metric instances “on the fly” using NewConstMetric, NewConstHistogram, and +// NewConstSummary (and their respective Must… versions). That will happen in +// the Collect method. The Describe method has to return separate Desc +// instances, representative of the “throw-away” metrics to be created later. +// NewDesc comes in handy to create those Desc instances. +// +// The Collector example illustrates the use case. You can also look at the +// source code of the processCollector (mirroring process metrics), the +// goCollector (mirroring Go metrics), or the expvarCollector (mirroring expvar +// metrics) as examples that are used in this package itself. +// +// If you just need to call a function to get a single float value to collect as +// a metric, GaugeFunc, CounterFunc, or UntypedFunc might be interesting +// shortcuts. +// +// Advanced Uses of the Registry +// +// While MustRegister is the by far most common way of registering a Collector, +// sometimes you might want to handle the errors the registration might cause. +// As suggested by the name, MustRegister panics if an error occurs. With the +// Register function, the error is returned and can be handled. +// +// An error is returned if the registered Collector is incompatible or +// inconsistent with already registered metrics. The registry aims for +// consistency of the collected metrics according to the Prometheus data model. +// Inconsistencies are ideally detected at registration time, not at collect +// time. The former will usually be detected at start-up time of a program, +// while the latter will only happen at scrape time, possibly not even on the +// first scrape if the inconsistency only becomes relevant later. That is the +// main reason why a Collector and a Metric have to describe themselves to the +// registry. +// +// So far, everything we did operated on the so-called default registry, as it +// can be found in the global DefaultRegisterer variable. With NewRegistry, you +// can create a custom registry, or you can even implement the Registerer or +// Gatherer interfaces yourself. The methods Register and Unregister work in the +// same way on a custom registry as the global functions Register and Unregister +// on the default registry. +// +// There are a number of uses for custom registries: You can use registries with +// special properties, see NewPedanticRegistry. You can avoid global state, as +// it is imposed by the DefaultRegisterer. You can use multiple registries at +// the same time to expose different metrics in different ways. You can use +// separate registries for testing purposes. +// +// Also note that the DefaultRegisterer comes registered with a Collector for Go +// runtime metrics (via NewGoCollector) and a Collector for process metrics (via +// NewProcessCollector). With a custom registry, you are in control and decide +// yourself about the Collectors to register. +// +// HTTP Exposition +// +// The Registry implements the Gatherer interface. The caller of the Gather +// method can then expose the gathered metrics in some way. Usually, the metrics +// are served via HTTP on the /metrics endpoint. That's happening in the example +// above. The tools to expose metrics via HTTP are in the promhttp sub-package. +// (The top-level functions in the prometheus package are deprecated.) +// +// Pushing to the Pushgateway +// +// Function for pushing to the Pushgateway can be found in the push sub-package. +// +// Graphite Bridge +// +// Functions and examples to push metrics from a Gatherer to Graphite can be +// found in the graphite sub-package. +// +// Other Means of Exposition +// +// More ways of exposing metrics can easily be added by following the approaches +// of the existing implementations. +package prometheus diff --git a/vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go b/vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go new file mode 100644 index 000000000..18a99d5fa --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go @@ -0,0 +1,119 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "encoding/json" + "expvar" +) + +type expvarCollector struct { + exports map[string]*Desc +} + +// NewExpvarCollector returns a newly allocated expvar Collector that still has +// to be registered with a Prometheus registry. +// +// An expvar Collector collects metrics from the expvar interface. It provides a +// quick way to expose numeric values that are already exported via expvar as +// Prometheus metrics. Note that the data models of expvar and Prometheus are +// fundamentally different, and that the expvar Collector is inherently slower +// than native Prometheus metrics. Thus, the expvar Collector is probably great +// for experiments and prototying, but you should seriously consider a more +// direct implementation of Prometheus metrics for monitoring production +// systems. +// +// The exports map has the following meaning: +// +// The keys in the map correspond to expvar keys, i.e. for every expvar key you +// want to export as Prometheus metric, you need an entry in the exports +// map. The descriptor mapped to each key describes how to export the expvar +// value. It defines the name and the help string of the Prometheus metric +// proxying the expvar value. The type will always be Untyped. +// +// For descriptors without variable labels, the expvar value must be a number or +// a bool. The number is then directly exported as the Prometheus sample +// value. (For a bool, 'false' translates to 0 and 'true' to 1). Expvar values +// that are not numbers or bools are silently ignored. +// +// If the descriptor has one variable label, the expvar value must be an expvar +// map. The keys in the expvar map become the various values of the one +// Prometheus label. The values in the expvar map must be numbers or bools again +// as above. +// +// For descriptors with more than one variable label, the expvar must be a +// nested expvar map, i.e. where the values of the topmost map are maps again +// etc. until a depth is reached that corresponds to the number of labels. The +// leaves of that structure must be numbers or bools as above to serve as the +// sample values. +// +// Anything that does not fit into the scheme above is silently ignored. +func NewExpvarCollector(exports map[string]*Desc) Collector { + return &expvarCollector{ + exports: exports, + } +} + +// Describe implements Collector. +func (e *expvarCollector) Describe(ch chan<- *Desc) { + for _, desc := range e.exports { + ch <- desc + } +} + +// Collect implements Collector. +func (e *expvarCollector) Collect(ch chan<- Metric) { + for name, desc := range e.exports { + var m Metric + expVar := expvar.Get(name) + if expVar == nil { + continue + } + var v interface{} + labels := make([]string, len(desc.variableLabels)) + if err := json.Unmarshal([]byte(expVar.String()), &v); err != nil { + ch <- NewInvalidMetric(desc, err) + continue + } + var processValue func(v interface{}, i int) + processValue = func(v interface{}, i int) { + if i >= len(labels) { + copiedLabels := append(make([]string, 0, len(labels)), labels...) + switch v := v.(type) { + case float64: + m = MustNewConstMetric(desc, UntypedValue, v, copiedLabels...) + case bool: + if v { + m = MustNewConstMetric(desc, UntypedValue, 1, copiedLabels...) + } else { + m = MustNewConstMetric(desc, UntypedValue, 0, copiedLabels...) + } + default: + return + } + ch <- m + return + } + vm, ok := v.(map[string]interface{}) + if !ok { + return + } + for lv, val := range vm { + labels[i] = lv + processValue(val, i+1) + } + } + processValue(v, 0) + } +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/fnv.go b/vendor/github.com/prometheus/client_golang/prometheus/fnv.go new file mode 100644 index 000000000..e3b67df8a --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/fnv.go @@ -0,0 +1,29 @@ +package prometheus + +// Inline and byte-free variant of hash/fnv's fnv64a. + +const ( + offset64 = 14695981039346656037 + prime64 = 1099511628211 +) + +// hashNew initializies a new fnv64a hash value. +func hashNew() uint64 { + return offset64 +} + +// hashAdd adds a string to a fnv64a hash value, returning the updated hash. +func hashAdd(h uint64, s string) uint64 { + for i := 0; i < len(s); i++ { + h ^= uint64(s[i]) + h *= prime64 + } + return h +} + +// hashAddByte adds a byte to a fnv64a hash value, returning the updated hash. +func hashAddByte(h uint64, b byte) uint64 { + h ^= uint64(b) + h *= prime64 + return h +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/gauge.go b/vendor/github.com/prometheus/client_golang/prometheus/gauge.go new file mode 100644 index 000000000..b47d70a59 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/gauge.go @@ -0,0 +1,212 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +// Gauge is a Metric that represents a single numerical value that can +// arbitrarily go up and down. +// +// A Gauge is typically used for measured values like temperatures or current +// memory usage, but also "counts" that can go up and down, like the number of +// running goroutines. +// +// To create Gauge instances, use NewGauge. +type Gauge interface { + Metric + Collector + + // Set sets the Gauge to an arbitrary value. + Set(float64) + // Inc increments the Gauge by 1. Use Add to increment it by arbitrary + // values. + Inc() + // Dec decrements the Gauge by 1. Use Sub to decrement it by arbitrary + // values. + Dec() + // Add adds the given value to the Gauge. (The value can be negative, + // resulting in a decrease of the Gauge.) + Add(float64) + // Sub subtracts the given value from the Gauge. (The value can be + // negative, resulting in an increase of the Gauge.) + Sub(float64) + + // SetToCurrentTime sets the Gauge to the current Unix time in seconds. + SetToCurrentTime() +} + +// GaugeOpts is an alias for Opts. See there for doc comments. +type GaugeOpts Opts + +// NewGauge creates a new Gauge based on the provided GaugeOpts. +func NewGauge(opts GaugeOpts) Gauge { + return newValue(NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + nil, + opts.ConstLabels, + ), GaugeValue, 0) +} + +// GaugeVec is a Collector that bundles a set of Gauges that all share the same +// Desc, but have different values for their variable labels. This is used if +// you want to count the same thing partitioned by various dimensions +// (e.g. number of operations queued, partitioned by user and operation +// type). Create instances with NewGaugeVec. +type GaugeVec struct { + *metricVec +} + +// NewGaugeVec creates a new GaugeVec based on the provided GaugeOpts and +// partitioned by the given label names. +func NewGaugeVec(opts GaugeOpts, labelNames []string) *GaugeVec { + desc := NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + labelNames, + opts.ConstLabels, + ) + return &GaugeVec{ + metricVec: newMetricVec(desc, func(lvs ...string) Metric { + return newValue(desc, GaugeValue, 0, lvs...) + }), + } +} + +// GetMetricWithLabelValues returns the Gauge for the given slice of label +// values (same order as the VariableLabels in Desc). If that combination of +// label values is accessed for the first time, a new Gauge is created. +// +// It is possible to call this method without using the returned Gauge to only +// create the new Gauge but leave it at its starting value 0. See also the +// SummaryVec example. +// +// Keeping the Gauge for later use is possible (and should be considered if +// performance is critical), but keep in mind that Reset, DeleteLabelValues and +// Delete can be used to delete the Gauge from the GaugeVec. In that case, the +// Gauge will still exist, but it will not be exported anymore, even if a +// Gauge with the same label values is created later. See also the CounterVec +// example. +// +// An error is returned if the number of label values is not the same as the +// number of VariableLabels in Desc (minus any curried labels). +// +// Note that for more than one label value, this method is prone to mistakes +// caused by an incorrect order of arguments. Consider GetMetricWith(Labels) as +// an alternative to avoid that type of mistake. For higher label numbers, the +// latter has a much more readable (albeit more verbose) syntax, but it comes +// with a performance overhead (for creating and processing the Labels map). +func (v *GaugeVec) GetMetricWithLabelValues(lvs ...string) (Gauge, error) { + metric, err := v.metricVec.getMetricWithLabelValues(lvs...) + if metric != nil { + return metric.(Gauge), err + } + return nil, err +} + +// GetMetricWith returns the Gauge for the given Labels map (the label names +// must match those of the VariableLabels in Desc). If that label map is +// accessed for the first time, a new Gauge is created. Implications of +// creating a Gauge without using it and keeping the Gauge for later use are +// the same as for GetMetricWithLabelValues. +// +// An error is returned if the number and names of the Labels are inconsistent +// with those of the VariableLabels in Desc (minus any curried labels). +// +// This method is used for the same purpose as +// GetMetricWithLabelValues(...string). See there for pros and cons of the two +// methods. +func (v *GaugeVec) GetMetricWith(labels Labels) (Gauge, error) { + metric, err := v.metricVec.getMetricWith(labels) + if metric != nil { + return metric.(Gauge), err + } + return nil, err +} + +// WithLabelValues works as GetMetricWithLabelValues, but panics where +// GetMetricWithLabelValues would have returned an error. Not returning an +// error allows shortcuts like +// myVec.WithLabelValues("404", "GET").Add(42) +func (v *GaugeVec) WithLabelValues(lvs ...string) Gauge { + g, err := v.GetMetricWithLabelValues(lvs...) + if err != nil { + panic(err) + } + return g +} + +// With works as GetMetricWith, but panics where GetMetricWithLabels would have +// returned an error. Not returning an error allows shortcuts like +// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42) +func (v *GaugeVec) With(labels Labels) Gauge { + g, err := v.GetMetricWith(labels) + if err != nil { + panic(err) + } + return g +} + +// CurryWith returns a vector curried with the provided labels, i.e. the +// returned vector has those labels pre-set for all labeled operations performed +// on it. The cardinality of the curried vector is reduced accordingly. The +// order of the remaining labels stays the same (just with the curried labels +// taken out of the sequence – which is relevant for the +// (GetMetric)WithLabelValues methods). It is possible to curry a curried +// vector, but only with labels not yet used for currying before. +// +// The metrics contained in the GaugeVec are shared between the curried and +// uncurried vectors. They are just accessed differently. Curried and uncurried +// vectors behave identically in terms of collection. Only one must be +// registered with a given registry (usually the uncurried version). The Reset +// method deletes all metrics, even if called on a curried vector. +func (v *GaugeVec) CurryWith(labels Labels) (*GaugeVec, error) { + vec, err := v.curryWith(labels) + if vec != nil { + return &GaugeVec{vec}, err + } + return nil, err +} + +// MustCurryWith works as CurryWith but panics where CurryWith would have +// returned an error. +func (v *GaugeVec) MustCurryWith(labels Labels) *GaugeVec { + vec, err := v.CurryWith(labels) + if err != nil { + panic(err) + } + return vec +} + +// GaugeFunc is a Gauge whose value is determined at collect time by calling a +// provided function. +// +// To create GaugeFunc instances, use NewGaugeFunc. +type GaugeFunc interface { + Metric + Collector +} + +// NewGaugeFunc creates a new GaugeFunc based on the provided GaugeOpts. The +// value reported is determined by calling the given function from within the +// Write method. Take into account that metric collection may happen +// concurrently. If that results in concurrent calls to Write, like in the case +// where a GaugeFunc is directly registered with Prometheus, the provided +// function must be concurrency-safe. +func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc { + return newValueFunc(NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + nil, + opts.ConstLabels, + ), GaugeValue, function) +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/go_collector.go b/vendor/github.com/prometheus/client_golang/prometheus/go_collector.go new file mode 100644 index 000000000..096454af9 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/go_collector.go @@ -0,0 +1,284 @@ +package prometheus + +import ( + "fmt" + "runtime" + "runtime/debug" + "time" +) + +type goCollector struct { + goroutinesDesc *Desc + threadsDesc *Desc + gcDesc *Desc + goInfoDesc *Desc + + // metrics to describe and collect + metrics memStatsMetrics +} + +// NewGoCollector returns a collector which exports metrics about the current +// go process. +func NewGoCollector() Collector { + return &goCollector{ + goroutinesDesc: NewDesc( + "go_goroutines", + "Number of goroutines that currently exist.", + nil, nil), + threadsDesc: NewDesc( + "go_threads", + "Number of OS threads created.", + nil, nil), + gcDesc: NewDesc( + "go_gc_duration_seconds", + "A summary of the GC invocation durations.", + nil, nil), + goInfoDesc: NewDesc( + "go_info", + "Information about the Go environment.", + nil, Labels{"version": runtime.Version()}), + metrics: memStatsMetrics{ + { + desc: NewDesc( + memstatNamespace("alloc_bytes"), + "Number of bytes allocated and still in use.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.Alloc) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("alloc_bytes_total"), + "Total number of bytes allocated, even if freed.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.TotalAlloc) }, + valType: CounterValue, + }, { + desc: NewDesc( + memstatNamespace("sys_bytes"), + "Number of bytes obtained from system.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.Sys) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("lookups_total"), + "Total number of pointer lookups.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.Lookups) }, + valType: CounterValue, + }, { + desc: NewDesc( + memstatNamespace("mallocs_total"), + "Total number of mallocs.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.Mallocs) }, + valType: CounterValue, + }, { + desc: NewDesc( + memstatNamespace("frees_total"), + "Total number of frees.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.Frees) }, + valType: CounterValue, + }, { + desc: NewDesc( + memstatNamespace("heap_alloc_bytes"), + "Number of heap bytes allocated and still in use.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapAlloc) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("heap_sys_bytes"), + "Number of heap bytes obtained from system.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapSys) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("heap_idle_bytes"), + "Number of heap bytes waiting to be used.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapIdle) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("heap_inuse_bytes"), + "Number of heap bytes that are in use.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapInuse) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("heap_released_bytes"), + "Number of heap bytes released to OS.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapReleased) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("heap_objects"), + "Number of allocated objects.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapObjects) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("stack_inuse_bytes"), + "Number of bytes in use by the stack allocator.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.StackInuse) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("stack_sys_bytes"), + "Number of bytes obtained from system for stack allocator.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.StackSys) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("mspan_inuse_bytes"), + "Number of bytes in use by mspan structures.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.MSpanInuse) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("mspan_sys_bytes"), + "Number of bytes used for mspan structures obtained from system.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.MSpanSys) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("mcache_inuse_bytes"), + "Number of bytes in use by mcache structures.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.MCacheInuse) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("mcache_sys_bytes"), + "Number of bytes used for mcache structures obtained from system.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.MCacheSys) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("buck_hash_sys_bytes"), + "Number of bytes used by the profiling bucket hash table.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.BuckHashSys) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("gc_sys_bytes"), + "Number of bytes used for garbage collection system metadata.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.GCSys) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("other_sys_bytes"), + "Number of bytes used for other system allocations.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.OtherSys) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("next_gc_bytes"), + "Number of heap bytes when next garbage collection will take place.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.NextGC) }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("last_gc_time_seconds"), + "Number of seconds since 1970 of last garbage collection.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return float64(ms.LastGC) / 1e9 }, + valType: GaugeValue, + }, { + desc: NewDesc( + memstatNamespace("gc_cpu_fraction"), + "The fraction of this program's available CPU time used by the GC since the program started.", + nil, nil, + ), + eval: func(ms *runtime.MemStats) float64 { return ms.GCCPUFraction }, + valType: GaugeValue, + }, + }, + } +} + +func memstatNamespace(s string) string { + return fmt.Sprintf("go_memstats_%s", s) +} + +// Describe returns all descriptions of the collector. +func (c *goCollector) Describe(ch chan<- *Desc) { + ch <- c.goroutinesDesc + ch <- c.threadsDesc + ch <- c.gcDesc + ch <- c.goInfoDesc + for _, i := range c.metrics { + ch <- i.desc + } +} + +// Collect returns the current state of all metrics of the collector. +func (c *goCollector) Collect(ch chan<- Metric) { + ch <- MustNewConstMetric(c.goroutinesDesc, GaugeValue, float64(runtime.NumGoroutine())) + n, _ := runtime.ThreadCreateProfile(nil) + ch <- MustNewConstMetric(c.threadsDesc, GaugeValue, float64(n)) + + var stats debug.GCStats + stats.PauseQuantiles = make([]time.Duration, 5) + debug.ReadGCStats(&stats) + + quantiles := make(map[float64]float64) + for idx, pq := range stats.PauseQuantiles[1:] { + quantiles[float64(idx+1)/float64(len(stats.PauseQuantiles)-1)] = pq.Seconds() + } + quantiles[0.0] = stats.PauseQuantiles[0].Seconds() + ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles) + + ch <- MustNewConstMetric(c.goInfoDesc, GaugeValue, 1) + + ms := &runtime.MemStats{} + runtime.ReadMemStats(ms) + for _, i := range c.metrics { + ch <- MustNewConstMetric(i.desc, i.valType, i.eval(ms)) + } +} + +// memStatsMetrics provide description, value, and value type for memstat metrics. +type memStatsMetrics []struct { + desc *Desc + eval func(*runtime.MemStats) float64 + valType ValueType +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/graphite/bridge.go b/vendor/github.com/prometheus/client_golang/prometheus/graphite/bridge.go new file mode 100644 index 000000000..11533374b --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/graphite/bridge.go @@ -0,0 +1,280 @@ +// Copyright 2016 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package graphite provides a bridge to push Prometheus metrics to a Graphite +// server. +package graphite + +import ( + "bufio" + "errors" + "fmt" + "io" + "net" + "sort" + "time" + + "github.com/prometheus/common/expfmt" + "github.com/prometheus/common/model" + "golang.org/x/net/context" + + dto "github.com/prometheus/client_model/go" + + "github.com/prometheus/client_golang/prometheus" +) + +const ( + defaultInterval = 15 * time.Second + millisecondsPerSecond = 1000 +) + +// HandlerErrorHandling defines how a Handler serving metrics will handle +// errors. +type HandlerErrorHandling int + +// These constants cause handlers serving metrics to behave as described if +// errors are encountered. +const ( + // Ignore errors and try to push as many metrics to Graphite as possible. + ContinueOnError HandlerErrorHandling = iota + + // Abort the push to Graphite upon the first error encountered. + AbortOnError +) + +// Config defines the Graphite bridge config. +type Config struct { + // The url to push data to. Required. + URL string + + // The prefix for the pushed Graphite metrics. Defaults to empty string. + Prefix string + + // The interval to use for pushing data to Graphite. Defaults to 15 seconds. + Interval time.Duration + + // The timeout for pushing metrics to Graphite. Defaults to 15 seconds. + Timeout time.Duration + + // The Gatherer to use for metrics. Defaults to prometheus.DefaultGatherer. + Gatherer prometheus.Gatherer + + // The logger that messages are written to. Defaults to no logging. + Logger Logger + + // ErrorHandling defines how errors are handled. Note that errors are + // logged regardless of the configured ErrorHandling provided Logger + // is not nil. + ErrorHandling HandlerErrorHandling +} + +// Bridge pushes metrics to the configured Graphite server. +type Bridge struct { + url string + prefix string + interval time.Duration + timeout time.Duration + + errorHandling HandlerErrorHandling + logger Logger + + g prometheus.Gatherer +} + +// Logger is the minimal interface Bridge needs for logging. Note that +// log.Logger from the standard library implements this interface, and it is +// easy to implement by custom loggers, if they don't do so already anyway. +type Logger interface { + Println(v ...interface{}) +} + +// NewBridge returns a pointer to a new Bridge struct. +func NewBridge(c *Config) (*Bridge, error) { + b := &Bridge{} + + if c.URL == "" { + return nil, errors.New("missing URL") + } + b.url = c.URL + + if c.Gatherer == nil { + b.g = prometheus.DefaultGatherer + } else { + b.g = c.Gatherer + } + + if c.Logger != nil { + b.logger = c.Logger + } + + if c.Prefix != "" { + b.prefix = c.Prefix + } + + var z time.Duration + if c.Interval == z { + b.interval = defaultInterval + } else { + b.interval = c.Interval + } + + if c.Timeout == z { + b.timeout = defaultInterval + } else { + b.timeout = c.Timeout + } + + b.errorHandling = c.ErrorHandling + + return b, nil +} + +// Run starts the event loop that pushes Prometheus metrics to Graphite at the +// configured interval. +func (b *Bridge) Run(ctx context.Context) { + ticker := time.NewTicker(b.interval) + defer ticker.Stop() + for { + select { + case <-ticker.C: + if err := b.Push(); err != nil && b.logger != nil { + b.logger.Println("error pushing to Graphite:", err) + } + case <-ctx.Done(): + return + } + } +} + +// Push pushes Prometheus metrics to the configured Graphite server. +func (b *Bridge) Push() error { + mfs, err := b.g.Gather() + if err != nil || len(mfs) == 0 { + switch b.errorHandling { + case AbortOnError: + return err + case ContinueOnError: + if b.logger != nil { + b.logger.Println("continue on error:", err) + } + default: + panic("unrecognized error handling value") + } + } + + conn, err := net.DialTimeout("tcp", b.url, b.timeout) + if err != nil { + return err + } + defer conn.Close() + + return writeMetrics(conn, mfs, b.prefix, model.Now()) +} + +func writeMetrics(w io.Writer, mfs []*dto.MetricFamily, prefix string, now model.Time) error { + vec, err := expfmt.ExtractSamples(&expfmt.DecodeOptions{ + Timestamp: now, + }, mfs...) + if err != nil { + return err + } + + buf := bufio.NewWriter(w) + for _, s := range vec { + if err := writeSanitized(buf, prefix); err != nil { + return err + } + if err := buf.WriteByte('.'); err != nil { + return err + } + if err := writeMetric(buf, s.Metric); err != nil { + return err + } + if _, err := fmt.Fprintf(buf, " %g %d\n", s.Value, int64(s.Timestamp)/millisecondsPerSecond); err != nil { + return err + } + if err := buf.Flush(); err != nil { + return err + } + } + + return nil +} + +func writeMetric(buf *bufio.Writer, m model.Metric) error { + metricName, hasName := m[model.MetricNameLabel] + numLabels := len(m) - 1 + if !hasName { + numLabels = len(m) + } + + labelStrings := make([]string, 0, numLabels) + for label, value := range m { + if label != model.MetricNameLabel { + labelStrings = append(labelStrings, fmt.Sprintf("%s %s", string(label), string(value))) + } + } + + var err error + switch numLabels { + case 0: + if hasName { + return writeSanitized(buf, string(metricName)) + } + default: + sort.Strings(labelStrings) + if err = writeSanitized(buf, string(metricName)); err != nil { + return err + } + for _, s := range labelStrings { + if err = buf.WriteByte('.'); err != nil { + return err + } + if err = writeSanitized(buf, s); err != nil { + return err + } + } + } + return nil +} + +func writeSanitized(buf *bufio.Writer, s string) error { + prevUnderscore := false + + for _, c := range s { + c = replaceInvalidRune(c) + if c == '_' { + if prevUnderscore { + continue + } + prevUnderscore = true + } else { + prevUnderscore = false + } + if _, err := buf.WriteRune(c); err != nil { + return err + } + } + + return nil +} + +func replaceInvalidRune(c rune) rune { + if c == ' ' { + return '.' + } + if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == ':' || (c >= '0' && c <= '9')) { + return '_' + } + return c +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/histogram.go b/vendor/github.com/prometheus/client_golang/prometheus/histogram.go new file mode 100644 index 000000000..331783a75 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/histogram.go @@ -0,0 +1,505 @@ +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "fmt" + "math" + "sort" + "sync/atomic" + + "github.com/golang/protobuf/proto" + + dto "github.com/prometheus/client_model/go" +) + +// A Histogram counts individual observations from an event or sample stream in +// configurable buckets. Similar to a summary, it also provides a sum of +// observations and an observation count. +// +// On the Prometheus server, quantiles can be calculated from a Histogram using +// the histogram_quantile function in the query language. +// +// Note that Histograms, in contrast to Summaries, can be aggregated with the +// Prometheus query language (see the documentation for detailed +// procedures). However, Histograms require the user to pre-define suitable +// buckets, and they are in general less accurate. The Observe method of a +// Histogram has a very low performance overhead in comparison with the Observe +// method of a Summary. +// +// To create Histogram instances, use NewHistogram. +type Histogram interface { + Metric + Collector + + // Observe adds a single observation to the histogram. + Observe(float64) +} + +// bucketLabel is used for the label that defines the upper bound of a +// bucket of a histogram ("le" -> "less or equal"). +const bucketLabel = "le" + +// DefBuckets are the default Histogram buckets. The default buckets are +// tailored to broadly measure the response time (in seconds) of a network +// service. Most likely, however, you will be required to define buckets +// customized to your use case. +var ( + DefBuckets = []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10} + + errBucketLabelNotAllowed = fmt.Errorf( + "%q is not allowed as label name in histograms", bucketLabel, + ) +) + +// LinearBuckets creates 'count' buckets, each 'width' wide, where the lowest +// bucket has an upper bound of 'start'. The final +Inf bucket is not counted +// and not included in the returned slice. The returned slice is meant to be +// used for the Buckets field of HistogramOpts. +// +// The function panics if 'count' is zero or negative. +func LinearBuckets(start, width float64, count int) []float64 { + if count < 1 { + panic("LinearBuckets needs a positive count") + } + buckets := make([]float64, count) + for i := range buckets { + buckets[i] = start + start += width + } + return buckets +} + +// ExponentialBuckets creates 'count' buckets, where the lowest bucket has an +// upper bound of 'start' and each following bucket's upper bound is 'factor' +// times the previous bucket's upper bound. The final +Inf bucket is not counted +// and not included in the returned slice. The returned slice is meant to be +// used for the Buckets field of HistogramOpts. +// +// The function panics if 'count' is 0 or negative, if 'start' is 0 or negative, +// or if 'factor' is less than or equal 1. +func ExponentialBuckets(start, factor float64, count int) []float64 { + if count < 1 { + panic("ExponentialBuckets needs a positive count") + } + if start <= 0 { + panic("ExponentialBuckets needs a positive start value") + } + if factor <= 1 { + panic("ExponentialBuckets needs a factor greater than 1") + } + buckets := make([]float64, count) + for i := range buckets { + buckets[i] = start + start *= factor + } + return buckets +} + +// HistogramOpts bundles the options for creating a Histogram metric. It is +// mandatory to set Name and Help to a non-empty string. All other fields are +// optional and can safely be left at their zero value. +type HistogramOpts struct { + // Namespace, Subsystem, and Name are components of the fully-qualified + // name of the Histogram (created by joining these components with + // "_"). Only Name is mandatory, the others merely help structuring the + // name. Note that the fully-qualified name of the Histogram must be a + // valid Prometheus metric name. + Namespace string + Subsystem string + Name string + + // Help provides information about this Histogram. Mandatory! + // + // Metrics with the same fully-qualified name must have the same Help + // string. + Help string + + // ConstLabels are used to attach fixed labels to this metric. Metrics + // with the same fully-qualified name must have the same label names in + // their ConstLabels. + // + // ConstLabels are only used rarely. In particular, do not use them to + // attach the same labels to all your metrics. Those use cases are + // better covered by target labels set by the scraping Prometheus + // server, or by one specific metric (e.g. a build_info or a + // machine_role metric). See also + // https://prometheus.io/docs/instrumenting/writing_exporters/#target-labels,-not-static-scraped-labels + ConstLabels Labels + + // Buckets defines the buckets into which observations are counted. Each + // element in the slice is the upper inclusive bound of a bucket. The + // values must be sorted in strictly increasing order. There is no need + // to add a highest bucket with +Inf bound, it will be added + // implicitly. The default value is DefBuckets. + Buckets []float64 +} + +// NewHistogram creates a new Histogram based on the provided HistogramOpts. It +// panics if the buckets in HistogramOpts are not in strictly increasing order. +func NewHistogram(opts HistogramOpts) Histogram { + return newHistogram( + NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + nil, + opts.ConstLabels, + ), + opts, + ) +} + +func newHistogram(desc *Desc, opts HistogramOpts, labelValues ...string) Histogram { + if len(desc.variableLabels) != len(labelValues) { + panic(errInconsistentCardinality) + } + + for _, n := range desc.variableLabels { + if n == bucketLabel { + panic(errBucketLabelNotAllowed) + } + } + for _, lp := range desc.constLabelPairs { + if lp.GetName() == bucketLabel { + panic(errBucketLabelNotAllowed) + } + } + + if len(opts.Buckets) == 0 { + opts.Buckets = DefBuckets + } + + h := &histogram{ + desc: desc, + upperBounds: opts.Buckets, + labelPairs: makeLabelPairs(desc, labelValues), + } + for i, upperBound := range h.upperBounds { + if i < len(h.upperBounds)-1 { + if upperBound >= h.upperBounds[i+1] { + panic(fmt.Errorf( + "histogram buckets must be in increasing order: %f >= %f", + upperBound, h.upperBounds[i+1], + )) + } + } else { + if math.IsInf(upperBound, +1) { + // The +Inf bucket is implicit. Remove it here. + h.upperBounds = h.upperBounds[:i] + } + } + } + // Finally we know the final length of h.upperBounds and can make counts. + h.counts = make([]uint64, len(h.upperBounds)) + + h.init(h) // Init self-collection. + return h +} + +type histogram struct { + // sumBits contains the bits of the float64 representing the sum of all + // observations. sumBits and count have to go first in the struct to + // guarantee alignment for atomic operations. + // http://golang.org/pkg/sync/atomic/#pkg-note-BUG + sumBits uint64 + count uint64 + + selfCollector + // Note that there is no mutex required. + + desc *Desc + + upperBounds []float64 + counts []uint64 + + labelPairs []*dto.LabelPair +} + +func (h *histogram) Desc() *Desc { + return h.desc +} + +func (h *histogram) Observe(v float64) { + // TODO(beorn7): For small numbers of buckets (<30), a linear search is + // slightly faster than the binary search. If we really care, we could + // switch from one search strategy to the other depending on the number + // of buckets. + // + // Microbenchmarks (BenchmarkHistogramNoLabels): + // 11 buckets: 38.3 ns/op linear - binary 48.7 ns/op + // 100 buckets: 78.1 ns/op linear - binary 54.9 ns/op + // 300 buckets: 154 ns/op linear - binary 61.6 ns/op + i := sort.SearchFloat64s(h.upperBounds, v) + if i < len(h.counts) { + atomic.AddUint64(&h.counts[i], 1) + } + atomic.AddUint64(&h.count, 1) + for { + oldBits := atomic.LoadUint64(&h.sumBits) + newBits := math.Float64bits(math.Float64frombits(oldBits) + v) + if atomic.CompareAndSwapUint64(&h.sumBits, oldBits, newBits) { + break + } + } +} + +func (h *histogram) Write(out *dto.Metric) error { + his := &dto.Histogram{} + buckets := make([]*dto.Bucket, len(h.upperBounds)) + + his.SampleSum = proto.Float64(math.Float64frombits(atomic.LoadUint64(&h.sumBits))) + his.SampleCount = proto.Uint64(atomic.LoadUint64(&h.count)) + var count uint64 + for i, upperBound := range h.upperBounds { + count += atomic.LoadUint64(&h.counts[i]) + buckets[i] = &dto.Bucket{ + CumulativeCount: proto.Uint64(count), + UpperBound: proto.Float64(upperBound), + } + } + his.Bucket = buckets + out.Histogram = his + out.Label = h.labelPairs + return nil +} + +// HistogramVec is a Collector that bundles a set of Histograms that all share the +// same Desc, but have different values for their variable labels. This is used +// if you want to count the same thing partitioned by various dimensions +// (e.g. HTTP request latencies, partitioned by status code and method). Create +// instances with NewHistogramVec. +type HistogramVec struct { + *metricVec +} + +// NewHistogramVec creates a new HistogramVec based on the provided HistogramOpts and +// partitioned by the given label names. +func NewHistogramVec(opts HistogramOpts, labelNames []string) *HistogramVec { + desc := NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + labelNames, + opts.ConstLabels, + ) + return &HistogramVec{ + metricVec: newMetricVec(desc, func(lvs ...string) Metric { + return newHistogram(desc, opts, lvs...) + }), + } +} + +// GetMetricWithLabelValues returns the Histogram for the given slice of label +// values (same order as the VariableLabels in Desc). If that combination of +// label values is accessed for the first time, a new Histogram is created. +// +// It is possible to call this method without using the returned Histogram to only +// create the new Histogram but leave it at its starting value, a Histogram without +// any observations. +// +// Keeping the Histogram for later use is possible (and should be considered if +// performance is critical), but keep in mind that Reset, DeleteLabelValues and +// Delete can be used to delete the Histogram from the HistogramVec. In that case, the +// Histogram will still exist, but it will not be exported anymore, even if a +// Histogram with the same label values is created later. See also the CounterVec +// example. +// +// An error is returned if the number of label values is not the same as the +// number of VariableLabels in Desc (minus any curried labels). +// +// Note that for more than one label value, this method is prone to mistakes +// caused by an incorrect order of arguments. Consider GetMetricWith(Labels) as +// an alternative to avoid that type of mistake. For higher label numbers, the +// latter has a much more readable (albeit more verbose) syntax, but it comes +// with a performance overhead (for creating and processing the Labels map). +// See also the GaugeVec example. +func (v *HistogramVec) GetMetricWithLabelValues(lvs ...string) (Observer, error) { + metric, err := v.metricVec.getMetricWithLabelValues(lvs...) + if metric != nil { + return metric.(Observer), err + } + return nil, err +} + +// GetMetricWith returns the Histogram for the given Labels map (the label names +// must match those of the VariableLabels in Desc). If that label map is +// accessed for the first time, a new Histogram is created. Implications of +// creating a Histogram without using it and keeping the Histogram for later use +// are the same as for GetMetricWithLabelValues. +// +// An error is returned if the number and names of the Labels are inconsistent +// with those of the VariableLabels in Desc (minus any curried labels). +// +// This method is used for the same purpose as +// GetMetricWithLabelValues(...string). See there for pros and cons of the two +// methods. +func (v *HistogramVec) GetMetricWith(labels Labels) (Observer, error) { + metric, err := v.metricVec.getMetricWith(labels) + if metric != nil { + return metric.(Observer), err + } + return nil, err +} + +// WithLabelValues works as GetMetricWithLabelValues, but panics where +// GetMetricWithLabelValues would have returned an error. Not returning an +// error allows shortcuts like +// myVec.WithLabelValues("404", "GET").Observe(42.21) +func (v *HistogramVec) WithLabelValues(lvs ...string) Observer { + h, err := v.GetMetricWithLabelValues(lvs...) + if err != nil { + panic(err) + } + return h +} + +// With works as GetMetricWith but panics where GetMetricWithLabels would have +// returned an error. Not returning an error allows shortcuts like +// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Observe(42.21) +func (v *HistogramVec) With(labels Labels) Observer { + h, err := v.GetMetricWith(labels) + if err != nil { + panic(err) + } + return h +} + +// CurryWith returns a vector curried with the provided labels, i.e. the +// returned vector has those labels pre-set for all labeled operations performed +// on it. The cardinality of the curried vector is reduced accordingly. The +// order of the remaining labels stays the same (just with the curried labels +// taken out of the sequence – which is relevant for the +// (GetMetric)WithLabelValues methods). It is possible to curry a curried +// vector, but only with labels not yet used for currying before. +// +// The metrics contained in the HistogramVec are shared between the curried and +// uncurried vectors. They are just accessed differently. Curried and uncurried +// vectors behave identically in terms of collection. Only one must be +// registered with a given registry (usually the uncurried version). The Reset +// method deletes all metrics, even if called on a curried vector. +func (v *HistogramVec) CurryWith(labels Labels) (ObserverVec, error) { + vec, err := v.curryWith(labels) + if vec != nil { + return &HistogramVec{vec}, err + } + return nil, err +} + +// MustCurryWith works as CurryWith but panics where CurryWith would have +// returned an error. +func (v *HistogramVec) MustCurryWith(labels Labels) ObserverVec { + vec, err := v.CurryWith(labels) + if err != nil { + panic(err) + } + return vec +} + +type constHistogram struct { + desc *Desc + count uint64 + sum float64 + buckets map[float64]uint64 + labelPairs []*dto.LabelPair +} + +func (h *constHistogram) Desc() *Desc { + return h.desc +} + +func (h *constHistogram) Write(out *dto.Metric) error { + his := &dto.Histogram{} + buckets := make([]*dto.Bucket, 0, len(h.buckets)) + + his.SampleCount = proto.Uint64(h.count) + his.SampleSum = proto.Float64(h.sum) + + for upperBound, count := range h.buckets { + buckets = append(buckets, &dto.Bucket{ + CumulativeCount: proto.Uint64(count), + UpperBound: proto.Float64(upperBound), + }) + } + + if len(buckets) > 0 { + sort.Sort(buckSort(buckets)) + } + his.Bucket = buckets + + out.Histogram = his + out.Label = h.labelPairs + + return nil +} + +// NewConstHistogram returns a metric representing a Prometheus histogram with +// fixed values for the count, sum, and bucket counts. As those parameters +// cannot be changed, the returned value does not implement the Histogram +// interface (but only the Metric interface). Users of this package will not +// have much use for it in regular operations. However, when implementing custom +// Collectors, it is useful as a throw-away metric that is generated on the fly +// to send it to Prometheus in the Collect method. +// +// buckets is a map of upper bounds to cumulative counts, excluding the +Inf +// bucket. +// +// NewConstHistogram returns an error if the length of labelValues is not +// consistent with the variable labels in Desc. +func NewConstHistogram( + desc *Desc, + count uint64, + sum float64, + buckets map[float64]uint64, + labelValues ...string, +) (Metric, error) { + if err := validateLabelValues(labelValues, len(desc.variableLabels)); err != nil { + return nil, err + } + return &constHistogram{ + desc: desc, + count: count, + sum: sum, + buckets: buckets, + labelPairs: makeLabelPairs(desc, labelValues), + }, nil +} + +// MustNewConstHistogram is a version of NewConstHistogram that panics where +// NewConstMetric would have returned an error. +func MustNewConstHistogram( + desc *Desc, + count uint64, + sum float64, + buckets map[float64]uint64, + labelValues ...string, +) Metric { + m, err := NewConstHistogram(desc, count, sum, buckets, labelValues...) + if err != nil { + panic(err) + } + return m +} + +type buckSort []*dto.Bucket + +func (s buckSort) Len() int { + return len(s) +} + +func (s buckSort) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +func (s buckSort) Less(i, j int) bool { + return s[i].GetUpperBound() < s[j].GetUpperBound() +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/http.go b/vendor/github.com/prometheus/client_golang/prometheus/http.go new file mode 100644 index 000000000..bfee5c6eb --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/http.go @@ -0,0 +1,524 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "bufio" + "bytes" + "compress/gzip" + "fmt" + "io" + "net" + "net/http" + "strconv" + "strings" + "sync" + "time" + + "github.com/prometheus/common/expfmt" +) + +// TODO(beorn7): Remove this whole file. It is a partial mirror of +// promhttp/http.go (to avoid circular import chains) where everything HTTP +// related should live. The functions here are just for avoiding +// breakage. Everything is deprecated. + +const ( + contentTypeHeader = "Content-Type" + contentLengthHeader = "Content-Length" + contentEncodingHeader = "Content-Encoding" + acceptEncodingHeader = "Accept-Encoding" +) + +var bufPool sync.Pool + +func getBuf() *bytes.Buffer { + buf := bufPool.Get() + if buf == nil { + return &bytes.Buffer{} + } + return buf.(*bytes.Buffer) +} + +func giveBuf(buf *bytes.Buffer) { + buf.Reset() + bufPool.Put(buf) +} + +// Handler returns an HTTP handler for the DefaultGatherer. It is +// already instrumented with InstrumentHandler (using "prometheus" as handler +// name). +// +// Deprecated: Please note the issues described in the doc comment of +// InstrumentHandler. You might want to consider using promhttp.Handler instead +// (which is not instrumented, but can be instrumented with the tooling provided +// in package promhttp). +func Handler() http.Handler { + return InstrumentHandler("prometheus", UninstrumentedHandler()) +} + +// UninstrumentedHandler returns an HTTP handler for the DefaultGatherer. +// +// Deprecated: Use promhttp.Handler instead. See there for further documentation. +func UninstrumentedHandler() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + mfs, err := DefaultGatherer.Gather() + if err != nil { + http.Error(w, "An error has occurred during metrics collection:\n\n"+err.Error(), http.StatusInternalServerError) + return + } + + contentType := expfmt.Negotiate(req.Header) + buf := getBuf() + defer giveBuf(buf) + writer, encoding := decorateWriter(req, buf) + enc := expfmt.NewEncoder(writer, contentType) + var lastErr error + for _, mf := range mfs { + if err := enc.Encode(mf); err != nil { + lastErr = err + http.Error(w, "An error has occurred during metrics encoding:\n\n"+err.Error(), http.StatusInternalServerError) + return + } + } + if closer, ok := writer.(io.Closer); ok { + closer.Close() + } + if lastErr != nil && buf.Len() == 0 { + http.Error(w, "No metrics encoded, last error:\n\n"+lastErr.Error(), http.StatusInternalServerError) + return + } + header := w.Header() + header.Set(contentTypeHeader, string(contentType)) + header.Set(contentLengthHeader, fmt.Sprint(buf.Len())) + if encoding != "" { + header.Set(contentEncodingHeader, encoding) + } + w.Write(buf.Bytes()) + }) +} + +// decorateWriter wraps a writer to handle gzip compression if requested. It +// returns the decorated writer and the appropriate "Content-Encoding" header +// (which is empty if no compression is enabled). +func decorateWriter(request *http.Request, writer io.Writer) (io.Writer, string) { + header := request.Header.Get(acceptEncodingHeader) + parts := strings.Split(header, ",") + for _, part := range parts { + part := strings.TrimSpace(part) + if part == "gzip" || strings.HasPrefix(part, "gzip;") { + return gzip.NewWriter(writer), "gzip" + } + } + return writer, "" +} + +var instLabels = []string{"method", "code"} + +type nower interface { + Now() time.Time +} + +type nowFunc func() time.Time + +func (n nowFunc) Now() time.Time { + return n() +} + +var now nower = nowFunc(func() time.Time { + return time.Now() +}) + +func nowSeries(t ...time.Time) nower { + return nowFunc(func() time.Time { + defer func() { + t = t[1:] + }() + + return t[0] + }) +} + +// InstrumentHandler wraps the given HTTP handler for instrumentation. It +// registers four metric collectors (if not already done) and reports HTTP +// metrics to the (newly or already) registered collectors: http_requests_total +// (CounterVec), http_request_duration_microseconds (Summary), +// http_request_size_bytes (Summary), http_response_size_bytes (Summary). Each +// has a constant label named "handler" with the provided handlerName as +// value. http_requests_total is a metric vector partitioned by HTTP method +// (label name "method") and HTTP status code (label name "code"). +// +// Deprecated: InstrumentHandler has several issues. Use the tooling provided in +// package promhttp instead. The issues are the following: +// +// - It uses Summaries rather than Histograms. Summaries are not useful if +// aggregation across multiple instances is required. +// +// - It uses microseconds as unit, which is deprecated and should be replaced by +// seconds. +// +// - The size of the request is calculated in a separate goroutine. Since this +// calculator requires access to the request header, it creates a race with +// any writes to the header performed during request handling. +// httputil.ReverseProxy is a prominent example for a handler +// performing such writes. +// +// - It has additional issues with HTTP/2, cf. +// https://github.com/prometheus/client_golang/issues/272. +func InstrumentHandler(handlerName string, handler http.Handler) http.HandlerFunc { + return InstrumentHandlerFunc(handlerName, handler.ServeHTTP) +} + +// InstrumentHandlerFunc wraps the given function for instrumentation. It +// otherwise works in the same way as InstrumentHandler (and shares the same +// issues). +// +// Deprecated: InstrumentHandlerFunc is deprecated for the same reasons as +// InstrumentHandler is. Use the tooling provided in package promhttp instead. +func InstrumentHandlerFunc(handlerName string, handlerFunc func(http.ResponseWriter, *http.Request)) http.HandlerFunc { + return InstrumentHandlerFuncWithOpts( + SummaryOpts{ + Subsystem: "http", + ConstLabels: Labels{"handler": handlerName}, + Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, + }, + handlerFunc, + ) +} + +// InstrumentHandlerWithOpts works like InstrumentHandler (and shares the same +// issues) but provides more flexibility (at the cost of a more complex call +// syntax). As InstrumentHandler, this function registers four metric +// collectors, but it uses the provided SummaryOpts to create them. However, the +// fields "Name" and "Help" in the SummaryOpts are ignored. "Name" is replaced +// by "requests_total", "request_duration_microseconds", "request_size_bytes", +// and "response_size_bytes", respectively. "Help" is replaced by an appropriate +// help string. The names of the variable labels of the http_requests_total +// CounterVec are "method" (get, post, etc.), and "code" (HTTP status code). +// +// If InstrumentHandlerWithOpts is called as follows, it mimics exactly the +// behavior of InstrumentHandler: +// +// prometheus.InstrumentHandlerWithOpts( +// prometheus.SummaryOpts{ +// Subsystem: "http", +// ConstLabels: prometheus.Labels{"handler": handlerName}, +// }, +// handler, +// ) +// +// Technical detail: "requests_total" is a CounterVec, not a SummaryVec, so it +// cannot use SummaryOpts. Instead, a CounterOpts struct is created internally, +// and all its fields are set to the equally named fields in the provided +// SummaryOpts. +// +// Deprecated: InstrumentHandlerWithOpts is deprecated for the same reasons as +// InstrumentHandler is. Use the tooling provided in package promhttp instead. +func InstrumentHandlerWithOpts(opts SummaryOpts, handler http.Handler) http.HandlerFunc { + return InstrumentHandlerFuncWithOpts(opts, handler.ServeHTTP) +} + +// InstrumentHandlerFuncWithOpts works like InstrumentHandlerFunc (and shares +// the same issues) but provides more flexibility (at the cost of a more complex +// call syntax). See InstrumentHandlerWithOpts for details how the provided +// SummaryOpts are used. +// +// Deprecated: InstrumentHandlerFuncWithOpts is deprecated for the same reasons +// as InstrumentHandler is. Use the tooling provided in package promhttp instead. +func InstrumentHandlerFuncWithOpts(opts SummaryOpts, handlerFunc func(http.ResponseWriter, *http.Request)) http.HandlerFunc { + reqCnt := NewCounterVec( + CounterOpts{ + Namespace: opts.Namespace, + Subsystem: opts.Subsystem, + Name: "requests_total", + Help: "Total number of HTTP requests made.", + ConstLabels: opts.ConstLabels, + }, + instLabels, + ) + if err := Register(reqCnt); err != nil { + if are, ok := err.(AlreadyRegisteredError); ok { + reqCnt = are.ExistingCollector.(*CounterVec) + } else { + panic(err) + } + } + + opts.Name = "request_duration_microseconds" + opts.Help = "The HTTP request latencies in microseconds." + reqDur := NewSummary(opts) + if err := Register(reqDur); err != nil { + if are, ok := err.(AlreadyRegisteredError); ok { + reqDur = are.ExistingCollector.(Summary) + } else { + panic(err) + } + } + + opts.Name = "request_size_bytes" + opts.Help = "The HTTP request sizes in bytes." + reqSz := NewSummary(opts) + if err := Register(reqSz); err != nil { + if are, ok := err.(AlreadyRegisteredError); ok { + reqSz = are.ExistingCollector.(Summary) + } else { + panic(err) + } + } + + opts.Name = "response_size_bytes" + opts.Help = "The HTTP response sizes in bytes." + resSz := NewSummary(opts) + if err := Register(resSz); err != nil { + if are, ok := err.(AlreadyRegisteredError); ok { + resSz = are.ExistingCollector.(Summary) + } else { + panic(err) + } + } + + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + now := time.Now() + + delegate := &responseWriterDelegator{ResponseWriter: w} + out := computeApproximateRequestSize(r) + + _, cn := w.(http.CloseNotifier) + _, fl := w.(http.Flusher) + _, hj := w.(http.Hijacker) + _, rf := w.(io.ReaderFrom) + var rw http.ResponseWriter + if cn && fl && hj && rf { + rw = &fancyResponseWriterDelegator{delegate} + } else { + rw = delegate + } + handlerFunc(rw, r) + + elapsed := float64(time.Since(now)) / float64(time.Microsecond) + + method := sanitizeMethod(r.Method) + code := sanitizeCode(delegate.status) + reqCnt.WithLabelValues(method, code).Inc() + reqDur.Observe(elapsed) + resSz.Observe(float64(delegate.written)) + reqSz.Observe(float64(<-out)) + }) +} + +func computeApproximateRequestSize(r *http.Request) <-chan int { + // Get URL length in current go routine for avoiding a race condition. + // HandlerFunc that runs in parallel may modify the URL. + s := 0 + if r.URL != nil { + s += len(r.URL.String()) + } + + out := make(chan int, 1) + + go func() { + s += len(r.Method) + s += len(r.Proto) + for name, values := range r.Header { + s += len(name) + for _, value := range values { + s += len(value) + } + } + s += len(r.Host) + + // N.B. r.Form and r.MultipartForm are assumed to be included in r.URL. + + if r.ContentLength != -1 { + s += int(r.ContentLength) + } + out <- s + close(out) + }() + + return out +} + +type responseWriterDelegator struct { + http.ResponseWriter + + handler, method string + status int + written int64 + wroteHeader bool +} + +func (r *responseWriterDelegator) WriteHeader(code int) { + r.status = code + r.wroteHeader = true + r.ResponseWriter.WriteHeader(code) +} + +func (r *responseWriterDelegator) Write(b []byte) (int, error) { + if !r.wroteHeader { + r.WriteHeader(http.StatusOK) + } + n, err := r.ResponseWriter.Write(b) + r.written += int64(n) + return n, err +} + +type fancyResponseWriterDelegator struct { + *responseWriterDelegator +} + +func (f *fancyResponseWriterDelegator) CloseNotify() <-chan bool { + return f.ResponseWriter.(http.CloseNotifier).CloseNotify() +} + +func (f *fancyResponseWriterDelegator) Flush() { + f.ResponseWriter.(http.Flusher).Flush() +} + +func (f *fancyResponseWriterDelegator) Hijack() (net.Conn, *bufio.ReadWriter, error) { + return f.ResponseWriter.(http.Hijacker).Hijack() +} + +func (f *fancyResponseWriterDelegator) ReadFrom(r io.Reader) (int64, error) { + if !f.wroteHeader { + f.WriteHeader(http.StatusOK) + } + n, err := f.ResponseWriter.(io.ReaderFrom).ReadFrom(r) + f.written += n + return n, err +} + +func sanitizeMethod(m string) string { + switch m { + case "GET", "get": + return "get" + case "PUT", "put": + return "put" + case "HEAD", "head": + return "head" + case "POST", "post": + return "post" + case "DELETE", "delete": + return "delete" + case "CONNECT", "connect": + return "connect" + case "OPTIONS", "options": + return "options" + case "NOTIFY", "notify": + return "notify" + default: + return strings.ToLower(m) + } +} + +func sanitizeCode(s int) string { + switch s { + case 100: + return "100" + case 101: + return "101" + + case 200: + return "200" + case 201: + return "201" + case 202: + return "202" + case 203: + return "203" + case 204: + return "204" + case 205: + return "205" + case 206: + return "206" + + case 300: + return "300" + case 301: + return "301" + case 302: + return "302" + case 304: + return "304" + case 305: + return "305" + case 307: + return "307" + + case 400: + return "400" + case 401: + return "401" + case 402: + return "402" + case 403: + return "403" + case 404: + return "404" + case 405: + return "405" + case 406: + return "406" + case 407: + return "407" + case 408: + return "408" + case 409: + return "409" + case 410: + return "410" + case 411: + return "411" + case 412: + return "412" + case 413: + return "413" + case 414: + return "414" + case 415: + return "415" + case 416: + return "416" + case 417: + return "417" + case 418: + return "418" + + case 500: + return "500" + case 501: + return "501" + case 502: + return "502" + case 503: + return "503" + case 504: + return "504" + case 505: + return "505" + + case 428: + return "428" + case 429: + return "429" + case 431: + return "431" + case 511: + return "511" + + default: + return strconv.Itoa(s) + } +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/labels.go b/vendor/github.com/prometheus/client_golang/prometheus/labels.go new file mode 100644 index 000000000..2502e3734 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/labels.go @@ -0,0 +1,57 @@ +package prometheus + +import ( + "errors" + "fmt" + "strings" + "unicode/utf8" + + "github.com/prometheus/common/model" +) + +// Labels represents a collection of label name -> value mappings. This type is +// commonly used with the With(Labels) and GetMetricWith(Labels) methods of +// metric vector Collectors, e.g.: +// myVec.With(Labels{"code": "404", "method": "GET"}).Add(42) +// +// The other use-case is the specification of constant label pairs in Opts or to +// create a Desc. +type Labels map[string]string + +// reservedLabelPrefix is a prefix which is not legal in user-supplied +// label names. +const reservedLabelPrefix = "__" + +var errInconsistentCardinality = errors.New("inconsistent label cardinality") + +func validateValuesInLabels(labels Labels, expectedNumberOfValues int) error { + if len(labels) != expectedNumberOfValues { + return errInconsistentCardinality + } + + for name, val := range labels { + if !utf8.ValidString(val) { + return fmt.Errorf("label %s: value %q is not valid UTF-8", name, val) + } + } + + return nil +} + +func validateLabelValues(vals []string, expectedNumberOfValues int) error { + if len(vals) != expectedNumberOfValues { + return errInconsistentCardinality + } + + for _, val := range vals { + if !utf8.ValidString(val) { + return fmt.Errorf("label value %q is not valid UTF-8", val) + } + } + + return nil +} + +func checkLabelName(l string) bool { + return model.LabelName(l).IsValid() && !strings.HasPrefix(l, reservedLabelPrefix) +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/metric.go b/vendor/github.com/prometheus/client_golang/prometheus/metric.go new file mode 100644 index 000000000..6213ee812 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/metric.go @@ -0,0 +1,158 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "strings" + + dto "github.com/prometheus/client_model/go" +) + +const separatorByte byte = 255 + +// A Metric models a single sample value with its meta data being exported to +// Prometheus. Implementations of Metric in this package are Gauge, Counter, +// Histogram, Summary, and Untyped. +type Metric interface { + // Desc returns the descriptor for the Metric. This method idempotently + // returns the same descriptor throughout the lifetime of the + // Metric. The returned descriptor is immutable by contract. A Metric + // unable to describe itself must return an invalid descriptor (created + // with NewInvalidDesc). + Desc() *Desc + // Write encodes the Metric into a "Metric" Protocol Buffer data + // transmission object. + // + // Metric implementations must observe concurrency safety as reads of + // this metric may occur at any time, and any blocking occurs at the + // expense of total performance of rendering all registered + // metrics. Ideally, Metric implementations should support concurrent + // readers. + // + // While populating dto.Metric, it is the responsibility of the + // implementation to ensure validity of the Metric protobuf (like valid + // UTF-8 strings or syntactically valid metric and label names). It is + // recommended to sort labels lexicographically. (Implementers may find + // LabelPairSorter useful for that.) Callers of Write should still make + // sure of sorting if they depend on it. + Write(*dto.Metric) error + // TODO(beorn7): The original rationale of passing in a pre-allocated + // dto.Metric protobuf to save allocations has disappeared. The + // signature of this method should be changed to "Write() (*dto.Metric, + // error)". +} + +// Opts bundles the options for creating most Metric types. Each metric +// implementation XXX has its own XXXOpts type, but in most cases, it is just be +// an alias of this type (which might change when the requirement arises.) +// +// It is mandatory to set Name and Help to a non-empty string. All other fields +// are optional and can safely be left at their zero value. +type Opts struct { + // Namespace, Subsystem, and Name are components of the fully-qualified + // name of the Metric (created by joining these components with + // "_"). Only Name is mandatory, the others merely help structuring the + // name. Note that the fully-qualified name of the metric must be a + // valid Prometheus metric name. + Namespace string + Subsystem string + Name string + + // Help provides information about this metric. Mandatory! + // + // Metrics with the same fully-qualified name must have the same Help + // string. + Help string + + // ConstLabels are used to attach fixed labels to this metric. Metrics + // with the same fully-qualified name must have the same label names in + // their ConstLabels. + // + // ConstLabels are only used rarely. In particular, do not use them to + // attach the same labels to all your metrics. Those use cases are + // better covered by target labels set by the scraping Prometheus + // server, or by one specific metric (e.g. a build_info or a + // machine_role metric). See also + // https://prometheus.io/docs/instrumenting/writing_exporters/#target-labels,-not-static-scraped-labels + ConstLabels Labels +} + +// BuildFQName joins the given three name components by "_". Empty name +// components are ignored. If the name parameter itself is empty, an empty +// string is returned, no matter what. Metric implementations included in this +// library use this function internally to generate the fully-qualified metric +// name from the name component in their Opts. Users of the library will only +// need this function if they implement their own Metric or instantiate a Desc +// (with NewDesc) directly. +func BuildFQName(namespace, subsystem, name string) string { + if name == "" { + return "" + } + switch { + case namespace != "" && subsystem != "": + return strings.Join([]string{namespace, subsystem, name}, "_") + case namespace != "": + return strings.Join([]string{namespace, name}, "_") + case subsystem != "": + return strings.Join([]string{subsystem, name}, "_") + } + return name +} + +// LabelPairSorter implements sort.Interface. It is used to sort a slice of +// dto.LabelPair pointers. This is useful for implementing the Write method of +// custom metrics. +type LabelPairSorter []*dto.LabelPair + +func (s LabelPairSorter) Len() int { + return len(s) +} + +func (s LabelPairSorter) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +func (s LabelPairSorter) Less(i, j int) bool { + return s[i].GetName() < s[j].GetName() +} + +type hashSorter []uint64 + +func (s hashSorter) Len() int { + return len(s) +} + +func (s hashSorter) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +func (s hashSorter) Less(i, j int) bool { + return s[i] < s[j] +} + +type invalidMetric struct { + desc *Desc + err error +} + +// NewInvalidMetric returns a metric whose Write method always returns the +// provided error. It is useful if a Collector finds itself unable to collect +// a metric and wishes to report an error to the registry. +func NewInvalidMetric(desc *Desc, err error) Metric { + return &invalidMetric{desc, err} +} + +func (m *invalidMetric) Desc() *Desc { return m.desc } + +func (m *invalidMetric) Write(*dto.Metric) error { return m.err } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/observer.go b/vendor/github.com/prometheus/client_golang/prometheus/observer.go new file mode 100644 index 000000000..5806cd09e --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/observer.go @@ -0,0 +1,52 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +// Observer is the interface that wraps the Observe method, which is used by +// Histogram and Summary to add observations. +type Observer interface { + Observe(float64) +} + +// The ObserverFunc type is an adapter to allow the use of ordinary +// functions as Observers. If f is a function with the appropriate +// signature, ObserverFunc(f) is an Observer that calls f. +// +// This adapter is usually used in connection with the Timer type, and there are +// two general use cases: +// +// The most common one is to use a Gauge as the Observer for a Timer. +// See the "Gauge" Timer example. +// +// The more advanced use case is to create a function that dynamically decides +// which Observer to use for observing the duration. See the "Complex" Timer +// example. +type ObserverFunc func(float64) + +// Observe calls f(value). It implements Observer. +func (f ObserverFunc) Observe(value float64) { + f(value) +} + +// ObserverVec is an interface implemented by `HistogramVec` and `SummaryVec`. +type ObserverVec interface { + GetMetricWith(Labels) (Observer, error) + GetMetricWithLabelValues(lvs ...string) (Observer, error) + With(Labels) Observer + WithLabelValues(...string) Observer + CurryWith(Labels) (ObserverVec, error) + MustCurryWith(Labels) ObserverVec + + Collector +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/process_collector.go b/vendor/github.com/prometheus/client_golang/prometheus/process_collector.go new file mode 100644 index 000000000..94b2553e1 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/process_collector.go @@ -0,0 +1,140 @@ +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import "github.com/prometheus/procfs" + +type processCollector struct { + pid int + collectFn func(chan<- Metric) + pidFn func() (int, error) + cpuTotal *Desc + openFDs, maxFDs *Desc + vsize, rss *Desc + startTime *Desc +} + +// NewProcessCollector returns a collector which exports the current state of +// process metrics including cpu, memory and file descriptor usage as well as +// the process start time for the given process id under the given namespace. +func NewProcessCollector(pid int, namespace string) Collector { + return NewProcessCollectorPIDFn( + func() (int, error) { return pid, nil }, + namespace, + ) +} + +// NewProcessCollectorPIDFn returns a collector which exports the current state +// of process metrics including cpu, memory and file descriptor usage as well +// as the process start time under the given namespace. The given pidFn is +// called on each collect and is used to determine the process to export +// metrics for. +func NewProcessCollectorPIDFn( + pidFn func() (int, error), + namespace string, +) Collector { + ns := "" + if len(namespace) > 0 { + ns = namespace + "_" + } + + c := processCollector{ + pidFn: pidFn, + collectFn: func(chan<- Metric) {}, + + cpuTotal: NewDesc( + ns+"process_cpu_seconds_total", + "Total user and system CPU time spent in seconds.", + nil, nil, + ), + openFDs: NewDesc( + ns+"process_open_fds", + "Number of open file descriptors.", + nil, nil, + ), + maxFDs: NewDesc( + ns+"process_max_fds", + "Maximum number of open file descriptors.", + nil, nil, + ), + vsize: NewDesc( + ns+"process_virtual_memory_bytes", + "Virtual memory size in bytes.", + nil, nil, + ), + rss: NewDesc( + ns+"process_resident_memory_bytes", + "Resident memory size in bytes.", + nil, nil, + ), + startTime: NewDesc( + ns+"process_start_time_seconds", + "Start time of the process since unix epoch in seconds.", + nil, nil, + ), + } + + // Set up process metric collection if supported by the runtime. + if _, err := procfs.NewStat(); err == nil { + c.collectFn = c.processCollect + } + + return &c +} + +// Describe returns all descriptions of the collector. +func (c *processCollector) Describe(ch chan<- *Desc) { + ch <- c.cpuTotal + ch <- c.openFDs + ch <- c.maxFDs + ch <- c.vsize + ch <- c.rss + ch <- c.startTime +} + +// Collect returns the current state of all metrics of the collector. +func (c *processCollector) Collect(ch chan<- Metric) { + c.collectFn(ch) +} + +// TODO(ts): Bring back error reporting by reverting 7faf9e7 as soon as the +// client allows users to configure the error behavior. +func (c *processCollector) processCollect(ch chan<- Metric) { + pid, err := c.pidFn() + if err != nil { + return + } + + p, err := procfs.NewProc(pid) + if err != nil { + return + } + + if stat, err := p.NewStat(); err == nil { + ch <- MustNewConstMetric(c.cpuTotal, CounterValue, stat.CPUTime()) + ch <- MustNewConstMetric(c.vsize, GaugeValue, float64(stat.VirtualMemory())) + ch <- MustNewConstMetric(c.rss, GaugeValue, float64(stat.ResidentMemory())) + if startTime, err := stat.StartTime(); err == nil { + ch <- MustNewConstMetric(c.startTime, GaugeValue, startTime) + } + } + + if fds, err := p.FileDescriptorsLen(); err == nil { + ch <- MustNewConstMetric(c.openFDs, GaugeValue, float64(fds)) + } + + if limits, err := p.NewLimits(); err == nil { + ch <- MustNewConstMetric(c.maxFDs, GaugeValue, float64(limits.OpenFiles)) + } +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator.go new file mode 100644 index 000000000..5ee095b09 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator.go @@ -0,0 +1,199 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package promhttp + +import ( + "bufio" + "io" + "net" + "net/http" +) + +const ( + closeNotifier = 1 << iota + flusher + hijacker + readerFrom + pusher +) + +type delegator interface { + http.ResponseWriter + + Status() int + Written() int64 +} + +type responseWriterDelegator struct { + http.ResponseWriter + + handler, method string + status int + written int64 + wroteHeader bool + observeWriteHeader func(int) +} + +func (r *responseWriterDelegator) Status() int { + return r.status +} + +func (r *responseWriterDelegator) Written() int64 { + return r.written +} + +func (r *responseWriterDelegator) WriteHeader(code int) { + r.status = code + r.wroteHeader = true + r.ResponseWriter.WriteHeader(code) + if r.observeWriteHeader != nil { + r.observeWriteHeader(code) + } +} + +func (r *responseWriterDelegator) Write(b []byte) (int, error) { + if !r.wroteHeader { + r.WriteHeader(http.StatusOK) + } + n, err := r.ResponseWriter.Write(b) + r.written += int64(n) + return n, err +} + +type closeNotifierDelegator struct{ *responseWriterDelegator } +type flusherDelegator struct{ *responseWriterDelegator } +type hijackerDelegator struct{ *responseWriterDelegator } +type readerFromDelegator struct{ *responseWriterDelegator } + +func (d *closeNotifierDelegator) CloseNotify() <-chan bool { + return d.ResponseWriter.(http.CloseNotifier).CloseNotify() +} +func (d *flusherDelegator) Flush() { + d.ResponseWriter.(http.Flusher).Flush() +} +func (d *hijackerDelegator) Hijack() (net.Conn, *bufio.ReadWriter, error) { + return d.ResponseWriter.(http.Hijacker).Hijack() +} +func (d *readerFromDelegator) ReadFrom(re io.Reader) (int64, error) { + if !d.wroteHeader { + d.WriteHeader(http.StatusOK) + } + n, err := d.ResponseWriter.(io.ReaderFrom).ReadFrom(re) + d.written += n + return n, err +} + +var pickDelegator = make([]func(*responseWriterDelegator) delegator, 32) + +func init() { + // TODO(beorn7): Code generation would help here. + pickDelegator[0] = func(d *responseWriterDelegator) delegator { // 0 + return d + } + pickDelegator[closeNotifier] = func(d *responseWriterDelegator) delegator { // 1 + return closeNotifierDelegator{d} + } + pickDelegator[flusher] = func(d *responseWriterDelegator) delegator { // 2 + return flusherDelegator{d} + } + pickDelegator[flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 3 + return struct { + *responseWriterDelegator + http.Flusher + http.CloseNotifier + }{d, &flusherDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[hijacker] = func(d *responseWriterDelegator) delegator { // 4 + return hijackerDelegator{d} + } + pickDelegator[hijacker+closeNotifier] = func(d *responseWriterDelegator) delegator { // 5 + return struct { + *responseWriterDelegator + http.Hijacker + http.CloseNotifier + }{d, &hijackerDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[hijacker+flusher] = func(d *responseWriterDelegator) delegator { // 6 + return struct { + *responseWriterDelegator + http.Hijacker + http.Flusher + }{d, &hijackerDelegator{d}, &flusherDelegator{d}} + } + pickDelegator[hijacker+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 7 + return struct { + *responseWriterDelegator + http.Hijacker + http.Flusher + http.CloseNotifier + }{d, &hijackerDelegator{d}, &flusherDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[readerFrom] = func(d *responseWriterDelegator) delegator { // 8 + return readerFromDelegator{d} + } + pickDelegator[readerFrom+closeNotifier] = func(d *responseWriterDelegator) delegator { // 9 + return struct { + *responseWriterDelegator + io.ReaderFrom + http.CloseNotifier + }{d, &readerFromDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[readerFrom+flusher] = func(d *responseWriterDelegator) delegator { // 10 + return struct { + *responseWriterDelegator + io.ReaderFrom + http.Flusher + }{d, &readerFromDelegator{d}, &flusherDelegator{d}} + } + pickDelegator[readerFrom+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 11 + return struct { + *responseWriterDelegator + io.ReaderFrom + http.Flusher + http.CloseNotifier + }{d, &readerFromDelegator{d}, &flusherDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[readerFrom+hijacker] = func(d *responseWriterDelegator) delegator { // 12 + return struct { + *responseWriterDelegator + io.ReaderFrom + http.Hijacker + }{d, &readerFromDelegator{d}, &hijackerDelegator{d}} + } + pickDelegator[readerFrom+hijacker+closeNotifier] = func(d *responseWriterDelegator) delegator { // 13 + return struct { + *responseWriterDelegator + io.ReaderFrom + http.Hijacker + http.CloseNotifier + }{d, &readerFromDelegator{d}, &hijackerDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[readerFrom+hijacker+flusher] = func(d *responseWriterDelegator) delegator { // 14 + return struct { + *responseWriterDelegator + io.ReaderFrom + http.Hijacker + http.Flusher + }{d, &readerFromDelegator{d}, &hijackerDelegator{d}, &flusherDelegator{d}} + } + pickDelegator[readerFrom+hijacker+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 15 + return struct { + *responseWriterDelegator + io.ReaderFrom + http.Hijacker + http.Flusher + http.CloseNotifier + }{d, &readerFromDelegator{d}, &hijackerDelegator{d}, &flusherDelegator{d}, &closeNotifierDelegator{d}} + } +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator_1_8.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator_1_8.go new file mode 100644 index 000000000..f4d386f7a --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator_1_8.go @@ -0,0 +1,181 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build go1.8 + +package promhttp + +import ( + "io" + "net/http" +) + +type pusherDelegator struct{ *responseWriterDelegator } + +func (d *pusherDelegator) Push(target string, opts *http.PushOptions) error { + return d.ResponseWriter.(http.Pusher).Push(target, opts) +} + +func init() { + pickDelegator[pusher] = func(d *responseWriterDelegator) delegator { // 16 + return pusherDelegator{d} + } + pickDelegator[pusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 17 + return struct { + *responseWriterDelegator + http.Pusher + http.CloseNotifier + }{d, &pusherDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[pusher+flusher] = func(d *responseWriterDelegator) delegator { // 18 + return struct { + *responseWriterDelegator + http.Pusher + http.Flusher + }{d, &pusherDelegator{d}, &flusherDelegator{d}} + } + pickDelegator[pusher+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 19 + return struct { + *responseWriterDelegator + http.Pusher + http.Flusher + http.CloseNotifier + }{d, &pusherDelegator{d}, &flusherDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[pusher+hijacker] = func(d *responseWriterDelegator) delegator { // 20 + return struct { + *responseWriterDelegator + http.Pusher + http.Hijacker + }{d, &pusherDelegator{d}, &hijackerDelegator{d}} + } + pickDelegator[pusher+hijacker+closeNotifier] = func(d *responseWriterDelegator) delegator { // 21 + return struct { + *responseWriterDelegator + http.Pusher + http.Hijacker + http.CloseNotifier + }{d, &pusherDelegator{d}, &hijackerDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[pusher+hijacker+flusher] = func(d *responseWriterDelegator) delegator { // 22 + return struct { + *responseWriterDelegator + http.Pusher + http.Hijacker + http.Flusher + }{d, &pusherDelegator{d}, &hijackerDelegator{d}, &flusherDelegator{d}} + } + pickDelegator[pusher+hijacker+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { //23 + return struct { + *responseWriterDelegator + http.Pusher + http.Hijacker + http.Flusher + http.CloseNotifier + }{d, &pusherDelegator{d}, &hijackerDelegator{d}, &flusherDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[pusher+readerFrom] = func(d *responseWriterDelegator) delegator { // 24 + return struct { + *responseWriterDelegator + http.Pusher + io.ReaderFrom + }{d, &pusherDelegator{d}, &readerFromDelegator{d}} + } + pickDelegator[pusher+readerFrom+closeNotifier] = func(d *responseWriterDelegator) delegator { // 25 + return struct { + *responseWriterDelegator + http.Pusher + io.ReaderFrom + http.CloseNotifier + }{d, &pusherDelegator{d}, &readerFromDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[pusher+readerFrom+flusher] = func(d *responseWriterDelegator) delegator { // 26 + return struct { + *responseWriterDelegator + http.Pusher + io.ReaderFrom + http.Flusher + }{d, &pusherDelegator{d}, &readerFromDelegator{d}, &flusherDelegator{d}} + } + pickDelegator[pusher+readerFrom+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 27 + return struct { + *responseWriterDelegator + http.Pusher + io.ReaderFrom + http.Flusher + http.CloseNotifier + }{d, &pusherDelegator{d}, &readerFromDelegator{d}, &flusherDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[pusher+readerFrom+hijacker] = func(d *responseWriterDelegator) delegator { // 28 + return struct { + *responseWriterDelegator + http.Pusher + io.ReaderFrom + http.Hijacker + }{d, &pusherDelegator{d}, &readerFromDelegator{d}, &hijackerDelegator{d}} + } + pickDelegator[pusher+readerFrom+hijacker+closeNotifier] = func(d *responseWriterDelegator) delegator { // 29 + return struct { + *responseWriterDelegator + http.Pusher + io.ReaderFrom + http.Hijacker + http.CloseNotifier + }{d, &pusherDelegator{d}, &readerFromDelegator{d}, &hijackerDelegator{d}, &closeNotifierDelegator{d}} + } + pickDelegator[pusher+readerFrom+hijacker+flusher] = func(d *responseWriterDelegator) delegator { // 30 + return struct { + *responseWriterDelegator + http.Pusher + io.ReaderFrom + http.Hijacker + http.Flusher + }{d, &pusherDelegator{d}, &readerFromDelegator{d}, &hijackerDelegator{d}, &flusherDelegator{d}} + } + pickDelegator[pusher+readerFrom+hijacker+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 31 + return struct { + *responseWriterDelegator + http.Pusher + io.ReaderFrom + http.Hijacker + http.Flusher + http.CloseNotifier + }{d, &pusherDelegator{d}, &readerFromDelegator{d}, &hijackerDelegator{d}, &flusherDelegator{d}, &closeNotifierDelegator{d}} + } +} + +func newDelegator(w http.ResponseWriter, observeWriteHeaderFunc func(int)) delegator { + d := &responseWriterDelegator{ + ResponseWriter: w, + observeWriteHeader: observeWriteHeaderFunc, + } + + id := 0 + if _, ok := w.(http.CloseNotifier); ok { + id += closeNotifier + } + if _, ok := w.(http.Flusher); ok { + id += flusher + } + if _, ok := w.(http.Hijacker); ok { + id += hijacker + } + if _, ok := w.(io.ReaderFrom); ok { + id += readerFrom + } + if _, ok := w.(http.Pusher); ok { + id += pusher + } + + return pickDelegator[id](d) +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator_pre_1_8.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator_pre_1_8.go new file mode 100644 index 000000000..8bb9b8b68 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator_pre_1_8.go @@ -0,0 +1,44 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !go1.8 + +package promhttp + +import ( + "io" + "net/http" +) + +func newDelegator(w http.ResponseWriter, observeWriteHeaderFunc func(int)) delegator { + d := &responseWriterDelegator{ + ResponseWriter: w, + observeWriteHeader: observeWriteHeaderFunc, + } + + id := 0 + if _, ok := w.(http.CloseNotifier); ok { + id += closeNotifier + } + if _, ok := w.(http.Flusher); ok { + id += flusher + } + if _, ok := w.(http.Hijacker); ok { + id += hijacker + } + if _, ok := w.(io.ReaderFrom); ok { + id += readerFrom + } + + return pickDelegator[id](d) +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go new file mode 100644 index 000000000..2d67f2496 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go @@ -0,0 +1,204 @@ +// Copyright 2016 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package promhttp provides tooling around HTTP servers and clients. +// +// First, the package allows the creation of http.Handler instances to expose +// Prometheus metrics via HTTP. promhttp.Handler acts on the +// prometheus.DefaultGatherer. With HandlerFor, you can create a handler for a +// custom registry or anything that implements the Gatherer interface. It also +// allows the creation of handlers that act differently on errors or allow to +// log errors. +// +// Second, the package provides tooling to instrument instances of http.Handler +// via middleware. Middleware wrappers follow the naming scheme +// InstrumentHandlerX, where X describes the intended use of the middleware. +// See each function's doc comment for specific details. +// +// Finally, the package allows for an http.RoundTripper to be instrumented via +// middleware. Middleware wrappers follow the naming scheme +// InstrumentRoundTripperX, where X describes the intended use of the +// middleware. See each function's doc comment for specific details. +package promhttp + +import ( + "bytes" + "compress/gzip" + "fmt" + "io" + "net/http" + "strings" + "sync" + + "github.com/prometheus/common/expfmt" + + "github.com/prometheus/client_golang/prometheus" +) + +const ( + contentTypeHeader = "Content-Type" + contentLengthHeader = "Content-Length" + contentEncodingHeader = "Content-Encoding" + acceptEncodingHeader = "Accept-Encoding" +) + +var bufPool sync.Pool + +func getBuf() *bytes.Buffer { + buf := bufPool.Get() + if buf == nil { + return &bytes.Buffer{} + } + return buf.(*bytes.Buffer) +} + +func giveBuf(buf *bytes.Buffer) { + buf.Reset() + bufPool.Put(buf) +} + +// Handler returns an HTTP handler for the prometheus.DefaultGatherer. The +// Handler uses the default HandlerOpts, i.e. report the first error as an HTTP +// error, no error logging, and compression if requested by the client. +// +// If you want to create a Handler for the DefaultGatherer with different +// HandlerOpts, create it with HandlerFor with prometheus.DefaultGatherer and +// your desired HandlerOpts. +func Handler() http.Handler { + return HandlerFor(prometheus.DefaultGatherer, HandlerOpts{}) +} + +// HandlerFor returns an http.Handler for the provided Gatherer. The behavior +// of the Handler is defined by the provided HandlerOpts. +func HandlerFor(reg prometheus.Gatherer, opts HandlerOpts) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + mfs, err := reg.Gather() + if err != nil { + if opts.ErrorLog != nil { + opts.ErrorLog.Println("error gathering metrics:", err) + } + switch opts.ErrorHandling { + case PanicOnError: + panic(err) + case ContinueOnError: + if len(mfs) == 0 { + http.Error(w, "No metrics gathered, last error:\n\n"+err.Error(), http.StatusInternalServerError) + return + } + case HTTPErrorOnError: + http.Error(w, "An error has occurred during metrics gathering:\n\n"+err.Error(), http.StatusInternalServerError) + return + } + } + + contentType := expfmt.Negotiate(req.Header) + buf := getBuf() + defer giveBuf(buf) + writer, encoding := decorateWriter(req, buf, opts.DisableCompression) + enc := expfmt.NewEncoder(writer, contentType) + var lastErr error + for _, mf := range mfs { + if err := enc.Encode(mf); err != nil { + lastErr = err + if opts.ErrorLog != nil { + opts.ErrorLog.Println("error encoding metric family:", err) + } + switch opts.ErrorHandling { + case PanicOnError: + panic(err) + case ContinueOnError: + // Handled later. + case HTTPErrorOnError: + http.Error(w, "An error has occurred during metrics encoding:\n\n"+err.Error(), http.StatusInternalServerError) + return + } + } + } + if closer, ok := writer.(io.Closer); ok { + closer.Close() + } + if lastErr != nil && buf.Len() == 0 { + http.Error(w, "No metrics encoded, last error:\n\n"+lastErr.Error(), http.StatusInternalServerError) + return + } + header := w.Header() + header.Set(contentTypeHeader, string(contentType)) + header.Set(contentLengthHeader, fmt.Sprint(buf.Len())) + if encoding != "" { + header.Set(contentEncodingHeader, encoding) + } + w.Write(buf.Bytes()) + // TODO(beorn7): Consider streaming serving of metrics. + }) +} + +// HandlerErrorHandling defines how a Handler serving metrics will handle +// errors. +type HandlerErrorHandling int + +// These constants cause handlers serving metrics to behave as described if +// errors are encountered. +const ( + // Serve an HTTP status code 500 upon the first error + // encountered. Report the error message in the body. + HTTPErrorOnError HandlerErrorHandling = iota + // Ignore errors and try to serve as many metrics as possible. However, + // if no metrics can be served, serve an HTTP status code 500 and the + // last error message in the body. Only use this in deliberate "best + // effort" metrics collection scenarios. It is recommended to at least + // log errors (by providing an ErrorLog in HandlerOpts) to not mask + // errors completely. + ContinueOnError + // Panic upon the first error encountered (useful for "crash only" apps). + PanicOnError +) + +// Logger is the minimal interface HandlerOpts needs for logging. Note that +// log.Logger from the standard library implements this interface, and it is +// easy to implement by custom loggers, if they don't do so already anyway. +type Logger interface { + Println(v ...interface{}) +} + +// HandlerOpts specifies options how to serve metrics via an http.Handler. The +// zero value of HandlerOpts is a reasonable default. +type HandlerOpts struct { + // ErrorLog specifies an optional logger for errors collecting and + // serving metrics. If nil, errors are not logged at all. + ErrorLog Logger + // ErrorHandling defines how errors are handled. Note that errors are + // logged regardless of the configured ErrorHandling provided ErrorLog + // is not nil. + ErrorHandling HandlerErrorHandling + // If DisableCompression is true, the handler will never compress the + // response, even if requested by the client. + DisableCompression bool +} + +// decorateWriter wraps a writer to handle gzip compression if requested. It +// returns the decorated writer and the appropriate "Content-Encoding" header +// (which is empty if no compression is enabled). +func decorateWriter(request *http.Request, writer io.Writer, compressionDisabled bool) (io.Writer, string) { + if compressionDisabled { + return writer, "" + } + header := request.Header.Get(acceptEncodingHeader) + parts := strings.Split(header, ",") + for _, part := range parts { + part := strings.TrimSpace(part) + if part == "gzip" || strings.HasPrefix(part, "gzip;") { + return gzip.NewWriter(writer), "gzip" + } + } + return writer, "" +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go new file mode 100644 index 000000000..91e2a5f9a --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go @@ -0,0 +1,97 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package promhttp + +import ( + "net/http" + "time" + + "github.com/prometheus/client_golang/prometheus" +) + +// The RoundTripperFunc type is an adapter to allow the use of ordinary +// functions as RoundTrippers. If f is a function with the appropriate +// signature, RountTripperFunc(f) is a RoundTripper that calls f. +type RoundTripperFunc func(req *http.Request) (*http.Response, error) + +// RoundTrip implements the RoundTripper interface. +func (rt RoundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) { + return rt(r) +} + +// InstrumentRoundTripperInFlight is a middleware that wraps the provided +// http.RoundTripper. It sets the provided prometheus.Gauge to the number of +// requests currently handled by the wrapped http.RoundTripper. +// +// See the example for ExampleInstrumentRoundTripperDuration for example usage. +func InstrumentRoundTripperInFlight(gauge prometheus.Gauge, next http.RoundTripper) RoundTripperFunc { + return RoundTripperFunc(func(r *http.Request) (*http.Response, error) { + gauge.Inc() + defer gauge.Dec() + return next.RoundTrip(r) + }) +} + +// InstrumentRoundTripperCounter is a middleware that wraps the provided +// http.RoundTripper to observe the request result with the provided CounterVec. +// The CounterVec must have zero, one, or two non-const non-curried labels. For +// those, the only allowed label names are "code" and "method". The function +// panics otherwise. Partitioning of the CounterVec happens by HTTP status code +// and/or HTTP method if the respective instance label names are present in the +// CounterVec. For unpartitioned counting, use a CounterVec with zero labels. +// +// If the wrapped RoundTripper panics or returns a non-nil error, the Counter +// is not incremented. +// +// See the example for ExampleInstrumentRoundTripperDuration for example usage. +func InstrumentRoundTripperCounter(counter *prometheus.CounterVec, next http.RoundTripper) RoundTripperFunc { + code, method := checkLabels(counter) + + return RoundTripperFunc(func(r *http.Request) (*http.Response, error) { + resp, err := next.RoundTrip(r) + if err == nil { + counter.With(labels(code, method, r.Method, resp.StatusCode)).Inc() + } + return resp, err + }) +} + +// InstrumentRoundTripperDuration is a middleware that wraps the provided +// http.RoundTripper to observe the request duration with the provided ObserverVec. +// The ObserverVec must have zero, one, or two labels. The only allowed label +// names are "code" and "method". The function panics if any other instance +// labels are provided. The Observe method of the Observer in the ObserverVec +// is called with the request duration in seconds. Partitioning happens by HTTP +// status code and/or HTTP method if the respective instance label names are +// present in the ObserverVec. For unpartitioned observations, use an +// ObserverVec with zero labels. Note that partitioning of Histograms is +// expensive and should be used judiciously. +// +// If the wrapped RoundTripper panics or returns a non-nil error, no values are +// reported. +// +// Note that this method is only guaranteed to never observe negative durations +// if used with Go1.9+. +func InstrumentRoundTripperDuration(obs prometheus.ObserverVec, next http.RoundTripper) RoundTripperFunc { + code, method := checkLabels(obs) + + return RoundTripperFunc(func(r *http.Request) (*http.Response, error) { + start := time.Now() + resp, err := next.RoundTrip(r) + if err == nil { + obs.With(labels(code, method, r.Method, resp.StatusCode)).Observe(time.Since(start).Seconds()) + } + return resp, err + }) +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client_1_8.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client_1_8.go new file mode 100644 index 000000000..0bd80c355 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client_1_8.go @@ -0,0 +1,144 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build go1.8 + +package promhttp + +import ( + "context" + "crypto/tls" + "net/http" + "net/http/httptrace" + "time" +) + +// InstrumentTrace is used to offer flexibility in instrumenting the available +// httptrace.ClientTrace hook functions. Each function is passed a float64 +// representing the time in seconds since the start of the http request. A user +// may choose to use separately buckets Histograms, or implement custom +// instance labels on a per function basis. +type InstrumentTrace struct { + GotConn func(float64) + PutIdleConn func(float64) + GotFirstResponseByte func(float64) + Got100Continue func(float64) + DNSStart func(float64) + DNSDone func(float64) + ConnectStart func(float64) + ConnectDone func(float64) + TLSHandshakeStart func(float64) + TLSHandshakeDone func(float64) + WroteHeaders func(float64) + Wait100Continue func(float64) + WroteRequest func(float64) +} + +// InstrumentRoundTripperTrace is a middleware that wraps the provided +// RoundTripper and reports times to hook functions provided in the +// InstrumentTrace struct. Hook functions that are not present in the provided +// InstrumentTrace struct are ignored. Times reported to the hook functions are +// time since the start of the request. Only with Go1.9+, those times are +// guaranteed to never be negative. (Earlier Go versions are not using a +// monotonic clock.) Note that partitioning of Histograms is expensive and +// should be used judiciously. +// +// For hook functions that receive an error as an argument, no observations are +// made in the event of a non-nil error value. +// +// See the example for ExampleInstrumentRoundTripperDuration for example usage. +func InstrumentRoundTripperTrace(it *InstrumentTrace, next http.RoundTripper) RoundTripperFunc { + return RoundTripperFunc(func(r *http.Request) (*http.Response, error) { + start := time.Now() + + trace := &httptrace.ClientTrace{ + GotConn: func(_ httptrace.GotConnInfo) { + if it.GotConn != nil { + it.GotConn(time.Since(start).Seconds()) + } + }, + PutIdleConn: func(err error) { + if err != nil { + return + } + if it.PutIdleConn != nil { + it.PutIdleConn(time.Since(start).Seconds()) + } + }, + DNSStart: func(_ httptrace.DNSStartInfo) { + if it.DNSStart != nil { + it.DNSStart(time.Since(start).Seconds()) + } + }, + DNSDone: func(_ httptrace.DNSDoneInfo) { + if it.DNSStart != nil { + it.DNSStart(time.Since(start).Seconds()) + } + }, + ConnectStart: func(_, _ string) { + if it.ConnectStart != nil { + it.ConnectStart(time.Since(start).Seconds()) + } + }, + ConnectDone: func(_, _ string, err error) { + if err != nil { + return + } + if it.ConnectDone != nil { + it.ConnectDone(time.Since(start).Seconds()) + } + }, + GotFirstResponseByte: func() { + if it.GotFirstResponseByte != nil { + it.GotFirstResponseByte(time.Since(start).Seconds()) + } + }, + Got100Continue: func() { + if it.Got100Continue != nil { + it.Got100Continue(time.Since(start).Seconds()) + } + }, + TLSHandshakeStart: func() { + if it.TLSHandshakeStart != nil { + it.TLSHandshakeStart(time.Since(start).Seconds()) + } + }, + TLSHandshakeDone: func(_ tls.ConnectionState, err error) { + if err != nil { + return + } + if it.TLSHandshakeDone != nil { + it.TLSHandshakeDone(time.Since(start).Seconds()) + } + }, + WroteHeaders: func() { + if it.WroteHeaders != nil { + it.WroteHeaders(time.Since(start).Seconds()) + } + }, + Wait100Continue: func() { + if it.Wait100Continue != nil { + it.Wait100Continue(time.Since(start).Seconds()) + } + }, + WroteRequest: func(_ httptrace.WroteRequestInfo) { + if it.WroteRequest != nil { + it.WroteRequest(time.Since(start).Seconds()) + } + }, + } + r = r.WithContext(httptrace.WithClientTrace(context.Background(), trace)) + + return next.RoundTrip(r) + }) +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go new file mode 100644 index 000000000..9db243805 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go @@ -0,0 +1,447 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package promhttp + +import ( + "errors" + "net/http" + "strconv" + "strings" + "time" + + dto "github.com/prometheus/client_model/go" + + "github.com/prometheus/client_golang/prometheus" +) + +// magicString is used for the hacky label test in checkLabels. Remove once fixed. +const magicString = "zZgWfBxLqvG8kc8IMv3POi2Bb0tZI3vAnBx+gBaFi9FyPzB/CzKUer1yufDa" + +// InstrumentHandlerInFlight is a middleware that wraps the provided +// http.Handler. It sets the provided prometheus.Gauge to the number of +// requests currently handled by the wrapped http.Handler. +// +// See the example for InstrumentHandlerDuration for example usage. +func InstrumentHandlerInFlight(g prometheus.Gauge, next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + g.Inc() + defer g.Dec() + next.ServeHTTP(w, r) + }) +} + +// InstrumentHandlerDuration is a middleware that wraps the provided +// http.Handler to observe the request duration with the provided ObserverVec. +// The ObserverVec must have zero, one, or two non-const non-curried labels. For +// those, the only allowed label names are "code" and "method". The function +// panics otherwise. The Observe method of the Observer in the ObserverVec is +// called with the request duration in seconds. Partitioning happens by HTTP +// status code and/or HTTP method if the respective instance label names are +// present in the ObserverVec. For unpartitioned observations, use an +// ObserverVec with zero labels. Note that partitioning of Histograms is +// expensive and should be used judiciously. +// +// If the wrapped Handler does not set a status code, a status code of 200 is assumed. +// +// If the wrapped Handler panics, no values are reported. +// +// Note that this method is only guaranteed to never observe negative durations +// if used with Go1.9+. +func InstrumentHandlerDuration(obs prometheus.ObserverVec, next http.Handler) http.HandlerFunc { + code, method := checkLabels(obs) + + if code { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + now := time.Now() + d := newDelegator(w, nil) + next.ServeHTTP(d, r) + + obs.With(labels(code, method, r.Method, d.Status())).Observe(time.Since(now).Seconds()) + }) + } + + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + now := time.Now() + next.ServeHTTP(w, r) + obs.With(labels(code, method, r.Method, 0)).Observe(time.Since(now).Seconds()) + }) +} + +// InstrumentHandlerCounter is a middleware that wraps the provided http.Handler +// to observe the request result with the provided CounterVec. The CounterVec +// must have zero, one, or two non-const non-curried labels. For those, the only +// allowed label names are "code" and "method". The function panics +// otherwise. Partitioning of the CounterVec happens by HTTP status code and/or +// HTTP method if the respective instance label names are present in the +// CounterVec. For unpartitioned counting, use a CounterVec with zero labels. +// +// If the wrapped Handler does not set a status code, a status code of 200 is assumed. +// +// If the wrapped Handler panics, the Counter is not incremented. +// +// See the example for InstrumentHandlerDuration for example usage. +func InstrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler) http.HandlerFunc { + code, method := checkLabels(counter) + + if code { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + d := newDelegator(w, nil) + next.ServeHTTP(d, r) + counter.With(labels(code, method, r.Method, d.Status())).Inc() + }) + } + + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + next.ServeHTTP(w, r) + counter.With(labels(code, method, r.Method, 0)).Inc() + }) +} + +// InstrumentHandlerTimeToWriteHeader is a middleware that wraps the provided +// http.Handler to observe with the provided ObserverVec the request duration +// until the response headers are written. The ObserverVec must have zero, one, +// or two non-const non-curried labels. For those, the only allowed label names +// are "code" and "method". The function panics otherwise. The Observe method of +// the Observer in the ObserverVec is called with the request duration in +// seconds. Partitioning happens by HTTP status code and/or HTTP method if the +// respective instance label names are present in the ObserverVec. For +// unpartitioned observations, use an ObserverVec with zero labels. Note that +// partitioning of Histograms is expensive and should be used judiciously. +// +// If the wrapped Handler panics before calling WriteHeader, no value is +// reported. +// +// Note that this method is only guaranteed to never observe negative durations +// if used with Go1.9+. +// +// See the example for InstrumentHandlerDuration for example usage. +func InstrumentHandlerTimeToWriteHeader(obs prometheus.ObserverVec, next http.Handler) http.HandlerFunc { + code, method := checkLabels(obs) + + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + now := time.Now() + d := newDelegator(w, func(status int) { + obs.With(labels(code, method, r.Method, status)).Observe(time.Since(now).Seconds()) + }) + next.ServeHTTP(d, r) + }) +} + +// InstrumentHandlerRequestSize is a middleware that wraps the provided +// http.Handler to observe the request size with the provided ObserverVec. The +// ObserverVec must have zero, one, or two non-const non-curried labels. For +// those, the only allowed label names are "code" and "method". The function +// panics otherwise. The Observe method of the Observer in the ObserverVec is +// called with the request size in bytes. Partitioning happens by HTTP status +// code and/or HTTP method if the respective instance label names are present in +// the ObserverVec. For unpartitioned observations, use an ObserverVec with zero +// labels. Note that partitioning of Histograms is expensive and should be used +// judiciously. +// +// If the wrapped Handler does not set a status code, a status code of 200 is assumed. +// +// If the wrapped Handler panics, no values are reported. +// +// See the example for InstrumentHandlerDuration for example usage. +func InstrumentHandlerRequestSize(obs prometheus.ObserverVec, next http.Handler) http.HandlerFunc { + code, method := checkLabels(obs) + + if code { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + d := newDelegator(w, nil) + next.ServeHTTP(d, r) + size := computeApproximateRequestSize(r) + obs.With(labels(code, method, r.Method, d.Status())).Observe(float64(size)) + }) + } + + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + next.ServeHTTP(w, r) + size := computeApproximateRequestSize(r) + obs.With(labels(code, method, r.Method, 0)).Observe(float64(size)) + }) +} + +// InstrumentHandlerResponseSize is a middleware that wraps the provided +// http.Handler to observe the response size with the provided ObserverVec. The +// ObserverVec must have zero, one, or two non-const non-curried labels. For +// those, the only allowed label names are "code" and "method". The function +// panics otherwise. The Observe method of the Observer in the ObserverVec is +// called with the response size in bytes. Partitioning happens by HTTP status +// code and/or HTTP method if the respective instance label names are present in +// the ObserverVec. For unpartitioned observations, use an ObserverVec with zero +// labels. Note that partitioning of Histograms is expensive and should be used +// judiciously. +// +// If the wrapped Handler does not set a status code, a status code of 200 is assumed. +// +// If the wrapped Handler panics, no values are reported. +// +// See the example for InstrumentHandlerDuration for example usage. +func InstrumentHandlerResponseSize(obs prometheus.ObserverVec, next http.Handler) http.Handler { + code, method := checkLabels(obs) + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + d := newDelegator(w, nil) + next.ServeHTTP(d, r) + obs.With(labels(code, method, r.Method, d.Status())).Observe(float64(d.Written())) + }) +} + +func checkLabels(c prometheus.Collector) (code bool, method bool) { + // TODO(beorn7): Remove this hacky way to check for instance labels + // once Descriptors can have their dimensionality queried. + var ( + desc *prometheus.Desc + m prometheus.Metric + pm dto.Metric + lvs []string + ) + + // Get the Desc from the Collector. + descc := make(chan *prometheus.Desc, 1) + c.Describe(descc) + + select { + case desc = <-descc: + default: + panic("no description provided by collector") + } + select { + case <-descc: + panic("more than one description provided by collector") + default: + } + + close(descc) + + // Create a ConstMetric with the Desc. Since we don't know how many + // variable labels there are, try for as long as it needs. + for err := errors.New("dummy"); err != nil; lvs = append(lvs, magicString) { + m, err = prometheus.NewConstMetric(desc, prometheus.UntypedValue, 0, lvs...) + } + + // Write out the metric into a proto message and look at the labels. + // If the value is not the magicString, it is a constLabel, which doesn't interest us. + // If the label is curried, it doesn't interest us. + // In all other cases, only "code" or "method" is allowed. + if err := m.Write(&pm); err != nil { + panic("error checking metric for labels") + } + for _, label := range pm.Label { + name, value := label.GetName(), label.GetValue() + if value != magicString || isLabelCurried(c, name) { + continue + } + switch name { + case "code": + code = true + case "method": + method = true + default: + panic("metric partitioned with non-supported labels") + } + } + return +} + +func isLabelCurried(c prometheus.Collector, label string) bool { + // This is even hackier than the label test above. + // We essentially try to curry again and see if it works. + // But for that, we need to type-convert to the two + // types we use here, ObserverVec or *CounterVec. + switch v := c.(type) { + case *prometheus.CounterVec: + if _, err := v.CurryWith(prometheus.Labels{label: "dummy"}); err == nil { + return false + } + case prometheus.ObserverVec: + if _, err := v.CurryWith(prometheus.Labels{label: "dummy"}); err == nil { + return false + } + default: + panic("unsupported metric vec type") + } + return true +} + +// emptyLabels is a one-time allocation for non-partitioned metrics to avoid +// unnecessary allocations on each request. +var emptyLabels = prometheus.Labels{} + +func labels(code, method bool, reqMethod string, status int) prometheus.Labels { + if !(code || method) { + return emptyLabels + } + labels := prometheus.Labels{} + + if code { + labels["code"] = sanitizeCode(status) + } + if method { + labels["method"] = sanitizeMethod(reqMethod) + } + + return labels +} + +func computeApproximateRequestSize(r *http.Request) int { + s := 0 + if r.URL != nil { + s += len(r.URL.String()) + } + + s += len(r.Method) + s += len(r.Proto) + for name, values := range r.Header { + s += len(name) + for _, value := range values { + s += len(value) + } + } + s += len(r.Host) + + // N.B. r.Form and r.MultipartForm are assumed to be included in r.URL. + + if r.ContentLength != -1 { + s += int(r.ContentLength) + } + return s +} + +func sanitizeMethod(m string) string { + switch m { + case "GET", "get": + return "get" + case "PUT", "put": + return "put" + case "HEAD", "head": + return "head" + case "POST", "post": + return "post" + case "DELETE", "delete": + return "delete" + case "CONNECT", "connect": + return "connect" + case "OPTIONS", "options": + return "options" + case "NOTIFY", "notify": + return "notify" + default: + return strings.ToLower(m) + } +} + +// If the wrapped http.Handler has not set a status code, i.e. the value is +// currently 0, santizeCode will return 200, for consistency with behavior in +// the stdlib. +func sanitizeCode(s int) string { + switch s { + case 100: + return "100" + case 101: + return "101" + + case 200, 0: + return "200" + case 201: + return "201" + case 202: + return "202" + case 203: + return "203" + case 204: + return "204" + case 205: + return "205" + case 206: + return "206" + + case 300: + return "300" + case 301: + return "301" + case 302: + return "302" + case 304: + return "304" + case 305: + return "305" + case 307: + return "307" + + case 400: + return "400" + case 401: + return "401" + case 402: + return "402" + case 403: + return "403" + case 404: + return "404" + case 405: + return "405" + case 406: + return "406" + case 407: + return "407" + case 408: + return "408" + case 409: + return "409" + case 410: + return "410" + case 411: + return "411" + case 412: + return "412" + case 413: + return "413" + case 414: + return "414" + case 415: + return "415" + case 416: + return "416" + case 417: + return "417" + case 418: + return "418" + + case 500: + return "500" + case 501: + return "501" + case 502: + return "502" + case 503: + return "503" + case 504: + return "504" + case 505: + return "505" + + case 428: + return "428" + case 429: + return "429" + case 431: + return "431" + case 511: + return "511" + + default: + return strconv.Itoa(s) + } +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/push/push.go b/vendor/github.com/prometheus/client_golang/prometheus/push/push.go new file mode 100644 index 000000000..8fb6f5f17 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/push/push.go @@ -0,0 +1,172 @@ +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Copyright (c) 2013, The Prometheus Authors +// All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found +// in the LICENSE file. + +// Package push provides functions to push metrics to a Pushgateway. The metrics +// to push are either collected from a provided registry, or from explicitly +// listed collectors. +// +// See the documentation of the Pushgateway to understand the meaning of the +// grouping parameters and the differences between push.Registry and +// push.Collectors on the one hand and push.AddRegistry and push.AddCollectors +// on the other hand: https://github.com/prometheus/pushgateway +package push + +import ( + "bytes" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "os" + "strings" + + "github.com/prometheus/common/expfmt" + "github.com/prometheus/common/model" + + "github.com/prometheus/client_golang/prometheus" +) + +const contentTypeHeader = "Content-Type" + +// FromGatherer triggers a metric collection by the provided Gatherer (which is +// usually implemented by a prometheus.Registry) and pushes all gathered metrics +// to the Pushgateway specified by url, using the provided job name and the +// (optional) further grouping labels (the grouping map may be nil). See the +// Pushgateway documentation for detailed implications of the job and other +// grouping labels. Neither the job name nor any grouping label value may +// contain a "/". The metrics pushed must not contain a job label of their own +// nor any of the grouping labels. +// +// You can use just host:port or ip:port as url, in which case 'http://' is +// added automatically. You can also include the schema in the URL. However, do +// not include the '/metrics/jobs/...' part. +// +// Note that all previously pushed metrics with the same job and other grouping +// labels will be replaced with the metrics pushed by this call. (It uses HTTP +// method 'PUT' to push to the Pushgateway.) +func FromGatherer(job string, grouping map[string]string, url string, g prometheus.Gatherer) error { + return push(job, grouping, url, g, "PUT") +} + +// AddFromGatherer works like FromGatherer, but only previously pushed metrics +// with the same name (and the same job and other grouping labels) will be +// replaced. (It uses HTTP method 'POST' to push to the Pushgateway.) +func AddFromGatherer(job string, grouping map[string]string, url string, g prometheus.Gatherer) error { + return push(job, grouping, url, g, "POST") +} + +func push(job string, grouping map[string]string, pushURL string, g prometheus.Gatherer, method string) error { + if !strings.Contains(pushURL, "://") { + pushURL = "http://" + pushURL + } + if strings.HasSuffix(pushURL, "/") { + pushURL = pushURL[:len(pushURL)-1] + } + + if strings.Contains(job, "/") { + return fmt.Errorf("job contains '/': %s", job) + } + urlComponents := []string{url.QueryEscape(job)} + for ln, lv := range grouping { + if !model.LabelName(ln).IsValid() { + return fmt.Errorf("grouping label has invalid name: %s", ln) + } + if strings.Contains(lv, "/") { + return fmt.Errorf("value of grouping label %s contains '/': %s", ln, lv) + } + urlComponents = append(urlComponents, ln, lv) + } + pushURL = fmt.Sprintf("%s/metrics/job/%s", pushURL, strings.Join(urlComponents, "/")) + + mfs, err := g.Gather() + if err != nil { + return err + } + buf := &bytes.Buffer{} + enc := expfmt.NewEncoder(buf, expfmt.FmtProtoDelim) + // Check for pre-existing grouping labels: + for _, mf := range mfs { + for _, m := range mf.GetMetric() { + for _, l := range m.GetLabel() { + if l.GetName() == "job" { + return fmt.Errorf("pushed metric %s (%s) already contains a job label", mf.GetName(), m) + } + if _, ok := grouping[l.GetName()]; ok { + return fmt.Errorf( + "pushed metric %s (%s) already contains grouping label %s", + mf.GetName(), m, l.GetName(), + ) + } + } + } + enc.Encode(mf) + } + req, err := http.NewRequest(method, pushURL, buf) + if err != nil { + return err + } + req.Header.Set(contentTypeHeader, string(expfmt.FmtProtoDelim)) + resp, err := http.DefaultClient.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + if resp.StatusCode != 202 { + body, _ := ioutil.ReadAll(resp.Body) // Ignore any further error as this is for an error message only. + return fmt.Errorf("unexpected status code %d while pushing to %s: %s", resp.StatusCode, pushURL, body) + } + return nil +} + +// Collectors works like FromGatherer, but it does not use a Gatherer. Instead, +// it collects from the provided collectors directly. It is a convenient way to +// push only a few metrics. +func Collectors(job string, grouping map[string]string, url string, collectors ...prometheus.Collector) error { + return pushCollectors(job, grouping, url, "PUT", collectors...) +} + +// AddCollectors works like AddFromGatherer, but it does not use a Gatherer. +// Instead, it collects from the provided collectors directly. It is a +// convenient way to push only a few metrics. +func AddCollectors(job string, grouping map[string]string, url string, collectors ...prometheus.Collector) error { + return pushCollectors(job, grouping, url, "POST", collectors...) +} + +func pushCollectors(job string, grouping map[string]string, url, method string, collectors ...prometheus.Collector) error { + r := prometheus.NewRegistry() + for _, collector := range collectors { + if err := r.Register(collector); err != nil { + return err + } + } + return push(job, grouping, url, r, method) +} + +// HostnameGroupingKey returns a label map with the only entry +// {instance=""}. This can be conveniently used as the grouping +// parameter if metrics should be pushed with the hostname as label. The +// returned map is created upon each call so that the caller is free to add more +// labels to the map. +func HostnameGroupingKey() map[string]string { + hostname, err := os.Hostname() + if err != nil { + return map[string]string{"instance": "unknown"} + } + return map[string]string{"instance": hostname} +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/registry.go b/vendor/github.com/prometheus/client_golang/prometheus/registry.go new file mode 100644 index 000000000..c84a4420e --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/registry.go @@ -0,0 +1,762 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "bytes" + "errors" + "fmt" + "os" + "sort" + "sync" + "unicode/utf8" + + "github.com/golang/protobuf/proto" + + dto "github.com/prometheus/client_model/go" +) + +const ( + // Capacity for the channel to collect metrics and descriptors. + capMetricChan = 1000 + capDescChan = 10 +) + +// DefaultRegisterer and DefaultGatherer are the implementations of the +// Registerer and Gatherer interface a number of convenience functions in this +// package act on. Initially, both variables point to the same Registry, which +// has a process collector (see NewProcessCollector) and a Go collector (see +// NewGoCollector) already registered. This approach to keep default instances +// as global state mirrors the approach of other packages in the Go standard +// library. Note that there are caveats. Change the variables with caution and +// only if you understand the consequences. Users who want to avoid global state +// altogether should not use the convenience function and act on custom +// instances instead. +var ( + defaultRegistry = NewRegistry() + DefaultRegisterer Registerer = defaultRegistry + DefaultGatherer Gatherer = defaultRegistry +) + +func init() { + MustRegister(NewProcessCollector(os.Getpid(), "")) + MustRegister(NewGoCollector()) +} + +// NewRegistry creates a new vanilla Registry without any Collectors +// pre-registered. +func NewRegistry() *Registry { + return &Registry{ + collectorsByID: map[uint64]Collector{}, + descIDs: map[uint64]struct{}{}, + dimHashesByName: map[string]uint64{}, + } +} + +// NewPedanticRegistry returns a registry that checks during collection if each +// collected Metric is consistent with its reported Desc, and if the Desc has +// actually been registered with the registry. +// +// Usually, a Registry will be happy as long as the union of all collected +// Metrics is consistent and valid even if some metrics are not consistent with +// their own Desc or a Desc provided by their registered Collector. Well-behaved +// Collectors and Metrics will only provide consistent Descs. This Registry is +// useful to test the implementation of Collectors and Metrics. +func NewPedanticRegistry() *Registry { + r := NewRegistry() + r.pedanticChecksEnabled = true + return r +} + +// Registerer is the interface for the part of a registry in charge of +// registering and unregistering. Users of custom registries should use +// Registerer as type for registration purposes (rather than the Registry type +// directly). In that way, they are free to use custom Registerer implementation +// (e.g. for testing purposes). +type Registerer interface { + // Register registers a new Collector to be included in metrics + // collection. It returns an error if the descriptors provided by the + // Collector are invalid or if they — in combination with descriptors of + // already registered Collectors — do not fulfill the consistency and + // uniqueness criteria described in the documentation of metric.Desc. + // + // If the provided Collector is equal to a Collector already registered + // (which includes the case of re-registering the same Collector), the + // returned error is an instance of AlreadyRegisteredError, which + // contains the previously registered Collector. + // + // It is in general not safe to register the same Collector multiple + // times concurrently. + Register(Collector) error + // MustRegister works like Register but registers any number of + // Collectors and panics upon the first registration that causes an + // error. + MustRegister(...Collector) + // Unregister unregisters the Collector that equals the Collector passed + // in as an argument. (Two Collectors are considered equal if their + // Describe method yields the same set of descriptors.) The function + // returns whether a Collector was unregistered. + // + // Note that even after unregistering, it will not be possible to + // register a new Collector that is inconsistent with the unregistered + // Collector, e.g. a Collector collecting metrics with the same name but + // a different help string. The rationale here is that the same registry + // instance must only collect consistent metrics throughout its + // lifetime. + Unregister(Collector) bool +} + +// Gatherer is the interface for the part of a registry in charge of gathering +// the collected metrics into a number of MetricFamilies. The Gatherer interface +// comes with the same general implication as described for the Registerer +// interface. +type Gatherer interface { + // Gather calls the Collect method of the registered Collectors and then + // gathers the collected metrics into a lexicographically sorted slice + // of MetricFamily protobufs. Even if an error occurs, Gather attempts + // to gather as many metrics as possible. Hence, if a non-nil error is + // returned, the returned MetricFamily slice could be nil (in case of a + // fatal error that prevented any meaningful metric collection) or + // contain a number of MetricFamily protobufs, some of which might be + // incomplete, and some might be missing altogether. The returned error + // (which might be a MultiError) explains the details. In scenarios + // where complete collection is critical, the returned MetricFamily + // protobufs should be disregarded if the returned error is non-nil. + Gather() ([]*dto.MetricFamily, error) +} + +// Register registers the provided Collector with the DefaultRegisterer. +// +// Register is a shortcut for DefaultRegisterer.Register(c). See there for more +// details. +func Register(c Collector) error { + return DefaultRegisterer.Register(c) +} + +// MustRegister registers the provided Collectors with the DefaultRegisterer and +// panics if any error occurs. +// +// MustRegister is a shortcut for DefaultRegisterer.MustRegister(cs...). See +// there for more details. +func MustRegister(cs ...Collector) { + DefaultRegisterer.MustRegister(cs...) +} + +// Unregister removes the registration of the provided Collector from the +// DefaultRegisterer. +// +// Unregister is a shortcut for DefaultRegisterer.Unregister(c). See there for +// more details. +func Unregister(c Collector) bool { + return DefaultRegisterer.Unregister(c) +} + +// GathererFunc turns a function into a Gatherer. +type GathererFunc func() ([]*dto.MetricFamily, error) + +// Gather implements Gatherer. +func (gf GathererFunc) Gather() ([]*dto.MetricFamily, error) { + return gf() +} + +// AlreadyRegisteredError is returned by the Register method if the Collector to +// be registered has already been registered before, or a different Collector +// that collects the same metrics has been registered before. Registration fails +// in that case, but you can detect from the kind of error what has +// happened. The error contains fields for the existing Collector and the +// (rejected) new Collector that equals the existing one. This can be used to +// find out if an equal Collector has been registered before and switch over to +// using the old one, as demonstrated in the example. +type AlreadyRegisteredError struct { + ExistingCollector, NewCollector Collector +} + +func (err AlreadyRegisteredError) Error() string { + return "duplicate metrics collector registration attempted" +} + +// MultiError is a slice of errors implementing the error interface. It is used +// by a Gatherer to report multiple errors during MetricFamily gathering. +type MultiError []error + +func (errs MultiError) Error() string { + if len(errs) == 0 { + return "" + } + buf := &bytes.Buffer{} + fmt.Fprintf(buf, "%d error(s) occurred:", len(errs)) + for _, err := range errs { + fmt.Fprintf(buf, "\n* %s", err) + } + return buf.String() +} + +// MaybeUnwrap returns nil if len(errs) is 0. It returns the first and only +// contained error as error if len(errs is 1). In all other cases, it returns +// the MultiError directly. This is helpful for returning a MultiError in a way +// that only uses the MultiError if needed. +func (errs MultiError) MaybeUnwrap() error { + switch len(errs) { + case 0: + return nil + case 1: + return errs[0] + default: + return errs + } +} + +// Registry registers Prometheus collectors, collects their metrics, and gathers +// them into MetricFamilies for exposition. It implements both Registerer and +// Gatherer. The zero value is not usable. Create instances with NewRegistry or +// NewPedanticRegistry. +type Registry struct { + mtx sync.RWMutex + collectorsByID map[uint64]Collector // ID is a hash of the descIDs. + descIDs map[uint64]struct{} + dimHashesByName map[string]uint64 + pedanticChecksEnabled bool +} + +// Register implements Registerer. +func (r *Registry) Register(c Collector) error { + var ( + descChan = make(chan *Desc, capDescChan) + newDescIDs = map[uint64]struct{}{} + newDimHashesByName = map[string]uint64{} + collectorID uint64 // Just a sum of all desc IDs. + duplicateDescErr error + ) + go func() { + c.Describe(descChan) + close(descChan) + }() + r.mtx.Lock() + defer r.mtx.Unlock() + // Conduct various tests... + for desc := range descChan { + + // Is the descriptor valid at all? + if desc.err != nil { + return fmt.Errorf("descriptor %s is invalid: %s", desc, desc.err) + } + + // Is the descID unique? + // (In other words: Is the fqName + constLabel combination unique?) + if _, exists := r.descIDs[desc.id]; exists { + duplicateDescErr = fmt.Errorf("descriptor %s already exists with the same fully-qualified name and const label values", desc) + } + // If it is not a duplicate desc in this collector, add it to + // the collectorID. (We allow duplicate descs within the same + // collector, but their existence must be a no-op.) + if _, exists := newDescIDs[desc.id]; !exists { + newDescIDs[desc.id] = struct{}{} + collectorID += desc.id + } + + // Are all the label names and the help string consistent with + // previous descriptors of the same name? + // First check existing descriptors... + if dimHash, exists := r.dimHashesByName[desc.fqName]; exists { + if dimHash != desc.dimHash { + return fmt.Errorf("a previously registered descriptor with the same fully-qualified name as %s has different label names or a different help string", desc) + } + } else { + // ...then check the new descriptors already seen. + if dimHash, exists := newDimHashesByName[desc.fqName]; exists { + if dimHash != desc.dimHash { + return fmt.Errorf("descriptors reported by collector have inconsistent label names or help strings for the same fully-qualified name, offender is %s", desc) + } + } else { + newDimHashesByName[desc.fqName] = desc.dimHash + } + } + } + // Did anything happen at all? + if len(newDescIDs) == 0 { + return errors.New("collector has no descriptors") + } + if existing, exists := r.collectorsByID[collectorID]; exists { + return AlreadyRegisteredError{ + ExistingCollector: existing, + NewCollector: c, + } + } + // If the collectorID is new, but at least one of the descs existed + // before, we are in trouble. + if duplicateDescErr != nil { + return duplicateDescErr + } + + // Only after all tests have passed, actually register. + r.collectorsByID[collectorID] = c + for hash := range newDescIDs { + r.descIDs[hash] = struct{}{} + } + for name, dimHash := range newDimHashesByName { + r.dimHashesByName[name] = dimHash + } + return nil +} + +// Unregister implements Registerer. +func (r *Registry) Unregister(c Collector) bool { + var ( + descChan = make(chan *Desc, capDescChan) + descIDs = map[uint64]struct{}{} + collectorID uint64 // Just a sum of the desc IDs. + ) + go func() { + c.Describe(descChan) + close(descChan) + }() + for desc := range descChan { + if _, exists := descIDs[desc.id]; !exists { + collectorID += desc.id + descIDs[desc.id] = struct{}{} + } + } + + r.mtx.RLock() + if _, exists := r.collectorsByID[collectorID]; !exists { + r.mtx.RUnlock() + return false + } + r.mtx.RUnlock() + + r.mtx.Lock() + defer r.mtx.Unlock() + + delete(r.collectorsByID, collectorID) + for id := range descIDs { + delete(r.descIDs, id) + } + // dimHashesByName is left untouched as those must be consistent + // throughout the lifetime of a program. + return true +} + +// MustRegister implements Registerer. +func (r *Registry) MustRegister(cs ...Collector) { + for _, c := range cs { + if err := r.Register(c); err != nil { + panic(err) + } + } +} + +// Gather implements Gatherer. +func (r *Registry) Gather() ([]*dto.MetricFamily, error) { + var ( + metricChan = make(chan Metric, capMetricChan) + metricHashes = map[uint64]struct{}{} + dimHashes = map[string]uint64{} + wg sync.WaitGroup + errs MultiError // The collected errors to return in the end. + registeredDescIDs map[uint64]struct{} // Only used for pedantic checks + ) + + r.mtx.RLock() + metricFamiliesByName := make(map[string]*dto.MetricFamily, len(r.dimHashesByName)) + + // Scatter. + // (Collectors could be complex and slow, so we call them all at once.) + wg.Add(len(r.collectorsByID)) + go func() { + wg.Wait() + close(metricChan) + }() + for _, collector := range r.collectorsByID { + go func(collector Collector) { + defer wg.Done() + collector.Collect(metricChan) + }(collector) + } + + // In case pedantic checks are enabled, we have to copy the map before + // giving up the RLock. + if r.pedanticChecksEnabled { + registeredDescIDs = make(map[uint64]struct{}, len(r.descIDs)) + for id := range r.descIDs { + registeredDescIDs[id] = struct{}{} + } + } + + r.mtx.RUnlock() + + // Drain metricChan in case of premature return. + defer func() { + for range metricChan { + } + }() + + // Gather. + for metric := range metricChan { + // This could be done concurrently, too, but it required locking + // of metricFamiliesByName (and of metricHashes if checks are + // enabled). Most likely not worth it. + desc := metric.Desc() + dtoMetric := &dto.Metric{} + if err := metric.Write(dtoMetric); err != nil { + errs = append(errs, fmt.Errorf( + "error collecting metric %v: %s", desc, err, + )) + continue + } + metricFamily, ok := metricFamiliesByName[desc.fqName] + if ok { + if metricFamily.GetHelp() != desc.help { + errs = append(errs, fmt.Errorf( + "collected metric %s %s has help %q but should have %q", + desc.fqName, dtoMetric, desc.help, metricFamily.GetHelp(), + )) + continue + } + // TODO(beorn7): Simplify switch once Desc has type. + switch metricFamily.GetType() { + case dto.MetricType_COUNTER: + if dtoMetric.Counter == nil { + errs = append(errs, fmt.Errorf( + "collected metric %s %s should be a Counter", + desc.fqName, dtoMetric, + )) + continue + } + case dto.MetricType_GAUGE: + if dtoMetric.Gauge == nil { + errs = append(errs, fmt.Errorf( + "collected metric %s %s should be a Gauge", + desc.fqName, dtoMetric, + )) + continue + } + case dto.MetricType_SUMMARY: + if dtoMetric.Summary == nil { + errs = append(errs, fmt.Errorf( + "collected metric %s %s should be a Summary", + desc.fqName, dtoMetric, + )) + continue + } + case dto.MetricType_UNTYPED: + if dtoMetric.Untyped == nil { + errs = append(errs, fmt.Errorf( + "collected metric %s %s should be Untyped", + desc.fqName, dtoMetric, + )) + continue + } + case dto.MetricType_HISTOGRAM: + if dtoMetric.Histogram == nil { + errs = append(errs, fmt.Errorf( + "collected metric %s %s should be a Histogram", + desc.fqName, dtoMetric, + )) + continue + } + default: + panic("encountered MetricFamily with invalid type") + } + } else { + metricFamily = &dto.MetricFamily{} + metricFamily.Name = proto.String(desc.fqName) + metricFamily.Help = proto.String(desc.help) + // TODO(beorn7): Simplify switch once Desc has type. + switch { + case dtoMetric.Gauge != nil: + metricFamily.Type = dto.MetricType_GAUGE.Enum() + case dtoMetric.Counter != nil: + metricFamily.Type = dto.MetricType_COUNTER.Enum() + case dtoMetric.Summary != nil: + metricFamily.Type = dto.MetricType_SUMMARY.Enum() + case dtoMetric.Untyped != nil: + metricFamily.Type = dto.MetricType_UNTYPED.Enum() + case dtoMetric.Histogram != nil: + metricFamily.Type = dto.MetricType_HISTOGRAM.Enum() + default: + errs = append(errs, fmt.Errorf( + "empty metric collected: %s", dtoMetric, + )) + continue + } + metricFamiliesByName[desc.fqName] = metricFamily + } + if err := checkMetricConsistency(metricFamily, dtoMetric, metricHashes, dimHashes); err != nil { + errs = append(errs, err) + continue + } + if r.pedanticChecksEnabled { + // Is the desc registered at all? + if _, exist := registeredDescIDs[desc.id]; !exist { + errs = append(errs, fmt.Errorf( + "collected metric %s %s with unregistered descriptor %s", + metricFamily.GetName(), dtoMetric, desc, + )) + continue + } + if err := checkDescConsistency(metricFamily, dtoMetric, desc); err != nil { + errs = append(errs, err) + continue + } + } + metricFamily.Metric = append(metricFamily.Metric, dtoMetric) + } + return normalizeMetricFamilies(metricFamiliesByName), errs.MaybeUnwrap() +} + +// Gatherers is a slice of Gatherer instances that implements the Gatherer +// interface itself. Its Gather method calls Gather on all Gatherers in the +// slice in order and returns the merged results. Errors returned from the +// Gather calles are all returned in a flattened MultiError. Duplicate and +// inconsistent Metrics are skipped (first occurrence in slice order wins) and +// reported in the returned error. +// +// Gatherers can be used to merge the Gather results from multiple +// Registries. It also provides a way to directly inject existing MetricFamily +// protobufs into the gathering by creating a custom Gatherer with a Gather +// method that simply returns the existing MetricFamily protobufs. Note that no +// registration is involved (in contrast to Collector registration), so +// obviously registration-time checks cannot happen. Any inconsistencies between +// the gathered MetricFamilies are reported as errors by the Gather method, and +// inconsistent Metrics are dropped. Invalid parts of the MetricFamilies +// (e.g. syntactically invalid metric or label names) will go undetected. +type Gatherers []Gatherer + +// Gather implements Gatherer. +func (gs Gatherers) Gather() ([]*dto.MetricFamily, error) { + var ( + metricFamiliesByName = map[string]*dto.MetricFamily{} + metricHashes = map[uint64]struct{}{} + dimHashes = map[string]uint64{} + errs MultiError // The collected errors to return in the end. + ) + + for i, g := range gs { + mfs, err := g.Gather() + if err != nil { + if multiErr, ok := err.(MultiError); ok { + for _, err := range multiErr { + errs = append(errs, fmt.Errorf("[from Gatherer #%d] %s", i+1, err)) + } + } else { + errs = append(errs, fmt.Errorf("[from Gatherer #%d] %s", i+1, err)) + } + } + for _, mf := range mfs { + existingMF, exists := metricFamiliesByName[mf.GetName()] + if exists { + if existingMF.GetHelp() != mf.GetHelp() { + errs = append(errs, fmt.Errorf( + "gathered metric family %s has help %q but should have %q", + mf.GetName(), mf.GetHelp(), existingMF.GetHelp(), + )) + continue + } + if existingMF.GetType() != mf.GetType() { + errs = append(errs, fmt.Errorf( + "gathered metric family %s has type %s but should have %s", + mf.GetName(), mf.GetType(), existingMF.GetType(), + )) + continue + } + } else { + existingMF = &dto.MetricFamily{} + existingMF.Name = mf.Name + existingMF.Help = mf.Help + existingMF.Type = mf.Type + metricFamiliesByName[mf.GetName()] = existingMF + } + for _, m := range mf.Metric { + if err := checkMetricConsistency(existingMF, m, metricHashes, dimHashes); err != nil { + errs = append(errs, err) + continue + } + existingMF.Metric = append(existingMF.Metric, m) + } + } + } + return normalizeMetricFamilies(metricFamiliesByName), errs.MaybeUnwrap() +} + +// metricSorter is a sortable slice of *dto.Metric. +type metricSorter []*dto.Metric + +func (s metricSorter) Len() int { + return len(s) +} + +func (s metricSorter) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +func (s metricSorter) Less(i, j int) bool { + if len(s[i].Label) != len(s[j].Label) { + // This should not happen. The metrics are + // inconsistent. However, we have to deal with the fact, as + // people might use custom collectors or metric family injection + // to create inconsistent metrics. So let's simply compare the + // number of labels in this case. That will still yield + // reproducible sorting. + return len(s[i].Label) < len(s[j].Label) + } + for n, lp := range s[i].Label { + vi := lp.GetValue() + vj := s[j].Label[n].GetValue() + if vi != vj { + return vi < vj + } + } + + // We should never arrive here. Multiple metrics with the same + // label set in the same scrape will lead to undefined ingestion + // behavior. However, as above, we have to provide stable sorting + // here, even for inconsistent metrics. So sort equal metrics + // by their timestamp, with missing timestamps (implying "now") + // coming last. + if s[i].TimestampMs == nil { + return false + } + if s[j].TimestampMs == nil { + return true + } + return s[i].GetTimestampMs() < s[j].GetTimestampMs() +} + +// normalizeMetricFamilies returns a MetricFamily slice with empty +// MetricFamilies pruned and the remaining MetricFamilies sorted by name within +// the slice, with the contained Metrics sorted within each MetricFamily. +func normalizeMetricFamilies(metricFamiliesByName map[string]*dto.MetricFamily) []*dto.MetricFamily { + for _, mf := range metricFamiliesByName { + sort.Sort(metricSorter(mf.Metric)) + } + names := make([]string, 0, len(metricFamiliesByName)) + for name, mf := range metricFamiliesByName { + if len(mf.Metric) > 0 { + names = append(names, name) + } + } + sort.Strings(names) + result := make([]*dto.MetricFamily, 0, len(names)) + for _, name := range names { + result = append(result, metricFamiliesByName[name]) + } + return result +} + +// checkMetricConsistency checks if the provided Metric is consistent with the +// provided MetricFamily. It also hashed the Metric labels and the MetricFamily +// name. If the resulting hash is already in the provided metricHashes, an error +// is returned. If not, it is added to metricHashes. The provided dimHashes maps +// MetricFamily names to their dimHash (hashed sorted label names). If dimHashes +// doesn't yet contain a hash for the provided MetricFamily, it is +// added. Otherwise, an error is returned if the existing dimHashes in not equal +// the calculated dimHash. +func checkMetricConsistency( + metricFamily *dto.MetricFamily, + dtoMetric *dto.Metric, + metricHashes map[uint64]struct{}, + dimHashes map[string]uint64, +) error { + // Type consistency with metric family. + if metricFamily.GetType() == dto.MetricType_GAUGE && dtoMetric.Gauge == nil || + metricFamily.GetType() == dto.MetricType_COUNTER && dtoMetric.Counter == nil || + metricFamily.GetType() == dto.MetricType_SUMMARY && dtoMetric.Summary == nil || + metricFamily.GetType() == dto.MetricType_HISTOGRAM && dtoMetric.Histogram == nil || + metricFamily.GetType() == dto.MetricType_UNTYPED && dtoMetric.Untyped == nil { + return fmt.Errorf( + "collected metric %s %s is not a %s", + metricFamily.GetName(), dtoMetric, metricFamily.GetType(), + ) + } + + for _, labelPair := range dtoMetric.GetLabel() { + if !utf8.ValidString(*labelPair.Value) { + return fmt.Errorf("collected metric's label %s is not utf8: %#v", *labelPair.Name, *labelPair.Value) + } + } + + // Is the metric unique (i.e. no other metric with the same name and the same label values)? + h := hashNew() + h = hashAdd(h, metricFamily.GetName()) + h = hashAddByte(h, separatorByte) + dh := hashNew() + // Make sure label pairs are sorted. We depend on it for the consistency + // check. + sort.Sort(LabelPairSorter(dtoMetric.Label)) + for _, lp := range dtoMetric.Label { + h = hashAdd(h, lp.GetValue()) + h = hashAddByte(h, separatorByte) + dh = hashAdd(dh, lp.GetName()) + dh = hashAddByte(dh, separatorByte) + } + if _, exists := metricHashes[h]; exists { + return fmt.Errorf( + "collected metric %s %s was collected before with the same name and label values", + metricFamily.GetName(), dtoMetric, + ) + } + if dimHash, ok := dimHashes[metricFamily.GetName()]; ok { + if dimHash != dh { + return fmt.Errorf( + "collected metric %s %s has label dimensions inconsistent with previously collected metrics in the same metric family", + metricFamily.GetName(), dtoMetric, + ) + } + } else { + dimHashes[metricFamily.GetName()] = dh + } + metricHashes[h] = struct{}{} + return nil +} + +func checkDescConsistency( + metricFamily *dto.MetricFamily, + dtoMetric *dto.Metric, + desc *Desc, +) error { + // Desc help consistency with metric family help. + if metricFamily.GetHelp() != desc.help { + return fmt.Errorf( + "collected metric %s %s has help %q but should have %q", + metricFamily.GetName(), dtoMetric, metricFamily.GetHelp(), desc.help, + ) + } + + // Is the desc consistent with the content of the metric? + lpsFromDesc := make([]*dto.LabelPair, 0, len(dtoMetric.Label)) + lpsFromDesc = append(lpsFromDesc, desc.constLabelPairs...) + for _, l := range desc.variableLabels { + lpsFromDesc = append(lpsFromDesc, &dto.LabelPair{ + Name: proto.String(l), + }) + } + if len(lpsFromDesc) != len(dtoMetric.Label) { + return fmt.Errorf( + "labels in collected metric %s %s are inconsistent with descriptor %s", + metricFamily.GetName(), dtoMetric, desc, + ) + } + sort.Sort(LabelPairSorter(lpsFromDesc)) + for i, lpFromDesc := range lpsFromDesc { + lpFromMetric := dtoMetric.Label[i] + if lpFromDesc.GetName() != lpFromMetric.GetName() || + lpFromDesc.Value != nil && lpFromDesc.GetValue() != lpFromMetric.GetValue() { + return fmt.Errorf( + "labels in collected metric %s %s are inconsistent with descriptor %s", + metricFamily.GetName(), dtoMetric, desc, + ) + } + } + return nil +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/summary.go b/vendor/github.com/prometheus/client_golang/prometheus/summary.go new file mode 100644 index 000000000..f7dc85b96 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/summary.go @@ -0,0 +1,609 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "fmt" + "math" + "sort" + "sync" + "time" + + "github.com/beorn7/perks/quantile" + "github.com/golang/protobuf/proto" + + dto "github.com/prometheus/client_model/go" +) + +// quantileLabel is used for the label that defines the quantile in a +// summary. +const quantileLabel = "quantile" + +// A Summary captures individual observations from an event or sample stream and +// summarizes them in a manner similar to traditional summary statistics: 1. sum +// of observations, 2. observation count, 3. rank estimations. +// +// A typical use-case is the observation of request latencies. By default, a +// Summary provides the median, the 90th and the 99th percentile of the latency +// as rank estimations. However, the default behavior will change in the +// upcoming v0.10 of the library. There will be no rank estiamtions at all by +// default. For a sane transition, it is recommended to set the desired rank +// estimations explicitly. +// +// Note that the rank estimations cannot be aggregated in a meaningful way with +// the Prometheus query language (i.e. you cannot average or add them). If you +// need aggregatable quantiles (e.g. you want the 99th percentile latency of all +// queries served across all instances of a service), consider the Histogram +// metric type. See the Prometheus documentation for more details. +// +// To create Summary instances, use NewSummary. +type Summary interface { + Metric + Collector + + // Observe adds a single observation to the summary. + Observe(float64) +} + +// DefObjectives are the default Summary quantile values. +// +// Deprecated: DefObjectives will not be used as the default objectives in +// v0.10 of the library. The default Summary will have no quantiles then. +var ( + DefObjectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001} + + errQuantileLabelNotAllowed = fmt.Errorf( + "%q is not allowed as label name in summaries", quantileLabel, + ) +) + +// Default values for SummaryOpts. +const ( + // DefMaxAge is the default duration for which observations stay + // relevant. + DefMaxAge time.Duration = 10 * time.Minute + // DefAgeBuckets is the default number of buckets used to calculate the + // age of observations. + DefAgeBuckets = 5 + // DefBufCap is the standard buffer size for collecting Summary observations. + DefBufCap = 500 +) + +// SummaryOpts bundles the options for creating a Summary metric. It is +// mandatory to set Name and Help to a non-empty string. While all other fields +// are optional and can safely be left at their zero value, it is recommended to +// explicitly set the Objectives field to the desired value as the default value +// will change in the upcoming v0.10 of the library. +type SummaryOpts struct { + // Namespace, Subsystem, and Name are components of the fully-qualified + // name of the Summary (created by joining these components with + // "_"). Only Name is mandatory, the others merely help structuring the + // name. Note that the fully-qualified name of the Summary must be a + // valid Prometheus metric name. + Namespace string + Subsystem string + Name string + + // Help provides information about this Summary. Mandatory! + // + // Metrics with the same fully-qualified name must have the same Help + // string. + Help string + + // ConstLabels are used to attach fixed labels to this metric. Metrics + // with the same fully-qualified name must have the same label names in + // their ConstLabels. + // + // ConstLabels are only used rarely. In particular, do not use them to + // attach the same labels to all your metrics. Those use cases are + // better covered by target labels set by the scraping Prometheus + // server, or by one specific metric (e.g. a build_info or a + // machine_role metric). See also + // https://prometheus.io/docs/instrumenting/writing_exporters/#target-labels,-not-static-scraped-labels + ConstLabels Labels + + // Objectives defines the quantile rank estimates with their respective + // absolute error. If Objectives[q] = e, then the value reported for q + // will be the φ-quantile value for some φ between q-e and q+e. The + // default value is DefObjectives. It is used if Objectives is left at + // its zero value (i.e. nil). To create a Summary without Objectives, + // set it to an empty map (i.e. map[float64]float64{}). + // + // Deprecated: Note that the current value of DefObjectives is + // deprecated. It will be replaced by an empty map in v0.10 of the + // library. Please explicitly set Objectives to the desired value. + Objectives map[float64]float64 + + // MaxAge defines the duration for which an observation stays relevant + // for the summary. Must be positive. The default value is DefMaxAge. + MaxAge time.Duration + + // AgeBuckets is the number of buckets used to exclude observations that + // are older than MaxAge from the summary. A higher number has a + // resource penalty, so only increase it if the higher resolution is + // really required. For very high observation rates, you might want to + // reduce the number of age buckets. With only one age bucket, you will + // effectively see a complete reset of the summary each time MaxAge has + // passed. The default value is DefAgeBuckets. + AgeBuckets uint32 + + // BufCap defines the default sample stream buffer size. The default + // value of DefBufCap should suffice for most uses. If there is a need + // to increase the value, a multiple of 500 is recommended (because that + // is the internal buffer size of the underlying package + // "github.com/bmizerany/perks/quantile"). + BufCap uint32 +} + +// Great fuck-up with the sliding-window decay algorithm... The Merge method of +// perk/quantile is actually not working as advertised - and it might be +// unfixable, as the underlying algorithm is apparently not capable of merging +// summaries in the first place. To avoid using Merge, we are currently adding +// observations to _each_ age bucket, i.e. the effort to add a sample is +// essentially multiplied by the number of age buckets. When rotating age +// buckets, we empty the previous head stream. On scrape time, we simply take +// the quantiles from the head stream (no merging required). Result: More effort +// on observation time, less effort on scrape time, which is exactly the +// opposite of what we try to accomplish, but at least the results are correct. +// +// The quite elegant previous contraption to merge the age buckets efficiently +// on scrape time (see code up commit 6b9530d72ea715f0ba612c0120e6e09fbf1d49d0) +// can't be used anymore. + +// NewSummary creates a new Summary based on the provided SummaryOpts. +func NewSummary(opts SummaryOpts) Summary { + return newSummary( + NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + nil, + opts.ConstLabels, + ), + opts, + ) +} + +func newSummary(desc *Desc, opts SummaryOpts, labelValues ...string) Summary { + if len(desc.variableLabels) != len(labelValues) { + panic(errInconsistentCardinality) + } + + for _, n := range desc.variableLabels { + if n == quantileLabel { + panic(errQuantileLabelNotAllowed) + } + } + for _, lp := range desc.constLabelPairs { + if lp.GetName() == quantileLabel { + panic(errQuantileLabelNotAllowed) + } + } + + if opts.Objectives == nil { + opts.Objectives = DefObjectives + } + + if opts.MaxAge < 0 { + panic(fmt.Errorf("illegal max age MaxAge=%v", opts.MaxAge)) + } + if opts.MaxAge == 0 { + opts.MaxAge = DefMaxAge + } + + if opts.AgeBuckets == 0 { + opts.AgeBuckets = DefAgeBuckets + } + + if opts.BufCap == 0 { + opts.BufCap = DefBufCap + } + + s := &summary{ + desc: desc, + + objectives: opts.Objectives, + sortedObjectives: make([]float64, 0, len(opts.Objectives)), + + labelPairs: makeLabelPairs(desc, labelValues), + + hotBuf: make([]float64, 0, opts.BufCap), + coldBuf: make([]float64, 0, opts.BufCap), + streamDuration: opts.MaxAge / time.Duration(opts.AgeBuckets), + } + s.headStreamExpTime = time.Now().Add(s.streamDuration) + s.hotBufExpTime = s.headStreamExpTime + + for i := uint32(0); i < opts.AgeBuckets; i++ { + s.streams = append(s.streams, s.newStream()) + } + s.headStream = s.streams[0] + + for qu := range s.objectives { + s.sortedObjectives = append(s.sortedObjectives, qu) + } + sort.Float64s(s.sortedObjectives) + + s.init(s) // Init self-collection. + return s +} + +type summary struct { + selfCollector + + bufMtx sync.Mutex // Protects hotBuf and hotBufExpTime. + mtx sync.Mutex // Protects every other moving part. + // Lock bufMtx before mtx if both are needed. + + desc *Desc + + objectives map[float64]float64 + sortedObjectives []float64 + + labelPairs []*dto.LabelPair + + sum float64 + cnt uint64 + + hotBuf, coldBuf []float64 + + streams []*quantile.Stream + streamDuration time.Duration + headStream *quantile.Stream + headStreamIdx int + headStreamExpTime, hotBufExpTime time.Time +} + +func (s *summary) Desc() *Desc { + return s.desc +} + +func (s *summary) Observe(v float64) { + s.bufMtx.Lock() + defer s.bufMtx.Unlock() + + now := time.Now() + if now.After(s.hotBufExpTime) { + s.asyncFlush(now) + } + s.hotBuf = append(s.hotBuf, v) + if len(s.hotBuf) == cap(s.hotBuf) { + s.asyncFlush(now) + } +} + +func (s *summary) Write(out *dto.Metric) error { + sum := &dto.Summary{} + qs := make([]*dto.Quantile, 0, len(s.objectives)) + + s.bufMtx.Lock() + s.mtx.Lock() + // Swap bufs even if hotBuf is empty to set new hotBufExpTime. + s.swapBufs(time.Now()) + s.bufMtx.Unlock() + + s.flushColdBuf() + sum.SampleCount = proto.Uint64(s.cnt) + sum.SampleSum = proto.Float64(s.sum) + + for _, rank := range s.sortedObjectives { + var q float64 + if s.headStream.Count() == 0 { + q = math.NaN() + } else { + q = s.headStream.Query(rank) + } + qs = append(qs, &dto.Quantile{ + Quantile: proto.Float64(rank), + Value: proto.Float64(q), + }) + } + + s.mtx.Unlock() + + if len(qs) > 0 { + sort.Sort(quantSort(qs)) + } + sum.Quantile = qs + + out.Summary = sum + out.Label = s.labelPairs + return nil +} + +func (s *summary) newStream() *quantile.Stream { + return quantile.NewTargeted(s.objectives) +} + +// asyncFlush needs bufMtx locked. +func (s *summary) asyncFlush(now time.Time) { + s.mtx.Lock() + s.swapBufs(now) + + // Unblock the original goroutine that was responsible for the mutation + // that triggered the compaction. But hold onto the global non-buffer + // state mutex until the operation finishes. + go func() { + s.flushColdBuf() + s.mtx.Unlock() + }() +} + +// rotateStreams needs mtx AND bufMtx locked. +func (s *summary) maybeRotateStreams() { + for !s.hotBufExpTime.Equal(s.headStreamExpTime) { + s.headStream.Reset() + s.headStreamIdx++ + if s.headStreamIdx >= len(s.streams) { + s.headStreamIdx = 0 + } + s.headStream = s.streams[s.headStreamIdx] + s.headStreamExpTime = s.headStreamExpTime.Add(s.streamDuration) + } +} + +// flushColdBuf needs mtx locked. +func (s *summary) flushColdBuf() { + for _, v := range s.coldBuf { + for _, stream := range s.streams { + stream.Insert(v) + } + s.cnt++ + s.sum += v + } + s.coldBuf = s.coldBuf[0:0] + s.maybeRotateStreams() +} + +// swapBufs needs mtx AND bufMtx locked, coldBuf must be empty. +func (s *summary) swapBufs(now time.Time) { + if len(s.coldBuf) != 0 { + panic("coldBuf is not empty") + } + s.hotBuf, s.coldBuf = s.coldBuf, s.hotBuf + // hotBuf is now empty and gets new expiration set. + for now.After(s.hotBufExpTime) { + s.hotBufExpTime = s.hotBufExpTime.Add(s.streamDuration) + } +} + +type quantSort []*dto.Quantile + +func (s quantSort) Len() int { + return len(s) +} + +func (s quantSort) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +func (s quantSort) Less(i, j int) bool { + return s[i].GetQuantile() < s[j].GetQuantile() +} + +// SummaryVec is a Collector that bundles a set of Summaries that all share the +// same Desc, but have different values for their variable labels. This is used +// if you want to count the same thing partitioned by various dimensions +// (e.g. HTTP request latencies, partitioned by status code and method). Create +// instances with NewSummaryVec. +type SummaryVec struct { + *metricVec +} + +// NewSummaryVec creates a new SummaryVec based on the provided SummaryOpts and +// partitioned by the given label names. +func NewSummaryVec(opts SummaryOpts, labelNames []string) *SummaryVec { + desc := NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + labelNames, + opts.ConstLabels, + ) + return &SummaryVec{ + metricVec: newMetricVec(desc, func(lvs ...string) Metric { + return newSummary(desc, opts, lvs...) + }), + } +} + +// GetMetricWithLabelValues returns the Summary for the given slice of label +// values (same order as the VariableLabels in Desc). If that combination of +// label values is accessed for the first time, a new Summary is created. +// +// It is possible to call this method without using the returned Summary to only +// create the new Summary but leave it at its starting value, a Summary without +// any observations. +// +// Keeping the Summary for later use is possible (and should be considered if +// performance is critical), but keep in mind that Reset, DeleteLabelValues and +// Delete can be used to delete the Summary from the SummaryVec. In that case, +// the Summary will still exist, but it will not be exported anymore, even if a +// Summary with the same label values is created later. See also the CounterVec +// example. +// +// An error is returned if the number of label values is not the same as the +// number of VariableLabels in Desc (minus any curried labels). +// +// Note that for more than one label value, this method is prone to mistakes +// caused by an incorrect order of arguments. Consider GetMetricWith(Labels) as +// an alternative to avoid that type of mistake. For higher label numbers, the +// latter has a much more readable (albeit more verbose) syntax, but it comes +// with a performance overhead (for creating and processing the Labels map). +// See also the GaugeVec example. +func (v *SummaryVec) GetMetricWithLabelValues(lvs ...string) (Observer, error) { + metric, err := v.metricVec.getMetricWithLabelValues(lvs...) + if metric != nil { + return metric.(Observer), err + } + return nil, err +} + +// GetMetricWith returns the Summary for the given Labels map (the label names +// must match those of the VariableLabels in Desc). If that label map is +// accessed for the first time, a new Summary is created. Implications of +// creating a Summary without using it and keeping the Summary for later use are +// the same as for GetMetricWithLabelValues. +// +// An error is returned if the number and names of the Labels are inconsistent +// with those of the VariableLabels in Desc (minus any curried labels). +// +// This method is used for the same purpose as +// GetMetricWithLabelValues(...string). See there for pros and cons of the two +// methods. +func (v *SummaryVec) GetMetricWith(labels Labels) (Observer, error) { + metric, err := v.metricVec.getMetricWith(labels) + if metric != nil { + return metric.(Observer), err + } + return nil, err +} + +// WithLabelValues works as GetMetricWithLabelValues, but panics where +// GetMetricWithLabelValues would have returned an error. Not returning an +// error allows shortcuts like +// myVec.WithLabelValues("404", "GET").Observe(42.21) +func (v *SummaryVec) WithLabelValues(lvs ...string) Observer { + s, err := v.GetMetricWithLabelValues(lvs...) + if err != nil { + panic(err) + } + return s +} + +// With works as GetMetricWith, but panics where GetMetricWithLabels would have +// returned an error. Not returning an error allows shortcuts like +// myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Observe(42.21) +func (v *SummaryVec) With(labels Labels) Observer { + s, err := v.GetMetricWith(labels) + if err != nil { + panic(err) + } + return s +} + +// CurryWith returns a vector curried with the provided labels, i.e. the +// returned vector has those labels pre-set for all labeled operations performed +// on it. The cardinality of the curried vector is reduced accordingly. The +// order of the remaining labels stays the same (just with the curried labels +// taken out of the sequence – which is relevant for the +// (GetMetric)WithLabelValues methods). It is possible to curry a curried +// vector, but only with labels not yet used for currying before. +// +// The metrics contained in the SummaryVec are shared between the curried and +// uncurried vectors. They are just accessed differently. Curried and uncurried +// vectors behave identically in terms of collection. Only one must be +// registered with a given registry (usually the uncurried version). The Reset +// method deletes all metrics, even if called on a curried vector. +func (v *SummaryVec) CurryWith(labels Labels) (ObserverVec, error) { + vec, err := v.curryWith(labels) + if vec != nil { + return &SummaryVec{vec}, err + } + return nil, err +} + +// MustCurryWith works as CurryWith but panics where CurryWith would have +// returned an error. +func (v *SummaryVec) MustCurryWith(labels Labels) ObserverVec { + vec, err := v.CurryWith(labels) + if err != nil { + panic(err) + } + return vec +} + +type constSummary struct { + desc *Desc + count uint64 + sum float64 + quantiles map[float64]float64 + labelPairs []*dto.LabelPair +} + +func (s *constSummary) Desc() *Desc { + return s.desc +} + +func (s *constSummary) Write(out *dto.Metric) error { + sum := &dto.Summary{} + qs := make([]*dto.Quantile, 0, len(s.quantiles)) + + sum.SampleCount = proto.Uint64(s.count) + sum.SampleSum = proto.Float64(s.sum) + + for rank, q := range s.quantiles { + qs = append(qs, &dto.Quantile{ + Quantile: proto.Float64(rank), + Value: proto.Float64(q), + }) + } + + if len(qs) > 0 { + sort.Sort(quantSort(qs)) + } + sum.Quantile = qs + + out.Summary = sum + out.Label = s.labelPairs + + return nil +} + +// NewConstSummary returns a metric representing a Prometheus summary with fixed +// values for the count, sum, and quantiles. As those parameters cannot be +// changed, the returned value does not implement the Summary interface (but +// only the Metric interface). Users of this package will not have much use for +// it in regular operations. However, when implementing custom Collectors, it is +// useful as a throw-away metric that is generated on the fly to send it to +// Prometheus in the Collect method. +// +// quantiles maps ranks to quantile values. For example, a median latency of +// 0.23s and a 99th percentile latency of 0.56s would be expressed as: +// map[float64]float64{0.5: 0.23, 0.99: 0.56} +// +// NewConstSummary returns an error if the length of labelValues is not +// consistent with the variable labels in Desc. +func NewConstSummary( + desc *Desc, + count uint64, + sum float64, + quantiles map[float64]float64, + labelValues ...string, +) (Metric, error) { + if err := validateLabelValues(labelValues, len(desc.variableLabels)); err != nil { + return nil, err + } + return &constSummary{ + desc: desc, + count: count, + sum: sum, + quantiles: quantiles, + labelPairs: makeLabelPairs(desc, labelValues), + }, nil +} + +// MustNewConstSummary is a version of NewConstSummary that panics where +// NewConstMetric would have returned an error. +func MustNewConstSummary( + desc *Desc, + count uint64, + sum float64, + quantiles map[float64]float64, + labelValues ...string, +) Metric { + m, err := NewConstSummary(desc, count, sum, quantiles, labelValues...) + if err != nil { + panic(err) + } + return m +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/timer.go b/vendor/github.com/prometheus/client_golang/prometheus/timer.go new file mode 100644 index 000000000..b8fc5f18c --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/timer.go @@ -0,0 +1,51 @@ +// Copyright 2016 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import "time" + +// Timer is a helper type to time functions. Use NewTimer to create new +// instances. +type Timer struct { + begin time.Time + observer Observer +} + +// NewTimer creates a new Timer. The provided Observer is used to observe a +// duration in seconds. Timer is usually used to time a function call in the +// following way: +// func TimeMe() { +// timer := NewTimer(myHistogram) +// defer timer.ObserveDuration() +// // Do actual work. +// } +func NewTimer(o Observer) *Timer { + return &Timer{ + begin: time.Now(), + observer: o, + } +} + +// ObserveDuration records the duration passed since the Timer was created with +// NewTimer. It calls the Observe method of the Observer provided during +// construction with the duration in seconds as an argument. ObserveDuration is +// usually called with a defer statement. +// +// Note that this method is only guaranteed to never observe negative durations +// if used with Go1.9+. +func (t *Timer) ObserveDuration() { + if t.observer != nil { + t.observer.Observe(time.Since(t.begin).Seconds()) + } +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/untyped.go b/vendor/github.com/prometheus/client_golang/prometheus/untyped.go new file mode 100644 index 000000000..0f9ce63f4 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/untyped.go @@ -0,0 +1,42 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +// UntypedOpts is an alias for Opts. See there for doc comments. +type UntypedOpts Opts + +// UntypedFunc works like GaugeFunc but the collected metric is of type +// "Untyped". UntypedFunc is useful to mirror an external metric of unknown +// type. +// +// To create UntypedFunc instances, use NewUntypedFunc. +type UntypedFunc interface { + Metric + Collector +} + +// NewUntypedFunc creates a new UntypedFunc based on the provided +// UntypedOpts. The value reported is determined by calling the given function +// from within the Write method. Take into account that metric collection may +// happen concurrently. If that results in concurrent calls to Write, like in +// the case where an UntypedFunc is directly registered with Prometheus, the +// provided function must be concurrency-safe. +func NewUntypedFunc(opts UntypedOpts, function func() float64) UntypedFunc { + return newValueFunc(NewDesc( + BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), + opts.Help, + nil, + opts.ConstLabels, + ), UntypedValue, function) +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/value.go b/vendor/github.com/prometheus/client_golang/prometheus/value.go new file mode 100644 index 000000000..4a9cca666 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/value.go @@ -0,0 +1,236 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "fmt" + "math" + "sort" + "sync/atomic" + "time" + + dto "github.com/prometheus/client_model/go" + + "github.com/golang/protobuf/proto" +) + +// ValueType is an enumeration of metric types that represent a simple value. +type ValueType int + +// Possible values for the ValueType enum. +const ( + _ ValueType = iota + CounterValue + GaugeValue + UntypedValue +) + +// value is a generic metric for simple values. It implements Metric, Collector, +// Counter, Gauge, and Untyped. Its effective type is determined by +// ValueType. This is a low-level building block used by the library to back the +// implementations of Counter, Gauge, and Untyped. +type value struct { + // valBits contains the bits of the represented float64 value. It has + // to go first in the struct to guarantee alignment for atomic + // operations. http://golang.org/pkg/sync/atomic/#pkg-note-BUG + valBits uint64 + + selfCollector + + desc *Desc + valType ValueType + labelPairs []*dto.LabelPair +} + +// newValue returns a newly allocated value with the given Desc, ValueType, +// sample value and label values. It panics if the number of label +// values is different from the number of variable labels in Desc. +func newValue(desc *Desc, valueType ValueType, val float64, labelValues ...string) *value { + if len(labelValues) != len(desc.variableLabels) { + panic(errInconsistentCardinality) + } + result := &value{ + desc: desc, + valType: valueType, + valBits: math.Float64bits(val), + labelPairs: makeLabelPairs(desc, labelValues), + } + result.init(result) + return result +} + +func (v *value) Desc() *Desc { + return v.desc +} + +func (v *value) Set(val float64) { + atomic.StoreUint64(&v.valBits, math.Float64bits(val)) +} + +func (v *value) SetToCurrentTime() { + v.Set(float64(time.Now().UnixNano()) / 1e9) +} + +func (v *value) Inc() { + v.Add(1) +} + +func (v *value) Dec() { + v.Add(-1) +} + +func (v *value) Add(val float64) { + for { + oldBits := atomic.LoadUint64(&v.valBits) + newBits := math.Float64bits(math.Float64frombits(oldBits) + val) + if atomic.CompareAndSwapUint64(&v.valBits, oldBits, newBits) { + return + } + } +} + +func (v *value) Sub(val float64) { + v.Add(val * -1) +} + +func (v *value) Write(out *dto.Metric) error { + val := math.Float64frombits(atomic.LoadUint64(&v.valBits)) + return populateMetric(v.valType, val, v.labelPairs, out) +} + +// valueFunc is a generic metric for simple values retrieved on collect time +// from a function. It implements Metric and Collector. Its effective type is +// determined by ValueType. This is a low-level building block used by the +// library to back the implementations of CounterFunc, GaugeFunc, and +// UntypedFunc. +type valueFunc struct { + selfCollector + + desc *Desc + valType ValueType + function func() float64 + labelPairs []*dto.LabelPair +} + +// newValueFunc returns a newly allocated valueFunc with the given Desc and +// ValueType. The value reported is determined by calling the given function +// from within the Write method. Take into account that metric collection may +// happen concurrently. If that results in concurrent calls to Write, like in +// the case where a valueFunc is directly registered with Prometheus, the +// provided function must be concurrency-safe. +func newValueFunc(desc *Desc, valueType ValueType, function func() float64) *valueFunc { + result := &valueFunc{ + desc: desc, + valType: valueType, + function: function, + labelPairs: makeLabelPairs(desc, nil), + } + result.init(result) + return result +} + +func (v *valueFunc) Desc() *Desc { + return v.desc +} + +func (v *valueFunc) Write(out *dto.Metric) error { + return populateMetric(v.valType, v.function(), v.labelPairs, out) +} + +// NewConstMetric returns a metric with one fixed value that cannot be +// changed. Users of this package will not have much use for it in regular +// operations. However, when implementing custom Collectors, it is useful as a +// throw-away metric that is generated on the fly to send it to Prometheus in +// the Collect method. NewConstMetric returns an error if the length of +// labelValues is not consistent with the variable labels in Desc. +func NewConstMetric(desc *Desc, valueType ValueType, value float64, labelValues ...string) (Metric, error) { + if err := validateLabelValues(labelValues, len(desc.variableLabels)); err != nil { + return nil, err + } + return &constMetric{ + desc: desc, + valType: valueType, + val: value, + labelPairs: makeLabelPairs(desc, labelValues), + }, nil +} + +// MustNewConstMetric is a version of NewConstMetric that panics where +// NewConstMetric would have returned an error. +func MustNewConstMetric(desc *Desc, valueType ValueType, value float64, labelValues ...string) Metric { + m, err := NewConstMetric(desc, valueType, value, labelValues...) + if err != nil { + panic(err) + } + return m +} + +type constMetric struct { + desc *Desc + valType ValueType + val float64 + labelPairs []*dto.LabelPair +} + +func (m *constMetric) Desc() *Desc { + return m.desc +} + +func (m *constMetric) Write(out *dto.Metric) error { + return populateMetric(m.valType, m.val, m.labelPairs, out) +} + +func populateMetric( + t ValueType, + v float64, + labelPairs []*dto.LabelPair, + m *dto.Metric, +) error { + m.Label = labelPairs + switch t { + case CounterValue: + m.Counter = &dto.Counter{Value: proto.Float64(v)} + case GaugeValue: + m.Gauge = &dto.Gauge{Value: proto.Float64(v)} + case UntypedValue: + m.Untyped = &dto.Untyped{Value: proto.Float64(v)} + default: + return fmt.Errorf("encountered unknown type %v", t) + } + return nil +} + +func makeLabelPairs(desc *Desc, labelValues []string) []*dto.LabelPair { + totalLen := len(desc.variableLabels) + len(desc.constLabelPairs) + if totalLen == 0 { + // Super fast path. + return nil + } + if len(desc.variableLabels) == 0 { + // Moderately fast path. + return desc.constLabelPairs + } + labelPairs := make([]*dto.LabelPair, 0, totalLen) + for i, n := range desc.variableLabels { + labelPairs = append(labelPairs, &dto.LabelPair{ + Name: proto.String(n), + Value: proto.String(labelValues[i]), + }) + } + for _, lp := range desc.constLabelPairs { + labelPairs = append(labelPairs, lp) + } + sort.Sort(LabelPairSorter(labelPairs)) + return labelPairs +} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/vec.go b/vendor/github.com/prometheus/client_golang/prometheus/vec.go new file mode 100644 index 000000000..cea158249 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/vec.go @@ -0,0 +1,469 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus + +import ( + "fmt" + "sync" + + "github.com/prometheus/common/model" +) + +// metricVec is a Collector to bundle metrics of the same name that differ in +// their label values. metricVec is not used directly (and therefore +// unexported). It is used as a building block for implementations of vectors of +// a given metric type, like GaugeVec, CounterVec, SummaryVec, and HistogramVec. +// It also handles label currying. It uses basicMetricVec internally. +type metricVec struct { + *metricMap + + curry []curriedLabelValue + + // hashAdd and hashAddByte can be replaced for testing collision handling. + hashAdd func(h uint64, s string) uint64 + hashAddByte func(h uint64, b byte) uint64 +} + +// newMetricVec returns an initialized metricVec. +func newMetricVec(desc *Desc, newMetric func(lvs ...string) Metric) *metricVec { + return &metricVec{ + metricMap: &metricMap{ + metrics: map[uint64][]metricWithLabelValues{}, + desc: desc, + newMetric: newMetric, + }, + hashAdd: hashAdd, + hashAddByte: hashAddByte, + } +} + +// DeleteLabelValues removes the metric where the variable labels are the same +// as those passed in as labels (same order as the VariableLabels in Desc). It +// returns true if a metric was deleted. +// +// It is not an error if the number of label values is not the same as the +// number of VariableLabels in Desc. However, such inconsistent label count can +// never match an actual metric, so the method will always return false in that +// case. +// +// Note that for more than one label value, this method is prone to mistakes +// caused by an incorrect order of arguments. Consider Delete(Labels) as an +// alternative to avoid that type of mistake. For higher label numbers, the +// latter has a much more readable (albeit more verbose) syntax, but it comes +// with a performance overhead (for creating and processing the Labels map). +// See also the CounterVec example. +func (m *metricVec) DeleteLabelValues(lvs ...string) bool { + h, err := m.hashLabelValues(lvs) + if err != nil { + return false + } + + return m.metricMap.deleteByHashWithLabelValues(h, lvs, m.curry) +} + +// Delete deletes the metric where the variable labels are the same as those +// passed in as labels. It returns true if a metric was deleted. +// +// It is not an error if the number and names of the Labels are inconsistent +// with those of the VariableLabels in Desc. However, such inconsistent Labels +// can never match an actual metric, so the method will always return false in +// that case. +// +// This method is used for the same purpose as DeleteLabelValues(...string). See +// there for pros and cons of the two methods. +func (m *metricVec) Delete(labels Labels) bool { + h, err := m.hashLabels(labels) + if err != nil { + return false + } + + return m.metricMap.deleteByHashWithLabels(h, labels, m.curry) +} + +func (m *metricVec) curryWith(labels Labels) (*metricVec, error) { + var ( + newCurry []curriedLabelValue + oldCurry = m.curry + iCurry int + ) + for i, label := range m.desc.variableLabels { + val, ok := labels[label] + if iCurry < len(oldCurry) && oldCurry[iCurry].index == i { + if ok { + return nil, fmt.Errorf("label name %q is already curried", label) + } + newCurry = append(newCurry, oldCurry[iCurry]) + iCurry++ + } else { + if !ok { + continue // Label stays uncurried. + } + newCurry = append(newCurry, curriedLabelValue{i, val}) + } + } + if l := len(oldCurry) + len(labels) - len(newCurry); l > 0 { + return nil, fmt.Errorf("%d unknown label(s) found during currying", l) + } + + return &metricVec{ + metricMap: m.metricMap, + curry: newCurry, + hashAdd: m.hashAdd, + hashAddByte: m.hashAddByte, + }, nil +} + +func (m *metricVec) getMetricWithLabelValues(lvs ...string) (Metric, error) { + h, err := m.hashLabelValues(lvs) + if err != nil { + return nil, err + } + + return m.metricMap.getOrCreateMetricWithLabelValues(h, lvs, m.curry), nil +} + +func (m *metricVec) getMetricWith(labels Labels) (Metric, error) { + h, err := m.hashLabels(labels) + if err != nil { + return nil, err + } + + return m.metricMap.getOrCreateMetricWithLabels(h, labels, m.curry), nil +} + +func (m *metricVec) hashLabelValues(vals []string) (uint64, error) { + if err := validateLabelValues(vals, len(m.desc.variableLabels)-len(m.curry)); err != nil { + return 0, err + } + + var ( + h = hashNew() + curry = m.curry + iVals, iCurry int + ) + for i := 0; i < len(m.desc.variableLabels); i++ { + if iCurry < len(curry) && curry[iCurry].index == i { + h = m.hashAdd(h, curry[iCurry].value) + iCurry++ + } else { + h = m.hashAdd(h, vals[iVals]) + iVals++ + } + h = m.hashAddByte(h, model.SeparatorByte) + } + return h, nil +} + +func (m *metricVec) hashLabels(labels Labels) (uint64, error) { + if err := validateValuesInLabels(labels, len(m.desc.variableLabels)-len(m.curry)); err != nil { + return 0, err + } + + var ( + h = hashNew() + curry = m.curry + iCurry int + ) + for i, label := range m.desc.variableLabels { + val, ok := labels[label] + if iCurry < len(curry) && curry[iCurry].index == i { + if ok { + return 0, fmt.Errorf("label name %q is already curried", label) + } + h = m.hashAdd(h, curry[iCurry].value) + iCurry++ + } else { + if !ok { + return 0, fmt.Errorf("label name %q missing in label map", label) + } + h = m.hashAdd(h, val) + } + h = m.hashAddByte(h, model.SeparatorByte) + } + return h, nil +} + +// metricWithLabelValues provides the metric and its label values for +// disambiguation on hash collision. +type metricWithLabelValues struct { + values []string + metric Metric +} + +// curriedLabelValue sets the curried value for a label at the given index. +type curriedLabelValue struct { + index int + value string +} + +// metricMap is a helper for metricVec and shared between differently curried +// metricVecs. +type metricMap struct { + mtx sync.RWMutex // Protects metrics. + metrics map[uint64][]metricWithLabelValues + desc *Desc + newMetric func(labelValues ...string) Metric +} + +// Describe implements Collector. It will send exactly one Desc to the provided +// channel. +func (m *metricMap) Describe(ch chan<- *Desc) { + ch <- m.desc +} + +// Collect implements Collector. +func (m *metricMap) Collect(ch chan<- Metric) { + m.mtx.RLock() + defer m.mtx.RUnlock() + + for _, metrics := range m.metrics { + for _, metric := range metrics { + ch <- metric.metric + } + } +} + +// Reset deletes all metrics in this vector. +func (m *metricMap) Reset() { + m.mtx.Lock() + defer m.mtx.Unlock() + + for h := range m.metrics { + delete(m.metrics, h) + } +} + +// deleteByHashWithLabelValues removes the metric from the hash bucket h. If +// there are multiple matches in the bucket, use lvs to select a metric and +// remove only that metric. +func (m *metricMap) deleteByHashWithLabelValues( + h uint64, lvs []string, curry []curriedLabelValue, +) bool { + m.mtx.Lock() + defer m.mtx.Unlock() + + metrics, ok := m.metrics[h] + if !ok { + return false + } + + i := findMetricWithLabelValues(metrics, lvs, curry) + if i >= len(metrics) { + return false + } + + if len(metrics) > 1 { + m.metrics[h] = append(metrics[:i], metrics[i+1:]...) + } else { + delete(m.metrics, h) + } + return true +} + +// deleteByHashWithLabels removes the metric from the hash bucket h. If there +// are multiple matches in the bucket, use lvs to select a metric and remove +// only that metric. +func (m *metricMap) deleteByHashWithLabels( + h uint64, labels Labels, curry []curriedLabelValue, +) bool { + metrics, ok := m.metrics[h] + if !ok { + return false + } + i := findMetricWithLabels(m.desc, metrics, labels, curry) + if i >= len(metrics) { + return false + } + + if len(metrics) > 1 { + m.metrics[h] = append(metrics[:i], metrics[i+1:]...) + } else { + delete(m.metrics, h) + } + return true +} + +// getOrCreateMetricWithLabelValues retrieves the metric by hash and label value +// or creates it and returns the new one. +// +// This function holds the mutex. +func (m *metricMap) getOrCreateMetricWithLabelValues( + hash uint64, lvs []string, curry []curriedLabelValue, +) Metric { + m.mtx.RLock() + metric, ok := m.getMetricWithHashAndLabelValues(hash, lvs, curry) + m.mtx.RUnlock() + if ok { + return metric + } + + m.mtx.Lock() + defer m.mtx.Unlock() + metric, ok = m.getMetricWithHashAndLabelValues(hash, lvs, curry) + if !ok { + inlinedLVs := inlineLabelValues(lvs, curry) + metric = m.newMetric(inlinedLVs...) + m.metrics[hash] = append(m.metrics[hash], metricWithLabelValues{values: inlinedLVs, metric: metric}) + } + return metric +} + +// getOrCreateMetricWithLabelValues retrieves the metric by hash and label value +// or creates it and returns the new one. +// +// This function holds the mutex. +func (m *metricMap) getOrCreateMetricWithLabels( + hash uint64, labels Labels, curry []curriedLabelValue, +) Metric { + m.mtx.RLock() + metric, ok := m.getMetricWithHashAndLabels(hash, labels, curry) + m.mtx.RUnlock() + if ok { + return metric + } + + m.mtx.Lock() + defer m.mtx.Unlock() + metric, ok = m.getMetricWithHashAndLabels(hash, labels, curry) + if !ok { + lvs := extractLabelValues(m.desc, labels, curry) + metric = m.newMetric(lvs...) + m.metrics[hash] = append(m.metrics[hash], metricWithLabelValues{values: lvs, metric: metric}) + } + return metric +} + +// getMetricWithHashAndLabelValues gets a metric while handling possible +// collisions in the hash space. Must be called while holding the read mutex. +func (m *metricMap) getMetricWithHashAndLabelValues( + h uint64, lvs []string, curry []curriedLabelValue, +) (Metric, bool) { + metrics, ok := m.metrics[h] + if ok { + if i := findMetricWithLabelValues(metrics, lvs, curry); i < len(metrics) { + return metrics[i].metric, true + } + } + return nil, false +} + +// getMetricWithHashAndLabels gets a metric while handling possible collisions in +// the hash space. Must be called while holding read mutex. +func (m *metricMap) getMetricWithHashAndLabels( + h uint64, labels Labels, curry []curriedLabelValue, +) (Metric, bool) { + metrics, ok := m.metrics[h] + if ok { + if i := findMetricWithLabels(m.desc, metrics, labels, curry); i < len(metrics) { + return metrics[i].metric, true + } + } + return nil, false +} + +// findMetricWithLabelValues returns the index of the matching metric or +// len(metrics) if not found. +func findMetricWithLabelValues( + metrics []metricWithLabelValues, lvs []string, curry []curriedLabelValue, +) int { + for i, metric := range metrics { + if matchLabelValues(metric.values, lvs, curry) { + return i + } + } + return len(metrics) +} + +// findMetricWithLabels returns the index of the matching metric or len(metrics) +// if not found. +func findMetricWithLabels( + desc *Desc, metrics []metricWithLabelValues, labels Labels, curry []curriedLabelValue, +) int { + for i, metric := range metrics { + if matchLabels(desc, metric.values, labels, curry) { + return i + } + } + return len(metrics) +} + +func matchLabelValues(values []string, lvs []string, curry []curriedLabelValue) bool { + if len(values) != len(lvs)+len(curry) { + return false + } + var iLVs, iCurry int + for i, v := range values { + if iCurry < len(curry) && curry[iCurry].index == i { + if v != curry[iCurry].value { + return false + } + iCurry++ + continue + } + if v != lvs[iLVs] { + return false + } + iLVs++ + } + return true +} + +func matchLabels(desc *Desc, values []string, labels Labels, curry []curriedLabelValue) bool { + if len(values) != len(labels)+len(curry) { + return false + } + iCurry := 0 + for i, k := range desc.variableLabels { + if iCurry < len(curry) && curry[iCurry].index == i { + if values[i] != curry[iCurry].value { + return false + } + iCurry++ + continue + } + if values[i] != labels[k] { + return false + } + } + return true +} + +func extractLabelValues(desc *Desc, labels Labels, curry []curriedLabelValue) []string { + labelValues := make([]string, len(labels)+len(curry)) + iCurry := 0 + for i, k := range desc.variableLabels { + if iCurry < len(curry) && curry[iCurry].index == i { + labelValues[i] = curry[iCurry].value + iCurry++ + continue + } + labelValues[i] = labels[k] + } + return labelValues +} + +func inlineLabelValues(lvs []string, curry []curriedLabelValue) []string { + labelValues := make([]string, len(lvs)+len(curry)) + var iCurry, iLVs int + for i := range labelValues { + if iCurry < len(curry) && curry[iCurry].index == i { + labelValues[i] = curry[iCurry].value + iCurry++ + continue + } + labelValues[i] = lvs[iLVs] + iLVs++ + } + return labelValues +} diff --git a/vendor/github.com/prometheus/client_model/go/LICENSE b/vendor/github.com/prometheus/client_model/go/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/vendor/github.com/prometheus/client_model/go/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/prometheus/client_model/go/metrics.pb.go b/vendor/github.com/prometheus/client_model/go/metrics.pb.go new file mode 100644 index 000000000..b065f8683 --- /dev/null +++ b/vendor/github.com/prometheus/client_model/go/metrics.pb.go @@ -0,0 +1,364 @@ +// Code generated by protoc-gen-go. +// source: metrics.proto +// DO NOT EDIT! + +/* +Package io_prometheus_client is a generated protocol buffer package. + +It is generated from these files: + metrics.proto + +It has these top-level messages: + LabelPair + Gauge + Counter + Quantile + Summary + Untyped + Histogram + Bucket + Metric + MetricFamily +*/ +package io_prometheus_client + +import proto "github.com/golang/protobuf/proto" +import math "math" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = math.Inf + +type MetricType int32 + +const ( + MetricType_COUNTER MetricType = 0 + MetricType_GAUGE MetricType = 1 + MetricType_SUMMARY MetricType = 2 + MetricType_UNTYPED MetricType = 3 + MetricType_HISTOGRAM MetricType = 4 +) + +var MetricType_name = map[int32]string{ + 0: "COUNTER", + 1: "GAUGE", + 2: "SUMMARY", + 3: "UNTYPED", + 4: "HISTOGRAM", +} +var MetricType_value = map[string]int32{ + "COUNTER": 0, + "GAUGE": 1, + "SUMMARY": 2, + "UNTYPED": 3, + "HISTOGRAM": 4, +} + +func (x MetricType) Enum() *MetricType { + p := new(MetricType) + *p = x + return p +} +func (x MetricType) String() string { + return proto.EnumName(MetricType_name, int32(x)) +} +func (x *MetricType) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(MetricType_value, data, "MetricType") + if err != nil { + return err + } + *x = MetricType(value) + return nil +} + +type LabelPair struct { + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + Value *string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *LabelPair) Reset() { *m = LabelPair{} } +func (m *LabelPair) String() string { return proto.CompactTextString(m) } +func (*LabelPair) ProtoMessage() {} + +func (m *LabelPair) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +func (m *LabelPair) GetValue() string { + if m != nil && m.Value != nil { + return *m.Value + } + return "" +} + +type Gauge struct { + Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Gauge) Reset() { *m = Gauge{} } +func (m *Gauge) String() string { return proto.CompactTextString(m) } +func (*Gauge) ProtoMessage() {} + +func (m *Gauge) GetValue() float64 { + if m != nil && m.Value != nil { + return *m.Value + } + return 0 +} + +type Counter struct { + Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Counter) Reset() { *m = Counter{} } +func (m *Counter) String() string { return proto.CompactTextString(m) } +func (*Counter) ProtoMessage() {} + +func (m *Counter) GetValue() float64 { + if m != nil && m.Value != nil { + return *m.Value + } + return 0 +} + +type Quantile struct { + Quantile *float64 `protobuf:"fixed64,1,opt,name=quantile" json:"quantile,omitempty"` + Value *float64 `protobuf:"fixed64,2,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Quantile) Reset() { *m = Quantile{} } +func (m *Quantile) String() string { return proto.CompactTextString(m) } +func (*Quantile) ProtoMessage() {} + +func (m *Quantile) GetQuantile() float64 { + if m != nil && m.Quantile != nil { + return *m.Quantile + } + return 0 +} + +func (m *Quantile) GetValue() float64 { + if m != nil && m.Value != nil { + return *m.Value + } + return 0 +} + +type Summary struct { + SampleCount *uint64 `protobuf:"varint,1,opt,name=sample_count" json:"sample_count,omitempty"` + SampleSum *float64 `protobuf:"fixed64,2,opt,name=sample_sum" json:"sample_sum,omitempty"` + Quantile []*Quantile `protobuf:"bytes,3,rep,name=quantile" json:"quantile,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Summary) Reset() { *m = Summary{} } +func (m *Summary) String() string { return proto.CompactTextString(m) } +func (*Summary) ProtoMessage() {} + +func (m *Summary) GetSampleCount() uint64 { + if m != nil && m.SampleCount != nil { + return *m.SampleCount + } + return 0 +} + +func (m *Summary) GetSampleSum() float64 { + if m != nil && m.SampleSum != nil { + return *m.SampleSum + } + return 0 +} + +func (m *Summary) GetQuantile() []*Quantile { + if m != nil { + return m.Quantile + } + return nil +} + +type Untyped struct { + Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Untyped) Reset() { *m = Untyped{} } +func (m *Untyped) String() string { return proto.CompactTextString(m) } +func (*Untyped) ProtoMessage() {} + +func (m *Untyped) GetValue() float64 { + if m != nil && m.Value != nil { + return *m.Value + } + return 0 +} + +type Histogram struct { + SampleCount *uint64 `protobuf:"varint,1,opt,name=sample_count" json:"sample_count,omitempty"` + SampleSum *float64 `protobuf:"fixed64,2,opt,name=sample_sum" json:"sample_sum,omitempty"` + Bucket []*Bucket `protobuf:"bytes,3,rep,name=bucket" json:"bucket,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Histogram) Reset() { *m = Histogram{} } +func (m *Histogram) String() string { return proto.CompactTextString(m) } +func (*Histogram) ProtoMessage() {} + +func (m *Histogram) GetSampleCount() uint64 { + if m != nil && m.SampleCount != nil { + return *m.SampleCount + } + return 0 +} + +func (m *Histogram) GetSampleSum() float64 { + if m != nil && m.SampleSum != nil { + return *m.SampleSum + } + return 0 +} + +func (m *Histogram) GetBucket() []*Bucket { + if m != nil { + return m.Bucket + } + return nil +} + +type Bucket struct { + CumulativeCount *uint64 `protobuf:"varint,1,opt,name=cumulative_count" json:"cumulative_count,omitempty"` + UpperBound *float64 `protobuf:"fixed64,2,opt,name=upper_bound" json:"upper_bound,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Bucket) Reset() { *m = Bucket{} } +func (m *Bucket) String() string { return proto.CompactTextString(m) } +func (*Bucket) ProtoMessage() {} + +func (m *Bucket) GetCumulativeCount() uint64 { + if m != nil && m.CumulativeCount != nil { + return *m.CumulativeCount + } + return 0 +} + +func (m *Bucket) GetUpperBound() float64 { + if m != nil && m.UpperBound != nil { + return *m.UpperBound + } + return 0 +} + +type Metric struct { + Label []*LabelPair `protobuf:"bytes,1,rep,name=label" json:"label,omitempty"` + Gauge *Gauge `protobuf:"bytes,2,opt,name=gauge" json:"gauge,omitempty"` + Counter *Counter `protobuf:"bytes,3,opt,name=counter" json:"counter,omitempty"` + Summary *Summary `protobuf:"bytes,4,opt,name=summary" json:"summary,omitempty"` + Untyped *Untyped `protobuf:"bytes,5,opt,name=untyped" json:"untyped,omitempty"` + Histogram *Histogram `protobuf:"bytes,7,opt,name=histogram" json:"histogram,omitempty"` + TimestampMs *int64 `protobuf:"varint,6,opt,name=timestamp_ms" json:"timestamp_ms,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Metric) Reset() { *m = Metric{} } +func (m *Metric) String() string { return proto.CompactTextString(m) } +func (*Metric) ProtoMessage() {} + +func (m *Metric) GetLabel() []*LabelPair { + if m != nil { + return m.Label + } + return nil +} + +func (m *Metric) GetGauge() *Gauge { + if m != nil { + return m.Gauge + } + return nil +} + +func (m *Metric) GetCounter() *Counter { + if m != nil { + return m.Counter + } + return nil +} + +func (m *Metric) GetSummary() *Summary { + if m != nil { + return m.Summary + } + return nil +} + +func (m *Metric) GetUntyped() *Untyped { + if m != nil { + return m.Untyped + } + return nil +} + +func (m *Metric) GetHistogram() *Histogram { + if m != nil { + return m.Histogram + } + return nil +} + +func (m *Metric) GetTimestampMs() int64 { + if m != nil && m.TimestampMs != nil { + return *m.TimestampMs + } + return 0 +} + +type MetricFamily struct { + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + Help *string `protobuf:"bytes,2,opt,name=help" json:"help,omitempty"` + Type *MetricType `protobuf:"varint,3,opt,name=type,enum=io.prometheus.client.MetricType" json:"type,omitempty"` + Metric []*Metric `protobuf:"bytes,4,rep,name=metric" json:"metric,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *MetricFamily) Reset() { *m = MetricFamily{} } +func (m *MetricFamily) String() string { return proto.CompactTextString(m) } +func (*MetricFamily) ProtoMessage() {} + +func (m *MetricFamily) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + +func (m *MetricFamily) GetHelp() string { + if m != nil && m.Help != nil { + return *m.Help + } + return "" +} + +func (m *MetricFamily) GetType() MetricType { + if m != nil && m.Type != nil { + return *m.Type + } + return MetricType_COUNTER +} + +func (m *MetricFamily) GetMetric() []*Metric { + if m != nil { + return m.Metric + } + return nil +} + +func init() { + proto.RegisterEnum("io.prometheus.client.MetricType", MetricType_name, MetricType_value) +} diff --git a/vendor/github.com/prometheus/common/expfmt/LICENSE b/vendor/github.com/prometheus/common/expfmt/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/vendor/github.com/prometheus/common/expfmt/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/prometheus/common/expfmt/decode.go b/vendor/github.com/prometheus/common/expfmt/decode.go new file mode 100644 index 000000000..a7a42d5ef --- /dev/null +++ b/vendor/github.com/prometheus/common/expfmt/decode.go @@ -0,0 +1,429 @@ +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package expfmt + +import ( + "fmt" + "io" + "math" + "mime" + "net/http" + + dto "github.com/prometheus/client_model/go" + + "github.com/matttproud/golang_protobuf_extensions/pbutil" + "github.com/prometheus/common/model" +) + +// Decoder types decode an input stream into metric families. +type Decoder interface { + Decode(*dto.MetricFamily) error +} + +// DecodeOptions contains options used by the Decoder and in sample extraction. +type DecodeOptions struct { + // Timestamp is added to each value from the stream that has no explicit timestamp set. + Timestamp model.Time +} + +// ResponseFormat extracts the correct format from a HTTP response header. +// If no matching format can be found FormatUnknown is returned. +func ResponseFormat(h http.Header) Format { + ct := h.Get(hdrContentType) + + mediatype, params, err := mime.ParseMediaType(ct) + if err != nil { + return FmtUnknown + } + + const textType = "text/plain" + + switch mediatype { + case ProtoType: + if p, ok := params["proto"]; ok && p != ProtoProtocol { + return FmtUnknown + } + if e, ok := params["encoding"]; ok && e != "delimited" { + return FmtUnknown + } + return FmtProtoDelim + + case textType: + if v, ok := params["version"]; ok && v != TextVersion { + return FmtUnknown + } + return FmtText + } + + return FmtUnknown +} + +// NewDecoder returns a new decoder based on the given input format. +// If the input format does not imply otherwise, a text format decoder is returned. +func NewDecoder(r io.Reader, format Format) Decoder { + switch format { + case FmtProtoDelim: + return &protoDecoder{r: r} + } + return &textDecoder{r: r} +} + +// protoDecoder implements the Decoder interface for protocol buffers. +type protoDecoder struct { + r io.Reader +} + +// Decode implements the Decoder interface. +func (d *protoDecoder) Decode(v *dto.MetricFamily) error { + _, err := pbutil.ReadDelimited(d.r, v) + if err != nil { + return err + } + if !model.IsValidMetricName(model.LabelValue(v.GetName())) { + return fmt.Errorf("invalid metric name %q", v.GetName()) + } + for _, m := range v.GetMetric() { + if m == nil { + continue + } + for _, l := range m.GetLabel() { + if l == nil { + continue + } + if !model.LabelValue(l.GetValue()).IsValid() { + return fmt.Errorf("invalid label value %q", l.GetValue()) + } + if !model.LabelName(l.GetName()).IsValid() { + return fmt.Errorf("invalid label name %q", l.GetName()) + } + } + } + return nil +} + +// textDecoder implements the Decoder interface for the text protocol. +type textDecoder struct { + r io.Reader + p TextParser + fams []*dto.MetricFamily +} + +// Decode implements the Decoder interface. +func (d *textDecoder) Decode(v *dto.MetricFamily) error { + // TODO(fabxc): Wrap this as a line reader to make streaming safer. + if len(d.fams) == 0 { + // No cached metric families, read everything and parse metrics. + fams, err := d.p.TextToMetricFamilies(d.r) + if err != nil { + return err + } + if len(fams) == 0 { + return io.EOF + } + d.fams = make([]*dto.MetricFamily, 0, len(fams)) + for _, f := range fams { + d.fams = append(d.fams, f) + } + } + + *v = *d.fams[0] + d.fams = d.fams[1:] + + return nil +} + +// SampleDecoder wraps a Decoder to extract samples from the metric families +// decoded by the wrapped Decoder. +type SampleDecoder struct { + Dec Decoder + Opts *DecodeOptions + + f dto.MetricFamily +} + +// Decode calls the Decode method of the wrapped Decoder and then extracts the +// samples from the decoded MetricFamily into the provided model.Vector. +func (sd *SampleDecoder) Decode(s *model.Vector) error { + err := sd.Dec.Decode(&sd.f) + if err != nil { + return err + } + *s, err = extractSamples(&sd.f, sd.Opts) + return err +} + +// ExtractSamples builds a slice of samples from the provided metric +// families. If an error occurs during sample extraction, it continues to +// extract from the remaining metric families. The returned error is the last +// error that has occured. +func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) (model.Vector, error) { + var ( + all model.Vector + lastErr error + ) + for _, f := range fams { + some, err := extractSamples(f, o) + if err != nil { + lastErr = err + continue + } + all = append(all, some...) + } + return all, lastErr +} + +func extractSamples(f *dto.MetricFamily, o *DecodeOptions) (model.Vector, error) { + switch f.GetType() { + case dto.MetricType_COUNTER: + return extractCounter(o, f), nil + case dto.MetricType_GAUGE: + return extractGauge(o, f), nil + case dto.MetricType_SUMMARY: + return extractSummary(o, f), nil + case dto.MetricType_UNTYPED: + return extractUntyped(o, f), nil + case dto.MetricType_HISTOGRAM: + return extractHistogram(o, f), nil + } + return nil, fmt.Errorf("expfmt.extractSamples: unknown metric family type %v", f.GetType()) +} + +func extractCounter(o *DecodeOptions, f *dto.MetricFamily) model.Vector { + samples := make(model.Vector, 0, len(f.Metric)) + + for _, m := range f.Metric { + if m.Counter == nil { + continue + } + + lset := make(model.LabelSet, len(m.Label)+1) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + lset[model.MetricNameLabel] = model.LabelValue(f.GetName()) + + smpl := &model.Sample{ + Metric: model.Metric(lset), + Value: model.SampleValue(m.Counter.GetValue()), + } + + if m.TimestampMs != nil { + smpl.Timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000) + } else { + smpl.Timestamp = o.Timestamp + } + + samples = append(samples, smpl) + } + + return samples +} + +func extractGauge(o *DecodeOptions, f *dto.MetricFamily) model.Vector { + samples := make(model.Vector, 0, len(f.Metric)) + + for _, m := range f.Metric { + if m.Gauge == nil { + continue + } + + lset := make(model.LabelSet, len(m.Label)+1) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + lset[model.MetricNameLabel] = model.LabelValue(f.GetName()) + + smpl := &model.Sample{ + Metric: model.Metric(lset), + Value: model.SampleValue(m.Gauge.GetValue()), + } + + if m.TimestampMs != nil { + smpl.Timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000) + } else { + smpl.Timestamp = o.Timestamp + } + + samples = append(samples, smpl) + } + + return samples +} + +func extractUntyped(o *DecodeOptions, f *dto.MetricFamily) model.Vector { + samples := make(model.Vector, 0, len(f.Metric)) + + for _, m := range f.Metric { + if m.Untyped == nil { + continue + } + + lset := make(model.LabelSet, len(m.Label)+1) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + lset[model.MetricNameLabel] = model.LabelValue(f.GetName()) + + smpl := &model.Sample{ + Metric: model.Metric(lset), + Value: model.SampleValue(m.Untyped.GetValue()), + } + + if m.TimestampMs != nil { + smpl.Timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000) + } else { + smpl.Timestamp = o.Timestamp + } + + samples = append(samples, smpl) + } + + return samples +} + +func extractSummary(o *DecodeOptions, f *dto.MetricFamily) model.Vector { + samples := make(model.Vector, 0, len(f.Metric)) + + for _, m := range f.Metric { + if m.Summary == nil { + continue + } + + timestamp := o.Timestamp + if m.TimestampMs != nil { + timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000) + } + + for _, q := range m.Summary.Quantile { + lset := make(model.LabelSet, len(m.Label)+2) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + // BUG(matt): Update other names to "quantile". + lset[model.LabelName(model.QuantileLabel)] = model.LabelValue(fmt.Sprint(q.GetQuantile())) + lset[model.MetricNameLabel] = model.LabelValue(f.GetName()) + + samples = append(samples, &model.Sample{ + Metric: model.Metric(lset), + Value: model.SampleValue(q.GetValue()), + Timestamp: timestamp, + }) + } + + lset := make(model.LabelSet, len(m.Label)+1) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_sum") + + samples = append(samples, &model.Sample{ + Metric: model.Metric(lset), + Value: model.SampleValue(m.Summary.GetSampleSum()), + Timestamp: timestamp, + }) + + lset = make(model.LabelSet, len(m.Label)+1) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_count") + + samples = append(samples, &model.Sample{ + Metric: model.Metric(lset), + Value: model.SampleValue(m.Summary.GetSampleCount()), + Timestamp: timestamp, + }) + } + + return samples +} + +func extractHistogram(o *DecodeOptions, f *dto.MetricFamily) model.Vector { + samples := make(model.Vector, 0, len(f.Metric)) + + for _, m := range f.Metric { + if m.Histogram == nil { + continue + } + + timestamp := o.Timestamp + if m.TimestampMs != nil { + timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000) + } + + infSeen := false + + for _, q := range m.Histogram.Bucket { + lset := make(model.LabelSet, len(m.Label)+2) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + lset[model.LabelName(model.BucketLabel)] = model.LabelValue(fmt.Sprint(q.GetUpperBound())) + lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_bucket") + + if math.IsInf(q.GetUpperBound(), +1) { + infSeen = true + } + + samples = append(samples, &model.Sample{ + Metric: model.Metric(lset), + Value: model.SampleValue(q.GetCumulativeCount()), + Timestamp: timestamp, + }) + } + + lset := make(model.LabelSet, len(m.Label)+1) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_sum") + + samples = append(samples, &model.Sample{ + Metric: model.Metric(lset), + Value: model.SampleValue(m.Histogram.GetSampleSum()), + Timestamp: timestamp, + }) + + lset = make(model.LabelSet, len(m.Label)+1) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_count") + + count := &model.Sample{ + Metric: model.Metric(lset), + Value: model.SampleValue(m.Histogram.GetSampleCount()), + Timestamp: timestamp, + } + samples = append(samples, count) + + if !infSeen { + // Append an infinity bucket sample. + lset := make(model.LabelSet, len(m.Label)+2) + for _, p := range m.Label { + lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + lset[model.LabelName(model.BucketLabel)] = model.LabelValue("+Inf") + lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_bucket") + + samples = append(samples, &model.Sample{ + Metric: model.Metric(lset), + Value: count.Value, + Timestamp: timestamp, + }) + } + } + + return samples +} diff --git a/vendor/github.com/prometheus/common/expfmt/encode.go b/vendor/github.com/prometheus/common/expfmt/encode.go new file mode 100644 index 000000000..11839ed65 --- /dev/null +++ b/vendor/github.com/prometheus/common/expfmt/encode.go @@ -0,0 +1,88 @@ +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package expfmt + +import ( + "fmt" + "io" + "net/http" + + "github.com/golang/protobuf/proto" + "github.com/matttproud/golang_protobuf_extensions/pbutil" + "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg" + + dto "github.com/prometheus/client_model/go" +) + +// Encoder types encode metric families into an underlying wire protocol. +type Encoder interface { + Encode(*dto.MetricFamily) error +} + +type encoder func(*dto.MetricFamily) error + +func (e encoder) Encode(v *dto.MetricFamily) error { + return e(v) +} + +// Negotiate returns the Content-Type based on the given Accept header. +// If no appropriate accepted type is found, FmtText is returned. +func Negotiate(h http.Header) Format { + for _, ac := range goautoneg.ParseAccept(h.Get(hdrAccept)) { + // Check for protocol buffer + if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol { + switch ac.Params["encoding"] { + case "delimited": + return FmtProtoDelim + case "text": + return FmtProtoText + case "compact-text": + return FmtProtoCompact + } + } + // Check for text format. + ver := ac.Params["version"] + if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") { + return FmtText + } + } + return FmtText +} + +// NewEncoder returns a new encoder based on content type negotiation. +func NewEncoder(w io.Writer, format Format) Encoder { + switch format { + case FmtProtoDelim: + return encoder(func(v *dto.MetricFamily) error { + _, err := pbutil.WriteDelimited(w, v) + return err + }) + case FmtProtoCompact: + return encoder(func(v *dto.MetricFamily) error { + _, err := fmt.Fprintln(w, v.String()) + return err + }) + case FmtProtoText: + return encoder(func(v *dto.MetricFamily) error { + _, err := fmt.Fprintln(w, proto.MarshalTextString(v)) + return err + }) + case FmtText: + return encoder(func(v *dto.MetricFamily) error { + _, err := MetricFamilyToText(w, v) + return err + }) + } + panic("expfmt.NewEncoder: unknown format") +} diff --git a/vendor/github.com/prometheus/common/expfmt/expfmt.go b/vendor/github.com/prometheus/common/expfmt/expfmt.go new file mode 100644 index 000000000..371ac7503 --- /dev/null +++ b/vendor/github.com/prometheus/common/expfmt/expfmt.go @@ -0,0 +1,38 @@ +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package expfmt contains tools for reading and writing Prometheus metrics. +package expfmt + +// Format specifies the HTTP content type of the different wire protocols. +type Format string + +// Constants to assemble the Content-Type values for the different wire protocols. +const ( + TextVersion = "0.0.4" + ProtoType = `application/vnd.google.protobuf` + ProtoProtocol = `io.prometheus.client.MetricFamily` + ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";" + + // The Content-Type values for the different wire protocols. + FmtUnknown Format = `` + FmtText Format = `text/plain; version=` + TextVersion + FmtProtoDelim Format = ProtoFmt + ` encoding=delimited` + FmtProtoText Format = ProtoFmt + ` encoding=text` + FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text` +) + +const ( + hdrContentType = "Content-Type" + hdrAccept = "Accept" +) diff --git a/vendor/github.com/prometheus/common/expfmt/fuzz.go b/vendor/github.com/prometheus/common/expfmt/fuzz.go new file mode 100644 index 000000000..dc2eedeef --- /dev/null +++ b/vendor/github.com/prometheus/common/expfmt/fuzz.go @@ -0,0 +1,36 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Build only when actually fuzzing +// +build gofuzz + +package expfmt + +import "bytes" + +// Fuzz text metric parser with with github.com/dvyukov/go-fuzz: +// +// go-fuzz-build github.com/prometheus/common/expfmt +// go-fuzz -bin expfmt-fuzz.zip -workdir fuzz +// +// Further input samples should go in the folder fuzz/corpus. +func Fuzz(in []byte) int { + parser := TextParser{} + _, err := parser.TextToMetricFamilies(bytes.NewReader(in)) + + if err != nil { + return 0 + } + + return 1 +} diff --git a/vendor/github.com/prometheus/common/expfmt/text_create.go b/vendor/github.com/prometheus/common/expfmt/text_create.go new file mode 100644 index 000000000..f11321cd0 --- /dev/null +++ b/vendor/github.com/prometheus/common/expfmt/text_create.go @@ -0,0 +1,303 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package expfmt + +import ( + "fmt" + "io" + "math" + "strings" + + dto "github.com/prometheus/client_model/go" + "github.com/prometheus/common/model" +) + +// MetricFamilyToText converts a MetricFamily proto message into text format and +// writes the resulting lines to 'out'. It returns the number of bytes written +// and any error encountered. The output will have the same order as the input, +// no further sorting is performed. Furthermore, this function assumes the input +// is already sanitized and does not perform any sanity checks. If the input +// contains duplicate metrics or invalid metric or label names, the conversion +// will result in invalid text format output. +// +// This method fulfills the type 'prometheus.encoder'. +func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (int, error) { + var written int + + // Fail-fast checks. + if len(in.Metric) == 0 { + return written, fmt.Errorf("MetricFamily has no metrics: %s", in) + } + name := in.GetName() + if name == "" { + return written, fmt.Errorf("MetricFamily has no name: %s", in) + } + + // Comments, first HELP, then TYPE. + if in.Help != nil { + n, err := fmt.Fprintf( + out, "# HELP %s %s\n", + name, escapeString(*in.Help, false), + ) + written += n + if err != nil { + return written, err + } + } + metricType := in.GetType() + n, err := fmt.Fprintf( + out, "# TYPE %s %s\n", + name, strings.ToLower(metricType.String()), + ) + written += n + if err != nil { + return written, err + } + + // Finally the samples, one line for each. + for _, metric := range in.Metric { + switch metricType { + case dto.MetricType_COUNTER: + if metric.Counter == nil { + return written, fmt.Errorf( + "expected counter in metric %s %s", name, metric, + ) + } + n, err = writeSample( + name, metric, "", "", + metric.Counter.GetValue(), + out, + ) + case dto.MetricType_GAUGE: + if metric.Gauge == nil { + return written, fmt.Errorf( + "expected gauge in metric %s %s", name, metric, + ) + } + n, err = writeSample( + name, metric, "", "", + metric.Gauge.GetValue(), + out, + ) + case dto.MetricType_UNTYPED: + if metric.Untyped == nil { + return written, fmt.Errorf( + "expected untyped in metric %s %s", name, metric, + ) + } + n, err = writeSample( + name, metric, "", "", + metric.Untyped.GetValue(), + out, + ) + case dto.MetricType_SUMMARY: + if metric.Summary == nil { + return written, fmt.Errorf( + "expected summary in metric %s %s", name, metric, + ) + } + for _, q := range metric.Summary.Quantile { + n, err = writeSample( + name, metric, + model.QuantileLabel, fmt.Sprint(q.GetQuantile()), + q.GetValue(), + out, + ) + written += n + if err != nil { + return written, err + } + } + n, err = writeSample( + name+"_sum", metric, "", "", + metric.Summary.GetSampleSum(), + out, + ) + if err != nil { + return written, err + } + written += n + n, err = writeSample( + name+"_count", metric, "", "", + float64(metric.Summary.GetSampleCount()), + out, + ) + case dto.MetricType_HISTOGRAM: + if metric.Histogram == nil { + return written, fmt.Errorf( + "expected histogram in metric %s %s", name, metric, + ) + } + infSeen := false + for _, q := range metric.Histogram.Bucket { + n, err = writeSample( + name+"_bucket", metric, + model.BucketLabel, fmt.Sprint(q.GetUpperBound()), + float64(q.GetCumulativeCount()), + out, + ) + written += n + if err != nil { + return written, err + } + if math.IsInf(q.GetUpperBound(), +1) { + infSeen = true + } + } + if !infSeen { + n, err = writeSample( + name+"_bucket", metric, + model.BucketLabel, "+Inf", + float64(metric.Histogram.GetSampleCount()), + out, + ) + if err != nil { + return written, err + } + written += n + } + n, err = writeSample( + name+"_sum", metric, "", "", + metric.Histogram.GetSampleSum(), + out, + ) + if err != nil { + return written, err + } + written += n + n, err = writeSample( + name+"_count", metric, "", "", + float64(metric.Histogram.GetSampleCount()), + out, + ) + default: + return written, fmt.Errorf( + "unexpected type in metric %s %s", name, metric, + ) + } + written += n + if err != nil { + return written, err + } + } + return written, nil +} + +// writeSample writes a single sample in text format to out, given the metric +// name, the metric proto message itself, optionally an additional label name +// and value (use empty strings if not required), and the value. The function +// returns the number of bytes written and any error encountered. +func writeSample( + name string, + metric *dto.Metric, + additionalLabelName, additionalLabelValue string, + value float64, + out io.Writer, +) (int, error) { + var written int + n, err := fmt.Fprint(out, name) + written += n + if err != nil { + return written, err + } + n, err = labelPairsToText( + metric.Label, + additionalLabelName, additionalLabelValue, + out, + ) + written += n + if err != nil { + return written, err + } + n, err = fmt.Fprintf(out, " %v", value) + written += n + if err != nil { + return written, err + } + if metric.TimestampMs != nil { + n, err = fmt.Fprintf(out, " %v", *metric.TimestampMs) + written += n + if err != nil { + return written, err + } + } + n, err = out.Write([]byte{'\n'}) + written += n + if err != nil { + return written, err + } + return written, nil +} + +// labelPairsToText converts a slice of LabelPair proto messages plus the +// explicitly given additional label pair into text formatted as required by the +// text format and writes it to 'out'. An empty slice in combination with an +// empty string 'additionalLabelName' results in nothing being +// written. Otherwise, the label pairs are written, escaped as required by the +// text format, and enclosed in '{...}'. The function returns the number of +// bytes written and any error encountered. +func labelPairsToText( + in []*dto.LabelPair, + additionalLabelName, additionalLabelValue string, + out io.Writer, +) (int, error) { + if len(in) == 0 && additionalLabelName == "" { + return 0, nil + } + var written int + separator := '{' + for _, lp := range in { + n, err := fmt.Fprintf( + out, `%c%s="%s"`, + separator, lp.GetName(), escapeString(lp.GetValue(), true), + ) + written += n + if err != nil { + return written, err + } + separator = ',' + } + if additionalLabelName != "" { + n, err := fmt.Fprintf( + out, `%c%s="%s"`, + separator, additionalLabelName, + escapeString(additionalLabelValue, true), + ) + written += n + if err != nil { + return written, err + } + } + n, err := out.Write([]byte{'}'}) + written += n + if err != nil { + return written, err + } + return written, nil +} + +var ( + escape = strings.NewReplacer("\\", `\\`, "\n", `\n`) + escapeWithDoubleQuote = strings.NewReplacer("\\", `\\`, "\n", `\n`, "\"", `\"`) +) + +// escapeString replaces '\' by '\\', new line character by '\n', and - if +// includeDoubleQuote is true - '"' by '\"'. +func escapeString(v string, includeDoubleQuote bool) string { + if includeDoubleQuote { + return escapeWithDoubleQuote.Replace(v) + } + + return escape.Replace(v) +} diff --git a/vendor/github.com/prometheus/common/expfmt/text_parse.go b/vendor/github.com/prometheus/common/expfmt/text_parse.go new file mode 100644 index 000000000..54bcfde29 --- /dev/null +++ b/vendor/github.com/prometheus/common/expfmt/text_parse.go @@ -0,0 +1,757 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package expfmt + +import ( + "bufio" + "bytes" + "fmt" + "io" + "math" + "strconv" + "strings" + + dto "github.com/prometheus/client_model/go" + + "github.com/golang/protobuf/proto" + "github.com/prometheus/common/model" +) + +// A stateFn is a function that represents a state in a state machine. By +// executing it, the state is progressed to the next state. The stateFn returns +// another stateFn, which represents the new state. The end state is represented +// by nil. +type stateFn func() stateFn + +// ParseError signals errors while parsing the simple and flat text-based +// exchange format. +type ParseError struct { + Line int + Msg string +} + +// Error implements the error interface. +func (e ParseError) Error() string { + return fmt.Sprintf("text format parsing error in line %d: %s", e.Line, e.Msg) +} + +// TextParser is used to parse the simple and flat text-based exchange format. Its +// zero value is ready to use. +type TextParser struct { + metricFamiliesByName map[string]*dto.MetricFamily + buf *bufio.Reader // Where the parsed input is read through. + err error // Most recent error. + lineCount int // Tracks the line count for error messages. + currentByte byte // The most recent byte read. + currentToken bytes.Buffer // Re-used each time a token has to be gathered from multiple bytes. + currentMF *dto.MetricFamily + currentMetric *dto.Metric + currentLabelPair *dto.LabelPair + + // The remaining member variables are only used for summaries/histograms. + currentLabels map[string]string // All labels including '__name__' but excluding 'quantile'/'le' + // Summary specific. + summaries map[uint64]*dto.Metric // Key is created with LabelsToSignature. + currentQuantile float64 + // Histogram specific. + histograms map[uint64]*dto.Metric // Key is created with LabelsToSignature. + currentBucket float64 + // These tell us if the currently processed line ends on '_count' or + // '_sum' respectively and belong to a summary/histogram, representing the sample + // count and sum of that summary/histogram. + currentIsSummaryCount, currentIsSummarySum bool + currentIsHistogramCount, currentIsHistogramSum bool +} + +// TextToMetricFamilies reads 'in' as the simple and flat text-based exchange +// format and creates MetricFamily proto messages. It returns the MetricFamily +// proto messages in a map where the metric names are the keys, along with any +// error encountered. +// +// If the input contains duplicate metrics (i.e. lines with the same metric name +// and exactly the same label set), the resulting MetricFamily will contain +// duplicate Metric proto messages. Similar is true for duplicate label +// names. Checks for duplicates have to be performed separately, if required. +// Also note that neither the metrics within each MetricFamily are sorted nor +// the label pairs within each Metric. Sorting is not required for the most +// frequent use of this method, which is sample ingestion in the Prometheus +// server. However, for presentation purposes, you might want to sort the +// metrics, and in some cases, you must sort the labels, e.g. for consumption by +// the metric family injection hook of the Prometheus registry. +// +// Summaries and histograms are rather special beasts. You would probably not +// use them in the simple text format anyway. This method can deal with +// summaries and histograms if they are presented in exactly the way the +// text.Create function creates them. +// +// This method must not be called concurrently. If you want to parse different +// input concurrently, instantiate a separate Parser for each goroutine. +func (p *TextParser) TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricFamily, error) { + p.reset(in) + for nextState := p.startOfLine; nextState != nil; nextState = nextState() { + // Magic happens here... + } + // Get rid of empty metric families. + for k, mf := range p.metricFamiliesByName { + if len(mf.GetMetric()) == 0 { + delete(p.metricFamiliesByName, k) + } + } + // If p.err is io.EOF now, we have run into a premature end of the input + // stream. Turn this error into something nicer and more + // meaningful. (io.EOF is often used as a signal for the legitimate end + // of an input stream.) + if p.err == io.EOF { + p.parseError("unexpected end of input stream") + } + return p.metricFamiliesByName, p.err +} + +func (p *TextParser) reset(in io.Reader) { + p.metricFamiliesByName = map[string]*dto.MetricFamily{} + if p.buf == nil { + p.buf = bufio.NewReader(in) + } else { + p.buf.Reset(in) + } + p.err = nil + p.lineCount = 0 + if p.summaries == nil || len(p.summaries) > 0 { + p.summaries = map[uint64]*dto.Metric{} + } + if p.histograms == nil || len(p.histograms) > 0 { + p.histograms = map[uint64]*dto.Metric{} + } + p.currentQuantile = math.NaN() + p.currentBucket = math.NaN() +} + +// startOfLine represents the state where the next byte read from p.buf is the +// start of a line (or whitespace leading up to it). +func (p *TextParser) startOfLine() stateFn { + p.lineCount++ + if p.skipBlankTab(); p.err != nil { + // End of input reached. This is the only case where + // that is not an error but a signal that we are done. + p.err = nil + return nil + } + switch p.currentByte { + case '#': + return p.startComment + case '\n': + return p.startOfLine // Empty line, start the next one. + } + return p.readingMetricName +} + +// startComment represents the state where the next byte read from p.buf is the +// start of a comment (or whitespace leading up to it). +func (p *TextParser) startComment() stateFn { + if p.skipBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + if p.currentByte == '\n' { + return p.startOfLine + } + if p.readTokenUntilWhitespace(); p.err != nil { + return nil // Unexpected end of input. + } + // If we have hit the end of line already, there is nothing left + // to do. This is not considered a syntax error. + if p.currentByte == '\n' { + return p.startOfLine + } + keyword := p.currentToken.String() + if keyword != "HELP" && keyword != "TYPE" { + // Generic comment, ignore by fast forwarding to end of line. + for p.currentByte != '\n' { + if p.currentByte, p.err = p.buf.ReadByte(); p.err != nil { + return nil // Unexpected end of input. + } + } + return p.startOfLine + } + // There is something. Next has to be a metric name. + if p.skipBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + if p.readTokenAsMetricName(); p.err != nil { + return nil // Unexpected end of input. + } + if p.currentByte == '\n' { + // At the end of the line already. + // Again, this is not considered a syntax error. + return p.startOfLine + } + if !isBlankOrTab(p.currentByte) { + p.parseError("invalid metric name in comment") + return nil + } + p.setOrCreateCurrentMF() + if p.skipBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + if p.currentByte == '\n' { + // At the end of the line already. + // Again, this is not considered a syntax error. + return p.startOfLine + } + switch keyword { + case "HELP": + return p.readingHelp + case "TYPE": + return p.readingType + } + panic(fmt.Sprintf("code error: unexpected keyword %q", keyword)) +} + +// readingMetricName represents the state where the last byte read (now in +// p.currentByte) is the first byte of a metric name. +func (p *TextParser) readingMetricName() stateFn { + if p.readTokenAsMetricName(); p.err != nil { + return nil + } + if p.currentToken.Len() == 0 { + p.parseError("invalid metric name") + return nil + } + p.setOrCreateCurrentMF() + // Now is the time to fix the type if it hasn't happened yet. + if p.currentMF.Type == nil { + p.currentMF.Type = dto.MetricType_UNTYPED.Enum() + } + p.currentMetric = &dto.Metric{} + // Do not append the newly created currentMetric to + // currentMF.Metric right now. First wait if this is a summary, + // and the metric exists already, which we can only know after + // having read all the labels. + if p.skipBlankTabIfCurrentBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + return p.readingLabels +} + +// readingLabels represents the state where the last byte read (now in +// p.currentByte) is either the first byte of the label set (i.e. a '{'), or the +// first byte of the value (otherwise). +func (p *TextParser) readingLabels() stateFn { + // Summaries/histograms are special. We have to reset the + // currentLabels map, currentQuantile and currentBucket before starting to + // read labels. + if p.currentMF.GetType() == dto.MetricType_SUMMARY || p.currentMF.GetType() == dto.MetricType_HISTOGRAM { + p.currentLabels = map[string]string{} + p.currentLabels[string(model.MetricNameLabel)] = p.currentMF.GetName() + p.currentQuantile = math.NaN() + p.currentBucket = math.NaN() + } + if p.currentByte != '{' { + return p.readingValue + } + return p.startLabelName +} + +// startLabelName represents the state where the next byte read from p.buf is +// the start of a label name (or whitespace leading up to it). +func (p *TextParser) startLabelName() stateFn { + if p.skipBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + if p.currentByte == '}' { + if p.skipBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + return p.readingValue + } + if p.readTokenAsLabelName(); p.err != nil { + return nil // Unexpected end of input. + } + if p.currentToken.Len() == 0 { + p.parseError(fmt.Sprintf("invalid label name for metric %q", p.currentMF.GetName())) + return nil + } + p.currentLabelPair = &dto.LabelPair{Name: proto.String(p.currentToken.String())} + if p.currentLabelPair.GetName() == string(model.MetricNameLabel) { + p.parseError(fmt.Sprintf("label name %q is reserved", model.MetricNameLabel)) + return nil + } + // Special summary/histogram treatment. Don't add 'quantile' and 'le' + // labels to 'real' labels. + if !(p.currentMF.GetType() == dto.MetricType_SUMMARY && p.currentLabelPair.GetName() == model.QuantileLabel) && + !(p.currentMF.GetType() == dto.MetricType_HISTOGRAM && p.currentLabelPair.GetName() == model.BucketLabel) { + p.currentMetric.Label = append(p.currentMetric.Label, p.currentLabelPair) + } + if p.skipBlankTabIfCurrentBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + if p.currentByte != '=' { + p.parseError(fmt.Sprintf("expected '=' after label name, found %q", p.currentByte)) + return nil + } + return p.startLabelValue +} + +// startLabelValue represents the state where the next byte read from p.buf is +// the start of a (quoted) label value (or whitespace leading up to it). +func (p *TextParser) startLabelValue() stateFn { + if p.skipBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + if p.currentByte != '"' { + p.parseError(fmt.Sprintf("expected '\"' at start of label value, found %q", p.currentByte)) + return nil + } + if p.readTokenAsLabelValue(); p.err != nil { + return nil + } + if !model.LabelValue(p.currentToken.String()).IsValid() { + p.parseError(fmt.Sprintf("invalid label value %q", p.currentToken.String())) + return nil + } + p.currentLabelPair.Value = proto.String(p.currentToken.String()) + // Special treatment of summaries: + // - Quantile labels are special, will result in dto.Quantile later. + // - Other labels have to be added to currentLabels for signature calculation. + if p.currentMF.GetType() == dto.MetricType_SUMMARY { + if p.currentLabelPair.GetName() == model.QuantileLabel { + if p.currentQuantile, p.err = strconv.ParseFloat(p.currentLabelPair.GetValue(), 64); p.err != nil { + // Create a more helpful error message. + p.parseError(fmt.Sprintf("expected float as value for 'quantile' label, got %q", p.currentLabelPair.GetValue())) + return nil + } + } else { + p.currentLabels[p.currentLabelPair.GetName()] = p.currentLabelPair.GetValue() + } + } + // Similar special treatment of histograms. + if p.currentMF.GetType() == dto.MetricType_HISTOGRAM { + if p.currentLabelPair.GetName() == model.BucketLabel { + if p.currentBucket, p.err = strconv.ParseFloat(p.currentLabelPair.GetValue(), 64); p.err != nil { + // Create a more helpful error message. + p.parseError(fmt.Sprintf("expected float as value for 'le' label, got %q", p.currentLabelPair.GetValue())) + return nil + } + } else { + p.currentLabels[p.currentLabelPair.GetName()] = p.currentLabelPair.GetValue() + } + } + if p.skipBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + switch p.currentByte { + case ',': + return p.startLabelName + + case '}': + if p.skipBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + return p.readingValue + default: + p.parseError(fmt.Sprintf("unexpected end of label value %q", p.currentLabelPair.Value)) + return nil + } +} + +// readingValue represents the state where the last byte read (now in +// p.currentByte) is the first byte of the sample value (i.e. a float). +func (p *TextParser) readingValue() stateFn { + // When we are here, we have read all the labels, so for the + // special case of a summary/histogram, we can finally find out + // if the metric already exists. + if p.currentMF.GetType() == dto.MetricType_SUMMARY { + signature := model.LabelsToSignature(p.currentLabels) + if summary := p.summaries[signature]; summary != nil { + p.currentMetric = summary + } else { + p.summaries[signature] = p.currentMetric + p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric) + } + } else if p.currentMF.GetType() == dto.MetricType_HISTOGRAM { + signature := model.LabelsToSignature(p.currentLabels) + if histogram := p.histograms[signature]; histogram != nil { + p.currentMetric = histogram + } else { + p.histograms[signature] = p.currentMetric + p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric) + } + } else { + p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric) + } + if p.readTokenUntilWhitespace(); p.err != nil { + return nil // Unexpected end of input. + } + value, err := strconv.ParseFloat(p.currentToken.String(), 64) + if err != nil { + // Create a more helpful error message. + p.parseError(fmt.Sprintf("expected float as value, got %q", p.currentToken.String())) + return nil + } + switch p.currentMF.GetType() { + case dto.MetricType_COUNTER: + p.currentMetric.Counter = &dto.Counter{Value: proto.Float64(value)} + case dto.MetricType_GAUGE: + p.currentMetric.Gauge = &dto.Gauge{Value: proto.Float64(value)} + case dto.MetricType_UNTYPED: + p.currentMetric.Untyped = &dto.Untyped{Value: proto.Float64(value)} + case dto.MetricType_SUMMARY: + // *sigh* + if p.currentMetric.Summary == nil { + p.currentMetric.Summary = &dto.Summary{} + } + switch { + case p.currentIsSummaryCount: + p.currentMetric.Summary.SampleCount = proto.Uint64(uint64(value)) + case p.currentIsSummarySum: + p.currentMetric.Summary.SampleSum = proto.Float64(value) + case !math.IsNaN(p.currentQuantile): + p.currentMetric.Summary.Quantile = append( + p.currentMetric.Summary.Quantile, + &dto.Quantile{ + Quantile: proto.Float64(p.currentQuantile), + Value: proto.Float64(value), + }, + ) + } + case dto.MetricType_HISTOGRAM: + // *sigh* + if p.currentMetric.Histogram == nil { + p.currentMetric.Histogram = &dto.Histogram{} + } + switch { + case p.currentIsHistogramCount: + p.currentMetric.Histogram.SampleCount = proto.Uint64(uint64(value)) + case p.currentIsHistogramSum: + p.currentMetric.Histogram.SampleSum = proto.Float64(value) + case !math.IsNaN(p.currentBucket): + p.currentMetric.Histogram.Bucket = append( + p.currentMetric.Histogram.Bucket, + &dto.Bucket{ + UpperBound: proto.Float64(p.currentBucket), + CumulativeCount: proto.Uint64(uint64(value)), + }, + ) + } + default: + p.err = fmt.Errorf("unexpected type for metric name %q", p.currentMF.GetName()) + } + if p.currentByte == '\n' { + return p.startOfLine + } + return p.startTimestamp +} + +// startTimestamp represents the state where the next byte read from p.buf is +// the start of the timestamp (or whitespace leading up to it). +func (p *TextParser) startTimestamp() stateFn { + if p.skipBlankTab(); p.err != nil { + return nil // Unexpected end of input. + } + if p.readTokenUntilWhitespace(); p.err != nil { + return nil // Unexpected end of input. + } + timestamp, err := strconv.ParseInt(p.currentToken.String(), 10, 64) + if err != nil { + // Create a more helpful error message. + p.parseError(fmt.Sprintf("expected integer as timestamp, got %q", p.currentToken.String())) + return nil + } + p.currentMetric.TimestampMs = proto.Int64(timestamp) + if p.readTokenUntilNewline(false); p.err != nil { + return nil // Unexpected end of input. + } + if p.currentToken.Len() > 0 { + p.parseError(fmt.Sprintf("spurious string after timestamp: %q", p.currentToken.String())) + return nil + } + return p.startOfLine +} + +// readingHelp represents the state where the last byte read (now in +// p.currentByte) is the first byte of the docstring after 'HELP'. +func (p *TextParser) readingHelp() stateFn { + if p.currentMF.Help != nil { + p.parseError(fmt.Sprintf("second HELP line for metric name %q", p.currentMF.GetName())) + return nil + } + // Rest of line is the docstring. + if p.readTokenUntilNewline(true); p.err != nil { + return nil // Unexpected end of input. + } + p.currentMF.Help = proto.String(p.currentToken.String()) + return p.startOfLine +} + +// readingType represents the state where the last byte read (now in +// p.currentByte) is the first byte of the type hint after 'HELP'. +func (p *TextParser) readingType() stateFn { + if p.currentMF.Type != nil { + p.parseError(fmt.Sprintf("second TYPE line for metric name %q, or TYPE reported after samples", p.currentMF.GetName())) + return nil + } + // Rest of line is the type. + if p.readTokenUntilNewline(false); p.err != nil { + return nil // Unexpected end of input. + } + metricType, ok := dto.MetricType_value[strings.ToUpper(p.currentToken.String())] + if !ok { + p.parseError(fmt.Sprintf("unknown metric type %q", p.currentToken.String())) + return nil + } + p.currentMF.Type = dto.MetricType(metricType).Enum() + return p.startOfLine +} + +// parseError sets p.err to a ParseError at the current line with the given +// message. +func (p *TextParser) parseError(msg string) { + p.err = ParseError{ + Line: p.lineCount, + Msg: msg, + } +} + +// skipBlankTab reads (and discards) bytes from p.buf until it encounters a byte +// that is neither ' ' nor '\t'. That byte is left in p.currentByte. +func (p *TextParser) skipBlankTab() { + for { + if p.currentByte, p.err = p.buf.ReadByte(); p.err != nil || !isBlankOrTab(p.currentByte) { + return + } + } +} + +// skipBlankTabIfCurrentBlankTab works exactly as skipBlankTab but doesn't do +// anything if p.currentByte is neither ' ' nor '\t'. +func (p *TextParser) skipBlankTabIfCurrentBlankTab() { + if isBlankOrTab(p.currentByte) { + p.skipBlankTab() + } +} + +// readTokenUntilWhitespace copies bytes from p.buf into p.currentToken. The +// first byte considered is the byte already read (now in p.currentByte). The +// first whitespace byte encountered is still copied into p.currentByte, but not +// into p.currentToken. +func (p *TextParser) readTokenUntilWhitespace() { + p.currentToken.Reset() + for p.err == nil && !isBlankOrTab(p.currentByte) && p.currentByte != '\n' { + p.currentToken.WriteByte(p.currentByte) + p.currentByte, p.err = p.buf.ReadByte() + } +} + +// readTokenUntilNewline copies bytes from p.buf into p.currentToken. The first +// byte considered is the byte already read (now in p.currentByte). The first +// newline byte encountered is still copied into p.currentByte, but not into +// p.currentToken. If recognizeEscapeSequence is true, two escape sequences are +// recognized: '\\' tranlates into '\', and '\n' into a line-feed character. All +// other escape sequences are invalid and cause an error. +func (p *TextParser) readTokenUntilNewline(recognizeEscapeSequence bool) { + p.currentToken.Reset() + escaped := false + for p.err == nil { + if recognizeEscapeSequence && escaped { + switch p.currentByte { + case '\\': + p.currentToken.WriteByte(p.currentByte) + case 'n': + p.currentToken.WriteByte('\n') + default: + p.parseError(fmt.Sprintf("invalid escape sequence '\\%c'", p.currentByte)) + return + } + escaped = false + } else { + switch p.currentByte { + case '\n': + return + case '\\': + escaped = true + default: + p.currentToken.WriteByte(p.currentByte) + } + } + p.currentByte, p.err = p.buf.ReadByte() + } +} + +// readTokenAsMetricName copies a metric name from p.buf into p.currentToken. +// The first byte considered is the byte already read (now in p.currentByte). +// The first byte not part of a metric name is still copied into p.currentByte, +// but not into p.currentToken. +func (p *TextParser) readTokenAsMetricName() { + p.currentToken.Reset() + if !isValidMetricNameStart(p.currentByte) { + return + } + for { + p.currentToken.WriteByte(p.currentByte) + p.currentByte, p.err = p.buf.ReadByte() + if p.err != nil || !isValidMetricNameContinuation(p.currentByte) { + return + } + } +} + +// readTokenAsLabelName copies a label name from p.buf into p.currentToken. +// The first byte considered is the byte already read (now in p.currentByte). +// The first byte not part of a label name is still copied into p.currentByte, +// but not into p.currentToken. +func (p *TextParser) readTokenAsLabelName() { + p.currentToken.Reset() + if !isValidLabelNameStart(p.currentByte) { + return + } + for { + p.currentToken.WriteByte(p.currentByte) + p.currentByte, p.err = p.buf.ReadByte() + if p.err != nil || !isValidLabelNameContinuation(p.currentByte) { + return + } + } +} + +// readTokenAsLabelValue copies a label value from p.buf into p.currentToken. +// In contrast to the other 'readTokenAs...' functions, which start with the +// last read byte in p.currentByte, this method ignores p.currentByte and starts +// with reading a new byte from p.buf. The first byte not part of a label value +// is still copied into p.currentByte, but not into p.currentToken. +func (p *TextParser) readTokenAsLabelValue() { + p.currentToken.Reset() + escaped := false + for { + if p.currentByte, p.err = p.buf.ReadByte(); p.err != nil { + return + } + if escaped { + switch p.currentByte { + case '"', '\\': + p.currentToken.WriteByte(p.currentByte) + case 'n': + p.currentToken.WriteByte('\n') + default: + p.parseError(fmt.Sprintf("invalid escape sequence '\\%c'", p.currentByte)) + return + } + escaped = false + continue + } + switch p.currentByte { + case '"': + return + case '\n': + p.parseError(fmt.Sprintf("label value %q contains unescaped new-line", p.currentToken.String())) + return + case '\\': + escaped = true + default: + p.currentToken.WriteByte(p.currentByte) + } + } +} + +func (p *TextParser) setOrCreateCurrentMF() { + p.currentIsSummaryCount = false + p.currentIsSummarySum = false + p.currentIsHistogramCount = false + p.currentIsHistogramSum = false + name := p.currentToken.String() + if p.currentMF = p.metricFamiliesByName[name]; p.currentMF != nil { + return + } + // Try out if this is a _sum or _count for a summary/histogram. + summaryName := summaryMetricName(name) + if p.currentMF = p.metricFamiliesByName[summaryName]; p.currentMF != nil { + if p.currentMF.GetType() == dto.MetricType_SUMMARY { + if isCount(name) { + p.currentIsSummaryCount = true + } + if isSum(name) { + p.currentIsSummarySum = true + } + return + } + } + histogramName := histogramMetricName(name) + if p.currentMF = p.metricFamiliesByName[histogramName]; p.currentMF != nil { + if p.currentMF.GetType() == dto.MetricType_HISTOGRAM { + if isCount(name) { + p.currentIsHistogramCount = true + } + if isSum(name) { + p.currentIsHistogramSum = true + } + return + } + } + p.currentMF = &dto.MetricFamily{Name: proto.String(name)} + p.metricFamiliesByName[name] = p.currentMF +} + +func isValidLabelNameStart(b byte) bool { + return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' +} + +func isValidLabelNameContinuation(b byte) bool { + return isValidLabelNameStart(b) || (b >= '0' && b <= '9') +} + +func isValidMetricNameStart(b byte) bool { + return isValidLabelNameStart(b) || b == ':' +} + +func isValidMetricNameContinuation(b byte) bool { + return isValidLabelNameContinuation(b) || b == ':' +} + +func isBlankOrTab(b byte) bool { + return b == ' ' || b == '\t' +} + +func isCount(name string) bool { + return len(name) > 6 && name[len(name)-6:] == "_count" +} + +func isSum(name string) bool { + return len(name) > 4 && name[len(name)-4:] == "_sum" +} + +func isBucket(name string) bool { + return len(name) > 7 && name[len(name)-7:] == "_bucket" +} + +func summaryMetricName(name string) string { + switch { + case isCount(name): + return name[:len(name)-6] + case isSum(name): + return name[:len(name)-4] + default: + return name + } +} + +func histogramMetricName(name string) string { + switch { + case isCount(name): + return name[:len(name)-6] + case isSum(name): + return name[:len(name)-4] + case isBucket(name): + return name[:len(name)-7] + default: + return name + } +} diff --git a/vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/LICENSE b/vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/autoneg.go b/vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/autoneg.go new file mode 100644 index 000000000..648b38cb6 --- /dev/null +++ b/vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/autoneg.go @@ -0,0 +1,162 @@ +/* +HTTP Content-Type Autonegotiation. + +The functions in this package implement the behaviour specified in +http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html + +Copyright (c) 2011, Open Knowledge Foundation Ltd. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + Neither the name of the Open Knowledge Foundation Ltd. nor the + names of its contributors may be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +*/ +package goautoneg + +import ( + "sort" + "strconv" + "strings" +) + +// Structure to represent a clause in an HTTP Accept Header +type Accept struct { + Type, SubType string + Q float64 + Params map[string]string +} + +// For internal use, so that we can use the sort interface +type accept_slice []Accept + +func (accept accept_slice) Len() int { + slice := []Accept(accept) + return len(slice) +} + +func (accept accept_slice) Less(i, j int) bool { + slice := []Accept(accept) + ai, aj := slice[i], slice[j] + if ai.Q > aj.Q { + return true + } + if ai.Type != "*" && aj.Type == "*" { + return true + } + if ai.SubType != "*" && aj.SubType == "*" { + return true + } + return false +} + +func (accept accept_slice) Swap(i, j int) { + slice := []Accept(accept) + slice[i], slice[j] = slice[j], slice[i] +} + +// Parse an Accept Header string returning a sorted list +// of clauses +func ParseAccept(header string) (accept []Accept) { + parts := strings.Split(header, ",") + accept = make([]Accept, 0, len(parts)) + for _, part := range parts { + part := strings.Trim(part, " ") + + a := Accept{} + a.Params = make(map[string]string) + a.Q = 1.0 + + mrp := strings.Split(part, ";") + + media_range := mrp[0] + sp := strings.Split(media_range, "/") + a.Type = strings.Trim(sp[0], " ") + + switch { + case len(sp) == 1 && a.Type == "*": + a.SubType = "*" + case len(sp) == 2: + a.SubType = strings.Trim(sp[1], " ") + default: + continue + } + + if len(mrp) == 1 { + accept = append(accept, a) + continue + } + + for _, param := range mrp[1:] { + sp := strings.SplitN(param, "=", 2) + if len(sp) != 2 { + continue + } + token := strings.Trim(sp[0], " ") + if token == "q" { + a.Q, _ = strconv.ParseFloat(sp[1], 32) + } else { + a.Params[token] = strings.Trim(sp[1], " ") + } + } + + accept = append(accept, a) + } + + slice := accept_slice(accept) + sort.Sort(slice) + + return +} + +// Negotiate the most appropriate content_type given the accept header +// and a list of alternatives. +func Negotiate(header string, alternatives []string) (content_type string) { + asp := make([][]string, 0, len(alternatives)) + for _, ctype := range alternatives { + asp = append(asp, strings.SplitN(ctype, "/", 2)) + } + for _, clause := range ParseAccept(header) { + for i, ctsp := range asp { + if clause.Type == ctsp[0] && clause.SubType == ctsp[1] { + content_type = alternatives[i] + return + } + if clause.Type == ctsp[0] && clause.SubType == "*" { + content_type = alternatives[i] + return + } + if clause.Type == "*" && clause.SubType == "*" { + content_type = alternatives[i] + return + } + } + } + return +} diff --git a/vendor/github.com/prometheus/common/model/LICENSE b/vendor/github.com/prometheus/common/model/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/vendor/github.com/prometheus/common/model/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/prometheus/common/model/alert.go b/vendor/github.com/prometheus/common/model/alert.go new file mode 100644 index 000000000..35e739c7a --- /dev/null +++ b/vendor/github.com/prometheus/common/model/alert.go @@ -0,0 +1,136 @@ +// Copyright 2013 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +import ( + "fmt" + "time" +) + +type AlertStatus string + +const ( + AlertFiring AlertStatus = "firing" + AlertResolved AlertStatus = "resolved" +) + +// Alert is a generic representation of an alert in the Prometheus eco-system. +type Alert struct { + // Label value pairs for purpose of aggregation, matching, and disposition + // dispatching. This must minimally include an "alertname" label. + Labels LabelSet `json:"labels"` + + // Extra key/value information which does not define alert identity. + Annotations LabelSet `json:"annotations"` + + // The known time range for this alert. Both ends are optional. + StartsAt time.Time `json:"startsAt,omitempty"` + EndsAt time.Time `json:"endsAt,omitempty"` + GeneratorURL string `json:"generatorURL"` +} + +// Name returns the name of the alert. It is equivalent to the "alertname" label. +func (a *Alert) Name() string { + return string(a.Labels[AlertNameLabel]) +} + +// Fingerprint returns a unique hash for the alert. It is equivalent to +// the fingerprint of the alert's label set. +func (a *Alert) Fingerprint() Fingerprint { + return a.Labels.Fingerprint() +} + +func (a *Alert) String() string { + s := fmt.Sprintf("%s[%s]", a.Name(), a.Fingerprint().String()[:7]) + if a.Resolved() { + return s + "[resolved]" + } + return s + "[active]" +} + +// Resolved returns true iff the activity interval ended in the past. +func (a *Alert) Resolved() bool { + return a.ResolvedAt(time.Now()) +} + +// ResolvedAt returns true off the activity interval ended before +// the given timestamp. +func (a *Alert) ResolvedAt(ts time.Time) bool { + if a.EndsAt.IsZero() { + return false + } + return !a.EndsAt.After(ts) +} + +// Status returns the status of the alert. +func (a *Alert) Status() AlertStatus { + if a.Resolved() { + return AlertResolved + } + return AlertFiring +} + +// Validate checks whether the alert data is inconsistent. +func (a *Alert) Validate() error { + if a.StartsAt.IsZero() { + return fmt.Errorf("start time missing") + } + if !a.EndsAt.IsZero() && a.EndsAt.Before(a.StartsAt) { + return fmt.Errorf("start time must be before end time") + } + if err := a.Labels.Validate(); err != nil { + return fmt.Errorf("invalid label set: %s", err) + } + if len(a.Labels) == 0 { + return fmt.Errorf("at least one label pair required") + } + if err := a.Annotations.Validate(); err != nil { + return fmt.Errorf("invalid annotations: %s", err) + } + return nil +} + +// Alert is a list of alerts that can be sorted in chronological order. +type Alerts []*Alert + +func (as Alerts) Len() int { return len(as) } +func (as Alerts) Swap(i, j int) { as[i], as[j] = as[j], as[i] } + +func (as Alerts) Less(i, j int) bool { + if as[i].StartsAt.Before(as[j].StartsAt) { + return true + } + if as[i].EndsAt.Before(as[j].EndsAt) { + return true + } + return as[i].Fingerprint() < as[j].Fingerprint() +} + +// HasFiring returns true iff one of the alerts is not resolved. +func (as Alerts) HasFiring() bool { + for _, a := range as { + if !a.Resolved() { + return true + } + } + return false +} + +// Status returns StatusFiring iff at least one of the alerts is firing. +func (as Alerts) Status() AlertStatus { + if as.HasFiring() { + return AlertFiring + } + return AlertResolved +} diff --git a/vendor/github.com/prometheus/common/model/fingerprinting.go b/vendor/github.com/prometheus/common/model/fingerprinting.go new file mode 100644 index 000000000..fc4de4106 --- /dev/null +++ b/vendor/github.com/prometheus/common/model/fingerprinting.go @@ -0,0 +1,105 @@ +// Copyright 2013 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +import ( + "fmt" + "strconv" +) + +// Fingerprint provides a hash-capable representation of a Metric. +// For our purposes, FNV-1A 64-bit is used. +type Fingerprint uint64 + +// FingerprintFromString transforms a string representation into a Fingerprint. +func FingerprintFromString(s string) (Fingerprint, error) { + num, err := strconv.ParseUint(s, 16, 64) + return Fingerprint(num), err +} + +// ParseFingerprint parses the input string into a fingerprint. +func ParseFingerprint(s string) (Fingerprint, error) { + num, err := strconv.ParseUint(s, 16, 64) + if err != nil { + return 0, err + } + return Fingerprint(num), nil +} + +func (f Fingerprint) String() string { + return fmt.Sprintf("%016x", uint64(f)) +} + +// Fingerprints represents a collection of Fingerprint subject to a given +// natural sorting scheme. It implements sort.Interface. +type Fingerprints []Fingerprint + +// Len implements sort.Interface. +func (f Fingerprints) Len() int { + return len(f) +} + +// Less implements sort.Interface. +func (f Fingerprints) Less(i, j int) bool { + return f[i] < f[j] +} + +// Swap implements sort.Interface. +func (f Fingerprints) Swap(i, j int) { + f[i], f[j] = f[j], f[i] +} + +// FingerprintSet is a set of Fingerprints. +type FingerprintSet map[Fingerprint]struct{} + +// Equal returns true if both sets contain the same elements (and not more). +func (s FingerprintSet) Equal(o FingerprintSet) bool { + if len(s) != len(o) { + return false + } + + for k := range s { + if _, ok := o[k]; !ok { + return false + } + } + + return true +} + +// Intersection returns the elements contained in both sets. +func (s FingerprintSet) Intersection(o FingerprintSet) FingerprintSet { + myLength, otherLength := len(s), len(o) + if myLength == 0 || otherLength == 0 { + return FingerprintSet{} + } + + subSet := s + superSet := o + + if otherLength < myLength { + subSet = o + superSet = s + } + + out := FingerprintSet{} + + for k := range subSet { + if _, ok := superSet[k]; ok { + out[k] = struct{}{} + } + } + + return out +} diff --git a/vendor/github.com/prometheus/common/model/fnv.go b/vendor/github.com/prometheus/common/model/fnv.go new file mode 100644 index 000000000..038fc1c90 --- /dev/null +++ b/vendor/github.com/prometheus/common/model/fnv.go @@ -0,0 +1,42 @@ +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +// Inline and byte-free variant of hash/fnv's fnv64a. + +const ( + offset64 = 14695981039346656037 + prime64 = 1099511628211 +) + +// hashNew initializies a new fnv64a hash value. +func hashNew() uint64 { + return offset64 +} + +// hashAdd adds a string to a fnv64a hash value, returning the updated hash. +func hashAdd(h uint64, s string) uint64 { + for i := 0; i < len(s); i++ { + h ^= uint64(s[i]) + h *= prime64 + } + return h +} + +// hashAddByte adds a byte to a fnv64a hash value, returning the updated hash. +func hashAddByte(h uint64, b byte) uint64 { + h ^= uint64(b) + h *= prime64 + return h +} diff --git a/vendor/github.com/prometheus/common/model/labels.go b/vendor/github.com/prometheus/common/model/labels.go new file mode 100644 index 000000000..41051a01a --- /dev/null +++ b/vendor/github.com/prometheus/common/model/labels.go @@ -0,0 +1,210 @@ +// Copyright 2013 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +import ( + "encoding/json" + "fmt" + "regexp" + "strings" + "unicode/utf8" +) + +const ( + // AlertNameLabel is the name of the label containing the an alert's name. + AlertNameLabel = "alertname" + + // ExportedLabelPrefix is the prefix to prepend to the label names present in + // exported metrics if a label of the same name is added by the server. + ExportedLabelPrefix = "exported_" + + // MetricNameLabel is the label name indicating the metric name of a + // timeseries. + MetricNameLabel = "__name__" + + // SchemeLabel is the name of the label that holds the scheme on which to + // scrape a target. + SchemeLabel = "__scheme__" + + // AddressLabel is the name of the label that holds the address of + // a scrape target. + AddressLabel = "__address__" + + // MetricsPathLabel is the name of the label that holds the path on which to + // scrape a target. + MetricsPathLabel = "__metrics_path__" + + // ReservedLabelPrefix is a prefix which is not legal in user-supplied + // label names. + ReservedLabelPrefix = "__" + + // MetaLabelPrefix is a prefix for labels that provide meta information. + // Labels with this prefix are used for intermediate label processing and + // will not be attached to time series. + MetaLabelPrefix = "__meta_" + + // TmpLabelPrefix is a prefix for temporary labels as part of relabelling. + // Labels with this prefix are used for intermediate label processing and + // will not be attached to time series. This is reserved for use in + // Prometheus configuration files by users. + TmpLabelPrefix = "__tmp_" + + // ParamLabelPrefix is a prefix for labels that provide URL parameters + // used to scrape a target. + ParamLabelPrefix = "__param_" + + // JobLabel is the label name indicating the job from which a timeseries + // was scraped. + JobLabel = "job" + + // InstanceLabel is the label name used for the instance label. + InstanceLabel = "instance" + + // BucketLabel is used for the label that defines the upper bound of a + // bucket of a histogram ("le" -> "less or equal"). + BucketLabel = "le" + + // QuantileLabel is used for the label that defines the quantile in a + // summary. + QuantileLabel = "quantile" +) + +// LabelNameRE is a regular expression matching valid label names. Note that the +// IsValid method of LabelName performs the same check but faster than a match +// with this regular expression. +var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$") + +// A LabelName is a key for a LabelSet or Metric. It has a value associated +// therewith. +type LabelName string + +// IsValid is true iff the label name matches the pattern of LabelNameRE. This +// method, however, does not use LabelNameRE for the check but a much faster +// hardcoded implementation. +func (ln LabelName) IsValid() bool { + if len(ln) == 0 { + return false + } + for i, b := range ln { + if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || (b >= '0' && b <= '9' && i > 0)) { + return false + } + } + return true +} + +// UnmarshalYAML implements the yaml.Unmarshaler interface. +func (ln *LabelName) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + if !LabelName(s).IsValid() { + return fmt.Errorf("%q is not a valid label name", s) + } + *ln = LabelName(s) + return nil +} + +// UnmarshalJSON implements the json.Unmarshaler interface. +func (ln *LabelName) UnmarshalJSON(b []byte) error { + var s string + if err := json.Unmarshal(b, &s); err != nil { + return err + } + if !LabelName(s).IsValid() { + return fmt.Errorf("%q is not a valid label name", s) + } + *ln = LabelName(s) + return nil +} + +// LabelNames is a sortable LabelName slice. In implements sort.Interface. +type LabelNames []LabelName + +func (l LabelNames) Len() int { + return len(l) +} + +func (l LabelNames) Less(i, j int) bool { + return l[i] < l[j] +} + +func (l LabelNames) Swap(i, j int) { + l[i], l[j] = l[j], l[i] +} + +func (l LabelNames) String() string { + labelStrings := make([]string, 0, len(l)) + for _, label := range l { + labelStrings = append(labelStrings, string(label)) + } + return strings.Join(labelStrings, ", ") +} + +// A LabelValue is an associated value for a LabelName. +type LabelValue string + +// IsValid returns true iff the string is a valid UTF8. +func (lv LabelValue) IsValid() bool { + return utf8.ValidString(string(lv)) +} + +// LabelValues is a sortable LabelValue slice. It implements sort.Interface. +type LabelValues []LabelValue + +func (l LabelValues) Len() int { + return len(l) +} + +func (l LabelValues) Less(i, j int) bool { + return string(l[i]) < string(l[j]) +} + +func (l LabelValues) Swap(i, j int) { + l[i], l[j] = l[j], l[i] +} + +// LabelPair pairs a name with a value. +type LabelPair struct { + Name LabelName + Value LabelValue +} + +// LabelPairs is a sortable slice of LabelPair pointers. It implements +// sort.Interface. +type LabelPairs []*LabelPair + +func (l LabelPairs) Len() int { + return len(l) +} + +func (l LabelPairs) Less(i, j int) bool { + switch { + case l[i].Name > l[j].Name: + return false + case l[i].Name < l[j].Name: + return true + case l[i].Value > l[j].Value: + return false + case l[i].Value < l[j].Value: + return true + default: + return false + } +} + +func (l LabelPairs) Swap(i, j int) { + l[i], l[j] = l[j], l[i] +} diff --git a/vendor/github.com/prometheus/common/model/labelset.go b/vendor/github.com/prometheus/common/model/labelset.go new file mode 100644 index 000000000..6eda08a73 --- /dev/null +++ b/vendor/github.com/prometheus/common/model/labelset.go @@ -0,0 +1,169 @@ +// Copyright 2013 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +import ( + "encoding/json" + "fmt" + "sort" + "strings" +) + +// A LabelSet is a collection of LabelName and LabelValue pairs. The LabelSet +// may be fully-qualified down to the point where it may resolve to a single +// Metric in the data store or not. All operations that occur within the realm +// of a LabelSet can emit a vector of Metric entities to which the LabelSet may +// match. +type LabelSet map[LabelName]LabelValue + +// Validate checks whether all names and values in the label set +// are valid. +func (ls LabelSet) Validate() error { + for ln, lv := range ls { + if !ln.IsValid() { + return fmt.Errorf("invalid name %q", ln) + } + if !lv.IsValid() { + return fmt.Errorf("invalid value %q", lv) + } + } + return nil +} + +// Equal returns true iff both label sets have exactly the same key/value pairs. +func (ls LabelSet) Equal(o LabelSet) bool { + if len(ls) != len(o) { + return false + } + for ln, lv := range ls { + olv, ok := o[ln] + if !ok { + return false + } + if olv != lv { + return false + } + } + return true +} + +// Before compares the metrics, using the following criteria: +// +// If m has fewer labels than o, it is before o. If it has more, it is not. +// +// If the number of labels is the same, the superset of all label names is +// sorted alphanumerically. The first differing label pair found in that order +// determines the outcome: If the label does not exist at all in m, then m is +// before o, and vice versa. Otherwise the label value is compared +// alphanumerically. +// +// If m and o are equal, the method returns false. +func (ls LabelSet) Before(o LabelSet) bool { + if len(ls) < len(o) { + return true + } + if len(ls) > len(o) { + return false + } + + lns := make(LabelNames, 0, len(ls)+len(o)) + for ln := range ls { + lns = append(lns, ln) + } + for ln := range o { + lns = append(lns, ln) + } + // It's probably not worth it to de-dup lns. + sort.Sort(lns) + for _, ln := range lns { + mlv, ok := ls[ln] + if !ok { + return true + } + olv, ok := o[ln] + if !ok { + return false + } + if mlv < olv { + return true + } + if mlv > olv { + return false + } + } + return false +} + +// Clone returns a copy of the label set. +func (ls LabelSet) Clone() LabelSet { + lsn := make(LabelSet, len(ls)) + for ln, lv := range ls { + lsn[ln] = lv + } + return lsn +} + +// Merge is a helper function to non-destructively merge two label sets. +func (l LabelSet) Merge(other LabelSet) LabelSet { + result := make(LabelSet, len(l)) + + for k, v := range l { + result[k] = v + } + + for k, v := range other { + result[k] = v + } + + return result +} + +func (l LabelSet) String() string { + lstrs := make([]string, 0, len(l)) + for l, v := range l { + lstrs = append(lstrs, fmt.Sprintf("%s=%q", l, v)) + } + + sort.Strings(lstrs) + return fmt.Sprintf("{%s}", strings.Join(lstrs, ", ")) +} + +// Fingerprint returns the LabelSet's fingerprint. +func (ls LabelSet) Fingerprint() Fingerprint { + return labelSetToFingerprint(ls) +} + +// FastFingerprint returns the LabelSet's Fingerprint calculated by a faster hashing +// algorithm, which is, however, more susceptible to hash collisions. +func (ls LabelSet) FastFingerprint() Fingerprint { + return labelSetToFastFingerprint(ls) +} + +// UnmarshalJSON implements the json.Unmarshaler interface. +func (l *LabelSet) UnmarshalJSON(b []byte) error { + var m map[LabelName]LabelValue + if err := json.Unmarshal(b, &m); err != nil { + return err + } + // encoding/json only unmarshals maps of the form map[string]T. It treats + // LabelName as a string and does not call its UnmarshalJSON method. + // Thus, we have to replicate the behavior here. + for ln := range m { + if !ln.IsValid() { + return fmt.Errorf("%q is not a valid label name", ln) + } + } + *l = LabelSet(m) + return nil +} diff --git a/vendor/github.com/prometheus/common/model/metric.go b/vendor/github.com/prometheus/common/model/metric.go new file mode 100644 index 000000000..f7250909b --- /dev/null +++ b/vendor/github.com/prometheus/common/model/metric.go @@ -0,0 +1,103 @@ +// Copyright 2013 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +import ( + "fmt" + "regexp" + "sort" + "strings" +) + +var ( + separator = []byte{0} + // MetricNameRE is a regular expression matching valid metric + // names. Note that the IsValidMetricName function performs the same + // check but faster than a match with this regular expression. + MetricNameRE = regexp.MustCompile(`^[a-zA-Z_:][a-zA-Z0-9_:]*$`) +) + +// A Metric is similar to a LabelSet, but the key difference is that a Metric is +// a singleton and refers to one and only one stream of samples. +type Metric LabelSet + +// Equal compares the metrics. +func (m Metric) Equal(o Metric) bool { + return LabelSet(m).Equal(LabelSet(o)) +} + +// Before compares the metrics' underlying label sets. +func (m Metric) Before(o Metric) bool { + return LabelSet(m).Before(LabelSet(o)) +} + +// Clone returns a copy of the Metric. +func (m Metric) Clone() Metric { + clone := make(Metric, len(m)) + for k, v := range m { + clone[k] = v + } + return clone +} + +func (m Metric) String() string { + metricName, hasName := m[MetricNameLabel] + numLabels := len(m) - 1 + if !hasName { + numLabels = len(m) + } + labelStrings := make([]string, 0, numLabels) + for label, value := range m { + if label != MetricNameLabel { + labelStrings = append(labelStrings, fmt.Sprintf("%s=%q", label, value)) + } + } + + switch numLabels { + case 0: + if hasName { + return string(metricName) + } + return "{}" + default: + sort.Strings(labelStrings) + return fmt.Sprintf("%s{%s}", metricName, strings.Join(labelStrings, ", ")) + } +} + +// Fingerprint returns a Metric's Fingerprint. +func (m Metric) Fingerprint() Fingerprint { + return LabelSet(m).Fingerprint() +} + +// FastFingerprint returns a Metric's Fingerprint calculated by a faster hashing +// algorithm, which is, however, more susceptible to hash collisions. +func (m Metric) FastFingerprint() Fingerprint { + return LabelSet(m).FastFingerprint() +} + +// IsValidMetricName returns true iff name matches the pattern of MetricNameRE. +// This function, however, does not use MetricNameRE for the check but a much +// faster hardcoded implementation. +func IsValidMetricName(n LabelValue) bool { + if len(n) == 0 { + return false + } + for i, b := range n { + if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || b == ':' || (b >= '0' && b <= '9' && i > 0)) { + return false + } + } + return true +} diff --git a/vendor/github.com/prometheus/common/model/model.go b/vendor/github.com/prometheus/common/model/model.go new file mode 100644 index 000000000..a7b969170 --- /dev/null +++ b/vendor/github.com/prometheus/common/model/model.go @@ -0,0 +1,16 @@ +// Copyright 2013 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package model contains common data structures that are shared across +// Prometheus components and libraries. +package model diff --git a/vendor/github.com/prometheus/common/model/signature.go b/vendor/github.com/prometheus/common/model/signature.go new file mode 100644 index 000000000..8762b13c6 --- /dev/null +++ b/vendor/github.com/prometheus/common/model/signature.go @@ -0,0 +1,144 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +import ( + "sort" +) + +// SeparatorByte is a byte that cannot occur in valid UTF-8 sequences and is +// used to separate label names, label values, and other strings from each other +// when calculating their combined hash value (aka signature aka fingerprint). +const SeparatorByte byte = 255 + +var ( + // cache the signature of an empty label set. + emptyLabelSignature = hashNew() +) + +// LabelsToSignature returns a quasi-unique signature (i.e., fingerprint) for a +// given label set. (Collisions are possible but unlikely if the number of label +// sets the function is applied to is small.) +func LabelsToSignature(labels map[string]string) uint64 { + if len(labels) == 0 { + return emptyLabelSignature + } + + labelNames := make([]string, 0, len(labels)) + for labelName := range labels { + labelNames = append(labelNames, labelName) + } + sort.Strings(labelNames) + + sum := hashNew() + for _, labelName := range labelNames { + sum = hashAdd(sum, labelName) + sum = hashAddByte(sum, SeparatorByte) + sum = hashAdd(sum, labels[labelName]) + sum = hashAddByte(sum, SeparatorByte) + } + return sum +} + +// labelSetToFingerprint works exactly as LabelsToSignature but takes a LabelSet as +// parameter (rather than a label map) and returns a Fingerprint. +func labelSetToFingerprint(ls LabelSet) Fingerprint { + if len(ls) == 0 { + return Fingerprint(emptyLabelSignature) + } + + labelNames := make(LabelNames, 0, len(ls)) + for labelName := range ls { + labelNames = append(labelNames, labelName) + } + sort.Sort(labelNames) + + sum := hashNew() + for _, labelName := range labelNames { + sum = hashAdd(sum, string(labelName)) + sum = hashAddByte(sum, SeparatorByte) + sum = hashAdd(sum, string(ls[labelName])) + sum = hashAddByte(sum, SeparatorByte) + } + return Fingerprint(sum) +} + +// labelSetToFastFingerprint works similar to labelSetToFingerprint but uses a +// faster and less allocation-heavy hash function, which is more susceptible to +// create hash collisions. Therefore, collision detection should be applied. +func labelSetToFastFingerprint(ls LabelSet) Fingerprint { + if len(ls) == 0 { + return Fingerprint(emptyLabelSignature) + } + + var result uint64 + for labelName, labelValue := range ls { + sum := hashNew() + sum = hashAdd(sum, string(labelName)) + sum = hashAddByte(sum, SeparatorByte) + sum = hashAdd(sum, string(labelValue)) + result ^= sum + } + return Fingerprint(result) +} + +// SignatureForLabels works like LabelsToSignature but takes a Metric as +// parameter (rather than a label map) and only includes the labels with the +// specified LabelNames into the signature calculation. The labels passed in +// will be sorted by this function. +func SignatureForLabels(m Metric, labels ...LabelName) uint64 { + if len(labels) == 0 { + return emptyLabelSignature + } + + sort.Sort(LabelNames(labels)) + + sum := hashNew() + for _, label := range labels { + sum = hashAdd(sum, string(label)) + sum = hashAddByte(sum, SeparatorByte) + sum = hashAdd(sum, string(m[label])) + sum = hashAddByte(sum, SeparatorByte) + } + return sum +} + +// SignatureWithoutLabels works like LabelsToSignature but takes a Metric as +// parameter (rather than a label map) and excludes the labels with any of the +// specified LabelNames from the signature calculation. +func SignatureWithoutLabels(m Metric, labels map[LabelName]struct{}) uint64 { + if len(m) == 0 { + return emptyLabelSignature + } + + labelNames := make(LabelNames, 0, len(m)) + for labelName := range m { + if _, exclude := labels[labelName]; !exclude { + labelNames = append(labelNames, labelName) + } + } + if len(labelNames) == 0 { + return emptyLabelSignature + } + sort.Sort(labelNames) + + sum := hashNew() + for _, labelName := range labelNames { + sum = hashAdd(sum, string(labelName)) + sum = hashAddByte(sum, SeparatorByte) + sum = hashAdd(sum, string(m[labelName])) + sum = hashAddByte(sum, SeparatorByte) + } + return sum +} diff --git a/vendor/github.com/prometheus/common/model/silence.go b/vendor/github.com/prometheus/common/model/silence.go new file mode 100644 index 000000000..7538e2997 --- /dev/null +++ b/vendor/github.com/prometheus/common/model/silence.go @@ -0,0 +1,106 @@ +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +import ( + "encoding/json" + "fmt" + "regexp" + "time" +) + +// Matcher describes a matches the value of a given label. +type Matcher struct { + Name LabelName `json:"name"` + Value string `json:"value"` + IsRegex bool `json:"isRegex"` +} + +func (m *Matcher) UnmarshalJSON(b []byte) error { + type plain Matcher + if err := json.Unmarshal(b, (*plain)(m)); err != nil { + return err + } + + if len(m.Name) == 0 { + return fmt.Errorf("label name in matcher must not be empty") + } + if m.IsRegex { + if _, err := regexp.Compile(m.Value); err != nil { + return err + } + } + return nil +} + +// Validate returns true iff all fields of the matcher have valid values. +func (m *Matcher) Validate() error { + if !m.Name.IsValid() { + return fmt.Errorf("invalid name %q", m.Name) + } + if m.IsRegex { + if _, err := regexp.Compile(m.Value); err != nil { + return fmt.Errorf("invalid regular expression %q", m.Value) + } + } else if !LabelValue(m.Value).IsValid() || len(m.Value) == 0 { + return fmt.Errorf("invalid value %q", m.Value) + } + return nil +} + +// Silence defines the representation of a silence definiton +// in the Prometheus eco-system. +type Silence struct { + ID uint64 `json:"id,omitempty"` + + Matchers []*Matcher `json:"matchers"` + + StartsAt time.Time `json:"startsAt"` + EndsAt time.Time `json:"endsAt"` + + CreatedAt time.Time `json:"createdAt,omitempty"` + CreatedBy string `json:"createdBy"` + Comment string `json:"comment,omitempty"` +} + +// Validate returns true iff all fields of the silence have valid values. +func (s *Silence) Validate() error { + if len(s.Matchers) == 0 { + return fmt.Errorf("at least one matcher required") + } + for _, m := range s.Matchers { + if err := m.Validate(); err != nil { + return fmt.Errorf("invalid matcher: %s", err) + } + } + if s.StartsAt.IsZero() { + return fmt.Errorf("start time missing") + } + if s.EndsAt.IsZero() { + return fmt.Errorf("end time missing") + } + if s.EndsAt.Before(s.StartsAt) { + return fmt.Errorf("start time must be before end time") + } + if s.CreatedBy == "" { + return fmt.Errorf("creator information missing") + } + if s.Comment == "" { + return fmt.Errorf("comment missing") + } + if s.CreatedAt.IsZero() { + return fmt.Errorf("creation timestamp missing") + } + return nil +} diff --git a/vendor/github.com/prometheus/common/model/time.go b/vendor/github.com/prometheus/common/model/time.go new file mode 100644 index 000000000..74ed5a9f7 --- /dev/null +++ b/vendor/github.com/prometheus/common/model/time.go @@ -0,0 +1,264 @@ +// Copyright 2013 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +import ( + "fmt" + "math" + "regexp" + "strconv" + "strings" + "time" +) + +const ( + // MinimumTick is the minimum supported time resolution. This has to be + // at least time.Second in order for the code below to work. + minimumTick = time.Millisecond + // second is the Time duration equivalent to one second. + second = int64(time.Second / minimumTick) + // The number of nanoseconds per minimum tick. + nanosPerTick = int64(minimumTick / time.Nanosecond) + + // Earliest is the earliest Time representable. Handy for + // initializing a high watermark. + Earliest = Time(math.MinInt64) + // Latest is the latest Time representable. Handy for initializing + // a low watermark. + Latest = Time(math.MaxInt64) +) + +// Time is the number of milliseconds since the epoch +// (1970-01-01 00:00 UTC) excluding leap seconds. +type Time int64 + +// Interval describes and interval between two timestamps. +type Interval struct { + Start, End Time +} + +// Now returns the current time as a Time. +func Now() Time { + return TimeFromUnixNano(time.Now().UnixNano()) +} + +// TimeFromUnix returns the Time equivalent to the Unix Time t +// provided in seconds. +func TimeFromUnix(t int64) Time { + return Time(t * second) +} + +// TimeFromUnixNano returns the Time equivalent to the Unix Time +// t provided in nanoseconds. +func TimeFromUnixNano(t int64) Time { + return Time(t / nanosPerTick) +} + +// Equal reports whether two Times represent the same instant. +func (t Time) Equal(o Time) bool { + return t == o +} + +// Before reports whether the Time t is before o. +func (t Time) Before(o Time) bool { + return t < o +} + +// After reports whether the Time t is after o. +func (t Time) After(o Time) bool { + return t > o +} + +// Add returns the Time t + d. +func (t Time) Add(d time.Duration) Time { + return t + Time(d/minimumTick) +} + +// Sub returns the Duration t - o. +func (t Time) Sub(o Time) time.Duration { + return time.Duration(t-o) * minimumTick +} + +// Time returns the time.Time representation of t. +func (t Time) Time() time.Time { + return time.Unix(int64(t)/second, (int64(t)%second)*nanosPerTick) +} + +// Unix returns t as a Unix time, the number of seconds elapsed +// since January 1, 1970 UTC. +func (t Time) Unix() int64 { + return int64(t) / second +} + +// UnixNano returns t as a Unix time, the number of nanoseconds elapsed +// since January 1, 1970 UTC. +func (t Time) UnixNano() int64 { + return int64(t) * nanosPerTick +} + +// The number of digits after the dot. +var dotPrecision = int(math.Log10(float64(second))) + +// String returns a string representation of the Time. +func (t Time) String() string { + return strconv.FormatFloat(float64(t)/float64(second), 'f', -1, 64) +} + +// MarshalJSON implements the json.Marshaler interface. +func (t Time) MarshalJSON() ([]byte, error) { + return []byte(t.String()), nil +} + +// UnmarshalJSON implements the json.Unmarshaler interface. +func (t *Time) UnmarshalJSON(b []byte) error { + p := strings.Split(string(b), ".") + switch len(p) { + case 1: + v, err := strconv.ParseInt(string(p[0]), 10, 64) + if err != nil { + return err + } + *t = Time(v * second) + + case 2: + v, err := strconv.ParseInt(string(p[0]), 10, 64) + if err != nil { + return err + } + v *= second + + prec := dotPrecision - len(p[1]) + if prec < 0 { + p[1] = p[1][:dotPrecision] + } else if prec > 0 { + p[1] = p[1] + strings.Repeat("0", prec) + } + + va, err := strconv.ParseInt(p[1], 10, 32) + if err != nil { + return err + } + + *t = Time(v + va) + + default: + return fmt.Errorf("invalid time %q", string(b)) + } + return nil +} + +// Duration wraps time.Duration. It is used to parse the custom duration format +// from YAML. +// This type should not propagate beyond the scope of input/output processing. +type Duration time.Duration + +// Set implements pflag/flag.Value +func (d *Duration) Set(s string) error { + var err error + *d, err = ParseDuration(s) + return err +} + +// Type implements pflag.Value +func (d *Duration) Type() string { + return "duration" +} + +var durationRE = regexp.MustCompile("^([0-9]+)(y|w|d|h|m|s|ms)$") + +// ParseDuration parses a string into a time.Duration, assuming that a year +// always has 365d, a week always has 7d, and a day always has 24h. +func ParseDuration(durationStr string) (Duration, error) { + matches := durationRE.FindStringSubmatch(durationStr) + if len(matches) != 3 { + return 0, fmt.Errorf("not a valid duration string: %q", durationStr) + } + var ( + n, _ = strconv.Atoi(matches[1]) + dur = time.Duration(n) * time.Millisecond + ) + switch unit := matches[2]; unit { + case "y": + dur *= 1000 * 60 * 60 * 24 * 365 + case "w": + dur *= 1000 * 60 * 60 * 24 * 7 + case "d": + dur *= 1000 * 60 * 60 * 24 + case "h": + dur *= 1000 * 60 * 60 + case "m": + dur *= 1000 * 60 + case "s": + dur *= 1000 + case "ms": + // Value already correct + default: + return 0, fmt.Errorf("invalid time unit in duration string: %q", unit) + } + return Duration(dur), nil +} + +func (d Duration) String() string { + var ( + ms = int64(time.Duration(d) / time.Millisecond) + unit = "ms" + ) + if ms == 0 { + return "0s" + } + factors := map[string]int64{ + "y": 1000 * 60 * 60 * 24 * 365, + "w": 1000 * 60 * 60 * 24 * 7, + "d": 1000 * 60 * 60 * 24, + "h": 1000 * 60 * 60, + "m": 1000 * 60, + "s": 1000, + "ms": 1, + } + + switch int64(0) { + case ms % factors["y"]: + unit = "y" + case ms % factors["w"]: + unit = "w" + case ms % factors["d"]: + unit = "d" + case ms % factors["h"]: + unit = "h" + case ms % factors["m"]: + unit = "m" + case ms % factors["s"]: + unit = "s" + } + return fmt.Sprintf("%v%v", ms/factors[unit], unit) +} + +// MarshalYAML implements the yaml.Marshaler interface. +func (d Duration) MarshalYAML() (interface{}, error) { + return d.String(), nil +} + +// UnmarshalYAML implements the yaml.Unmarshaler interface. +func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + dur, err := ParseDuration(s) + if err != nil { + return err + } + *d = dur + return nil +} diff --git a/vendor/github.com/prometheus/common/model/value.go b/vendor/github.com/prometheus/common/model/value.go new file mode 100644 index 000000000..c9ed3ffd8 --- /dev/null +++ b/vendor/github.com/prometheus/common/model/value.go @@ -0,0 +1,416 @@ +// Copyright 2013 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package model + +import ( + "encoding/json" + "fmt" + "math" + "sort" + "strconv" + "strings" +) + +var ( + // ZeroSamplePair is the pseudo zero-value of SamplePair used to signal a + // non-existing sample pair. It is a SamplePair with timestamp Earliest and + // value 0.0. Note that the natural zero value of SamplePair has a timestamp + // of 0, which is possible to appear in a real SamplePair and thus not + // suitable to signal a non-existing SamplePair. + ZeroSamplePair = SamplePair{Timestamp: Earliest} + + // ZeroSample is the pseudo zero-value of Sample used to signal a + // non-existing sample. It is a Sample with timestamp Earliest, value 0.0, + // and metric nil. Note that the natural zero value of Sample has a timestamp + // of 0, which is possible to appear in a real Sample and thus not suitable + // to signal a non-existing Sample. + ZeroSample = Sample{Timestamp: Earliest} +) + +// A SampleValue is a representation of a value for a given sample at a given +// time. +type SampleValue float64 + +// MarshalJSON implements json.Marshaler. +func (v SampleValue) MarshalJSON() ([]byte, error) { + return json.Marshal(v.String()) +} + +// UnmarshalJSON implements json.Unmarshaler. +func (v *SampleValue) UnmarshalJSON(b []byte) error { + if len(b) < 2 || b[0] != '"' || b[len(b)-1] != '"' { + return fmt.Errorf("sample value must be a quoted string") + } + f, err := strconv.ParseFloat(string(b[1:len(b)-1]), 64) + if err != nil { + return err + } + *v = SampleValue(f) + return nil +} + +// Equal returns true if the value of v and o is equal or if both are NaN. Note +// that v==o is false if both are NaN. If you want the conventional float +// behavior, use == to compare two SampleValues. +func (v SampleValue) Equal(o SampleValue) bool { + if v == o { + return true + } + return math.IsNaN(float64(v)) && math.IsNaN(float64(o)) +} + +func (v SampleValue) String() string { + return strconv.FormatFloat(float64(v), 'f', -1, 64) +} + +// SamplePair pairs a SampleValue with a Timestamp. +type SamplePair struct { + Timestamp Time + Value SampleValue +} + +// MarshalJSON implements json.Marshaler. +func (s SamplePair) MarshalJSON() ([]byte, error) { + t, err := json.Marshal(s.Timestamp) + if err != nil { + return nil, err + } + v, err := json.Marshal(s.Value) + if err != nil { + return nil, err + } + return []byte(fmt.Sprintf("[%s,%s]", t, v)), nil +} + +// UnmarshalJSON implements json.Unmarshaler. +func (s *SamplePair) UnmarshalJSON(b []byte) error { + v := [...]json.Unmarshaler{&s.Timestamp, &s.Value} + return json.Unmarshal(b, &v) +} + +// Equal returns true if this SamplePair and o have equal Values and equal +// Timestamps. The sematics of Value equality is defined by SampleValue.Equal. +func (s *SamplePair) Equal(o *SamplePair) bool { + return s == o || (s.Value.Equal(o.Value) && s.Timestamp.Equal(o.Timestamp)) +} + +func (s SamplePair) String() string { + return fmt.Sprintf("%s @[%s]", s.Value, s.Timestamp) +} + +// Sample is a sample pair associated with a metric. +type Sample struct { + Metric Metric `json:"metric"` + Value SampleValue `json:"value"` + Timestamp Time `json:"timestamp"` +} + +// Equal compares first the metrics, then the timestamp, then the value. The +// sematics of value equality is defined by SampleValue.Equal. +func (s *Sample) Equal(o *Sample) bool { + if s == o { + return true + } + + if !s.Metric.Equal(o.Metric) { + return false + } + if !s.Timestamp.Equal(o.Timestamp) { + return false + } + + return s.Value.Equal(o.Value) +} + +func (s Sample) String() string { + return fmt.Sprintf("%s => %s", s.Metric, SamplePair{ + Timestamp: s.Timestamp, + Value: s.Value, + }) +} + +// MarshalJSON implements json.Marshaler. +func (s Sample) MarshalJSON() ([]byte, error) { + v := struct { + Metric Metric `json:"metric"` + Value SamplePair `json:"value"` + }{ + Metric: s.Metric, + Value: SamplePair{ + Timestamp: s.Timestamp, + Value: s.Value, + }, + } + + return json.Marshal(&v) +} + +// UnmarshalJSON implements json.Unmarshaler. +func (s *Sample) UnmarshalJSON(b []byte) error { + v := struct { + Metric Metric `json:"metric"` + Value SamplePair `json:"value"` + }{ + Metric: s.Metric, + Value: SamplePair{ + Timestamp: s.Timestamp, + Value: s.Value, + }, + } + + if err := json.Unmarshal(b, &v); err != nil { + return err + } + + s.Metric = v.Metric + s.Timestamp = v.Value.Timestamp + s.Value = v.Value.Value + + return nil +} + +// Samples is a sortable Sample slice. It implements sort.Interface. +type Samples []*Sample + +func (s Samples) Len() int { + return len(s) +} + +// Less compares first the metrics, then the timestamp. +func (s Samples) Less(i, j int) bool { + switch { + case s[i].Metric.Before(s[j].Metric): + return true + case s[j].Metric.Before(s[i].Metric): + return false + case s[i].Timestamp.Before(s[j].Timestamp): + return true + default: + return false + } +} + +func (s Samples) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Equal compares two sets of samples and returns true if they are equal. +func (s Samples) Equal(o Samples) bool { + if len(s) != len(o) { + return false + } + + for i, sample := range s { + if !sample.Equal(o[i]) { + return false + } + } + return true +} + +// SampleStream is a stream of Values belonging to an attached COWMetric. +type SampleStream struct { + Metric Metric `json:"metric"` + Values []SamplePair `json:"values"` +} + +func (ss SampleStream) String() string { + vals := make([]string, len(ss.Values)) + for i, v := range ss.Values { + vals[i] = v.String() + } + return fmt.Sprintf("%s =>\n%s", ss.Metric, strings.Join(vals, "\n")) +} + +// Value is a generic interface for values resulting from a query evaluation. +type Value interface { + Type() ValueType + String() string +} + +func (Matrix) Type() ValueType { return ValMatrix } +func (Vector) Type() ValueType { return ValVector } +func (*Scalar) Type() ValueType { return ValScalar } +func (*String) Type() ValueType { return ValString } + +type ValueType int + +const ( + ValNone ValueType = iota + ValScalar + ValVector + ValMatrix + ValString +) + +// MarshalJSON implements json.Marshaler. +func (et ValueType) MarshalJSON() ([]byte, error) { + return json.Marshal(et.String()) +} + +func (et *ValueType) UnmarshalJSON(b []byte) error { + var s string + if err := json.Unmarshal(b, &s); err != nil { + return err + } + switch s { + case "": + *et = ValNone + case "scalar": + *et = ValScalar + case "vector": + *et = ValVector + case "matrix": + *et = ValMatrix + case "string": + *et = ValString + default: + return fmt.Errorf("unknown value type %q", s) + } + return nil +} + +func (e ValueType) String() string { + switch e { + case ValNone: + return "" + case ValScalar: + return "scalar" + case ValVector: + return "vector" + case ValMatrix: + return "matrix" + case ValString: + return "string" + } + panic("ValueType.String: unhandled value type") +} + +// Scalar is a scalar value evaluated at the set timestamp. +type Scalar struct { + Value SampleValue `json:"value"` + Timestamp Time `json:"timestamp"` +} + +func (s Scalar) String() string { + return fmt.Sprintf("scalar: %v @[%v]", s.Value, s.Timestamp) +} + +// MarshalJSON implements json.Marshaler. +func (s Scalar) MarshalJSON() ([]byte, error) { + v := strconv.FormatFloat(float64(s.Value), 'f', -1, 64) + return json.Marshal([...]interface{}{s.Timestamp, string(v)}) +} + +// UnmarshalJSON implements json.Unmarshaler. +func (s *Scalar) UnmarshalJSON(b []byte) error { + var f string + v := [...]interface{}{&s.Timestamp, &f} + + if err := json.Unmarshal(b, &v); err != nil { + return err + } + + value, err := strconv.ParseFloat(f, 64) + if err != nil { + return fmt.Errorf("error parsing sample value: %s", err) + } + s.Value = SampleValue(value) + return nil +} + +// String is a string value evaluated at the set timestamp. +type String struct { + Value string `json:"value"` + Timestamp Time `json:"timestamp"` +} + +func (s *String) String() string { + return s.Value +} + +// MarshalJSON implements json.Marshaler. +func (s String) MarshalJSON() ([]byte, error) { + return json.Marshal([]interface{}{s.Timestamp, s.Value}) +} + +// UnmarshalJSON implements json.Unmarshaler. +func (s *String) UnmarshalJSON(b []byte) error { + v := [...]interface{}{&s.Timestamp, &s.Value} + return json.Unmarshal(b, &v) +} + +// Vector is basically only an alias for Samples, but the +// contract is that in a Vector, all Samples have the same timestamp. +type Vector []*Sample + +func (vec Vector) String() string { + entries := make([]string, len(vec)) + for i, s := range vec { + entries[i] = s.String() + } + return strings.Join(entries, "\n") +} + +func (vec Vector) Len() int { return len(vec) } +func (vec Vector) Swap(i, j int) { vec[i], vec[j] = vec[j], vec[i] } + +// Less compares first the metrics, then the timestamp. +func (vec Vector) Less(i, j int) bool { + switch { + case vec[i].Metric.Before(vec[j].Metric): + return true + case vec[j].Metric.Before(vec[i].Metric): + return false + case vec[i].Timestamp.Before(vec[j].Timestamp): + return true + default: + return false + } +} + +// Equal compares two sets of samples and returns true if they are equal. +func (vec Vector) Equal(o Vector) bool { + if len(vec) != len(o) { + return false + } + + for i, sample := range vec { + if !sample.Equal(o[i]) { + return false + } + } + return true +} + +// Matrix is a list of time series. +type Matrix []*SampleStream + +func (m Matrix) Len() int { return len(m) } +func (m Matrix) Less(i, j int) bool { return m[i].Metric.Before(m[j].Metric) } +func (m Matrix) Swap(i, j int) { m[i], m[j] = m[j], m[i] } + +func (mat Matrix) String() string { + matCp := make(Matrix, len(mat)) + copy(matCp, mat) + sort.Sort(matCp) + + strs := make([]string, len(matCp)) + + for i, ss := range matCp { + strs[i] = ss.String() + } + + return strings.Join(strs, "\n") +} diff --git a/vendor/github.com/prometheus/procfs/LICENSE b/vendor/github.com/prometheus/procfs/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/prometheus/procfs/bcache/bcache.go b/vendor/github.com/prometheus/procfs/bcache/bcache.go new file mode 100644 index 000000000..1db178cec --- /dev/null +++ b/vendor/github.com/prometheus/procfs/bcache/bcache.go @@ -0,0 +1,84 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package bcache provides access to statistics exposed by the bcache (Linux +// block cache). +package bcache + +// Stats contains bcache runtime statistics, parsed from /sys/fs/bcache/. +// +// The names and meanings of each statistic were taken from bcache.txt and +// files in drivers/md/bcache in the Linux kernel source. Counters are uint64 +// (in-kernel counters are mostly unsigned long). +type Stats struct { + // The name of the bcache used to source these statistics. + Name string + Bcache BcacheStats + Bdevs []BdevStats + Caches []CacheStats +} + +// BcacheStats contains statistics tied to a bcache ID. +type BcacheStats struct { + AverageKeySize uint64 + BtreeCacheSize uint64 + CacheAvailablePercent uint64 + Congested uint64 + RootUsagePercent uint64 + TreeDepth uint64 + Internal InternalStats + FiveMin PeriodStats + Total PeriodStats +} + +// BdevStats contains statistics for one backing device. +type BdevStats struct { + Name string + DirtyData uint64 + FiveMin PeriodStats + Total PeriodStats +} + +// CacheStats contains statistics for one cache device. +type CacheStats struct { + Name string + IOErrors uint64 + MetadataWritten uint64 + Written uint64 + Priority PriorityStats +} + +// PriorityStats contains statistics from the priority_stats file. +type PriorityStats struct { + UnusedPercent uint64 + MetadataPercent uint64 +} + +// InternalStats contains internal bcache statistics. +type InternalStats struct { + ActiveJournalEntries uint64 + BtreeNodes uint64 + BtreeReadAverageDurationNanoSeconds uint64 + CacheReadRaces uint64 +} + +// PeriodStats contains statistics for a time period (5 min or total). +type PeriodStats struct { + Bypassed uint64 + CacheBypassHits uint64 + CacheBypassMisses uint64 + CacheHits uint64 + CacheMissCollisions uint64 + CacheMisses uint64 + CacheReadaheads uint64 +} diff --git a/vendor/github.com/prometheus/procfs/bcache/get.go b/vendor/github.com/prometheus/procfs/bcache/get.go new file mode 100644 index 000000000..b6d97de15 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/bcache/get.go @@ -0,0 +1,330 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package bcache + +import ( + "bufio" + "fmt" + "io/ioutil" + "os" + "path" + "path/filepath" + "strconv" + "strings" +) + +// ParsePseudoFloat parses the peculiar format produced by bcache's bch_hprint. +func parsePseudoFloat(str string) (float64, error) { + ss := strings.Split(str, ".") + + intPart, err := strconv.ParseFloat(ss[0], 64) + if err != nil { + return 0, err + } + + if len(ss) == 1 { + // Pure integers are fine. + return intPart, nil + } + fracPart, err := strconv.ParseFloat(ss[1], 64) + if err != nil { + return 0, err + } + // fracPart is a number between 0 and 1023 divided by 100; it is off + // by a small amount. Unexpected bumps in time lines may occur because + // for bch_hprint .1 != .10 and .10 > .9 (at least up to Linux + // v4.12-rc3). + + // Restore the proper order: + fracPart = fracPart / 10.24 + return intPart + fracPart, nil +} + +// Dehumanize converts a human-readable byte slice into a uint64. +func dehumanize(hbytes []byte) (uint64, error) { + ll := len(hbytes) + if ll == 0 { + return 0, fmt.Errorf("zero-length reply") + } + lastByte := hbytes[ll-1] + mul := float64(1) + var ( + mant float64 + err error + ) + // If lastByte is beyond the range of ASCII digits, it must be a + // multiplier. + if lastByte > 57 { + // Remove multiplier from slice. + hbytes = hbytes[:len(hbytes)-1] + + const ( + _ = 1 << (10 * iota) + KiB + MiB + GiB + TiB + PiB + EiB + ZiB + YiB + ) + + multipliers := map[rune]float64{ + // Source for conversion rules: + // linux-kernel/drivers/md/bcache/util.c:bch_hprint() + 'k': KiB, + 'M': MiB, + 'G': GiB, + 'T': TiB, + 'P': PiB, + 'E': EiB, + 'Z': ZiB, + 'Y': YiB, + } + mul = multipliers[rune(lastByte)] + mant, err = parsePseudoFloat(string(hbytes)) + if err != nil { + return 0, err + } + } else { + // Not humanized by bch_hprint + mant, err = strconv.ParseFloat(string(hbytes), 64) + if err != nil { + return 0, err + } + } + res := uint64(mant * mul) + return res, nil +} + +type parser struct { + uuidPath string + subDir string + currentDir string + err error +} + +func (p *parser) setSubDir(pathElements ...string) { + p.subDir = path.Join(pathElements...) + p.currentDir = path.Join(p.uuidPath, p.subDir) +} + +func (p *parser) readValue(fileName string) uint64 { + if p.err != nil { + return 0 + } + path := path.Join(p.currentDir, fileName) + byt, err := ioutil.ReadFile(path) + if err != nil { + p.err = fmt.Errorf("failed to read: %s", path) + return 0 + } + // Remove trailing newline. + byt = byt[:len(byt)-1] + res, err := dehumanize(byt) + p.err = err + return res +} + +// ParsePriorityStats parses lines from the priority_stats file. +func parsePriorityStats(line string, ps *PriorityStats) error { + var ( + value uint64 + err error + ) + switch { + case strings.HasPrefix(line, "Unused:"): + fields := strings.Fields(line) + rawValue := fields[len(fields)-1] + valueStr := strings.TrimSuffix(rawValue, "%") + value, err = strconv.ParseUint(valueStr, 10, 64) + if err != nil { + return err + } + ps.UnusedPercent = value + case strings.HasPrefix(line, "Metadata:"): + fields := strings.Fields(line) + rawValue := fields[len(fields)-1] + valueStr := strings.TrimSuffix(rawValue, "%") + value, err = strconv.ParseUint(valueStr, 10, 64) + if err != nil { + return err + } + ps.MetadataPercent = value + } + return nil +} + +func (p *parser) getPriorityStats() PriorityStats { + var res PriorityStats + + if p.err != nil { + return res + } + + path := path.Join(p.currentDir, "priority_stats") + + file, err := os.Open(path) + if err != nil { + p.err = fmt.Errorf("failed to read: %s", path) + return res + } + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + err = parsePriorityStats(scanner.Text(), &res) + if err != nil { + p.err = fmt.Errorf("failed to parse: %s (%s)", path, err) + return res + } + } + if err := scanner.Err(); err != nil { + p.err = fmt.Errorf("failed to parse: %s (%s)", path, err) + return res + } + return res +} + +// GetStats collects from sysfs files data tied to one bcache ID. +func GetStats(uuidPath string) (*Stats, error) { + var bs Stats + + par := parser{uuidPath: uuidPath} + + // bcache stats + + // dir + par.setSubDir("") + bs.Bcache.AverageKeySize = par.readValue("average_key_size") + bs.Bcache.BtreeCacheSize = par.readValue("btree_cache_size") + bs.Bcache.CacheAvailablePercent = par.readValue("cache_available_percent") + bs.Bcache.Congested = par.readValue("congested") + bs.Bcache.RootUsagePercent = par.readValue("root_usage_percent") + bs.Bcache.TreeDepth = par.readValue("tree_depth") + + // bcache stats (internal) + + // dir /internal + par.setSubDir("internal") + bs.Bcache.Internal.ActiveJournalEntries = par.readValue("active_journal_entries") + bs.Bcache.Internal.BtreeNodes = par.readValue("btree_nodes") + bs.Bcache.Internal.BtreeReadAverageDurationNanoSeconds = par.readValue("btree_read_average_duration_us") + bs.Bcache.Internal.CacheReadRaces = par.readValue("cache_read_races") + + // bcache stats (period) + + // dir /stats_five_minute + par.setSubDir("stats_five_minute") + bs.Bcache.FiveMin.Bypassed = par.readValue("bypassed") + bs.Bcache.FiveMin.CacheHits = par.readValue("cache_hits") + + bs.Bcache.FiveMin.Bypassed = par.readValue("bypassed") + bs.Bcache.FiveMin.CacheBypassHits = par.readValue("cache_bypass_hits") + bs.Bcache.FiveMin.CacheBypassMisses = par.readValue("cache_bypass_misses") + bs.Bcache.FiveMin.CacheHits = par.readValue("cache_hits") + bs.Bcache.FiveMin.CacheMissCollisions = par.readValue("cache_miss_collisions") + bs.Bcache.FiveMin.CacheMisses = par.readValue("cache_misses") + bs.Bcache.FiveMin.CacheReadaheads = par.readValue("cache_readaheads") + + // dir /stats_total + par.setSubDir("stats_total") + bs.Bcache.Total.Bypassed = par.readValue("bypassed") + bs.Bcache.Total.CacheHits = par.readValue("cache_hits") + + bs.Bcache.Total.Bypassed = par.readValue("bypassed") + bs.Bcache.Total.CacheBypassHits = par.readValue("cache_bypass_hits") + bs.Bcache.Total.CacheBypassMisses = par.readValue("cache_bypass_misses") + bs.Bcache.Total.CacheHits = par.readValue("cache_hits") + bs.Bcache.Total.CacheMissCollisions = par.readValue("cache_miss_collisions") + bs.Bcache.Total.CacheMisses = par.readValue("cache_misses") + bs.Bcache.Total.CacheReadaheads = par.readValue("cache_readaheads") + + if par.err != nil { + return nil, par.err + } + + // bdev stats + + reg := path.Join(uuidPath, "bdev[0-9]*") + bdevDirs, err := filepath.Glob(reg) + if err != nil { + return nil, err + } + + bs.Bdevs = make([]BdevStats, len(bdevDirs)) + + for ii, bdevDir := range bdevDirs { + var bds = &bs.Bdevs[ii] + + bds.Name = filepath.Base(bdevDir) + + par.setSubDir(bds.Name) + bds.DirtyData = par.readValue("dirty_data") + + // dir //stats_five_minute + par.setSubDir(bds.Name, "stats_five_minute") + bds.FiveMin.Bypassed = par.readValue("bypassed") + bds.FiveMin.CacheBypassHits = par.readValue("cache_bypass_hits") + bds.FiveMin.CacheBypassMisses = par.readValue("cache_bypass_misses") + bds.FiveMin.CacheHits = par.readValue("cache_hits") + bds.FiveMin.CacheMissCollisions = par.readValue("cache_miss_collisions") + bds.FiveMin.CacheMisses = par.readValue("cache_misses") + bds.FiveMin.CacheReadaheads = par.readValue("cache_readaheads") + + // dir //stats_total + par.setSubDir("stats_total") + bds.Total.Bypassed = par.readValue("bypassed") + bds.Total.CacheBypassHits = par.readValue("cache_bypass_hits") + bds.Total.CacheBypassMisses = par.readValue("cache_bypass_misses") + bds.Total.CacheHits = par.readValue("cache_hits") + bds.Total.CacheMissCollisions = par.readValue("cache_miss_collisions") + bds.Total.CacheMisses = par.readValue("cache_misses") + bds.Total.CacheReadaheads = par.readValue("cache_readaheads") + } + + if par.err != nil { + return nil, par.err + } + + // cache stats + + reg = path.Join(uuidPath, "cache[0-9]*") + cacheDirs, err := filepath.Glob(reg) + if err != nil { + return nil, err + } + bs.Caches = make([]CacheStats, len(cacheDirs)) + + for ii, cacheDir := range cacheDirs { + var cs = &bs.Caches[ii] + cs.Name = filepath.Base(cacheDir) + + // dir is / + par.setSubDir(cs.Name) + cs.IOErrors = par.readValue("io_errors") + cs.MetadataWritten = par.readValue("metadata_written") + cs.Written = par.readValue("written") + + ps := par.getPriorityStats() + cs.Priority = ps + } + + if par.err != nil { + return nil, par.err + } + + return &bs, nil +} diff --git a/vendor/github.com/prometheus/procfs/buddyinfo.go b/vendor/github.com/prometheus/procfs/buddyinfo.go new file mode 100644 index 000000000..d3a826807 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/buddyinfo.go @@ -0,0 +1,95 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package procfs + +import ( + "bufio" + "fmt" + "io" + "os" + "strconv" + "strings" +) + +// A BuddyInfo is the details parsed from /proc/buddyinfo. +// The data is comprised of an array of free fragments of each size. +// The sizes are 2^n*PAGE_SIZE, where n is the array index. +type BuddyInfo struct { + Node string + Zone string + Sizes []float64 +} + +// NewBuddyInfo reads the buddyinfo statistics. +func NewBuddyInfo() ([]BuddyInfo, error) { + fs, err := NewFS(DefaultMountPoint) + if err != nil { + return nil, err + } + + return fs.NewBuddyInfo() +} + +// NewBuddyInfo reads the buddyinfo statistics from the specified `proc` filesystem. +func (fs FS) NewBuddyInfo() ([]BuddyInfo, error) { + file, err := os.Open(fs.Path("buddyinfo")) + if err != nil { + return nil, err + } + defer file.Close() + + return parseBuddyInfo(file) +} + +func parseBuddyInfo(r io.Reader) ([]BuddyInfo, error) { + var ( + buddyInfo = []BuddyInfo{} + scanner = bufio.NewScanner(r) + bucketCount = -1 + ) + + for scanner.Scan() { + var err error + line := scanner.Text() + parts := strings.Fields(line) + + if len(parts) < 4 { + return nil, fmt.Errorf("invalid number of fields when parsing buddyinfo") + } + + node := strings.TrimRight(parts[1], ",") + zone := strings.TrimRight(parts[3], ",") + arraySize := len(parts[4:]) + + if bucketCount == -1 { + bucketCount = arraySize + } else { + if bucketCount != arraySize { + return nil, fmt.Errorf("mismatch in number of buddyinfo buckets, previous count %d, new count %d", bucketCount, arraySize) + } + } + + sizes := make([]float64, arraySize) + for i := 0; i < arraySize; i++ { + sizes[i], err = strconv.ParseFloat(parts[i+4], 64) + if err != nil { + return nil, fmt.Errorf("invalid value in buddyinfo: %s", err) + } + } + + buddyInfo = append(buddyInfo, BuddyInfo{node, zone, sizes}) + } + + return buddyInfo, scanner.Err() +} diff --git a/vendor/github.com/prometheus/procfs/doc.go b/vendor/github.com/prometheus/procfs/doc.go new file mode 100644 index 000000000..e2acd6d40 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/doc.go @@ -0,0 +1,45 @@ +// Copyright 2014 Prometheus Team +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package procfs provides functions to retrieve system, kernel and process +// metrics from the pseudo-filesystem proc. +// +// Example: +// +// package main +// +// import ( +// "fmt" +// "log" +// +// "github.com/prometheus/procfs" +// ) +// +// func main() { +// p, err := procfs.Self() +// if err != nil { +// log.Fatalf("could not get process: %s", err) +// } +// +// stat, err := p.NewStat() +// if err != nil { +// log.Fatalf("could not get process stat: %s", err) +// } +// +// fmt.Printf("command: %s\n", stat.Comm) +// fmt.Printf("cpu time: %fs\n", stat.CPUTime()) +// fmt.Printf("vsize: %dB\n", stat.VirtualMemory()) +// fmt.Printf("rss: %dB\n", stat.ResidentMemory()) +// } +// +package procfs diff --git a/vendor/github.com/prometheus/procfs/fs.go b/vendor/github.com/prometheus/procfs/fs.go new file mode 100644 index 000000000..17546756b --- /dev/null +++ b/vendor/github.com/prometheus/procfs/fs.go @@ -0,0 +1,46 @@ +package procfs + +import ( + "fmt" + "os" + "path" + + "github.com/prometheus/procfs/xfs" +) + +// FS represents the pseudo-filesystem proc, which provides an interface to +// kernel data structures. +type FS string + +// DefaultMountPoint is the common mount point of the proc filesystem. +const DefaultMountPoint = "/proc" + +// NewFS returns a new FS mounted under the given mountPoint. It will error +// if the mount point can't be read. +func NewFS(mountPoint string) (FS, error) { + info, err := os.Stat(mountPoint) + if err != nil { + return "", fmt.Errorf("could not read %s: %s", mountPoint, err) + } + if !info.IsDir() { + return "", fmt.Errorf("mount point %s is not a directory", mountPoint) + } + + return FS(mountPoint), nil +} + +// Path returns the path of the given subsystem relative to the procfs root. +func (fs FS) Path(p ...string) string { + return path.Join(append([]string{string(fs)}, p...)...) +} + +// XFSStats retrieves XFS filesystem runtime statistics. +func (fs FS) XFSStats() (*xfs.Stats, error) { + f, err := os.Open(fs.Path("fs/xfs/stat")) + if err != nil { + return nil, err + } + defer f.Close() + + return xfs.ParseStats(f) +} diff --git a/vendor/github.com/prometheus/procfs/ipvs.go b/vendor/github.com/prometheus/procfs/ipvs.go new file mode 100644 index 000000000..5761b4570 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/ipvs.go @@ -0,0 +1,246 @@ +package procfs + +import ( + "bufio" + "encoding/hex" + "errors" + "fmt" + "io" + "io/ioutil" + "net" + "os" + "strconv" + "strings" +) + +// IPVSStats holds IPVS statistics, as exposed by the kernel in `/proc/net/ip_vs_stats`. +type IPVSStats struct { + // Total count of connections. + Connections uint64 + // Total incoming packages processed. + IncomingPackets uint64 + // Total outgoing packages processed. + OutgoingPackets uint64 + // Total incoming traffic. + IncomingBytes uint64 + // Total outgoing traffic. + OutgoingBytes uint64 +} + +// IPVSBackendStatus holds current metrics of one virtual / real address pair. +type IPVSBackendStatus struct { + // The local (virtual) IP address. + LocalAddress net.IP + // The remote (real) IP address. + RemoteAddress net.IP + // The local (virtual) port. + LocalPort uint16 + // The remote (real) port. + RemotePort uint16 + // The local firewall mark + LocalMark string + // The transport protocol (TCP, UDP). + Proto string + // The current number of active connections for this virtual/real address pair. + ActiveConn uint64 + // The current number of inactive connections for this virtual/real address pair. + InactConn uint64 + // The current weight of this virtual/real address pair. + Weight uint64 +} + +// NewIPVSStats reads the IPVS statistics. +func NewIPVSStats() (IPVSStats, error) { + fs, err := NewFS(DefaultMountPoint) + if err != nil { + return IPVSStats{}, err + } + + return fs.NewIPVSStats() +} + +// NewIPVSStats reads the IPVS statistics from the specified `proc` filesystem. +func (fs FS) NewIPVSStats() (IPVSStats, error) { + file, err := os.Open(fs.Path("net/ip_vs_stats")) + if err != nil { + return IPVSStats{}, err + } + defer file.Close() + + return parseIPVSStats(file) +} + +// parseIPVSStats performs the actual parsing of `ip_vs_stats`. +func parseIPVSStats(file io.Reader) (IPVSStats, error) { + var ( + statContent []byte + statLines []string + statFields []string + stats IPVSStats + ) + + statContent, err := ioutil.ReadAll(file) + if err != nil { + return IPVSStats{}, err + } + + statLines = strings.SplitN(string(statContent), "\n", 4) + if len(statLines) != 4 { + return IPVSStats{}, errors.New("ip_vs_stats corrupt: too short") + } + + statFields = strings.Fields(statLines[2]) + if len(statFields) != 5 { + return IPVSStats{}, errors.New("ip_vs_stats corrupt: unexpected number of fields") + } + + stats.Connections, err = strconv.ParseUint(statFields[0], 16, 64) + if err != nil { + return IPVSStats{}, err + } + stats.IncomingPackets, err = strconv.ParseUint(statFields[1], 16, 64) + if err != nil { + return IPVSStats{}, err + } + stats.OutgoingPackets, err = strconv.ParseUint(statFields[2], 16, 64) + if err != nil { + return IPVSStats{}, err + } + stats.IncomingBytes, err = strconv.ParseUint(statFields[3], 16, 64) + if err != nil { + return IPVSStats{}, err + } + stats.OutgoingBytes, err = strconv.ParseUint(statFields[4], 16, 64) + if err != nil { + return IPVSStats{}, err + } + + return stats, nil +} + +// NewIPVSBackendStatus reads and returns the status of all (virtual,real) server pairs. +func NewIPVSBackendStatus() ([]IPVSBackendStatus, error) { + fs, err := NewFS(DefaultMountPoint) + if err != nil { + return []IPVSBackendStatus{}, err + } + + return fs.NewIPVSBackendStatus() +} + +// NewIPVSBackendStatus reads and returns the status of all (virtual,real) server pairs from the specified `proc` filesystem. +func (fs FS) NewIPVSBackendStatus() ([]IPVSBackendStatus, error) { + file, err := os.Open(fs.Path("net/ip_vs")) + if err != nil { + return nil, err + } + defer file.Close() + + return parseIPVSBackendStatus(file) +} + +func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) { + var ( + status []IPVSBackendStatus + scanner = bufio.NewScanner(file) + proto string + localMark string + localAddress net.IP + localPort uint16 + err error + ) + + for scanner.Scan() { + fields := strings.Fields(scanner.Text()) + if len(fields) == 0 { + continue + } + switch { + case fields[0] == "IP" || fields[0] == "Prot" || fields[1] == "RemoteAddress:Port": + continue + case fields[0] == "TCP" || fields[0] == "UDP": + if len(fields) < 2 { + continue + } + proto = fields[0] + localMark = "" + localAddress, localPort, err = parseIPPort(fields[1]) + if err != nil { + return nil, err + } + case fields[0] == "FWM": + if len(fields) < 2 { + continue + } + proto = fields[0] + localMark = fields[1] + localAddress = nil + localPort = 0 + case fields[0] == "->": + if len(fields) < 6 { + continue + } + remoteAddress, remotePort, err := parseIPPort(fields[1]) + if err != nil { + return nil, err + } + weight, err := strconv.ParseUint(fields[3], 10, 64) + if err != nil { + return nil, err + } + activeConn, err := strconv.ParseUint(fields[4], 10, 64) + if err != nil { + return nil, err + } + inactConn, err := strconv.ParseUint(fields[5], 10, 64) + if err != nil { + return nil, err + } + status = append(status, IPVSBackendStatus{ + LocalAddress: localAddress, + LocalPort: localPort, + LocalMark: localMark, + RemoteAddress: remoteAddress, + RemotePort: remotePort, + Proto: proto, + Weight: weight, + ActiveConn: activeConn, + InactConn: inactConn, + }) + } + } + return status, nil +} + +func parseIPPort(s string) (net.IP, uint16, error) { + var ( + ip net.IP + err error + ) + + switch len(s) { + case 13: + ip, err = hex.DecodeString(s[0:8]) + if err != nil { + return nil, 0, err + } + case 46: + ip = net.ParseIP(s[1:40]) + if ip == nil { + return nil, 0, fmt.Errorf("invalid IPv6 address: %s", s[1:40]) + } + default: + return nil, 0, fmt.Errorf("unexpected IP:Port: %s", s) + } + + portString := s[len(s)-4:] + if len(portString) != 4 { + return nil, 0, fmt.Errorf("unexpected port string format: %s", portString) + } + port, err := strconv.ParseUint(portString, 16, 16) + if err != nil { + return nil, 0, err + } + + return ip, uint16(port), nil +} diff --git a/vendor/github.com/prometheus/procfs/mdstat.go b/vendor/github.com/prometheus/procfs/mdstat.go new file mode 100644 index 000000000..d7a248c0d --- /dev/null +++ b/vendor/github.com/prometheus/procfs/mdstat.go @@ -0,0 +1,138 @@ +package procfs + +import ( + "fmt" + "io/ioutil" + "regexp" + "strconv" + "strings" +) + +var ( + statuslineRE = regexp.MustCompile(`(\d+) blocks .*\[(\d+)/(\d+)\] \[[U_]+\]`) + buildlineRE = regexp.MustCompile(`\((\d+)/\d+\)`) +) + +// MDStat holds info parsed from /proc/mdstat. +type MDStat struct { + // Name of the device. + Name string + // activity-state of the device. + ActivityState string + // Number of active disks. + DisksActive int64 + // Total number of disks the device consists of. + DisksTotal int64 + // Number of blocks the device holds. + BlocksTotal int64 + // Number of blocks on the device that are in sync. + BlocksSynced int64 +} + +// ParseMDStat parses an mdstat-file and returns a struct with the relevant infos. +func (fs FS) ParseMDStat() (mdstates []MDStat, err error) { + mdStatusFilePath := fs.Path("mdstat") + content, err := ioutil.ReadFile(mdStatusFilePath) + if err != nil { + return []MDStat{}, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) + } + + mdStates := []MDStat{} + lines := strings.Split(string(content), "\n") + for i, l := range lines { + if l == "" { + continue + } + if l[0] == ' ' { + continue + } + if strings.HasPrefix(l, "Personalities") || strings.HasPrefix(l, "unused") { + continue + } + + mainLine := strings.Split(l, " ") + if len(mainLine) < 3 { + return mdStates, fmt.Errorf("error parsing mdline: %s", l) + } + mdName := mainLine[0] + activityState := mainLine[2] + + if len(lines) <= i+3 { + return mdStates, fmt.Errorf( + "error parsing %s: too few lines for md device %s", + mdStatusFilePath, + mdName, + ) + } + + active, total, size, err := evalStatusline(lines[i+1]) + if err != nil { + return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) + } + + // j is the line number of the syncing-line. + j := i + 2 + if strings.Contains(lines[i+2], "bitmap") { // skip bitmap line + j = i + 3 + } + + // If device is syncing at the moment, get the number of currently + // synced bytes, otherwise that number equals the size of the device. + syncedBlocks := size + if strings.Contains(lines[j], "recovery") || strings.Contains(lines[j], "resync") { + syncedBlocks, err = evalBuildline(lines[j]) + if err != nil { + return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) + } + } + + mdStates = append(mdStates, MDStat{ + Name: mdName, + ActivityState: activityState, + DisksActive: active, + DisksTotal: total, + BlocksTotal: size, + BlocksSynced: syncedBlocks, + }) + } + + return mdStates, nil +} + +func evalStatusline(statusline string) (active, total, size int64, err error) { + matches := statuslineRE.FindStringSubmatch(statusline) + if len(matches) != 4 { + return 0, 0, 0, fmt.Errorf("unexpected statusline: %s", statusline) + } + + size, err = strconv.ParseInt(matches[1], 10, 64) + if err != nil { + return 0, 0, 0, fmt.Errorf("unexpected statusline %s: %s", statusline, err) + } + + total, err = strconv.ParseInt(matches[2], 10, 64) + if err != nil { + return 0, 0, 0, fmt.Errorf("unexpected statusline %s: %s", statusline, err) + } + + active, err = strconv.ParseInt(matches[3], 10, 64) + if err != nil { + return 0, 0, 0, fmt.Errorf("unexpected statusline %s: %s", statusline, err) + } + + return active, total, size, nil +} + +func evalBuildline(buildline string) (syncedBlocks int64, err error) { + matches := buildlineRE.FindStringSubmatch(buildline) + if len(matches) != 2 { + return 0, fmt.Errorf("unexpected buildline: %s", buildline) + } + + syncedBlocks, err = strconv.ParseInt(matches[1], 10, 64) + if err != nil { + return 0, fmt.Errorf("%s in buildline: %s", err, buildline) + } + + return syncedBlocks, nil +} diff --git a/vendor/github.com/prometheus/procfs/mountstats.go b/vendor/github.com/prometheus/procfs/mountstats.go new file mode 100644 index 000000000..6b2b0ba9d --- /dev/null +++ b/vendor/github.com/prometheus/procfs/mountstats.go @@ -0,0 +1,556 @@ +package procfs + +// While implementing parsing of /proc/[pid]/mountstats, this blog was used +// heavily as a reference: +// https://utcc.utoronto.ca/~cks/space/blog/linux/NFSMountstatsIndex +// +// Special thanks to Chris Siebenmann for all of his posts explaining the +// various statistics available for NFS. + +import ( + "bufio" + "fmt" + "io" + "strconv" + "strings" + "time" +) + +// Constants shared between multiple functions. +const ( + deviceEntryLen = 8 + + fieldBytesLen = 8 + fieldEventsLen = 27 + + statVersion10 = "1.0" + statVersion11 = "1.1" + + fieldTransport10Len = 10 + fieldTransport11Len = 13 +) + +// A Mount is a device mount parsed from /proc/[pid]/mountstats. +type Mount struct { + // Name of the device. + Device string + // The mount point of the device. + Mount string + // The filesystem type used by the device. + Type string + // If available additional statistics related to this Mount. + // Use a type assertion to determine if additional statistics are available. + Stats MountStats +} + +// A MountStats is a type which contains detailed statistics for a specific +// type of Mount. +type MountStats interface { + mountStats() +} + +// A MountStatsNFS is a MountStats implementation for NFSv3 and v4 mounts. +type MountStatsNFS struct { + // The version of statistics provided. + StatVersion string + // The age of the NFS mount. + Age time.Duration + // Statistics related to byte counters for various operations. + Bytes NFSBytesStats + // Statistics related to various NFS event occurrences. + Events NFSEventsStats + // Statistics broken down by filesystem operation. + Operations []NFSOperationStats + // Statistics about the NFS RPC transport. + Transport NFSTransportStats +} + +// mountStats implements MountStats. +func (m MountStatsNFS) mountStats() {} + +// A NFSBytesStats contains statistics about the number of bytes read and written +// by an NFS client to and from an NFS server. +type NFSBytesStats struct { + // Number of bytes read using the read() syscall. + Read uint64 + // Number of bytes written using the write() syscall. + Write uint64 + // Number of bytes read using the read() syscall in O_DIRECT mode. + DirectRead uint64 + // Number of bytes written using the write() syscall in O_DIRECT mode. + DirectWrite uint64 + // Number of bytes read from the NFS server, in total. + ReadTotal uint64 + // Number of bytes written to the NFS server, in total. + WriteTotal uint64 + // Number of pages read directly via mmap()'d files. + ReadPages uint64 + // Number of pages written directly via mmap()'d files. + WritePages uint64 +} + +// A NFSEventsStats contains statistics about NFS event occurrences. +type NFSEventsStats struct { + // Number of times cached inode attributes are re-validated from the server. + InodeRevalidate uint64 + // Number of times cached dentry nodes are re-validated from the server. + DnodeRevalidate uint64 + // Number of times an inode cache is cleared. + DataInvalidate uint64 + // Number of times cached inode attributes are invalidated. + AttributeInvalidate uint64 + // Number of times files or directories have been open()'d. + VFSOpen uint64 + // Number of times a directory lookup has occurred. + VFSLookup uint64 + // Number of times permissions have been checked. + VFSAccess uint64 + // Number of updates (and potential writes) to pages. + VFSUpdatePage uint64 + // Number of pages read directly via mmap()'d files. + VFSReadPage uint64 + // Number of times a group of pages have been read. + VFSReadPages uint64 + // Number of pages written directly via mmap()'d files. + VFSWritePage uint64 + // Number of times a group of pages have been written. + VFSWritePages uint64 + // Number of times directory entries have been read with getdents(). + VFSGetdents uint64 + // Number of times attributes have been set on inodes. + VFSSetattr uint64 + // Number of pending writes that have been forcefully flushed to the server. + VFSFlush uint64 + // Number of times fsync() has been called on directories and files. + VFSFsync uint64 + // Number of times locking has been attempted on a file. + VFSLock uint64 + // Number of times files have been closed and released. + VFSFileRelease uint64 + // Unknown. Possibly unused. + CongestionWait uint64 + // Number of times files have been truncated. + Truncation uint64 + // Number of times a file has been grown due to writes beyond its existing end. + WriteExtension uint64 + // Number of times a file was removed while still open by another process. + SillyRename uint64 + // Number of times the NFS server gave less data than expected while reading. + ShortRead uint64 + // Number of times the NFS server wrote less data than expected while writing. + ShortWrite uint64 + // Number of times the NFS server indicated EJUKEBOX; retrieving data from + // offline storage. + JukeboxDelay uint64 + // Number of NFS v4.1+ pNFS reads. + PNFSRead uint64 + // Number of NFS v4.1+ pNFS writes. + PNFSWrite uint64 +} + +// A NFSOperationStats contains statistics for a single operation. +type NFSOperationStats struct { + // The name of the operation. + Operation string + // Number of requests performed for this operation. + Requests uint64 + // Number of times an actual RPC request has been transmitted for this operation. + Transmissions uint64 + // Number of times a request has had a major timeout. + MajorTimeouts uint64 + // Number of bytes sent for this operation, including RPC headers and payload. + BytesSent uint64 + // Number of bytes received for this operation, including RPC headers and payload. + BytesReceived uint64 + // Duration all requests spent queued for transmission before they were sent. + CumulativeQueueTime time.Duration + // Duration it took to get a reply back after the request was transmitted. + CumulativeTotalResponseTime time.Duration + // Duration from when a request was enqueued to when it was completely handled. + CumulativeTotalRequestTime time.Duration +} + +// A NFSTransportStats contains statistics for the NFS mount RPC requests and +// responses. +type NFSTransportStats struct { + // The local port used for the NFS mount. + Port uint64 + // Number of times the client has had to establish a connection from scratch + // to the NFS server. + Bind uint64 + // Number of times the client has made a TCP connection to the NFS server. + Connect uint64 + // Duration (in jiffies, a kernel internal unit of time) the NFS mount has + // spent waiting for connections to the server to be established. + ConnectIdleTime uint64 + // Duration since the NFS mount last saw any RPC traffic. + IdleTime time.Duration + // Number of RPC requests for this mount sent to the NFS server. + Sends uint64 + // Number of RPC responses for this mount received from the NFS server. + Receives uint64 + // Number of times the NFS server sent a response with a transaction ID + // unknown to this client. + BadTransactionIDs uint64 + // A running counter, incremented on each request as the current difference + // ebetween sends and receives. + CumulativeActiveRequests uint64 + // A running counter, incremented on each request by the current backlog + // queue size. + CumulativeBacklog uint64 + + // Stats below only available with stat version 1.1. + + // Maximum number of simultaneously active RPC requests ever used. + MaximumRPCSlotsUsed uint64 + // A running counter, incremented on each request as the current size of the + // sending queue. + CumulativeSendingQueue uint64 + // A running counter, incremented on each request as the current size of the + // pending queue. + CumulativePendingQueue uint64 +} + +// parseMountStats parses a /proc/[pid]/mountstats file and returns a slice +// of Mount structures containing detailed information about each mount. +// If available, statistics for each mount are parsed as well. +func parseMountStats(r io.Reader) ([]*Mount, error) { + const ( + device = "device" + statVersionPrefix = "statvers=" + + nfs3Type = "nfs" + nfs4Type = "nfs4" + ) + + var mounts []*Mount + + s := bufio.NewScanner(r) + for s.Scan() { + // Only look for device entries in this function + ss := strings.Fields(string(s.Bytes())) + if len(ss) == 0 || ss[0] != device { + continue + } + + m, err := parseMount(ss) + if err != nil { + return nil, err + } + + // Does this mount also possess statistics information? + if len(ss) > deviceEntryLen { + // Only NFSv3 and v4 are supported for parsing statistics + if m.Type != nfs3Type && m.Type != nfs4Type { + return nil, fmt.Errorf("cannot parse MountStats for fstype %q", m.Type) + } + + statVersion := strings.TrimPrefix(ss[8], statVersionPrefix) + + stats, err := parseMountStatsNFS(s, statVersion) + if err != nil { + return nil, err + } + + m.Stats = stats + } + + mounts = append(mounts, m) + } + + return mounts, s.Err() +} + +// parseMount parses an entry in /proc/[pid]/mountstats in the format: +// device [device] mounted on [mount] with fstype [type] +func parseMount(ss []string) (*Mount, error) { + if len(ss) < deviceEntryLen { + return nil, fmt.Errorf("invalid device entry: %v", ss) + } + + // Check for specific words appearing at specific indices to ensure + // the format is consistent with what we expect + format := []struct { + i int + s string + }{ + {i: 0, s: "device"}, + {i: 2, s: "mounted"}, + {i: 3, s: "on"}, + {i: 5, s: "with"}, + {i: 6, s: "fstype"}, + } + + for _, f := range format { + if ss[f.i] != f.s { + return nil, fmt.Errorf("invalid device entry: %v", ss) + } + } + + return &Mount{ + Device: ss[1], + Mount: ss[4], + Type: ss[7], + }, nil +} + +// parseMountStatsNFS parses a MountStatsNFS by scanning additional information +// related to NFS statistics. +func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, error) { + // Field indicators for parsing specific types of data + const ( + fieldAge = "age:" + fieldBytes = "bytes:" + fieldEvents = "events:" + fieldPerOpStats = "per-op" + fieldTransport = "xprt:" + ) + + stats := &MountStatsNFS{ + StatVersion: statVersion, + } + + for s.Scan() { + ss := strings.Fields(string(s.Bytes())) + if len(ss) == 0 { + break + } + if len(ss) < 2 { + return nil, fmt.Errorf("not enough information for NFS stats: %v", ss) + } + + switch ss[0] { + case fieldAge: + // Age integer is in seconds + d, err := time.ParseDuration(ss[1] + "s") + if err != nil { + return nil, err + } + + stats.Age = d + case fieldBytes: + bstats, err := parseNFSBytesStats(ss[1:]) + if err != nil { + return nil, err + } + + stats.Bytes = *bstats + case fieldEvents: + estats, err := parseNFSEventsStats(ss[1:]) + if err != nil { + return nil, err + } + + stats.Events = *estats + case fieldTransport: + if len(ss) < 3 { + return nil, fmt.Errorf("not enough information for NFS transport stats: %v", ss) + } + + tstats, err := parseNFSTransportStats(ss[2:], statVersion) + if err != nil { + return nil, err + } + + stats.Transport = *tstats + } + + // When encountering "per-operation statistics", we must break this + // loop and parse them separately to ensure we can terminate parsing + // before reaching another device entry; hence why this 'if' statement + // is not just another switch case + if ss[0] == fieldPerOpStats { + break + } + } + + if err := s.Err(); err != nil { + return nil, err + } + + // NFS per-operation stats appear last before the next device entry + perOpStats, err := parseNFSOperationStats(s) + if err != nil { + return nil, err + } + + stats.Operations = perOpStats + + return stats, nil +} + +// parseNFSBytesStats parses a NFSBytesStats line using an input set of +// integer fields. +func parseNFSBytesStats(ss []string) (*NFSBytesStats, error) { + if len(ss) != fieldBytesLen { + return nil, fmt.Errorf("invalid NFS bytes stats: %v", ss) + } + + ns := make([]uint64, 0, fieldBytesLen) + for _, s := range ss { + n, err := strconv.ParseUint(s, 10, 64) + if err != nil { + return nil, err + } + + ns = append(ns, n) + } + + return &NFSBytesStats{ + Read: ns[0], + Write: ns[1], + DirectRead: ns[2], + DirectWrite: ns[3], + ReadTotal: ns[4], + WriteTotal: ns[5], + ReadPages: ns[6], + WritePages: ns[7], + }, nil +} + +// parseNFSEventsStats parses a NFSEventsStats line using an input set of +// integer fields. +func parseNFSEventsStats(ss []string) (*NFSEventsStats, error) { + if len(ss) != fieldEventsLen { + return nil, fmt.Errorf("invalid NFS events stats: %v", ss) + } + + ns := make([]uint64, 0, fieldEventsLen) + for _, s := range ss { + n, err := strconv.ParseUint(s, 10, 64) + if err != nil { + return nil, err + } + + ns = append(ns, n) + } + + return &NFSEventsStats{ + InodeRevalidate: ns[0], + DnodeRevalidate: ns[1], + DataInvalidate: ns[2], + AttributeInvalidate: ns[3], + VFSOpen: ns[4], + VFSLookup: ns[5], + VFSAccess: ns[6], + VFSUpdatePage: ns[7], + VFSReadPage: ns[8], + VFSReadPages: ns[9], + VFSWritePage: ns[10], + VFSWritePages: ns[11], + VFSGetdents: ns[12], + VFSSetattr: ns[13], + VFSFlush: ns[14], + VFSFsync: ns[15], + VFSLock: ns[16], + VFSFileRelease: ns[17], + CongestionWait: ns[18], + Truncation: ns[19], + WriteExtension: ns[20], + SillyRename: ns[21], + ShortRead: ns[22], + ShortWrite: ns[23], + JukeboxDelay: ns[24], + PNFSRead: ns[25], + PNFSWrite: ns[26], + }, nil +} + +// parseNFSOperationStats parses a slice of NFSOperationStats by scanning +// additional information about per-operation statistics until an empty +// line is reached. +func parseNFSOperationStats(s *bufio.Scanner) ([]NFSOperationStats, error) { + const ( + // Number of expected fields in each per-operation statistics set + numFields = 9 + ) + + var ops []NFSOperationStats + + for s.Scan() { + ss := strings.Fields(string(s.Bytes())) + if len(ss) == 0 { + // Must break when reading a blank line after per-operation stats to + // enable top-level function to parse the next device entry + break + } + + if len(ss) != numFields { + return nil, fmt.Errorf("invalid NFS per-operations stats: %v", ss) + } + + // Skip string operation name for integers + ns := make([]uint64, 0, numFields-1) + for _, st := range ss[1:] { + n, err := strconv.ParseUint(st, 10, 64) + if err != nil { + return nil, err + } + + ns = append(ns, n) + } + + ops = append(ops, NFSOperationStats{ + Operation: strings.TrimSuffix(ss[0], ":"), + Requests: ns[0], + Transmissions: ns[1], + MajorTimeouts: ns[2], + BytesSent: ns[3], + BytesReceived: ns[4], + CumulativeQueueTime: time.Duration(ns[5]) * time.Millisecond, + CumulativeTotalResponseTime: time.Duration(ns[6]) * time.Millisecond, + CumulativeTotalRequestTime: time.Duration(ns[7]) * time.Millisecond, + }) + } + + return ops, s.Err() +} + +// parseNFSTransportStats parses a NFSTransportStats line using an input set of +// integer fields matched to a specific stats version. +func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats, error) { + switch statVersion { + case statVersion10: + if len(ss) != fieldTransport10Len { + return nil, fmt.Errorf("invalid NFS transport stats 1.0 statement: %v", ss) + } + case statVersion11: + if len(ss) != fieldTransport11Len { + return nil, fmt.Errorf("invalid NFS transport stats 1.1 statement: %v", ss) + } + default: + return nil, fmt.Errorf("unrecognized NFS transport stats version: %q", statVersion) + } + + // Allocate enough for v1.1 stats since zero value for v1.1 stats will be okay + // in a v1.0 response. + // + // Note: slice length must be set to length of v1.1 stats to avoid a panic when + // only v1.0 stats are present. + // See: https://github.com/prometheus/node_exporter/issues/571. + ns := make([]uint64, fieldTransport11Len) + for i, s := range ss { + n, err := strconv.ParseUint(s, 10, 64) + if err != nil { + return nil, err + } + + ns[i] = n + } + + return &NFSTransportStats{ + Port: ns[0], + Bind: ns[1], + Connect: ns[2], + ConnectIdleTime: ns[3], + IdleTime: time.Duration(ns[4]) * time.Second, + Sends: ns[5], + Receives: ns[6], + BadTransactionIDs: ns[7], + CumulativeActiveRequests: ns[8], + CumulativeBacklog: ns[9], + MaximumRPCSlotsUsed: ns[10], + CumulativeSendingQueue: ns[11], + CumulativePendingQueue: ns[12], + }, nil +} diff --git a/vendor/github.com/prometheus/procfs/net_dev.go b/vendor/github.com/prometheus/procfs/net_dev.go new file mode 100644 index 000000000..f8c184efe --- /dev/null +++ b/vendor/github.com/prometheus/procfs/net_dev.go @@ -0,0 +1,203 @@ +package procfs + +import ( + "bufio" + "errors" + "os" + "sort" + "strconv" + "strings" +) + +// NetDevLine is single line parsed from /proc/net/dev or /proc/[pid]/net/dev. +type NetDevLine struct { + Name string `json:"name"` // The name of the interface. + RxBytes uint64 `json:"rx_bytes"` // Cumulative count of bytes received. + RxPackets uint64 `json:"rx_packets"` // Cumulative count of packets received. + RxErrors uint64 `json:"rx_errors"` // Cumulative count of receive errors encountered. + RxDropped uint64 `json:"rx_dropped"` // Cumulative count of packets dropped while receiving. + RxFIFO uint64 `json:"rx_fifo"` // Cumulative count of FIFO buffer errors. + RxFrame uint64 `json:"rx_frame"` // Cumulative count of packet framing errors. + RxCompressed uint64 `json:"rx_compressed"` // Cumulative count of compressed packets received by the device driver. + RxMulticast uint64 `json:"rx_multicast"` // Cumulative count of multicast frames received by the device driver. + TxBytes uint64 `json:"tx_bytes"` // Cumulative count of bytes transmitted. + TxPackets uint64 `json:"tx_packets"` // Cumulative count of packets transmitted. + TxErrors uint64 `json:"tx_errors"` // Cumulative count of transmit errors encountered. + TxDropped uint64 `json:"tx_dropped"` // Cumulative count of packets dropped while transmitting. + TxFIFO uint64 `json:"tx_fifo"` // Cumulative count of FIFO buffer errors. + TxCollisions uint64 `json:"tx_collisions"` // Cumulative count of collisions detected on the interface. + TxCarrier uint64 `json:"tx_carrier"` // Cumulative count of carrier losses detected by the device driver. + TxCompressed uint64 `json:"tx_compressed"` // Cumulative count of compressed packets transmitted by the device driver. +} + +// NetDev is parsed from /proc/net/dev or /proc/[pid]/net/dev. The map keys +// are interface names. +type NetDev map[string]NetDevLine + +// NewNetDev returns kernel/system statistics read from /proc/net/dev. +func NewNetDev() (NetDev, error) { + fs, err := NewFS(DefaultMountPoint) + if err != nil { + return nil, err + } + + return fs.NewNetDev() +} + +// NewNetDev returns kernel/system statistics read from /proc/net/dev. +func (fs FS) NewNetDev() (NetDev, error) { + return newNetDev(fs.Path("net/dev")) +} + +// NewNetDev returns kernel/system statistics read from /proc/[pid]/net/dev. +func (p Proc) NewNetDev() (NetDev, error) { + return newNetDev(p.path("net/dev")) +} + +// newNetDev creates a new NetDev from the contents of the given file. +func newNetDev(file string) (NetDev, error) { + f, err := os.Open(file) + if err != nil { + return NetDev{}, err + } + defer f.Close() + + nd := NetDev{} + s := bufio.NewScanner(f) + for n := 0; s.Scan(); n++ { + // Skip the 2 header lines. + if n < 2 { + continue + } + + line, err := nd.parseLine(s.Text()) + if err != nil { + return nd, err + } + + nd[line.Name] = *line + } + + return nd, s.Err() +} + +// parseLine parses a single line from the /proc/net/dev file. Header lines +// must be filtered prior to calling this method. +func (nd NetDev) parseLine(rawLine string) (*NetDevLine, error) { + parts := strings.SplitN(rawLine, ":", 2) + if len(parts) != 2 { + return nil, errors.New("invalid net/dev line, missing colon") + } + fields := strings.Fields(strings.TrimSpace(parts[1])) + + var err error + line := &NetDevLine{} + + // Interface Name + line.Name = strings.TrimSpace(parts[0]) + if line.Name == "" { + return nil, errors.New("invalid net/dev line, empty interface name") + } + + // RX + line.RxBytes, err = strconv.ParseUint(fields[0], 10, 64) + if err != nil { + return nil, err + } + line.RxPackets, err = strconv.ParseUint(fields[1], 10, 64) + if err != nil { + return nil, err + } + line.RxErrors, err = strconv.ParseUint(fields[2], 10, 64) + if err != nil { + return nil, err + } + line.RxDropped, err = strconv.ParseUint(fields[3], 10, 64) + if err != nil { + return nil, err + } + line.RxFIFO, err = strconv.ParseUint(fields[4], 10, 64) + if err != nil { + return nil, err + } + line.RxFrame, err = strconv.ParseUint(fields[5], 10, 64) + if err != nil { + return nil, err + } + line.RxCompressed, err = strconv.ParseUint(fields[6], 10, 64) + if err != nil { + return nil, err + } + line.RxMulticast, err = strconv.ParseUint(fields[7], 10, 64) + if err != nil { + return nil, err + } + + // TX + line.TxBytes, err = strconv.ParseUint(fields[8], 10, 64) + if err != nil { + return nil, err + } + line.TxPackets, err = strconv.ParseUint(fields[9], 10, 64) + if err != nil { + return nil, err + } + line.TxErrors, err = strconv.ParseUint(fields[10], 10, 64) + if err != nil { + return nil, err + } + line.TxDropped, err = strconv.ParseUint(fields[11], 10, 64) + if err != nil { + return nil, err + } + line.TxFIFO, err = strconv.ParseUint(fields[12], 10, 64) + if err != nil { + return nil, err + } + line.TxCollisions, err = strconv.ParseUint(fields[13], 10, 64) + if err != nil { + return nil, err + } + line.TxCarrier, err = strconv.ParseUint(fields[14], 10, 64) + if err != nil { + return nil, err + } + line.TxCompressed, err = strconv.ParseUint(fields[15], 10, 64) + if err != nil { + return nil, err + } + + return line, nil +} + +// Total aggregates the values across interfaces and returns a new NetDevLine. +// The Name field will be a sorted comma seperated list of interface names. +func (nd NetDev) Total() NetDevLine { + total := NetDevLine{} + + names := make([]string, 0, len(nd)) + for _, ifc := range nd { + names = append(names, ifc.Name) + total.RxBytes += ifc.RxBytes + total.RxPackets += ifc.RxPackets + total.RxPackets += ifc.RxPackets + total.RxErrors += ifc.RxErrors + total.RxDropped += ifc.RxDropped + total.RxFIFO += ifc.RxFIFO + total.RxFrame += ifc.RxFrame + total.RxCompressed += ifc.RxCompressed + total.RxMulticast += ifc.RxMulticast + total.TxBytes += ifc.TxBytes + total.TxPackets += ifc.TxPackets + total.TxErrors += ifc.TxErrors + total.TxDropped += ifc.TxDropped + total.TxFIFO += ifc.TxFIFO + total.TxCollisions += ifc.TxCollisions + total.TxCarrier += ifc.TxCarrier + total.TxCompressed += ifc.TxCompressed + } + sort.Strings(names) + total.Name = strings.Join(names, ", ") + + return total +} diff --git a/vendor/github.com/prometheus/procfs/proc.go b/vendor/github.com/prometheus/procfs/proc.go new file mode 100644 index 000000000..8717e1fe0 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/proc.go @@ -0,0 +1,224 @@ +package procfs + +import ( + "fmt" + "io/ioutil" + "os" + "strconv" + "strings" +) + +// Proc provides information about a running process. +type Proc struct { + // The process ID. + PID int + + fs FS +} + +// Procs represents a list of Proc structs. +type Procs []Proc + +func (p Procs) Len() int { return len(p) } +func (p Procs) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p Procs) Less(i, j int) bool { return p[i].PID < p[j].PID } + +// Self returns a process for the current process read via /proc/self. +func Self() (Proc, error) { + fs, err := NewFS(DefaultMountPoint) + if err != nil { + return Proc{}, err + } + return fs.Self() +} + +// NewProc returns a process for the given pid under /proc. +func NewProc(pid int) (Proc, error) { + fs, err := NewFS(DefaultMountPoint) + if err != nil { + return Proc{}, err + } + return fs.NewProc(pid) +} + +// AllProcs returns a list of all currently available processes under /proc. +func AllProcs() (Procs, error) { + fs, err := NewFS(DefaultMountPoint) + if err != nil { + return Procs{}, err + } + return fs.AllProcs() +} + +// Self returns a process for the current process. +func (fs FS) Self() (Proc, error) { + p, err := os.Readlink(fs.Path("self")) + if err != nil { + return Proc{}, err + } + pid, err := strconv.Atoi(strings.Replace(p, string(fs), "", -1)) + if err != nil { + return Proc{}, err + } + return fs.NewProc(pid) +} + +// NewProc returns a process for the given pid. +func (fs FS) NewProc(pid int) (Proc, error) { + if _, err := os.Stat(fs.Path(strconv.Itoa(pid))); err != nil { + return Proc{}, err + } + return Proc{PID: pid, fs: fs}, nil +} + +// AllProcs returns a list of all currently available processes. +func (fs FS) AllProcs() (Procs, error) { + d, err := os.Open(fs.Path()) + if err != nil { + return Procs{}, err + } + defer d.Close() + + names, err := d.Readdirnames(-1) + if err != nil { + return Procs{}, fmt.Errorf("could not read %s: %s", d.Name(), err) + } + + p := Procs{} + for _, n := range names { + pid, err := strconv.ParseInt(n, 10, 64) + if err != nil { + continue + } + p = append(p, Proc{PID: int(pid), fs: fs}) + } + + return p, nil +} + +// CmdLine returns the command line of a process. +func (p Proc) CmdLine() ([]string, error) { + f, err := os.Open(p.path("cmdline")) + if err != nil { + return nil, err + } + defer f.Close() + + data, err := ioutil.ReadAll(f) + if err != nil { + return nil, err + } + + if len(data) < 1 { + return []string{}, nil + } + + return strings.Split(string(data[:len(data)-1]), string(byte(0))), nil +} + +// Comm returns the command name of a process. +func (p Proc) Comm() (string, error) { + f, err := os.Open(p.path("comm")) + if err != nil { + return "", err + } + defer f.Close() + + data, err := ioutil.ReadAll(f) + if err != nil { + return "", err + } + + return strings.TrimSpace(string(data)), nil +} + +// Executable returns the absolute path of the executable command of a process. +func (p Proc) Executable() (string, error) { + exe, err := os.Readlink(p.path("exe")) + if os.IsNotExist(err) { + return "", nil + } + + return exe, err +} + +// FileDescriptors returns the currently open file descriptors of a process. +func (p Proc) FileDescriptors() ([]uintptr, error) { + names, err := p.fileDescriptors() + if err != nil { + return nil, err + } + + fds := make([]uintptr, len(names)) + for i, n := range names { + fd, err := strconv.ParseInt(n, 10, 32) + if err != nil { + return nil, fmt.Errorf("could not parse fd %s: %s", n, err) + } + fds[i] = uintptr(fd) + } + + return fds, nil +} + +// FileDescriptorTargets returns the targets of all file descriptors of a process. +// If a file descriptor is not a symlink to a file (like a socket), that value will be the empty string. +func (p Proc) FileDescriptorTargets() ([]string, error) { + names, err := p.fileDescriptors() + if err != nil { + return nil, err + } + + targets := make([]string, len(names)) + + for i, name := range names { + target, err := os.Readlink(p.path("fd", name)) + if err == nil { + targets[i] = target + } + } + + return targets, nil +} + +// FileDescriptorsLen returns the number of currently open file descriptors of +// a process. +func (p Proc) FileDescriptorsLen() (int, error) { + fds, err := p.fileDescriptors() + if err != nil { + return 0, err + } + + return len(fds), nil +} + +// MountStats retrieves statistics and configuration for mount points in a +// process's namespace. +func (p Proc) MountStats() ([]*Mount, error) { + f, err := os.Open(p.path("mountstats")) + if err != nil { + return nil, err + } + defer f.Close() + + return parseMountStats(f) +} + +func (p Proc) fileDescriptors() ([]string, error) { + d, err := os.Open(p.path("fd")) + if err != nil { + return nil, err + } + defer d.Close() + + names, err := d.Readdirnames(-1) + if err != nil { + return nil, fmt.Errorf("could not read %s: %s", d.Name(), err) + } + + return names, nil +} + +func (p Proc) path(pa ...string) string { + return p.fs.Path(append([]string{strconv.Itoa(p.PID)}, pa...)...) +} diff --git a/vendor/github.com/prometheus/procfs/proc_io.go b/vendor/github.com/prometheus/procfs/proc_io.go new file mode 100644 index 000000000..e7f6674d0 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/proc_io.go @@ -0,0 +1,52 @@ +package procfs + +import ( + "fmt" + "io/ioutil" + "os" +) + +// ProcIO models the content of /proc//io. +type ProcIO struct { + // Chars read. + RChar uint64 + // Chars written. + WChar uint64 + // Read syscalls. + SyscR uint64 + // Write syscalls. + SyscW uint64 + // Bytes read. + ReadBytes uint64 + // Bytes written. + WriteBytes uint64 + // Bytes written, but taking into account truncation. See + // Documentation/filesystems/proc.txt in the kernel sources for + // detailed explanation. + CancelledWriteBytes int64 +} + +// NewIO creates a new ProcIO instance from a given Proc instance. +func (p Proc) NewIO() (ProcIO, error) { + pio := ProcIO{} + + f, err := os.Open(p.path("io")) + if err != nil { + return pio, err + } + defer f.Close() + + data, err := ioutil.ReadAll(f) + if err != nil { + return pio, err + } + + ioFormat := "rchar: %d\nwchar: %d\nsyscr: %d\nsyscw: %d\n" + + "read_bytes: %d\nwrite_bytes: %d\n" + + "cancelled_write_bytes: %d\n" + + _, err = fmt.Sscanf(string(data), ioFormat, &pio.RChar, &pio.WChar, &pio.SyscR, + &pio.SyscW, &pio.ReadBytes, &pio.WriteBytes, &pio.CancelledWriteBytes) + + return pio, err +} diff --git a/vendor/github.com/prometheus/procfs/proc_limits.go b/vendor/github.com/prometheus/procfs/proc_limits.go new file mode 100644 index 000000000..b684a5b55 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/proc_limits.go @@ -0,0 +1,137 @@ +package procfs + +import ( + "bufio" + "fmt" + "os" + "regexp" + "strconv" +) + +// ProcLimits represents the soft limits for each of the process's resource +// limits. For more information see getrlimit(2): +// http://man7.org/linux/man-pages/man2/getrlimit.2.html. +type ProcLimits struct { + // CPU time limit in seconds. + CPUTime int64 + // Maximum size of files that the process may create. + FileSize int64 + // Maximum size of the process's data segment (initialized data, + // uninitialized data, and heap). + DataSize int64 + // Maximum size of the process stack in bytes. + StackSize int64 + // Maximum size of a core file. + CoreFileSize int64 + // Limit of the process's resident set in pages. + ResidentSet int64 + // Maximum number of processes that can be created for the real user ID of + // the calling process. + Processes int64 + // Value one greater than the maximum file descriptor number that can be + // opened by this process. + OpenFiles int64 + // Maximum number of bytes of memory that may be locked into RAM. + LockedMemory int64 + // Maximum size of the process's virtual memory address space in bytes. + AddressSpace int64 + // Limit on the combined number of flock(2) locks and fcntl(2) leases that + // this process may establish. + FileLocks int64 + // Limit of signals that may be queued for the real user ID of the calling + // process. + PendingSignals int64 + // Limit on the number of bytes that can be allocated for POSIX message + // queues for the real user ID of the calling process. + MsqqueueSize int64 + // Limit of the nice priority set using setpriority(2) or nice(2). + NicePriority int64 + // Limit of the real-time priority set using sched_setscheduler(2) or + // sched_setparam(2). + RealtimePriority int64 + // Limit (in microseconds) on the amount of CPU time that a process + // scheduled under a real-time scheduling policy may consume without making + // a blocking system call. + RealtimeTimeout int64 +} + +const ( + limitsFields = 3 + limitsUnlimited = "unlimited" +) + +var ( + limitsDelimiter = regexp.MustCompile(" +") +) + +// NewLimits returns the current soft limits of the process. +func (p Proc) NewLimits() (ProcLimits, error) { + f, err := os.Open(p.path("limits")) + if err != nil { + return ProcLimits{}, err + } + defer f.Close() + + var ( + l = ProcLimits{} + s = bufio.NewScanner(f) + ) + for s.Scan() { + fields := limitsDelimiter.Split(s.Text(), limitsFields) + if len(fields) != limitsFields { + return ProcLimits{}, fmt.Errorf( + "couldn't parse %s line %s", f.Name(), s.Text()) + } + + switch fields[0] { + case "Max cpu time": + l.CPUTime, err = parseInt(fields[1]) + case "Max file size": + l.FileSize, err = parseInt(fields[1]) + case "Max data size": + l.DataSize, err = parseInt(fields[1]) + case "Max stack size": + l.StackSize, err = parseInt(fields[1]) + case "Max core file size": + l.CoreFileSize, err = parseInt(fields[1]) + case "Max resident set": + l.ResidentSet, err = parseInt(fields[1]) + case "Max processes": + l.Processes, err = parseInt(fields[1]) + case "Max open files": + l.OpenFiles, err = parseInt(fields[1]) + case "Max locked memory": + l.LockedMemory, err = parseInt(fields[1]) + case "Max address space": + l.AddressSpace, err = parseInt(fields[1]) + case "Max file locks": + l.FileLocks, err = parseInt(fields[1]) + case "Max pending signals": + l.PendingSignals, err = parseInt(fields[1]) + case "Max msgqueue size": + l.MsqqueueSize, err = parseInt(fields[1]) + case "Max nice priority": + l.NicePriority, err = parseInt(fields[1]) + case "Max realtime priority": + l.RealtimePriority, err = parseInt(fields[1]) + case "Max realtime timeout": + l.RealtimeTimeout, err = parseInt(fields[1]) + } + if err != nil { + return ProcLimits{}, err + } + } + + return l, s.Err() +} + +func parseInt(s string) (int64, error) { + if s == limitsUnlimited { + return -1, nil + } + i, err := strconv.ParseInt(s, 10, 64) + if err != nil { + return 0, fmt.Errorf("couldn't parse value %s: %s", s, err) + } + return i, nil +} diff --git a/vendor/github.com/prometheus/procfs/proc_ns.go b/vendor/github.com/prometheus/procfs/proc_ns.go new file mode 100644 index 000000000..befdd2690 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/proc_ns.go @@ -0,0 +1,55 @@ +package procfs + +import ( + "fmt" + "os" + "strconv" + "strings" +) + +// Namespace represents a single namespace of a process. +type Namespace struct { + Type string // Namespace type. + Inode uint32 // Inode number of the namespace. If two processes are in the same namespace their inodes will match. +} + +// Namespaces contains all of the namespaces that the process is contained in. +type Namespaces map[string]Namespace + +// NewNamespaces reads from /proc/[pid/ns/* to get the namespaces of which the +// process is a member. +func (p Proc) NewNamespaces() (Namespaces, error) { + d, err := os.Open(p.path("ns")) + if err != nil { + return nil, err + } + defer d.Close() + + names, err := d.Readdirnames(-1) + if err != nil { + return nil, fmt.Errorf("failed to read contents of ns dir: %v", err) + } + + ns := make(Namespaces, len(names)) + for _, name := range names { + target, err := os.Readlink(p.path("ns", name)) + if err != nil { + return nil, err + } + + fields := strings.SplitN(target, ":", 2) + if len(fields) != 2 { + return nil, fmt.Errorf("failed to parse namespace type and inode from '%v'", target) + } + + typ := fields[0] + inode, err := strconv.ParseUint(strings.Trim(fields[1], "[]"), 10, 32) + if err != nil { + return nil, fmt.Errorf("failed to parse inode from '%v': %v", fields[1], err) + } + + ns[name] = Namespace{typ, uint32(inode)} + } + + return ns, nil +} diff --git a/vendor/github.com/prometheus/procfs/proc_stat.go b/vendor/github.com/prometheus/procfs/proc_stat.go new file mode 100644 index 000000000..724e271b9 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/proc_stat.go @@ -0,0 +1,175 @@ +package procfs + +import ( + "bytes" + "fmt" + "io/ioutil" + "os" +) + +// Originally, this USER_HZ value was dynamically retrieved via a sysconf call +// which required cgo. However, that caused a lot of problems regarding +// cross-compilation. Alternatives such as running a binary to determine the +// value, or trying to derive it in some other way were all problematic. After +// much research it was determined that USER_HZ is actually hardcoded to 100 on +// all Go-supported platforms as of the time of this writing. This is why we +// decided to hardcode it here as well. It is not impossible that there could +// be systems with exceptions, but they should be very exotic edge cases, and +// in that case, the worst outcome will be two misreported metrics. +// +// See also the following discussions: +// +// - https://github.com/prometheus/node_exporter/issues/52 +// - https://github.com/prometheus/procfs/pull/2 +// - http://stackoverflow.com/questions/17410841/how-does-user-hz-solve-the-jiffy-scaling-issue +const userHZ = 100 + +// ProcStat provides status information about the process, +// read from /proc/[pid]/stat. +type ProcStat struct { + // The process ID. + PID int + // The filename of the executable. + Comm string + // The process state. + State string + // The PID of the parent of this process. + PPID int + // The process group ID of the process. + PGRP int + // The session ID of the process. + Session int + // The controlling terminal of the process. + TTY int + // The ID of the foreground process group of the controlling terminal of + // the process. + TPGID int + // The kernel flags word of the process. + Flags uint + // The number of minor faults the process has made which have not required + // loading a memory page from disk. + MinFlt uint + // The number of minor faults that the process's waited-for children have + // made. + CMinFlt uint + // The number of major faults the process has made which have required + // loading a memory page from disk. + MajFlt uint + // The number of major faults that the process's waited-for children have + // made. + CMajFlt uint + // Amount of time that this process has been scheduled in user mode, + // measured in clock ticks. + UTime uint + // Amount of time that this process has been scheduled in kernel mode, + // measured in clock ticks. + STime uint + // Amount of time that this process's waited-for children have been + // scheduled in user mode, measured in clock ticks. + CUTime uint + // Amount of time that this process's waited-for children have been + // scheduled in kernel mode, measured in clock ticks. + CSTime uint + // For processes running a real-time scheduling policy, this is the negated + // scheduling priority, minus one. + Priority int + // The nice value, a value in the range 19 (low priority) to -20 (high + // priority). + Nice int + // Number of threads in this process. + NumThreads int + // The time the process started after system boot, the value is expressed + // in clock ticks. + Starttime uint64 + // Virtual memory size in bytes. + VSize int + // Resident set size in pages. + RSS int + + fs FS +} + +// NewStat returns the current status information of the process. +func (p Proc) NewStat() (ProcStat, error) { + f, err := os.Open(p.path("stat")) + if err != nil { + return ProcStat{}, err + } + defer f.Close() + + data, err := ioutil.ReadAll(f) + if err != nil { + return ProcStat{}, err + } + + var ( + ignore int + + s = ProcStat{PID: p.PID, fs: p.fs} + l = bytes.Index(data, []byte("(")) + r = bytes.LastIndex(data, []byte(")")) + ) + + if l < 0 || r < 0 { + return ProcStat{}, fmt.Errorf( + "unexpected format, couldn't extract comm: %s", + data, + ) + } + + s.Comm = string(data[l+1 : r]) + _, err = fmt.Fscan( + bytes.NewBuffer(data[r+2:]), + &s.State, + &s.PPID, + &s.PGRP, + &s.Session, + &s.TTY, + &s.TPGID, + &s.Flags, + &s.MinFlt, + &s.CMinFlt, + &s.MajFlt, + &s.CMajFlt, + &s.UTime, + &s.STime, + &s.CUTime, + &s.CSTime, + &s.Priority, + &s.Nice, + &s.NumThreads, + &ignore, + &s.Starttime, + &s.VSize, + &s.RSS, + ) + if err != nil { + return ProcStat{}, err + } + + return s, nil +} + +// VirtualMemory returns the virtual memory size in bytes. +func (s ProcStat) VirtualMemory() int { + return s.VSize +} + +// ResidentMemory returns the resident memory size in bytes. +func (s ProcStat) ResidentMemory() int { + return s.RSS * os.Getpagesize() +} + +// StartTime returns the unix timestamp of the process in seconds. +func (s ProcStat) StartTime() (float64, error) { + stat, err := s.fs.NewStat() + if err != nil { + return 0, err + } + return float64(stat.BootTime) + (float64(s.Starttime) / userHZ), nil +} + +// CPUTime returns the total CPU user and system time in seconds. +func (s ProcStat) CPUTime() float64 { + return float64(s.UTime+s.STime) / userHZ +} diff --git a/vendor/github.com/prometheus/procfs/stat.go b/vendor/github.com/prometheus/procfs/stat.go new file mode 100644 index 000000000..701f4df64 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/stat.go @@ -0,0 +1,219 @@ +package procfs + +import ( + "bufio" + "fmt" + "io" + "os" + "strconv" + "strings" +) + +// CPUStat shows how much time the cpu spend in various stages. +type CPUStat struct { + User float64 + Nice float64 + System float64 + Idle float64 + Iowait float64 + IRQ float64 + SoftIRQ float64 + Steal float64 + Guest float64 + GuestNice float64 +} + +// SoftIRQStat represent the softirq statistics as exported in the procfs stat file. +// A nice introduction can be found at https://0xax.gitbooks.io/linux-insides/content/interrupts/interrupts-9.html +// It is possible to get per-cpu stats by reading /proc/softirqs +type SoftIRQStat struct { + Hi uint64 + Timer uint64 + NetTx uint64 + NetRx uint64 + Block uint64 + BlockIoPoll uint64 + Tasklet uint64 + Sched uint64 + Hrtimer uint64 + Rcu uint64 +} + +// Stat represents kernel/system statistics. +type Stat struct { + // Boot time in seconds since the Epoch. + BootTime uint64 + // Summed up cpu statistics. + CPUTotal CPUStat + // Per-CPU statistics. + CPU []CPUStat + // Number of times interrupts were handled, which contains numbered and unnumbered IRQs. + IRQTotal uint64 + // Number of times a numbered IRQ was triggered. + IRQ []uint64 + // Number of times a context switch happened. + ContextSwitches uint64 + // Number of times a process was created. + ProcessCreated uint64 + // Number of processes currently running. + ProcessesRunning uint64 + // Number of processes currently blocked (waiting for IO). + ProcessesBlocked uint64 + // Number of times a softirq was scheduled. + SoftIRQTotal uint64 + // Detailed softirq statistics. + SoftIRQ SoftIRQStat +} + +// NewStat returns kernel/system statistics read from /proc/stat. +func NewStat() (Stat, error) { + fs, err := NewFS(DefaultMountPoint) + if err != nil { + return Stat{}, err + } + + return fs.NewStat() +} + +// Parse a cpu statistics line and returns the CPUStat struct plus the cpu id (or -1 for the overall sum). +func parseCPUStat(line string) (CPUStat, int64, error) { + cpuStat := CPUStat{} + var cpu string + + count, err := fmt.Sscanf(line, "%s %f %f %f %f %f %f %f %f %f %f", + &cpu, + &cpuStat.User, &cpuStat.Nice, &cpuStat.System, &cpuStat.Idle, + &cpuStat.Iowait, &cpuStat.IRQ, &cpuStat.SoftIRQ, &cpuStat.Steal, + &cpuStat.Guest, &cpuStat.GuestNice) + + if err != nil && err != io.EOF { + return CPUStat{}, -1, fmt.Errorf("couldn't parse %s (cpu): %s", line, err) + } + if count == 0 { + return CPUStat{}, -1, fmt.Errorf("couldn't parse %s (cpu): 0 elements parsed", line) + } + + cpuStat.User /= userHZ + cpuStat.Nice /= userHZ + cpuStat.System /= userHZ + cpuStat.Idle /= userHZ + cpuStat.Iowait /= userHZ + cpuStat.IRQ /= userHZ + cpuStat.SoftIRQ /= userHZ + cpuStat.Steal /= userHZ + cpuStat.Guest /= userHZ + cpuStat.GuestNice /= userHZ + + if cpu == "cpu" { + return cpuStat, -1, nil + } + + cpuID, err := strconv.ParseInt(cpu[3:], 10, 64) + if err != nil { + return CPUStat{}, -1, fmt.Errorf("couldn't parse %s (cpu/cpuid): %s", line, err) + } + + return cpuStat, cpuID, nil +} + +// Parse a softirq line. +func parseSoftIRQStat(line string) (SoftIRQStat, uint64, error) { + softIRQStat := SoftIRQStat{} + var total uint64 + var prefix string + + _, err := fmt.Sscanf(line, "%s %d %d %d %d %d %d %d %d %d %d %d", + &prefix, &total, + &softIRQStat.Hi, &softIRQStat.Timer, &softIRQStat.NetTx, &softIRQStat.NetRx, + &softIRQStat.Block, &softIRQStat.BlockIoPoll, + &softIRQStat.Tasklet, &softIRQStat.Sched, + &softIRQStat.Hrtimer, &softIRQStat.Rcu) + + if err != nil { + return SoftIRQStat{}, 0, fmt.Errorf("couldn't parse %s (softirq): %s", line, err) + } + + return softIRQStat, total, nil +} + +// NewStat returns an information about current kernel/system statistics. +func (fs FS) NewStat() (Stat, error) { + // See https://www.kernel.org/doc/Documentation/filesystems/proc.txt + + f, err := os.Open(fs.Path("stat")) + if err != nil { + return Stat{}, err + } + defer f.Close() + + stat := Stat{} + + scanner := bufio.NewScanner(f) + for scanner.Scan() { + line := scanner.Text() + parts := strings.Fields(scanner.Text()) + // require at least + if len(parts) < 2 { + continue + } + switch { + case parts[0] == "btime": + if stat.BootTime, err = strconv.ParseUint(parts[1], 10, 64); err != nil { + return Stat{}, fmt.Errorf("couldn't parse %s (btime): %s", parts[1], err) + } + case parts[0] == "intr": + if stat.IRQTotal, err = strconv.ParseUint(parts[1], 10, 64); err != nil { + return Stat{}, fmt.Errorf("couldn't parse %s (intr): %s", parts[1], err) + } + numberedIRQs := parts[2:] + stat.IRQ = make([]uint64, len(numberedIRQs)) + for i, count := range numberedIRQs { + if stat.IRQ[i], err = strconv.ParseUint(count, 10, 64); err != nil { + return Stat{}, fmt.Errorf("couldn't parse %s (intr%d): %s", count, i, err) + } + } + case parts[0] == "ctxt": + if stat.ContextSwitches, err = strconv.ParseUint(parts[1], 10, 64); err != nil { + return Stat{}, fmt.Errorf("couldn't parse %s (ctxt): %s", parts[1], err) + } + case parts[0] == "processes": + if stat.ProcessCreated, err = strconv.ParseUint(parts[1], 10, 64); err != nil { + return Stat{}, fmt.Errorf("couldn't parse %s (processes): %s", parts[1], err) + } + case parts[0] == "procs_running": + if stat.ProcessesRunning, err = strconv.ParseUint(parts[1], 10, 64); err != nil { + return Stat{}, fmt.Errorf("couldn't parse %s (procs_running): %s", parts[1], err) + } + case parts[0] == "procs_blocked": + if stat.ProcessesBlocked, err = strconv.ParseUint(parts[1], 10, 64); err != nil { + return Stat{}, fmt.Errorf("couldn't parse %s (procs_blocked): %s", parts[1], err) + } + case parts[0] == "softirq": + softIRQStats, total, err := parseSoftIRQStat(line) + if err != nil { + return Stat{}, err + } + stat.SoftIRQTotal = total + stat.SoftIRQ = softIRQStats + case strings.HasPrefix(parts[0], "cpu"): + cpuStat, cpuID, err := parseCPUStat(line) + if err != nil { + return Stat{}, err + } + if cpuID == -1 { + stat.CPUTotal = cpuStat + } else { + for int64(len(stat.CPU)) <= cpuID { + stat.CPU = append(stat.CPU, CPUStat{}) + } + stat.CPU[cpuID] = cpuStat + } + } + } + + if err := scanner.Err(); err != nil { + return Stat{}, fmt.Errorf("couldn't parse %s: %s", f.Name(), err) + } + + return stat, nil +} diff --git a/vendor/github.com/prometheus/procfs/sysfs/doc.go b/vendor/github.com/prometheus/procfs/sysfs/doc.go new file mode 100644 index 000000000..9a6c244e9 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/sysfs/doc.go @@ -0,0 +1,16 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package sysfs provides functions to retrieve system and kernel metrics +// from the pseudo-filesystem sys. +package sysfs diff --git a/vendor/github.com/prometheus/procfs/sysfs/fs.go b/vendor/github.com/prometheus/procfs/sysfs/fs.go new file mode 100644 index 000000000..fb15d438a --- /dev/null +++ b/vendor/github.com/prometheus/procfs/sysfs/fs.go @@ -0,0 +1,108 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package sysfs + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/prometheus/procfs/bcache" + "github.com/prometheus/procfs/xfs" +) + +// FS represents the pseudo-filesystem sys, which provides an interface to +// kernel data structures. +type FS string + +// DefaultMountPoint is the common mount point of the sys filesystem. +const DefaultMountPoint = "/sys" + +// NewFS returns a new FS mounted under the given mountPoint. It will error +// if the mount point can't be read. +func NewFS(mountPoint string) (FS, error) { + info, err := os.Stat(mountPoint) + if err != nil { + return "", fmt.Errorf("could not read %s: %s", mountPoint, err) + } + if !info.IsDir() { + return "", fmt.Errorf("mount point %s is not a directory", mountPoint) + } + + return FS(mountPoint), nil +} + +// Path returns the path of the given subsystem relative to the sys root. +func (fs FS) Path(p ...string) string { + return filepath.Join(append([]string{string(fs)}, p...)...) +} + +// XFSStats retrieves XFS filesystem runtime statistics for each mounted XFS +// filesystem. Only available on kernel 4.4+. On older kernels, an empty +// slice of *xfs.Stats will be returned. +func (fs FS) XFSStats() ([]*xfs.Stats, error) { + matches, err := filepath.Glob(fs.Path("fs/xfs/*/stats/stats")) + if err != nil { + return nil, err + } + + stats := make([]*xfs.Stats, 0, len(matches)) + for _, m := range matches { + f, err := os.Open(m) + if err != nil { + return nil, err + } + + // "*" used in glob above indicates the name of the filesystem. + name := filepath.Base(filepath.Dir(filepath.Dir(m))) + + // File must be closed after parsing, regardless of success or + // failure. Defer is not used because of the loop. + s, err := xfs.ParseStats(f) + _ = f.Close() + if err != nil { + return nil, err + } + + s.Name = name + stats = append(stats, s) + } + + return stats, nil +} + +// BcacheStats retrieves bcache runtime statistics for each bcache. +func (fs FS) BcacheStats() ([]*bcache.Stats, error) { + matches, err := filepath.Glob(fs.Path("fs/bcache/*-*")) + if err != nil { + return nil, err + } + + stats := make([]*bcache.Stats, 0, len(matches)) + for _, uuidPath := range matches { + // "*-*" in glob above indicates the name of the bcache. + name := filepath.Base(uuidPath) + + // stats + s, err := bcache.GetStats(uuidPath) + if err != nil { + return nil, err + } + + s.Name = name + stats = append(stats, s) + } + + return stats, nil +} diff --git a/vendor/github.com/prometheus/procfs/xfrm.go b/vendor/github.com/prometheus/procfs/xfrm.go new file mode 100644 index 000000000..ffe9df50d --- /dev/null +++ b/vendor/github.com/prometheus/procfs/xfrm.go @@ -0,0 +1,187 @@ +// Copyright 2017 Prometheus Team +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package procfs + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +// XfrmStat models the contents of /proc/net/xfrm_stat. +type XfrmStat struct { + // All errors which are not matched by other + XfrmInError int + // No buffer is left + XfrmInBufferError int + // Header Error + XfrmInHdrError int + // No state found + // i.e. either inbound SPI, address, or IPSEC protocol at SA is wrong + XfrmInNoStates int + // Transformation protocol specific error + // e.g. SA Key is wrong + XfrmInStateProtoError int + // Transformation mode specific error + XfrmInStateModeError int + // Sequence error + // e.g. sequence number is out of window + XfrmInStateSeqError int + // State is expired + XfrmInStateExpired int + // State has mismatch option + // e.g. UDP encapsulation type is mismatched + XfrmInStateMismatch int + // State is invalid + XfrmInStateInvalid int + // No matching template for states + // e.g. Inbound SAs are correct but SP rule is wrong + XfrmInTmplMismatch int + // No policy is found for states + // e.g. Inbound SAs are correct but no SP is found + XfrmInNoPols int + // Policy discards + XfrmInPolBlock int + // Policy error + XfrmInPolError int + // All errors which are not matched by others + XfrmOutError int + // Bundle generation error + XfrmOutBundleGenError int + // Bundle check error + XfrmOutBundleCheckError int + // No state was found + XfrmOutNoStates int + // Transformation protocol specific error + XfrmOutStateProtoError int + // Transportation mode specific error + XfrmOutStateModeError int + // Sequence error + // i.e sequence number overflow + XfrmOutStateSeqError int + // State is expired + XfrmOutStateExpired int + // Policy discads + XfrmOutPolBlock int + // Policy is dead + XfrmOutPolDead int + // Policy Error + XfrmOutPolError int + XfrmFwdHdrError int + XfrmOutStateInvalid int + XfrmAcquireError int +} + +// NewXfrmStat reads the xfrm_stat statistics. +func NewXfrmStat() (XfrmStat, error) { + fs, err := NewFS(DefaultMountPoint) + if err != nil { + return XfrmStat{}, err + } + + return fs.NewXfrmStat() +} + +// NewXfrmStat reads the xfrm_stat statistics from the 'proc' filesystem. +func (fs FS) NewXfrmStat() (XfrmStat, error) { + file, err := os.Open(fs.Path("net/xfrm_stat")) + if err != nil { + return XfrmStat{}, err + } + defer file.Close() + + var ( + x = XfrmStat{} + s = bufio.NewScanner(file) + ) + + for s.Scan() { + fields := strings.Fields(s.Text()) + + if len(fields) != 2 { + return XfrmStat{}, fmt.Errorf( + "couldnt parse %s line %s", file.Name(), s.Text()) + } + + name := fields[0] + value, err := strconv.Atoi(fields[1]) + if err != nil { + return XfrmStat{}, err + } + + switch name { + case "XfrmInError": + x.XfrmInError = value + case "XfrmInBufferError": + x.XfrmInBufferError = value + case "XfrmInHdrError": + x.XfrmInHdrError = value + case "XfrmInNoStates": + x.XfrmInNoStates = value + case "XfrmInStateProtoError": + x.XfrmInStateProtoError = value + case "XfrmInStateModeError": + x.XfrmInStateModeError = value + case "XfrmInStateSeqError": + x.XfrmInStateSeqError = value + case "XfrmInStateExpired": + x.XfrmInStateExpired = value + case "XfrmInStateInvalid": + x.XfrmInStateInvalid = value + case "XfrmInTmplMismatch": + x.XfrmInTmplMismatch = value + case "XfrmInNoPols": + x.XfrmInNoPols = value + case "XfrmInPolBlock": + x.XfrmInPolBlock = value + case "XfrmInPolError": + x.XfrmInPolError = value + case "XfrmOutError": + x.XfrmOutError = value + case "XfrmInStateMismatch": + x.XfrmInStateMismatch = value + case "XfrmOutBundleGenError": + x.XfrmOutBundleGenError = value + case "XfrmOutBundleCheckError": + x.XfrmOutBundleCheckError = value + case "XfrmOutNoStates": + x.XfrmOutNoStates = value + case "XfrmOutStateProtoError": + x.XfrmOutStateProtoError = value + case "XfrmOutStateModeError": + x.XfrmOutStateModeError = value + case "XfrmOutStateSeqError": + x.XfrmOutStateSeqError = value + case "XfrmOutStateExpired": + x.XfrmOutStateExpired = value + case "XfrmOutPolBlock": + x.XfrmOutPolBlock = value + case "XfrmOutPolDead": + x.XfrmOutPolDead = value + case "XfrmOutPolError": + x.XfrmOutPolError = value + case "XfrmFwdHdrError": + x.XfrmFwdHdrError = value + case "XfrmOutStateInvalid": + x.XfrmOutStateInvalid = value + case "XfrmAcquireError": + x.XfrmAcquireError = value + } + + } + + return x, s.Err() +} diff --git a/vendor/github.com/prometheus/procfs/xfs/parse.go b/vendor/github.com/prometheus/procfs/xfs/parse.go new file mode 100644 index 000000000..c8f6279f3 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/xfs/parse.go @@ -0,0 +1,359 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package xfs + +import ( + "bufio" + "fmt" + "io" + "strconv" + "strings" +) + +// ParseStats parses a Stats from an input io.Reader, using the format +// found in /proc/fs/xfs/stat. +func ParseStats(r io.Reader) (*Stats, error) { + const ( + // Fields parsed into stats structures. + fieldExtentAlloc = "extent_alloc" + fieldAbt = "abt" + fieldBlkMap = "blk_map" + fieldBmbt = "bmbt" + fieldDir = "dir" + fieldTrans = "trans" + fieldIg = "ig" + fieldLog = "log" + fieldRw = "rw" + fieldAttr = "attr" + fieldIcluster = "icluster" + fieldVnodes = "vnodes" + fieldBuf = "buf" + fieldXpc = "xpc" + + // Unimplemented at this time due to lack of documentation. + fieldPushAil = "push_ail" + fieldXstrat = "xstrat" + fieldAbtb2 = "abtb2" + fieldAbtc2 = "abtc2" + fieldBmbt2 = "bmbt2" + fieldIbt2 = "ibt2" + fieldFibt2 = "fibt2" + fieldQm = "qm" + fieldDebug = "debug" + ) + + var xfss Stats + + s := bufio.NewScanner(r) + for s.Scan() { + // Expect at least a string label and a single integer value, ex: + // - abt 0 + // - rw 1 2 + ss := strings.Fields(string(s.Bytes())) + if len(ss) < 2 { + continue + } + label := ss[0] + + // Extended precision counters are uint64 values. + if label == fieldXpc { + us, err := parseUint64s(ss[1:]) + if err != nil { + return nil, err + } + + xfss.ExtendedPrecision, err = extendedPrecisionStats(us) + if err != nil { + return nil, err + } + + continue + } + + // All other counters are uint32 values. + us, err := parseUint32s(ss[1:]) + if err != nil { + return nil, err + } + + switch label { + case fieldExtentAlloc: + xfss.ExtentAllocation, err = extentAllocationStats(us) + case fieldAbt: + xfss.AllocationBTree, err = btreeStats(us) + case fieldBlkMap: + xfss.BlockMapping, err = blockMappingStats(us) + case fieldBmbt: + xfss.BlockMapBTree, err = btreeStats(us) + case fieldDir: + xfss.DirectoryOperation, err = directoryOperationStats(us) + case fieldTrans: + xfss.Transaction, err = transactionStats(us) + case fieldIg: + xfss.InodeOperation, err = inodeOperationStats(us) + case fieldLog: + xfss.LogOperation, err = logOperationStats(us) + case fieldRw: + xfss.ReadWrite, err = readWriteStats(us) + case fieldAttr: + xfss.AttributeOperation, err = attributeOperationStats(us) + case fieldIcluster: + xfss.InodeClustering, err = inodeClusteringStats(us) + case fieldVnodes: + xfss.Vnode, err = vnodeStats(us) + case fieldBuf: + xfss.Buffer, err = bufferStats(us) + } + if err != nil { + return nil, err + } + } + + return &xfss, s.Err() +} + +// extentAllocationStats builds an ExtentAllocationStats from a slice of uint32s. +func extentAllocationStats(us []uint32) (ExtentAllocationStats, error) { + if l := len(us); l != 4 { + return ExtentAllocationStats{}, fmt.Errorf("incorrect number of values for XFS extent allocation stats: %d", l) + } + + return ExtentAllocationStats{ + ExtentsAllocated: us[0], + BlocksAllocated: us[1], + ExtentsFreed: us[2], + BlocksFreed: us[3], + }, nil +} + +// btreeStats builds a BTreeStats from a slice of uint32s. +func btreeStats(us []uint32) (BTreeStats, error) { + if l := len(us); l != 4 { + return BTreeStats{}, fmt.Errorf("incorrect number of values for XFS btree stats: %d", l) + } + + return BTreeStats{ + Lookups: us[0], + Compares: us[1], + RecordsInserted: us[2], + RecordsDeleted: us[3], + }, nil +} + +// BlockMappingStat builds a BlockMappingStats from a slice of uint32s. +func blockMappingStats(us []uint32) (BlockMappingStats, error) { + if l := len(us); l != 7 { + return BlockMappingStats{}, fmt.Errorf("incorrect number of values for XFS block mapping stats: %d", l) + } + + return BlockMappingStats{ + Reads: us[0], + Writes: us[1], + Unmaps: us[2], + ExtentListInsertions: us[3], + ExtentListDeletions: us[4], + ExtentListLookups: us[5], + ExtentListCompares: us[6], + }, nil +} + +// DirectoryOperationStats builds a DirectoryOperationStats from a slice of uint32s. +func directoryOperationStats(us []uint32) (DirectoryOperationStats, error) { + if l := len(us); l != 4 { + return DirectoryOperationStats{}, fmt.Errorf("incorrect number of values for XFS directory operation stats: %d", l) + } + + return DirectoryOperationStats{ + Lookups: us[0], + Creates: us[1], + Removes: us[2], + Getdents: us[3], + }, nil +} + +// TransactionStats builds a TransactionStats from a slice of uint32s. +func transactionStats(us []uint32) (TransactionStats, error) { + if l := len(us); l != 3 { + return TransactionStats{}, fmt.Errorf("incorrect number of values for XFS transaction stats: %d", l) + } + + return TransactionStats{ + Sync: us[0], + Async: us[1], + Empty: us[2], + }, nil +} + +// InodeOperationStats builds an InodeOperationStats from a slice of uint32s. +func inodeOperationStats(us []uint32) (InodeOperationStats, error) { + if l := len(us); l != 7 { + return InodeOperationStats{}, fmt.Errorf("incorrect number of values for XFS inode operation stats: %d", l) + } + + return InodeOperationStats{ + Attempts: us[0], + Found: us[1], + Recycle: us[2], + Missed: us[3], + Duplicate: us[4], + Reclaims: us[5], + AttributeChange: us[6], + }, nil +} + +// LogOperationStats builds a LogOperationStats from a slice of uint32s. +func logOperationStats(us []uint32) (LogOperationStats, error) { + if l := len(us); l != 5 { + return LogOperationStats{}, fmt.Errorf("incorrect number of values for XFS log operation stats: %d", l) + } + + return LogOperationStats{ + Writes: us[0], + Blocks: us[1], + NoInternalBuffers: us[2], + Force: us[3], + ForceSleep: us[4], + }, nil +} + +// ReadWriteStats builds a ReadWriteStats from a slice of uint32s. +func readWriteStats(us []uint32) (ReadWriteStats, error) { + if l := len(us); l != 2 { + return ReadWriteStats{}, fmt.Errorf("incorrect number of values for XFS read write stats: %d", l) + } + + return ReadWriteStats{ + Read: us[0], + Write: us[1], + }, nil +} + +// AttributeOperationStats builds an AttributeOperationStats from a slice of uint32s. +func attributeOperationStats(us []uint32) (AttributeOperationStats, error) { + if l := len(us); l != 4 { + return AttributeOperationStats{}, fmt.Errorf("incorrect number of values for XFS attribute operation stats: %d", l) + } + + return AttributeOperationStats{ + Get: us[0], + Set: us[1], + Remove: us[2], + List: us[3], + }, nil +} + +// InodeClusteringStats builds an InodeClusteringStats from a slice of uint32s. +func inodeClusteringStats(us []uint32) (InodeClusteringStats, error) { + if l := len(us); l != 3 { + return InodeClusteringStats{}, fmt.Errorf("incorrect number of values for XFS inode clustering stats: %d", l) + } + + return InodeClusteringStats{ + Iflush: us[0], + Flush: us[1], + FlushInode: us[2], + }, nil +} + +// VnodeStats builds a VnodeStats from a slice of uint32s. +func vnodeStats(us []uint32) (VnodeStats, error) { + // The attribute "Free" appears to not be available on older XFS + // stats versions. Therefore, 7 or 8 elements may appear in + // this slice. + l := len(us) + if l != 7 && l != 8 { + return VnodeStats{}, fmt.Errorf("incorrect number of values for XFS vnode stats: %d", l) + } + + s := VnodeStats{ + Active: us[0], + Allocate: us[1], + Get: us[2], + Hold: us[3], + Release: us[4], + Reclaim: us[5], + Remove: us[6], + } + + // Skip adding free, unless it is present. The zero value will + // be used in place of an actual count. + if l == 7 { + return s, nil + } + + s.Free = us[7] + return s, nil +} + +// BufferStats builds a BufferStats from a slice of uint32s. +func bufferStats(us []uint32) (BufferStats, error) { + if l := len(us); l != 9 { + return BufferStats{}, fmt.Errorf("incorrect number of values for XFS buffer stats: %d", l) + } + + return BufferStats{ + Get: us[0], + Create: us[1], + GetLocked: us[2], + GetLockedWaited: us[3], + BusyLocked: us[4], + MissLocked: us[5], + PageRetries: us[6], + PageFound: us[7], + GetRead: us[8], + }, nil +} + +// ExtendedPrecisionStats builds an ExtendedPrecisionStats from a slice of uint32s. +func extendedPrecisionStats(us []uint64) (ExtendedPrecisionStats, error) { + if l := len(us); l != 3 { + return ExtendedPrecisionStats{}, fmt.Errorf("incorrect number of values for XFS extended precision stats: %d", l) + } + + return ExtendedPrecisionStats{ + FlushBytes: us[0], + WriteBytes: us[1], + ReadBytes: us[2], + }, nil +} + +// parseUint32s parses a slice of strings into a slice of uint32s. +func parseUint32s(ss []string) ([]uint32, error) { + us := make([]uint32, 0, len(ss)) + for _, s := range ss { + u, err := strconv.ParseUint(s, 10, 32) + if err != nil { + return nil, err + } + + us = append(us, uint32(u)) + } + + return us, nil +} + +// parseUint64s parses a slice of strings into a slice of uint64s. +func parseUint64s(ss []string) ([]uint64, error) { + us := make([]uint64, 0, len(ss)) + for _, s := range ss { + u, err := strconv.ParseUint(s, 10, 64) + if err != nil { + return nil, err + } + + us = append(us, u) + } + + return us, nil +} diff --git a/vendor/github.com/prometheus/procfs/xfs/xfs.go b/vendor/github.com/prometheus/procfs/xfs/xfs.go new file mode 100644 index 000000000..d86794b7c --- /dev/null +++ b/vendor/github.com/prometheus/procfs/xfs/xfs.go @@ -0,0 +1,163 @@ +// Copyright 2017 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package xfs provides access to statistics exposed by the XFS filesystem. +package xfs + +// Stats contains XFS filesystem runtime statistics, parsed from +// /proc/fs/xfs/stat. +// +// The names and meanings of each statistic were taken from +// http://xfs.org/index.php/Runtime_Stats and xfs_stats.h in the Linux +// kernel source. Most counters are uint32s (same data types used in +// xfs_stats.h), but some of the "extended precision stats" are uint64s. +type Stats struct { + // The name of the filesystem used to source these statistics. + // If empty, this indicates aggregated statistics for all XFS + // filesystems on the host. + Name string + + ExtentAllocation ExtentAllocationStats + AllocationBTree BTreeStats + BlockMapping BlockMappingStats + BlockMapBTree BTreeStats + DirectoryOperation DirectoryOperationStats + Transaction TransactionStats + InodeOperation InodeOperationStats + LogOperation LogOperationStats + ReadWrite ReadWriteStats + AttributeOperation AttributeOperationStats + InodeClustering InodeClusteringStats + Vnode VnodeStats + Buffer BufferStats + ExtendedPrecision ExtendedPrecisionStats +} + +// ExtentAllocationStats contains statistics regarding XFS extent allocations. +type ExtentAllocationStats struct { + ExtentsAllocated uint32 + BlocksAllocated uint32 + ExtentsFreed uint32 + BlocksFreed uint32 +} + +// BTreeStats contains statistics regarding an XFS internal B-tree. +type BTreeStats struct { + Lookups uint32 + Compares uint32 + RecordsInserted uint32 + RecordsDeleted uint32 +} + +// BlockMappingStats contains statistics regarding XFS block maps. +type BlockMappingStats struct { + Reads uint32 + Writes uint32 + Unmaps uint32 + ExtentListInsertions uint32 + ExtentListDeletions uint32 + ExtentListLookups uint32 + ExtentListCompares uint32 +} + +// DirectoryOperationStats contains statistics regarding XFS directory entries. +type DirectoryOperationStats struct { + Lookups uint32 + Creates uint32 + Removes uint32 + Getdents uint32 +} + +// TransactionStats contains statistics regarding XFS metadata transactions. +type TransactionStats struct { + Sync uint32 + Async uint32 + Empty uint32 +} + +// InodeOperationStats contains statistics regarding XFS inode operations. +type InodeOperationStats struct { + Attempts uint32 + Found uint32 + Recycle uint32 + Missed uint32 + Duplicate uint32 + Reclaims uint32 + AttributeChange uint32 +} + +// LogOperationStats contains statistics regarding the XFS log buffer. +type LogOperationStats struct { + Writes uint32 + Blocks uint32 + NoInternalBuffers uint32 + Force uint32 + ForceSleep uint32 +} + +// ReadWriteStats contains statistics regarding the number of read and write +// system calls for XFS filesystems. +type ReadWriteStats struct { + Read uint32 + Write uint32 +} + +// AttributeOperationStats contains statistics regarding manipulation of +// XFS extended file attributes. +type AttributeOperationStats struct { + Get uint32 + Set uint32 + Remove uint32 + List uint32 +} + +// InodeClusteringStats contains statistics regarding XFS inode clustering +// operations. +type InodeClusteringStats struct { + Iflush uint32 + Flush uint32 + FlushInode uint32 +} + +// VnodeStats contains statistics regarding XFS vnode operations. +type VnodeStats struct { + Active uint32 + Allocate uint32 + Get uint32 + Hold uint32 + Release uint32 + Reclaim uint32 + Remove uint32 + Free uint32 +} + +// BufferStats contains statistics regarding XFS read/write I/O buffers. +type BufferStats struct { + Get uint32 + Create uint32 + GetLocked uint32 + GetLockedWaited uint32 + BusyLocked uint32 + MissLocked uint32 + PageRetries uint32 + PageFound uint32 + GetRead uint32 +} + +// ExtendedPrecisionStats contains high precision counters used to track the +// total number of bytes read, written, or flushed, during XFS operations. +type ExtendedPrecisionStats struct { + FlushBytes uint64 + WriteBytes uint64 + ReadBytes uint64 +} diff --git a/vendor/github.com/sirupsen/logrus/LICENSE b/vendor/github.com/sirupsen/logrus/LICENSE new file mode 100644 index 000000000..f090cb42f --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Simon Eskildsen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/github.com/sirupsen/logrus/alt_exit.go b/vendor/github.com/sirupsen/logrus/alt_exit.go new file mode 100644 index 000000000..8af90637a --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/alt_exit.go @@ -0,0 +1,64 @@ +package logrus + +// The following code was sourced and modified from the +// https://github.com/tebeka/atexit package governed by the following license: +// +// Copyright (c) 2012 Miki Tebeka . +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import ( + "fmt" + "os" +) + +var handlers = []func(){} + +func runHandler(handler func()) { + defer func() { + if err := recover(); err != nil { + fmt.Fprintln(os.Stderr, "Error: Logrus exit handler error:", err) + } + }() + + handler() +} + +func runHandlers() { + for _, handler := range handlers { + runHandler(handler) + } +} + +// Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code) +func Exit(code int) { + runHandlers() + os.Exit(code) +} + +// RegisterExitHandler adds a Logrus Exit handler, call logrus.Exit to invoke +// all handlers. The handlers will also be invoked when any Fatal log entry is +// made. +// +// This method is useful when a caller wishes to use logrus to log a fatal +// message but also needs to gracefully shutdown. An example usecase could be +// closing database connections, or sending a alert that the application is +// closing. +func RegisterExitHandler(handler func()) { + handlers = append(handlers, handler) +} diff --git a/vendor/github.com/sirupsen/logrus/doc.go b/vendor/github.com/sirupsen/logrus/doc.go new file mode 100644 index 000000000..da67aba06 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/doc.go @@ -0,0 +1,26 @@ +/* +Package logrus is a structured logger for Go, completely API compatible with the standard library logger. + + +The simplest way to use Logrus is simply the package-level exported logger: + + package main + + import ( + log "github.com/sirupsen/logrus" + ) + + func main() { + log.WithFields(log.Fields{ + "animal": "walrus", + "number": 1, + "size": 10, + }).Info("A walrus appears") + } + +Output: + time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10 + +For a full guide visit https://github.com/sirupsen/logrus +*/ +package logrus diff --git a/vendor/github.com/sirupsen/logrus/entry.go b/vendor/github.com/sirupsen/logrus/entry.go new file mode 100644 index 000000000..1fad45e08 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/entry.go @@ -0,0 +1,279 @@ +package logrus + +import ( + "bytes" + "fmt" + "os" + "sync" + "time" +) + +var bufferPool *sync.Pool + +func init() { + bufferPool = &sync.Pool{ + New: func() interface{} { + return new(bytes.Buffer) + }, + } +} + +// Defines the key when adding errors using WithError. +var ErrorKey = "error" + +// An entry is the final or intermediate Logrus logging entry. It contains all +// the fields passed with WithField{,s}. It's finally logged when Debug, Info, +// Warn, Error, Fatal or Panic is called on it. These objects can be reused and +// passed around as much as you wish to avoid field duplication. +type Entry struct { + Logger *Logger + + // Contains all the fields set by the user. + Data Fields + + // Time at which the log entry was created + Time time.Time + + // Level the log entry was logged at: Debug, Info, Warn, Error, Fatal or Panic + // This field will be set on entry firing and the value will be equal to the one in Logger struct field. + Level Level + + // Message passed to Debug, Info, Warn, Error, Fatal or Panic + Message string + + // When formatter is called in entry.log(), an Buffer may be set to entry + Buffer *bytes.Buffer +} + +func NewEntry(logger *Logger) *Entry { + return &Entry{ + Logger: logger, + // Default is three fields, give a little extra room + Data: make(Fields, 5), + } +} + +// Returns the string representation from the reader and ultimately the +// formatter. +func (entry *Entry) String() (string, error) { + serialized, err := entry.Logger.Formatter.Format(entry) + if err != nil { + return "", err + } + str := string(serialized) + return str, nil +} + +// Add an error as single field (using the key defined in ErrorKey) to the Entry. +func (entry *Entry) WithError(err error) *Entry { + return entry.WithField(ErrorKey, err) +} + +// Add a single field to the Entry. +func (entry *Entry) WithField(key string, value interface{}) *Entry { + return entry.WithFields(Fields{key: value}) +} + +// Add a map of fields to the Entry. +func (entry *Entry) WithFields(fields Fields) *Entry { + data := make(Fields, len(entry.Data)+len(fields)) + for k, v := range entry.Data { + data[k] = v + } + for k, v := range fields { + data[k] = v + } + return &Entry{Logger: entry.Logger, Data: data} +} + +// This function is not declared with a pointer value because otherwise +// race conditions will occur when using multiple goroutines +func (entry Entry) log(level Level, msg string) { + var buffer *bytes.Buffer + entry.Time = time.Now() + entry.Level = level + entry.Message = msg + + entry.Logger.mu.Lock() + err := entry.Logger.Hooks.Fire(level, &entry) + entry.Logger.mu.Unlock() + if err != nil { + entry.Logger.mu.Lock() + fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err) + entry.Logger.mu.Unlock() + } + buffer = bufferPool.Get().(*bytes.Buffer) + buffer.Reset() + defer bufferPool.Put(buffer) + entry.Buffer = buffer + serialized, err := entry.Logger.Formatter.Format(&entry) + entry.Buffer = nil + if err != nil { + entry.Logger.mu.Lock() + fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err) + entry.Logger.mu.Unlock() + } else { + entry.Logger.mu.Lock() + _, err = entry.Logger.Out.Write(serialized) + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) + } + entry.Logger.mu.Unlock() + } + + // To avoid Entry#log() returning a value that only would make sense for + // panic() to use in Entry#Panic(), we avoid the allocation by checking + // directly here. + if level <= PanicLevel { + panic(&entry) + } +} + +func (entry *Entry) Debug(args ...interface{}) { + if entry.Logger.level() >= DebugLevel { + entry.log(DebugLevel, fmt.Sprint(args...)) + } +} + +func (entry *Entry) Print(args ...interface{}) { + entry.Info(args...) +} + +func (entry *Entry) Info(args ...interface{}) { + if entry.Logger.level() >= InfoLevel { + entry.log(InfoLevel, fmt.Sprint(args...)) + } +} + +func (entry *Entry) Warn(args ...interface{}) { + if entry.Logger.level() >= WarnLevel { + entry.log(WarnLevel, fmt.Sprint(args...)) + } +} + +func (entry *Entry) Warning(args ...interface{}) { + entry.Warn(args...) +} + +func (entry *Entry) Error(args ...interface{}) { + if entry.Logger.level() >= ErrorLevel { + entry.log(ErrorLevel, fmt.Sprint(args...)) + } +} + +func (entry *Entry) Fatal(args ...interface{}) { + if entry.Logger.level() >= FatalLevel { + entry.log(FatalLevel, fmt.Sprint(args...)) + } + Exit(1) +} + +func (entry *Entry) Panic(args ...interface{}) { + if entry.Logger.level() >= PanicLevel { + entry.log(PanicLevel, fmt.Sprint(args...)) + } + panic(fmt.Sprint(args...)) +} + +// Entry Printf family functions + +func (entry *Entry) Debugf(format string, args ...interface{}) { + if entry.Logger.level() >= DebugLevel { + entry.Debug(fmt.Sprintf(format, args...)) + } +} + +func (entry *Entry) Infof(format string, args ...interface{}) { + if entry.Logger.level() >= InfoLevel { + entry.Info(fmt.Sprintf(format, args...)) + } +} + +func (entry *Entry) Printf(format string, args ...interface{}) { + entry.Infof(format, args...) +} + +func (entry *Entry) Warnf(format string, args ...interface{}) { + if entry.Logger.level() >= WarnLevel { + entry.Warn(fmt.Sprintf(format, args...)) + } +} + +func (entry *Entry) Warningf(format string, args ...interface{}) { + entry.Warnf(format, args...) +} + +func (entry *Entry) Errorf(format string, args ...interface{}) { + if entry.Logger.level() >= ErrorLevel { + entry.Error(fmt.Sprintf(format, args...)) + } +} + +func (entry *Entry) Fatalf(format string, args ...interface{}) { + if entry.Logger.level() >= FatalLevel { + entry.Fatal(fmt.Sprintf(format, args...)) + } + Exit(1) +} + +func (entry *Entry) Panicf(format string, args ...interface{}) { + if entry.Logger.level() >= PanicLevel { + entry.Panic(fmt.Sprintf(format, args...)) + } +} + +// Entry Println family functions + +func (entry *Entry) Debugln(args ...interface{}) { + if entry.Logger.level() >= DebugLevel { + entry.Debug(entry.sprintlnn(args...)) + } +} + +func (entry *Entry) Infoln(args ...interface{}) { + if entry.Logger.level() >= InfoLevel { + entry.Info(entry.sprintlnn(args...)) + } +} + +func (entry *Entry) Println(args ...interface{}) { + entry.Infoln(args...) +} + +func (entry *Entry) Warnln(args ...interface{}) { + if entry.Logger.level() >= WarnLevel { + entry.Warn(entry.sprintlnn(args...)) + } +} + +func (entry *Entry) Warningln(args ...interface{}) { + entry.Warnln(args...) +} + +func (entry *Entry) Errorln(args ...interface{}) { + if entry.Logger.level() >= ErrorLevel { + entry.Error(entry.sprintlnn(args...)) + } +} + +func (entry *Entry) Fatalln(args ...interface{}) { + if entry.Logger.level() >= FatalLevel { + entry.Fatal(entry.sprintlnn(args...)) + } + Exit(1) +} + +func (entry *Entry) Panicln(args ...interface{}) { + if entry.Logger.level() >= PanicLevel { + entry.Panic(entry.sprintlnn(args...)) + } +} + +// Sprintlnn => Sprint no newline. This is to get the behavior of how +// fmt.Sprintln where spaces are always added between operands, regardless of +// their type. Instead of vendoring the Sprintln implementation to spare a +// string allocation, we do the simplest thing. +func (entry *Entry) sprintlnn(args ...interface{}) string { + msg := fmt.Sprintln(args...) + return msg[:len(msg)-1] +} diff --git a/vendor/github.com/sirupsen/logrus/exported.go b/vendor/github.com/sirupsen/logrus/exported.go new file mode 100644 index 000000000..013183eda --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/exported.go @@ -0,0 +1,193 @@ +package logrus + +import ( + "io" +) + +var ( + // std is the name of the standard logger in stdlib `log` + std = New() +) + +func StandardLogger() *Logger { + return std +} + +// SetOutput sets the standard logger output. +func SetOutput(out io.Writer) { + std.mu.Lock() + defer std.mu.Unlock() + std.Out = out +} + +// SetFormatter sets the standard logger formatter. +func SetFormatter(formatter Formatter) { + std.mu.Lock() + defer std.mu.Unlock() + std.Formatter = formatter +} + +// SetLevel sets the standard logger level. +func SetLevel(level Level) { + std.mu.Lock() + defer std.mu.Unlock() + std.SetLevel(level) +} + +// GetLevel returns the standard logger level. +func GetLevel() Level { + std.mu.Lock() + defer std.mu.Unlock() + return std.level() +} + +// AddHook adds a hook to the standard logger hooks. +func AddHook(hook Hook) { + std.mu.Lock() + defer std.mu.Unlock() + std.Hooks.Add(hook) +} + +// WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key. +func WithError(err error) *Entry { + return std.WithField(ErrorKey, err) +} + +// WithField creates an entry from the standard logger and adds a field to +// it. If you want multiple fields, use `WithFields`. +// +// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal +// or Panic on the Entry it returns. +func WithField(key string, value interface{}) *Entry { + return std.WithField(key, value) +} + +// WithFields creates an entry from the standard logger and adds multiple +// fields to it. This is simply a helper for `WithField`, invoking it +// once for each field. +// +// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal +// or Panic on the Entry it returns. +func WithFields(fields Fields) *Entry { + return std.WithFields(fields) +} + +// Debug logs a message at level Debug on the standard logger. +func Debug(args ...interface{}) { + std.Debug(args...) +} + +// Print logs a message at level Info on the standard logger. +func Print(args ...interface{}) { + std.Print(args...) +} + +// Info logs a message at level Info on the standard logger. +func Info(args ...interface{}) { + std.Info(args...) +} + +// Warn logs a message at level Warn on the standard logger. +func Warn(args ...interface{}) { + std.Warn(args...) +} + +// Warning logs a message at level Warn on the standard logger. +func Warning(args ...interface{}) { + std.Warning(args...) +} + +// Error logs a message at level Error on the standard logger. +func Error(args ...interface{}) { + std.Error(args...) +} + +// Panic logs a message at level Panic on the standard logger. +func Panic(args ...interface{}) { + std.Panic(args...) +} + +// Fatal logs a message at level Fatal on the standard logger. +func Fatal(args ...interface{}) { + std.Fatal(args...) +} + +// Debugf logs a message at level Debug on the standard logger. +func Debugf(format string, args ...interface{}) { + std.Debugf(format, args...) +} + +// Printf logs a message at level Info on the standard logger. +func Printf(format string, args ...interface{}) { + std.Printf(format, args...) +} + +// Infof logs a message at level Info on the standard logger. +func Infof(format string, args ...interface{}) { + std.Infof(format, args...) +} + +// Warnf logs a message at level Warn on the standard logger. +func Warnf(format string, args ...interface{}) { + std.Warnf(format, args...) +} + +// Warningf logs a message at level Warn on the standard logger. +func Warningf(format string, args ...interface{}) { + std.Warningf(format, args...) +} + +// Errorf logs a message at level Error on the standard logger. +func Errorf(format string, args ...interface{}) { + std.Errorf(format, args...) +} + +// Panicf logs a message at level Panic on the standard logger. +func Panicf(format string, args ...interface{}) { + std.Panicf(format, args...) +} + +// Fatalf logs a message at level Fatal on the standard logger. +func Fatalf(format string, args ...interface{}) { + std.Fatalf(format, args...) +} + +// Debugln logs a message at level Debug on the standard logger. +func Debugln(args ...interface{}) { + std.Debugln(args...) +} + +// Println logs a message at level Info on the standard logger. +func Println(args ...interface{}) { + std.Println(args...) +} + +// Infoln logs a message at level Info on the standard logger. +func Infoln(args ...interface{}) { + std.Infoln(args...) +} + +// Warnln logs a message at level Warn on the standard logger. +func Warnln(args ...interface{}) { + std.Warnln(args...) +} + +// Warningln logs a message at level Warn on the standard logger. +func Warningln(args ...interface{}) { + std.Warningln(args...) +} + +// Errorln logs a message at level Error on the standard logger. +func Errorln(args ...interface{}) { + std.Errorln(args...) +} + +// Panicln logs a message at level Panic on the standard logger. +func Panicln(args ...interface{}) { + std.Panicln(args...) +} + +// Fatalln logs a message at level Fatal on the standard logger. +func Fatalln(args ...interface{}) { + std.Fatalln(args...) +} diff --git a/vendor/github.com/sirupsen/logrus/formatter.go b/vendor/github.com/sirupsen/logrus/formatter.go new file mode 100644 index 000000000..b183ff5b1 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/formatter.go @@ -0,0 +1,45 @@ +package logrus + +import "time" + +const defaultTimestampFormat = time.RFC3339 + +// The Formatter interface is used to implement a custom Formatter. It takes an +// `Entry`. It exposes all the fields, including the default ones: +// +// * `entry.Data["msg"]`. The message passed from Info, Warn, Error .. +// * `entry.Data["time"]`. The timestamp. +// * `entry.Data["level"]. The level the entry was logged at. +// +// Any additional fields added with `WithField` or `WithFields` are also in +// `entry.Data`. Format is expected to return an array of bytes which are then +// logged to `logger.Out`. +type Formatter interface { + Format(*Entry) ([]byte, error) +} + +// This is to not silently overwrite `time`, `msg` and `level` fields when +// dumping it. If this code wasn't there doing: +// +// logrus.WithField("level", 1).Info("hello") +// +// Would just silently drop the user provided level. Instead with this code +// it'll logged as: +// +// {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."} +// +// It's not exported because it's still using Data in an opinionated way. It's to +// avoid code duplication between the two default formatters. +func prefixFieldClashes(data Fields) { + if t, ok := data["time"]; ok { + data["fields.time"] = t + } + + if m, ok := data["msg"]; ok { + data["fields.msg"] = m + } + + if l, ok := data["level"]; ok { + data["fields.level"] = l + } +} diff --git a/vendor/github.com/sirupsen/logrus/hooks.go b/vendor/github.com/sirupsen/logrus/hooks.go new file mode 100644 index 000000000..3f151cdc3 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/hooks.go @@ -0,0 +1,34 @@ +package logrus + +// A hook to be fired when logging on the logging levels returned from +// `Levels()` on your implementation of the interface. Note that this is not +// fired in a goroutine or a channel with workers, you should handle such +// functionality yourself if your call is non-blocking and you don't wish for +// the logging calls for levels returned from `Levels()` to block. +type Hook interface { + Levels() []Level + Fire(*Entry) error +} + +// Internal type for storing the hooks on a logger instance. +type LevelHooks map[Level][]Hook + +// Add a hook to an instance of logger. This is called with +// `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface. +func (hooks LevelHooks) Add(hook Hook) { + for _, level := range hook.Levels() { + hooks[level] = append(hooks[level], hook) + } +} + +// Fire all the hooks for the passed level. Used by `entry.log` to fire +// appropriate hooks for a log entry. +func (hooks LevelHooks) Fire(level Level, entry *Entry) error { + for _, hook := range hooks[level] { + if err := hook.Fire(entry); err != nil { + return err + } + } + + return nil +} diff --git a/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go b/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go new file mode 100644 index 000000000..329ce0d60 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go @@ -0,0 +1,55 @@ +// +build !windows,!nacl,!plan9 + +package syslog + +import ( + "fmt" + "log/syslog" + "os" + + "github.com/sirupsen/logrus" +) + +// SyslogHook to send logs via syslog. +type SyslogHook struct { + Writer *syslog.Writer + SyslogNetwork string + SyslogRaddr string +} + +// Creates a hook to be added to an instance of logger. This is called with +// `hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_DEBUG, "")` +// `if err == nil { log.Hooks.Add(hook) }` +func NewSyslogHook(network, raddr string, priority syslog.Priority, tag string) (*SyslogHook, error) { + w, err := syslog.Dial(network, raddr, priority, tag) + return &SyslogHook{w, network, raddr}, err +} + +func (hook *SyslogHook) Fire(entry *logrus.Entry) error { + line, err := entry.String() + if err != nil { + fmt.Fprintf(os.Stderr, "Unable to read entry, %v", err) + return err + } + + switch entry.Level { + case logrus.PanicLevel: + return hook.Writer.Crit(line) + case logrus.FatalLevel: + return hook.Writer.Crit(line) + case logrus.ErrorLevel: + return hook.Writer.Err(line) + case logrus.WarnLevel: + return hook.Writer.Warning(line) + case logrus.InfoLevel: + return hook.Writer.Info(line) + case logrus.DebugLevel: + return hook.Writer.Debug(line) + default: + return nil + } +} + +func (hook *SyslogHook) Levels() []logrus.Level { + return logrus.AllLevels +} diff --git a/vendor/github.com/sirupsen/logrus/hooks/test/test.go b/vendor/github.com/sirupsen/logrus/hooks/test/test.go new file mode 100644 index 000000000..62c4845df --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/hooks/test/test.go @@ -0,0 +1,95 @@ +// The Test package is used for testing logrus. It is here for backwards +// compatibility from when logrus' organization was upper-case. Please use +// lower-case logrus and the `null` package instead of this one. +package test + +import ( + "io/ioutil" + "sync" + + "github.com/sirupsen/logrus" +) + +// Hook is a hook designed for dealing with logs in test scenarios. +type Hook struct { + // Entries is an array of all entries that have been received by this hook. + // For safe access, use the AllEntries() method, rather than reading this + // value directly. + Entries []*logrus.Entry + mu sync.RWMutex +} + +// NewGlobal installs a test hook for the global logger. +func NewGlobal() *Hook { + + hook := new(Hook) + logrus.AddHook(hook) + + return hook + +} + +// NewLocal installs a test hook for a given local logger. +func NewLocal(logger *logrus.Logger) *Hook { + + hook := new(Hook) + logger.Hooks.Add(hook) + + return hook + +} + +// NewNullLogger creates a discarding logger and installs the test hook. +func NewNullLogger() (*logrus.Logger, *Hook) { + + logger := logrus.New() + logger.Out = ioutil.Discard + + return logger, NewLocal(logger) + +} + +func (t *Hook) Fire(e *logrus.Entry) error { + t.mu.Lock() + defer t.mu.Unlock() + t.Entries = append(t.Entries, e) + return nil +} + +func (t *Hook) Levels() []logrus.Level { + return logrus.AllLevels +} + +// LastEntry returns the last entry that was logged or nil. +func (t *Hook) LastEntry() *logrus.Entry { + t.mu.RLock() + defer t.mu.RUnlock() + i := len(t.Entries) - 1 + if i < 0 { + return nil + } + // Make a copy, for safety + e := *t.Entries[i] + return &e +} + +// AllEntries returns all entries that were logged. +func (t *Hook) AllEntries() []*logrus.Entry { + t.mu.RLock() + defer t.mu.RUnlock() + // Make a copy so the returned value won't race with future log requests + entries := make([]*logrus.Entry, len(t.Entries)) + for i, entry := range t.Entries { + // Make a copy, for safety + e := *entry + entries[i] = &e + } + return entries +} + +// Reset removes all Entries from this test hook. +func (t *Hook) Reset() { + t.mu.Lock() + defer t.mu.Unlock() + t.Entries = make([]*logrus.Entry, 0) +} diff --git a/vendor/github.com/sirupsen/logrus/json_formatter.go b/vendor/github.com/sirupsen/logrus/json_formatter.go new file mode 100644 index 000000000..fb01c1b10 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/json_formatter.go @@ -0,0 +1,79 @@ +package logrus + +import ( + "encoding/json" + "fmt" +) + +type fieldKey string + +// FieldMap allows customization of the key names for default fields. +type FieldMap map[fieldKey]string + +// Default key names for the default fields +const ( + FieldKeyMsg = "msg" + FieldKeyLevel = "level" + FieldKeyTime = "time" +) + +func (f FieldMap) resolve(key fieldKey) string { + if k, ok := f[key]; ok { + return k + } + + return string(key) +} + +// JSONFormatter formats logs into parsable json +type JSONFormatter struct { + // TimestampFormat sets the format used for marshaling timestamps. + TimestampFormat string + + // DisableTimestamp allows disabling automatic timestamps in output + DisableTimestamp bool + + // FieldMap allows users to customize the names of keys for default fields. + // As an example: + // formatter := &JSONFormatter{ + // FieldMap: FieldMap{ + // FieldKeyTime: "@timestamp", + // FieldKeyLevel: "@level", + // FieldKeyMsg: "@message", + // }, + // } + FieldMap FieldMap +} + +// Format renders a single log entry +func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { + data := make(Fields, len(entry.Data)+3) + for k, v := range entry.Data { + switch v := v.(type) { + case error: + // Otherwise errors are ignored by `encoding/json` + // https://github.com/sirupsen/logrus/issues/137 + data[k] = v.Error() + default: + data[k] = v + } + } + prefixFieldClashes(data) + + timestampFormat := f.TimestampFormat + if timestampFormat == "" { + timestampFormat = defaultTimestampFormat + } + + if !f.DisableTimestamp { + data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat) + } + data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message + data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String() + + serialized, err := json.Marshal(data) + if err != nil { + return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) + } + return append(serialized, '\n'), nil +} diff --git a/vendor/github.com/sirupsen/logrus/logger.go b/vendor/github.com/sirupsen/logrus/logger.go new file mode 100644 index 000000000..fdaf8a653 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/logger.go @@ -0,0 +1,323 @@ +package logrus + +import ( + "io" + "os" + "sync" + "sync/atomic" +) + +type Logger struct { + // The logs are `io.Copy`'d to this in a mutex. It's common to set this to a + // file, or leave it default which is `os.Stderr`. You can also set this to + // something more adventorous, such as logging to Kafka. + Out io.Writer + // Hooks for the logger instance. These allow firing events based on logging + // levels and log entries. For example, to send errors to an error tracking + // service, log to StatsD or dump the core on fatal errors. + Hooks LevelHooks + // All log entries pass through the formatter before logged to Out. The + // included formatters are `TextFormatter` and `JSONFormatter` for which + // TextFormatter is the default. In development (when a TTY is attached) it + // logs with colors, but to a file it wouldn't. You can easily implement your + // own that implements the `Formatter` interface, see the `README` or included + // formatters for examples. + Formatter Formatter + // The logging level the logger should log at. This is typically (and defaults + // to) `logrus.Info`, which allows Info(), Warn(), Error() and Fatal() to be + // logged. + Level Level + // Used to sync writing to the log. Locking is enabled by Default + mu MutexWrap + // Reusable empty entry + entryPool sync.Pool +} + +type MutexWrap struct { + lock sync.Mutex + disabled bool +} + +func (mw *MutexWrap) Lock() { + if !mw.disabled { + mw.lock.Lock() + } +} + +func (mw *MutexWrap) Unlock() { + if !mw.disabled { + mw.lock.Unlock() + } +} + +func (mw *MutexWrap) Disable() { + mw.disabled = true +} + +// Creates a new logger. Configuration should be set by changing `Formatter`, +// `Out` and `Hooks` directly on the default logger instance. You can also just +// instantiate your own: +// +// var log = &Logger{ +// Out: os.Stderr, +// Formatter: new(JSONFormatter), +// Hooks: make(LevelHooks), +// Level: logrus.DebugLevel, +// } +// +// It's recommended to make this a global instance called `log`. +func New() *Logger { + return &Logger{ + Out: os.Stderr, + Formatter: new(TextFormatter), + Hooks: make(LevelHooks), + Level: InfoLevel, + } +} + +func (logger *Logger) newEntry() *Entry { + entry, ok := logger.entryPool.Get().(*Entry) + if ok { + return entry + } + return NewEntry(logger) +} + +func (logger *Logger) releaseEntry(entry *Entry) { + logger.entryPool.Put(entry) +} + +// Adds a field to the log entry, note that it doesn't log until you call +// Debug, Print, Info, Warn, Fatal or Panic. It only creates a log entry. +// If you want multiple fields, use `WithFields`. +func (logger *Logger) WithField(key string, value interface{}) *Entry { + entry := logger.newEntry() + defer logger.releaseEntry(entry) + return entry.WithField(key, value) +} + +// Adds a struct of fields to the log entry. All it does is call `WithField` for +// each `Field`. +func (logger *Logger) WithFields(fields Fields) *Entry { + entry := logger.newEntry() + defer logger.releaseEntry(entry) + return entry.WithFields(fields) +} + +// Add an error as single field to the log entry. All it does is call +// `WithError` for the given `error`. +func (logger *Logger) WithError(err error) *Entry { + entry := logger.newEntry() + defer logger.releaseEntry(entry) + return entry.WithError(err) +} + +func (logger *Logger) Debugf(format string, args ...interface{}) { + if logger.level() >= DebugLevel { + entry := logger.newEntry() + entry.Debugf(format, args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Infof(format string, args ...interface{}) { + if logger.level() >= InfoLevel { + entry := logger.newEntry() + entry.Infof(format, args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Printf(format string, args ...interface{}) { + entry := logger.newEntry() + entry.Printf(format, args...) + logger.releaseEntry(entry) +} + +func (logger *Logger) Warnf(format string, args ...interface{}) { + if logger.level() >= WarnLevel { + entry := logger.newEntry() + entry.Warnf(format, args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Warningf(format string, args ...interface{}) { + if logger.level() >= WarnLevel { + entry := logger.newEntry() + entry.Warnf(format, args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Errorf(format string, args ...interface{}) { + if logger.level() >= ErrorLevel { + entry := logger.newEntry() + entry.Errorf(format, args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Fatalf(format string, args ...interface{}) { + if logger.level() >= FatalLevel { + entry := logger.newEntry() + entry.Fatalf(format, args...) + logger.releaseEntry(entry) + } + Exit(1) +} + +func (logger *Logger) Panicf(format string, args ...interface{}) { + if logger.level() >= PanicLevel { + entry := logger.newEntry() + entry.Panicf(format, args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Debug(args ...interface{}) { + if logger.level() >= DebugLevel { + entry := logger.newEntry() + entry.Debug(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Info(args ...interface{}) { + if logger.level() >= InfoLevel { + entry := logger.newEntry() + entry.Info(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Print(args ...interface{}) { + entry := logger.newEntry() + entry.Info(args...) + logger.releaseEntry(entry) +} + +func (logger *Logger) Warn(args ...interface{}) { + if logger.level() >= WarnLevel { + entry := logger.newEntry() + entry.Warn(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Warning(args ...interface{}) { + if logger.level() >= WarnLevel { + entry := logger.newEntry() + entry.Warn(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Error(args ...interface{}) { + if logger.level() >= ErrorLevel { + entry := logger.newEntry() + entry.Error(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Fatal(args ...interface{}) { + if logger.level() >= FatalLevel { + entry := logger.newEntry() + entry.Fatal(args...) + logger.releaseEntry(entry) + } + Exit(1) +} + +func (logger *Logger) Panic(args ...interface{}) { + if logger.level() >= PanicLevel { + entry := logger.newEntry() + entry.Panic(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Debugln(args ...interface{}) { + if logger.level() >= DebugLevel { + entry := logger.newEntry() + entry.Debugln(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Infoln(args ...interface{}) { + if logger.level() >= InfoLevel { + entry := logger.newEntry() + entry.Infoln(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Println(args ...interface{}) { + entry := logger.newEntry() + entry.Println(args...) + logger.releaseEntry(entry) +} + +func (logger *Logger) Warnln(args ...interface{}) { + if logger.level() >= WarnLevel { + entry := logger.newEntry() + entry.Warnln(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Warningln(args ...interface{}) { + if logger.level() >= WarnLevel { + entry := logger.newEntry() + entry.Warnln(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Errorln(args ...interface{}) { + if logger.level() >= ErrorLevel { + entry := logger.newEntry() + entry.Errorln(args...) + logger.releaseEntry(entry) + } +} + +func (logger *Logger) Fatalln(args ...interface{}) { + if logger.level() >= FatalLevel { + entry := logger.newEntry() + entry.Fatalln(args...) + logger.releaseEntry(entry) + } + Exit(1) +} + +func (logger *Logger) Panicln(args ...interface{}) { + if logger.level() >= PanicLevel { + entry := logger.newEntry() + entry.Panicln(args...) + logger.releaseEntry(entry) + } +} + +//When file is opened with appending mode, it's safe to +//write concurrently to a file (within 4k message on Linux). +//In these cases user can choose to disable the lock. +func (logger *Logger) SetNoLock() { + logger.mu.Disable() +} + +func (logger *Logger) level() Level { + return Level(atomic.LoadUint32((*uint32)(&logger.Level))) +} + +func (logger *Logger) SetLevel(level Level) { + atomic.StoreUint32((*uint32)(&logger.Level), uint32(level)) +} + +func (logger *Logger) AddHook(hook Hook) { + logger.mu.Lock() + defer logger.mu.Unlock() + logger.Hooks.Add(hook) +} diff --git a/vendor/github.com/sirupsen/logrus/logrus.go b/vendor/github.com/sirupsen/logrus/logrus.go new file mode 100644 index 000000000..dd3899974 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/logrus.go @@ -0,0 +1,143 @@ +package logrus + +import ( + "fmt" + "log" + "strings" +) + +// Fields type, used to pass to `WithFields`. +type Fields map[string]interface{} + +// Level type +type Level uint32 + +// Convert the Level to a string. E.g. PanicLevel becomes "panic". +func (level Level) String() string { + switch level { + case DebugLevel: + return "debug" + case InfoLevel: + return "info" + case WarnLevel: + return "warning" + case ErrorLevel: + return "error" + case FatalLevel: + return "fatal" + case PanicLevel: + return "panic" + } + + return "unknown" +} + +// ParseLevel takes a string level and returns the Logrus log level constant. +func ParseLevel(lvl string) (Level, error) { + switch strings.ToLower(lvl) { + case "panic": + return PanicLevel, nil + case "fatal": + return FatalLevel, nil + case "error": + return ErrorLevel, nil + case "warn", "warning": + return WarnLevel, nil + case "info": + return InfoLevel, nil + case "debug": + return DebugLevel, nil + } + + var l Level + return l, fmt.Errorf("not a valid logrus Level: %q", lvl) +} + +// A constant exposing all logging levels +var AllLevels = []Level{ + PanicLevel, + FatalLevel, + ErrorLevel, + WarnLevel, + InfoLevel, + DebugLevel, +} + +// These are the different logging levels. You can set the logging level to log +// on your instance of logger, obtained with `logrus.New()`. +const ( + // PanicLevel level, highest level of severity. Logs and then calls panic with the + // message passed to Debug, Info, ... + PanicLevel Level = iota + // FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the + // logging level is set to Panic. + FatalLevel + // ErrorLevel level. Logs. Used for errors that should definitely be noted. + // Commonly used for hooks to send errors to an error tracking service. + ErrorLevel + // WarnLevel level. Non-critical entries that deserve eyes. + WarnLevel + // InfoLevel level. General operational entries about what's going on inside the + // application. + InfoLevel + // DebugLevel level. Usually only enabled when debugging. Very verbose logging. + DebugLevel +) + +// Won't compile if StdLogger can't be realized by a log.Logger +var ( + _ StdLogger = &log.Logger{} + _ StdLogger = &Entry{} + _ StdLogger = &Logger{} +) + +// StdLogger is what your logrus-enabled library should take, that way +// it'll accept a stdlib logger and a logrus logger. There's no standard +// interface, this is the closest we get, unfortunately. +type StdLogger interface { + Print(...interface{}) + Printf(string, ...interface{}) + Println(...interface{}) + + Fatal(...interface{}) + Fatalf(string, ...interface{}) + Fatalln(...interface{}) + + Panic(...interface{}) + Panicf(string, ...interface{}) + Panicln(...interface{}) +} + +// The FieldLogger interface generalizes the Entry and Logger types +type FieldLogger interface { + WithField(key string, value interface{}) *Entry + WithFields(fields Fields) *Entry + WithError(err error) *Entry + + Debugf(format string, args ...interface{}) + Infof(format string, args ...interface{}) + Printf(format string, args ...interface{}) + Warnf(format string, args ...interface{}) + Warningf(format string, args ...interface{}) + Errorf(format string, args ...interface{}) + Fatalf(format string, args ...interface{}) + Panicf(format string, args ...interface{}) + + Debug(args ...interface{}) + Info(args ...interface{}) + Print(args ...interface{}) + Warn(args ...interface{}) + Warning(args ...interface{}) + Error(args ...interface{}) + Fatal(args ...interface{}) + Panic(args ...interface{}) + + Debugln(args ...interface{}) + Infoln(args ...interface{}) + Println(args ...interface{}) + Warnln(args ...interface{}) + Warningln(args ...interface{}) + Errorln(args ...interface{}) + Fatalln(args ...interface{}) + Panicln(args ...interface{}) +} diff --git a/vendor/github.com/sirupsen/logrus/terminal_bsd.go b/vendor/github.com/sirupsen/logrus/terminal_bsd.go new file mode 100644 index 000000000..d7b3893f3 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/terminal_bsd.go @@ -0,0 +1,10 @@ +// +build darwin freebsd openbsd netbsd dragonfly +// +build !appengine + +package logrus + +import "golang.org/x/sys/unix" + +const ioctlReadTermios = unix.TIOCGETA + +type Termios unix.Termios diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_appengine.go b/vendor/github.com/sirupsen/logrus/terminal_check_appengine.go new file mode 100644 index 000000000..2403de981 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/terminal_check_appengine.go @@ -0,0 +1,11 @@ +// +build appengine + +package logrus + +import ( + "io" +) + +func checkIfTerminal(w io.Writer) bool { + return true +} diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go b/vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go new file mode 100644 index 000000000..116bcb4e3 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go @@ -0,0 +1,19 @@ +// +build !appengine + +package logrus + +import ( + "io" + "os" + + "golang.org/x/crypto/ssh/terminal" +) + +func checkIfTerminal(w io.Writer) bool { + switch v := w.(type) { + case *os.File: + return terminal.IsTerminal(int(v.Fd())) + default: + return false + } +} diff --git a/vendor/github.com/sirupsen/logrus/terminal_linux.go b/vendor/github.com/sirupsen/logrus/terminal_linux.go new file mode 100644 index 000000000..88d7298e2 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/terminal_linux.go @@ -0,0 +1,14 @@ +// Based on ssh/terminal: +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !appengine + +package logrus + +import "golang.org/x/sys/unix" + +const ioctlReadTermios = unix.TCGETS + +type Termios unix.Termios diff --git a/vendor/github.com/sirupsen/logrus/text_formatter.go b/vendor/github.com/sirupsen/logrus/text_formatter.go new file mode 100644 index 000000000..61b21caea --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/text_formatter.go @@ -0,0 +1,178 @@ +package logrus + +import ( + "bytes" + "fmt" + "sort" + "strings" + "sync" + "time" +) + +const ( + nocolor = 0 + red = 31 + green = 32 + yellow = 33 + blue = 36 + gray = 37 +) + +var ( + baseTimestamp time.Time +) + +func init() { + baseTimestamp = time.Now() +} + +// TextFormatter formats logs into text +type TextFormatter struct { + // Set to true to bypass checking for a TTY before outputting colors. + ForceColors bool + + // Force disabling colors. + DisableColors bool + + // Disable timestamp logging. useful when output is redirected to logging + // system that already adds timestamps. + DisableTimestamp bool + + // Enable logging the full timestamp when a TTY is attached instead of just + // the time passed since beginning of execution. + FullTimestamp bool + + // TimestampFormat to use for display when a full timestamp is printed + TimestampFormat string + + // The fields are sorted by default for a consistent output. For applications + // that log extremely frequently and don't use the JSON formatter this may not + // be desired. + DisableSorting bool + + // QuoteEmptyFields will wrap empty fields in quotes if true + QuoteEmptyFields bool + + // Whether the logger's out is to a terminal + isTerminal bool + + sync.Once +} + +func (f *TextFormatter) init(entry *Entry) { + if entry.Logger != nil { + f.isTerminal = checkIfTerminal(entry.Logger.Out) + } +} + +// Format renders a single log entry +func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { + var b *bytes.Buffer + keys := make([]string, 0, len(entry.Data)) + for k := range entry.Data { + keys = append(keys, k) + } + + if !f.DisableSorting { + sort.Strings(keys) + } + if entry.Buffer != nil { + b = entry.Buffer + } else { + b = &bytes.Buffer{} + } + + prefixFieldClashes(entry.Data) + + f.Do(func() { f.init(entry) }) + + isColored := (f.ForceColors || f.isTerminal) && !f.DisableColors + + timestampFormat := f.TimestampFormat + if timestampFormat == "" { + timestampFormat = defaultTimestampFormat + } + if isColored { + f.printColored(b, entry, keys, timestampFormat) + } else { + if !f.DisableTimestamp { + f.appendKeyValue(b, "time", entry.Time.Format(timestampFormat)) + } + f.appendKeyValue(b, "level", entry.Level.String()) + if entry.Message != "" { + f.appendKeyValue(b, "msg", entry.Message) + } + for _, key := range keys { + f.appendKeyValue(b, key, entry.Data[key]) + } + } + + b.WriteByte('\n') + return b.Bytes(), nil +} + +func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, timestampFormat string) { + var levelColor int + switch entry.Level { + case DebugLevel: + levelColor = gray + case WarnLevel: + levelColor = yellow + case ErrorLevel, FatalLevel, PanicLevel: + levelColor = red + default: + levelColor = blue + } + + levelText := strings.ToUpper(entry.Level.String())[0:4] + + if f.DisableTimestamp { + fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m %-44s ", levelColor, levelText, entry.Message) + } else if !f.FullTimestamp { + fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), entry.Message) + } else { + fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), entry.Message) + } + for _, k := range keys { + v := entry.Data[k] + fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k) + f.appendValue(b, v) + } +} + +func (f *TextFormatter) needsQuoting(text string) bool { + if f.QuoteEmptyFields && len(text) == 0 { + return true + } + for _, ch := range text { + if !((ch >= 'a' && ch <= 'z') || + (ch >= 'A' && ch <= 'Z') || + (ch >= '0' && ch <= '9') || + ch == '-' || ch == '.' || ch == '_' || ch == '/' || ch == '@' || ch == '^' || ch == '+') { + return true + } + } + return false +} + +func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) { + if b.Len() > 0 { + b.WriteByte(' ') + } + b.WriteString(key) + b.WriteByte('=') + f.appendValue(b, value) +} + +func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) { + stringVal, ok := value.(string) + if !ok { + stringVal = fmt.Sprint(value) + } + + if !f.needsQuoting(stringVal) { + b.WriteString(stringVal) + } else { + b.WriteString(fmt.Sprintf("%q", stringVal)) + } +} diff --git a/vendor/github.com/sirupsen/logrus/writer.go b/vendor/github.com/sirupsen/logrus/writer.go new file mode 100644 index 000000000..7bdebedc6 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/writer.go @@ -0,0 +1,62 @@ +package logrus + +import ( + "bufio" + "io" + "runtime" +) + +func (logger *Logger) Writer() *io.PipeWriter { + return logger.WriterLevel(InfoLevel) +} + +func (logger *Logger) WriterLevel(level Level) *io.PipeWriter { + return NewEntry(logger).WriterLevel(level) +} + +func (entry *Entry) Writer() *io.PipeWriter { + return entry.WriterLevel(InfoLevel) +} + +func (entry *Entry) WriterLevel(level Level) *io.PipeWriter { + reader, writer := io.Pipe() + + var printFunc func(args ...interface{}) + + switch level { + case DebugLevel: + printFunc = entry.Debug + case InfoLevel: + printFunc = entry.Info + case WarnLevel: + printFunc = entry.Warn + case ErrorLevel: + printFunc = entry.Error + case FatalLevel: + printFunc = entry.Fatal + case PanicLevel: + printFunc = entry.Panic + default: + printFunc = entry.Print + } + + go entry.writerScanner(reader, printFunc) + runtime.SetFinalizer(writer, writerFinalizer) + + return writer +} + +func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) { + scanner := bufio.NewScanner(reader) + for scanner.Scan() { + printFunc(scanner.Text()) + } + if err := scanner.Err(); err != nil { + entry.Errorf("Error while reading from Writer: %s", err) + } + reader.Close() +} + +func writerFinalizer(writer *io.PipeWriter) { + writer.Close() +} diff --git a/vendor/github.com/cznic/b/LICENSE b/vendor/golang.org/x/crypto/ssh/terminal/LICENSE similarity index 92% rename from vendor/github.com/cznic/b/LICENSE rename to vendor/golang.org/x/crypto/ssh/terminal/LICENSE index 54c6e9087..6a66aea5e 100644 --- a/vendor/github.com/cznic/b/LICENSE +++ b/vendor/golang.org/x/crypto/ssh/terminal/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014 The b Authors. All rights reserved. +Copyright (c) 2009 The Go Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the names of the authors nor the names of the + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/vendor/golang.org/x/crypto/ssh/terminal/terminal.go b/vendor/golang.org/x/crypto/ssh/terminal/terminal.go new file mode 100644 index 000000000..9a887598f --- /dev/null +++ b/vendor/golang.org/x/crypto/ssh/terminal/terminal.go @@ -0,0 +1,951 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package terminal + +import ( + "bytes" + "io" + "sync" + "unicode/utf8" +) + +// EscapeCodes contains escape sequences that can be written to the terminal in +// order to achieve different styles of text. +type EscapeCodes struct { + // Foreground colors + Black, Red, Green, Yellow, Blue, Magenta, Cyan, White []byte + + // Reset all attributes + Reset []byte +} + +var vt100EscapeCodes = EscapeCodes{ + Black: []byte{keyEscape, '[', '3', '0', 'm'}, + Red: []byte{keyEscape, '[', '3', '1', 'm'}, + Green: []byte{keyEscape, '[', '3', '2', 'm'}, + Yellow: []byte{keyEscape, '[', '3', '3', 'm'}, + Blue: []byte{keyEscape, '[', '3', '4', 'm'}, + Magenta: []byte{keyEscape, '[', '3', '5', 'm'}, + Cyan: []byte{keyEscape, '[', '3', '6', 'm'}, + White: []byte{keyEscape, '[', '3', '7', 'm'}, + + Reset: []byte{keyEscape, '[', '0', 'm'}, +} + +// Terminal contains the state for running a VT100 terminal that is capable of +// reading lines of input. +type Terminal struct { + // AutoCompleteCallback, if non-null, is called for each keypress with + // the full input line and the current position of the cursor (in + // bytes, as an index into |line|). If it returns ok=false, the key + // press is processed normally. Otherwise it returns a replacement line + // and the new cursor position. + AutoCompleteCallback func(line string, pos int, key rune) (newLine string, newPos int, ok bool) + + // Escape contains a pointer to the escape codes for this terminal. + // It's always a valid pointer, although the escape codes themselves + // may be empty if the terminal doesn't support them. + Escape *EscapeCodes + + // lock protects the terminal and the state in this object from + // concurrent processing of a key press and a Write() call. + lock sync.Mutex + + c io.ReadWriter + prompt []rune + + // line is the current line being entered. + line []rune + // pos is the logical position of the cursor in line + pos int + // echo is true if local echo is enabled + echo bool + // pasteActive is true iff there is a bracketed paste operation in + // progress. + pasteActive bool + + // cursorX contains the current X value of the cursor where the left + // edge is 0. cursorY contains the row number where the first row of + // the current line is 0. + cursorX, cursorY int + // maxLine is the greatest value of cursorY so far. + maxLine int + + termWidth, termHeight int + + // outBuf contains the terminal data to be sent. + outBuf []byte + // remainder contains the remainder of any partial key sequences after + // a read. It aliases into inBuf. + remainder []byte + inBuf [256]byte + + // history contains previously entered commands so that they can be + // accessed with the up and down keys. + history stRingBuffer + // historyIndex stores the currently accessed history entry, where zero + // means the immediately previous entry. + historyIndex int + // When navigating up and down the history it's possible to return to + // the incomplete, initial line. That value is stored in + // historyPending. + historyPending string +} + +// NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is +// a local terminal, that terminal must first have been put into raw mode. +// prompt is a string that is written at the start of each input line (i.e. +// "> "). +func NewTerminal(c io.ReadWriter, prompt string) *Terminal { + return &Terminal{ + Escape: &vt100EscapeCodes, + c: c, + prompt: []rune(prompt), + termWidth: 80, + termHeight: 24, + echo: true, + historyIndex: -1, + } +} + +const ( + keyCtrlD = 4 + keyCtrlU = 21 + keyEnter = '\r' + keyEscape = 27 + keyBackspace = 127 + keyUnknown = 0xd800 /* UTF-16 surrogate area */ + iota + keyUp + keyDown + keyLeft + keyRight + keyAltLeft + keyAltRight + keyHome + keyEnd + keyDeleteWord + keyDeleteLine + keyClearScreen + keyPasteStart + keyPasteEnd +) + +var ( + crlf = []byte{'\r', '\n'} + pasteStart = []byte{keyEscape, '[', '2', '0', '0', '~'} + pasteEnd = []byte{keyEscape, '[', '2', '0', '1', '~'} +) + +// bytesToKey tries to parse a key sequence from b. If successful, it returns +// the key and the remainder of the input. Otherwise it returns utf8.RuneError. +func bytesToKey(b []byte, pasteActive bool) (rune, []byte) { + if len(b) == 0 { + return utf8.RuneError, nil + } + + if !pasteActive { + switch b[0] { + case 1: // ^A + return keyHome, b[1:] + case 5: // ^E + return keyEnd, b[1:] + case 8: // ^H + return keyBackspace, b[1:] + case 11: // ^K + return keyDeleteLine, b[1:] + case 12: // ^L + return keyClearScreen, b[1:] + case 23: // ^W + return keyDeleteWord, b[1:] + } + } + + if b[0] != keyEscape { + if !utf8.FullRune(b) { + return utf8.RuneError, b + } + r, l := utf8.DecodeRune(b) + return r, b[l:] + } + + if !pasteActive && len(b) >= 3 && b[0] == keyEscape && b[1] == '[' { + switch b[2] { + case 'A': + return keyUp, b[3:] + case 'B': + return keyDown, b[3:] + case 'C': + return keyRight, b[3:] + case 'D': + return keyLeft, b[3:] + case 'H': + return keyHome, b[3:] + case 'F': + return keyEnd, b[3:] + } + } + + if !pasteActive && len(b) >= 6 && b[0] == keyEscape && b[1] == '[' && b[2] == '1' && b[3] == ';' && b[4] == '3' { + switch b[5] { + case 'C': + return keyAltRight, b[6:] + case 'D': + return keyAltLeft, b[6:] + } + } + + if !pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteStart) { + return keyPasteStart, b[6:] + } + + if pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteEnd) { + return keyPasteEnd, b[6:] + } + + // If we get here then we have a key that we don't recognise, or a + // partial sequence. It's not clear how one should find the end of a + // sequence without knowing them all, but it seems that [a-zA-Z~] only + // appears at the end of a sequence. + for i, c := range b[0:] { + if c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '~' { + return keyUnknown, b[i+1:] + } + } + + return utf8.RuneError, b +} + +// queue appends data to the end of t.outBuf +func (t *Terminal) queue(data []rune) { + t.outBuf = append(t.outBuf, []byte(string(data))...) +} + +var eraseUnderCursor = []rune{' ', keyEscape, '[', 'D'} +var space = []rune{' '} + +func isPrintable(key rune) bool { + isInSurrogateArea := key >= 0xd800 && key <= 0xdbff + return key >= 32 && !isInSurrogateArea +} + +// moveCursorToPos appends data to t.outBuf which will move the cursor to the +// given, logical position in the text. +func (t *Terminal) moveCursorToPos(pos int) { + if !t.echo { + return + } + + x := visualLength(t.prompt) + pos + y := x / t.termWidth + x = x % t.termWidth + + up := 0 + if y < t.cursorY { + up = t.cursorY - y + } + + down := 0 + if y > t.cursorY { + down = y - t.cursorY + } + + left := 0 + if x < t.cursorX { + left = t.cursorX - x + } + + right := 0 + if x > t.cursorX { + right = x - t.cursorX + } + + t.cursorX = x + t.cursorY = y + t.move(up, down, left, right) +} + +func (t *Terminal) move(up, down, left, right int) { + movement := make([]rune, 3*(up+down+left+right)) + m := movement + for i := 0; i < up; i++ { + m[0] = keyEscape + m[1] = '[' + m[2] = 'A' + m = m[3:] + } + for i := 0; i < down; i++ { + m[0] = keyEscape + m[1] = '[' + m[2] = 'B' + m = m[3:] + } + for i := 0; i < left; i++ { + m[0] = keyEscape + m[1] = '[' + m[2] = 'D' + m = m[3:] + } + for i := 0; i < right; i++ { + m[0] = keyEscape + m[1] = '[' + m[2] = 'C' + m = m[3:] + } + + t.queue(movement) +} + +func (t *Terminal) clearLineToRight() { + op := []rune{keyEscape, '[', 'K'} + t.queue(op) +} + +const maxLineLength = 4096 + +func (t *Terminal) setLine(newLine []rune, newPos int) { + if t.echo { + t.moveCursorToPos(0) + t.writeLine(newLine) + for i := len(newLine); i < len(t.line); i++ { + t.writeLine(space) + } + t.moveCursorToPos(newPos) + } + t.line = newLine + t.pos = newPos +} + +func (t *Terminal) advanceCursor(places int) { + t.cursorX += places + t.cursorY += t.cursorX / t.termWidth + if t.cursorY > t.maxLine { + t.maxLine = t.cursorY + } + t.cursorX = t.cursorX % t.termWidth + + if places > 0 && t.cursorX == 0 { + // Normally terminals will advance the current position + // when writing a character. But that doesn't happen + // for the last character in a line. However, when + // writing a character (except a new line) that causes + // a line wrap, the position will be advanced two + // places. + // + // So, if we are stopping at the end of a line, we + // need to write a newline so that our cursor can be + // advanced to the next line. + t.outBuf = append(t.outBuf, '\r', '\n') + } +} + +func (t *Terminal) eraseNPreviousChars(n int) { + if n == 0 { + return + } + + if t.pos < n { + n = t.pos + } + t.pos -= n + t.moveCursorToPos(t.pos) + + copy(t.line[t.pos:], t.line[n+t.pos:]) + t.line = t.line[:len(t.line)-n] + if t.echo { + t.writeLine(t.line[t.pos:]) + for i := 0; i < n; i++ { + t.queue(space) + } + t.advanceCursor(n) + t.moveCursorToPos(t.pos) + } +} + +// countToLeftWord returns then number of characters from the cursor to the +// start of the previous word. +func (t *Terminal) countToLeftWord() int { + if t.pos == 0 { + return 0 + } + + pos := t.pos - 1 + for pos > 0 { + if t.line[pos] != ' ' { + break + } + pos-- + } + for pos > 0 { + if t.line[pos] == ' ' { + pos++ + break + } + pos-- + } + + return t.pos - pos +} + +// countToRightWord returns then number of characters from the cursor to the +// start of the next word. +func (t *Terminal) countToRightWord() int { + pos := t.pos + for pos < len(t.line) { + if t.line[pos] == ' ' { + break + } + pos++ + } + for pos < len(t.line) { + if t.line[pos] != ' ' { + break + } + pos++ + } + return pos - t.pos +} + +// visualLength returns the number of visible glyphs in s. +func visualLength(runes []rune) int { + inEscapeSeq := false + length := 0 + + for _, r := range runes { + switch { + case inEscapeSeq: + if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') { + inEscapeSeq = false + } + case r == '\x1b': + inEscapeSeq = true + default: + length++ + } + } + + return length +} + +// handleKey processes the given key and, optionally, returns a line of text +// that the user has entered. +func (t *Terminal) handleKey(key rune) (line string, ok bool) { + if t.pasteActive && key != keyEnter { + t.addKeyToLine(key) + return + } + + switch key { + case keyBackspace: + if t.pos == 0 { + return + } + t.eraseNPreviousChars(1) + case keyAltLeft: + // move left by a word. + t.pos -= t.countToLeftWord() + t.moveCursorToPos(t.pos) + case keyAltRight: + // move right by a word. + t.pos += t.countToRightWord() + t.moveCursorToPos(t.pos) + case keyLeft: + if t.pos == 0 { + return + } + t.pos-- + t.moveCursorToPos(t.pos) + case keyRight: + if t.pos == len(t.line) { + return + } + t.pos++ + t.moveCursorToPos(t.pos) + case keyHome: + if t.pos == 0 { + return + } + t.pos = 0 + t.moveCursorToPos(t.pos) + case keyEnd: + if t.pos == len(t.line) { + return + } + t.pos = len(t.line) + t.moveCursorToPos(t.pos) + case keyUp: + entry, ok := t.history.NthPreviousEntry(t.historyIndex + 1) + if !ok { + return "", false + } + if t.historyIndex == -1 { + t.historyPending = string(t.line) + } + t.historyIndex++ + runes := []rune(entry) + t.setLine(runes, len(runes)) + case keyDown: + switch t.historyIndex { + case -1: + return + case 0: + runes := []rune(t.historyPending) + t.setLine(runes, len(runes)) + t.historyIndex-- + default: + entry, ok := t.history.NthPreviousEntry(t.historyIndex - 1) + if ok { + t.historyIndex-- + runes := []rune(entry) + t.setLine(runes, len(runes)) + } + } + case keyEnter: + t.moveCursorToPos(len(t.line)) + t.queue([]rune("\r\n")) + line = string(t.line) + ok = true + t.line = t.line[:0] + t.pos = 0 + t.cursorX = 0 + t.cursorY = 0 + t.maxLine = 0 + case keyDeleteWord: + // Delete zero or more spaces and then one or more characters. + t.eraseNPreviousChars(t.countToLeftWord()) + case keyDeleteLine: + // Delete everything from the current cursor position to the + // end of line. + for i := t.pos; i < len(t.line); i++ { + t.queue(space) + t.advanceCursor(1) + } + t.line = t.line[:t.pos] + t.moveCursorToPos(t.pos) + case keyCtrlD: + // Erase the character under the current position. + // The EOF case when the line is empty is handled in + // readLine(). + if t.pos < len(t.line) { + t.pos++ + t.eraseNPreviousChars(1) + } + case keyCtrlU: + t.eraseNPreviousChars(t.pos) + case keyClearScreen: + // Erases the screen and moves the cursor to the home position. + t.queue([]rune("\x1b[2J\x1b[H")) + t.queue(t.prompt) + t.cursorX, t.cursorY = 0, 0 + t.advanceCursor(visualLength(t.prompt)) + t.setLine(t.line, t.pos) + default: + if t.AutoCompleteCallback != nil { + prefix := string(t.line[:t.pos]) + suffix := string(t.line[t.pos:]) + + t.lock.Unlock() + newLine, newPos, completeOk := t.AutoCompleteCallback(prefix+suffix, len(prefix), key) + t.lock.Lock() + + if completeOk { + t.setLine([]rune(newLine), utf8.RuneCount([]byte(newLine)[:newPos])) + return + } + } + if !isPrintable(key) { + return + } + if len(t.line) == maxLineLength { + return + } + t.addKeyToLine(key) + } + return +} + +// addKeyToLine inserts the given key at the current position in the current +// line. +func (t *Terminal) addKeyToLine(key rune) { + if len(t.line) == cap(t.line) { + newLine := make([]rune, len(t.line), 2*(1+len(t.line))) + copy(newLine, t.line) + t.line = newLine + } + t.line = t.line[:len(t.line)+1] + copy(t.line[t.pos+1:], t.line[t.pos:]) + t.line[t.pos] = key + if t.echo { + t.writeLine(t.line[t.pos:]) + } + t.pos++ + t.moveCursorToPos(t.pos) +} + +func (t *Terminal) writeLine(line []rune) { + for len(line) != 0 { + remainingOnLine := t.termWidth - t.cursorX + todo := len(line) + if todo > remainingOnLine { + todo = remainingOnLine + } + t.queue(line[:todo]) + t.advanceCursor(visualLength(line[:todo])) + line = line[todo:] + } +} + +// writeWithCRLF writes buf to w but replaces all occurrences of \n with \r\n. +func writeWithCRLF(w io.Writer, buf []byte) (n int, err error) { + for len(buf) > 0 { + i := bytes.IndexByte(buf, '\n') + todo := len(buf) + if i >= 0 { + todo = i + } + + var nn int + nn, err = w.Write(buf[:todo]) + n += nn + if err != nil { + return n, err + } + buf = buf[todo:] + + if i >= 0 { + if _, err = w.Write(crlf); err != nil { + return n, err + } + n++ + buf = buf[1:] + } + } + + return n, nil +} + +func (t *Terminal) Write(buf []byte) (n int, err error) { + t.lock.Lock() + defer t.lock.Unlock() + + if t.cursorX == 0 && t.cursorY == 0 { + // This is the easy case: there's nothing on the screen that we + // have to move out of the way. + return writeWithCRLF(t.c, buf) + } + + // We have a prompt and possibly user input on the screen. We + // have to clear it first. + t.move(0 /* up */, 0 /* down */, t.cursorX /* left */, 0 /* right */) + t.cursorX = 0 + t.clearLineToRight() + + for t.cursorY > 0 { + t.move(1 /* up */, 0, 0, 0) + t.cursorY-- + t.clearLineToRight() + } + + if _, err = t.c.Write(t.outBuf); err != nil { + return + } + t.outBuf = t.outBuf[:0] + + if n, err = writeWithCRLF(t.c, buf); err != nil { + return + } + + t.writeLine(t.prompt) + if t.echo { + t.writeLine(t.line) + } + + t.moveCursorToPos(t.pos) + + if _, err = t.c.Write(t.outBuf); err != nil { + return + } + t.outBuf = t.outBuf[:0] + return +} + +// ReadPassword temporarily changes the prompt and reads a password, without +// echo, from the terminal. +func (t *Terminal) ReadPassword(prompt string) (line string, err error) { + t.lock.Lock() + defer t.lock.Unlock() + + oldPrompt := t.prompt + t.prompt = []rune(prompt) + t.echo = false + + line, err = t.readLine() + + t.prompt = oldPrompt + t.echo = true + + return +} + +// ReadLine returns a line of input from the terminal. +func (t *Terminal) ReadLine() (line string, err error) { + t.lock.Lock() + defer t.lock.Unlock() + + return t.readLine() +} + +func (t *Terminal) readLine() (line string, err error) { + // t.lock must be held at this point + + if t.cursorX == 0 && t.cursorY == 0 { + t.writeLine(t.prompt) + t.c.Write(t.outBuf) + t.outBuf = t.outBuf[:0] + } + + lineIsPasted := t.pasteActive + + for { + rest := t.remainder + lineOk := false + for !lineOk { + var key rune + key, rest = bytesToKey(rest, t.pasteActive) + if key == utf8.RuneError { + break + } + if !t.pasteActive { + if key == keyCtrlD { + if len(t.line) == 0 { + return "", io.EOF + } + } + if key == keyPasteStart { + t.pasteActive = true + if len(t.line) == 0 { + lineIsPasted = true + } + continue + } + } else if key == keyPasteEnd { + t.pasteActive = false + continue + } + if !t.pasteActive { + lineIsPasted = false + } + line, lineOk = t.handleKey(key) + } + if len(rest) > 0 { + n := copy(t.inBuf[:], rest) + t.remainder = t.inBuf[:n] + } else { + t.remainder = nil + } + t.c.Write(t.outBuf) + t.outBuf = t.outBuf[:0] + if lineOk { + if t.echo { + t.historyIndex = -1 + t.history.Add(line) + } + if lineIsPasted { + err = ErrPasteIndicator + } + return + } + + // t.remainder is a slice at the beginning of t.inBuf + // containing a partial key sequence + readBuf := t.inBuf[len(t.remainder):] + var n int + + t.lock.Unlock() + n, err = t.c.Read(readBuf) + t.lock.Lock() + + if err != nil { + return + } + + t.remainder = t.inBuf[:n+len(t.remainder)] + } +} + +// SetPrompt sets the prompt to be used when reading subsequent lines. +func (t *Terminal) SetPrompt(prompt string) { + t.lock.Lock() + defer t.lock.Unlock() + + t.prompt = []rune(prompt) +} + +func (t *Terminal) clearAndRepaintLinePlusNPrevious(numPrevLines int) { + // Move cursor to column zero at the start of the line. + t.move(t.cursorY, 0, t.cursorX, 0) + t.cursorX, t.cursorY = 0, 0 + t.clearLineToRight() + for t.cursorY < numPrevLines { + // Move down a line + t.move(0, 1, 0, 0) + t.cursorY++ + t.clearLineToRight() + } + // Move back to beginning. + t.move(t.cursorY, 0, 0, 0) + t.cursorX, t.cursorY = 0, 0 + + t.queue(t.prompt) + t.advanceCursor(visualLength(t.prompt)) + t.writeLine(t.line) + t.moveCursorToPos(t.pos) +} + +func (t *Terminal) SetSize(width, height int) error { + t.lock.Lock() + defer t.lock.Unlock() + + if width == 0 { + width = 1 + } + + oldWidth := t.termWidth + t.termWidth, t.termHeight = width, height + + switch { + case width == oldWidth: + // If the width didn't change then nothing else needs to be + // done. + return nil + case len(t.line) == 0 && t.cursorX == 0 && t.cursorY == 0: + // If there is nothing on current line and no prompt printed, + // just do nothing + return nil + case width < oldWidth: + // Some terminals (e.g. xterm) will truncate lines that were + // too long when shinking. Others, (e.g. gnome-terminal) will + // attempt to wrap them. For the former, repainting t.maxLine + // works great, but that behaviour goes badly wrong in the case + // of the latter because they have doubled every full line. + + // We assume that we are working on a terminal that wraps lines + // and adjust the cursor position based on every previous line + // wrapping and turning into two. This causes the prompt on + // xterms to move upwards, which isn't great, but it avoids a + // huge mess with gnome-terminal. + if t.cursorX >= t.termWidth { + t.cursorX = t.termWidth - 1 + } + t.cursorY *= 2 + t.clearAndRepaintLinePlusNPrevious(t.maxLine * 2) + case width > oldWidth: + // If the terminal expands then our position calculations will + // be wrong in the future because we think the cursor is + // |t.pos| chars into the string, but there will be a gap at + // the end of any wrapped line. + // + // But the position will actually be correct until we move, so + // we can move back to the beginning and repaint everything. + t.clearAndRepaintLinePlusNPrevious(t.maxLine) + } + + _, err := t.c.Write(t.outBuf) + t.outBuf = t.outBuf[:0] + return err +} + +type pasteIndicatorError struct{} + +func (pasteIndicatorError) Error() string { + return "terminal: ErrPasteIndicator not correctly handled" +} + +// ErrPasteIndicator may be returned from ReadLine as the error, in addition +// to valid line data. It indicates that bracketed paste mode is enabled and +// that the returned line consists only of pasted data. Programs may wish to +// interpret pasted data more literally than typed data. +var ErrPasteIndicator = pasteIndicatorError{} + +// SetBracketedPasteMode requests that the terminal bracket paste operations +// with markers. Not all terminals support this but, if it is supported, then +// enabling this mode will stop any autocomplete callback from running due to +// pastes. Additionally, any lines that are completely pasted will be returned +// from ReadLine with the error set to ErrPasteIndicator. +func (t *Terminal) SetBracketedPasteMode(on bool) { + if on { + io.WriteString(t.c, "\x1b[?2004h") + } else { + io.WriteString(t.c, "\x1b[?2004l") + } +} + +// stRingBuffer is a ring buffer of strings. +type stRingBuffer struct { + // entries contains max elements. + entries []string + max int + // head contains the index of the element most recently added to the ring. + head int + // size contains the number of elements in the ring. + size int +} + +func (s *stRingBuffer) Add(a string) { + if s.entries == nil { + const defaultNumEntries = 100 + s.entries = make([]string, defaultNumEntries) + s.max = defaultNumEntries + } + + s.head = (s.head + 1) % s.max + s.entries[s.head] = a + if s.size < s.max { + s.size++ + } +} + +// NthPreviousEntry returns the value passed to the nth previous call to Add. +// If n is zero then the immediately prior value is returned, if one, then the +// next most recent, and so on. If such an element doesn't exist then ok is +// false. +func (s *stRingBuffer) NthPreviousEntry(n int) (value string, ok bool) { + if n >= s.size { + return "", false + } + index := s.head - n + if index < 0 { + index += s.max + } + return s.entries[index], true +} + +// readPasswordLine reads from reader until it finds \n or io.EOF. +// The slice returned does not include the \n. +// readPasswordLine also ignores any \r it finds. +func readPasswordLine(reader io.Reader) ([]byte, error) { + var buf [1]byte + var ret []byte + + for { + n, err := reader.Read(buf[:]) + if n > 0 { + switch buf[0] { + case '\n': + return ret, nil + case '\r': + // remove \r from passwords on Windows + default: + ret = append(ret, buf[0]) + } + continue + } + if err != nil { + if err == io.EOF && len(ret) > 0 { + return ret, nil + } + return ret, err + } + } +} diff --git a/vendor/golang.org/x/crypto/ssh/terminal/util.go b/vendor/golang.org/x/crypto/ssh/terminal/util.go new file mode 100644 index 000000000..02dad484e --- /dev/null +++ b/vendor/golang.org/x/crypto/ssh/terminal/util.go @@ -0,0 +1,116 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin dragonfly freebsd linux,!appengine netbsd openbsd + +// Package terminal provides support functions for dealing with terminals, as +// commonly found on UNIX systems. +// +// Putting a terminal into raw mode is the most common requirement: +// +// oldState, err := terminal.MakeRaw(0) +// if err != nil { +// panic(err) +// } +// defer terminal.Restore(0, oldState) +package terminal // import "golang.org/x/crypto/ssh/terminal" + +import ( + "golang.org/x/sys/unix" +) + +// State contains the state of a terminal. +type State struct { + termios unix.Termios +} + +// IsTerminal returns true if the given file descriptor is a terminal. +func IsTerminal(fd int) bool { + _, err := unix.IoctlGetTermios(fd, ioctlReadTermios) + return err == nil +} + +// MakeRaw put the terminal connected to the given file descriptor into raw +// mode and returns the previous state of the terminal so that it can be +// restored. +func MakeRaw(fd int) (*State, error) { + termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios) + if err != nil { + return nil, err + } + + oldState := State{termios: *termios} + + // This attempts to replicate the behaviour documented for cfmakeraw in + // the termios(3) manpage. + termios.Iflag &^= unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON + termios.Oflag &^= unix.OPOST + termios.Lflag &^= unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN + termios.Cflag &^= unix.CSIZE | unix.PARENB + termios.Cflag |= unix.CS8 + termios.Cc[unix.VMIN] = 1 + termios.Cc[unix.VTIME] = 0 + if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, termios); err != nil { + return nil, err + } + + return &oldState, nil +} + +// GetState returns the current state of a terminal which may be useful to +// restore the terminal after a signal. +func GetState(fd int) (*State, error) { + termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios) + if err != nil { + return nil, err + } + + return &State{termios: *termios}, nil +} + +// Restore restores the terminal connected to the given file descriptor to a +// previous state. +func Restore(fd int, state *State) error { + return unix.IoctlSetTermios(fd, ioctlWriteTermios, &state.termios) +} + +// GetSize returns the dimensions of the given terminal. +func GetSize(fd int) (width, height int, err error) { + ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ) + if err != nil { + return -1, -1, err + } + return int(ws.Col), int(ws.Row), nil +} + +// passwordReader is an io.Reader that reads from a specific file descriptor. +type passwordReader int + +func (r passwordReader) Read(buf []byte) (int, error) { + return unix.Read(int(r), buf) +} + +// ReadPassword reads a line of input from a terminal without local echo. This +// is commonly used for inputting passwords and other sensitive data. The slice +// returned does not include the \n. +func ReadPassword(fd int) ([]byte, error) { + termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios) + if err != nil { + return nil, err + } + + newState := *termios + newState.Lflag &^= unix.ECHO + newState.Lflag |= unix.ICANON | unix.ISIG + newState.Iflag |= unix.ICRNL + if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, &newState); err != nil { + return nil, err + } + + defer func() { + unix.IoctlSetTermios(fd, ioctlWriteTermios, termios) + }() + + return readPasswordLine(passwordReader(fd)) +} diff --git a/vendor/golang.org/x/crypto/ssh/terminal/util_bsd.go b/vendor/golang.org/x/crypto/ssh/terminal/util_bsd.go new file mode 100644 index 000000000..cb23a5904 --- /dev/null +++ b/vendor/golang.org/x/crypto/ssh/terminal/util_bsd.go @@ -0,0 +1,12 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin dragonfly freebsd netbsd openbsd + +package terminal + +import "golang.org/x/sys/unix" + +const ioctlReadTermios = unix.TIOCGETA +const ioctlWriteTermios = unix.TIOCSETA diff --git a/vendor/golang.org/x/crypto/ssh/terminal/util_linux.go b/vendor/golang.org/x/crypto/ssh/terminal/util_linux.go new file mode 100644 index 000000000..5fadfe8a1 --- /dev/null +++ b/vendor/golang.org/x/crypto/ssh/terminal/util_linux.go @@ -0,0 +1,10 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package terminal + +import "golang.org/x/sys/unix" + +const ioctlReadTermios = unix.TCGETS +const ioctlWriteTermios = unix.TCSETS diff --git a/vendor/golang.org/x/crypto/ssh/terminal/util_plan9.go b/vendor/golang.org/x/crypto/ssh/terminal/util_plan9.go new file mode 100644 index 000000000..799f049f0 --- /dev/null +++ b/vendor/golang.org/x/crypto/ssh/terminal/util_plan9.go @@ -0,0 +1,58 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package terminal provides support functions for dealing with terminals, as +// commonly found on UNIX systems. +// +// Putting a terminal into raw mode is the most common requirement: +// +// oldState, err := terminal.MakeRaw(0) +// if err != nil { +// panic(err) +// } +// defer terminal.Restore(0, oldState) +package terminal + +import ( + "fmt" + "runtime" +) + +type State struct{} + +// IsTerminal returns true if the given file descriptor is a terminal. +func IsTerminal(fd int) bool { + return false +} + +// MakeRaw put the terminal connected to the given file descriptor into raw +// mode and returns the previous state of the terminal so that it can be +// restored. +func MakeRaw(fd int) (*State, error) { + return nil, fmt.Errorf("terminal: MakeRaw not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) +} + +// GetState returns the current state of a terminal which may be useful to +// restore the terminal after a signal. +func GetState(fd int) (*State, error) { + return nil, fmt.Errorf("terminal: GetState not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) +} + +// Restore restores the terminal connected to the given file descriptor to a +// previous state. +func Restore(fd int, state *State) error { + return fmt.Errorf("terminal: Restore not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) +} + +// GetSize returns the dimensions of the given terminal. +func GetSize(fd int) (width, height int, err error) { + return 0, 0, fmt.Errorf("terminal: GetSize not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) +} + +// ReadPassword reads a line of input from a terminal without local echo. This +// is commonly used for inputting passwords and other sensitive data. The slice +// returned does not include the \n. +func ReadPassword(fd int) ([]byte, error) { + return nil, fmt.Errorf("terminal: ReadPassword not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) +} diff --git a/vendor/golang.org/x/crypto/ssh/terminal/util_solaris.go b/vendor/golang.org/x/crypto/ssh/terminal/util_solaris.go new file mode 100644 index 000000000..a2e1b57dc --- /dev/null +++ b/vendor/golang.org/x/crypto/ssh/terminal/util_solaris.go @@ -0,0 +1,128 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build solaris + +package terminal // import "golang.org/x/crypto/ssh/terminal" + +import ( + "golang.org/x/sys/unix" + "io" + "syscall" +) + +// State contains the state of a terminal. +type State struct { + state *unix.Termios +} + +// IsTerminal returns true if the given file descriptor is a terminal. +func IsTerminal(fd int) bool { + _, err := unix.IoctlGetTermio(fd, unix.TCGETA) + return err == nil +} + +// ReadPassword reads a line of input from a terminal without local echo. This +// is commonly used for inputting passwords and other sensitive data. The slice +// returned does not include the \n. +func ReadPassword(fd int) ([]byte, error) { + // see also: http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libast/common/uwin/getpass.c + val, err := unix.IoctlGetTermios(fd, unix.TCGETS) + if err != nil { + return nil, err + } + oldState := *val + + newState := oldState + newState.Lflag &^= syscall.ECHO + newState.Lflag |= syscall.ICANON | syscall.ISIG + newState.Iflag |= syscall.ICRNL + err = unix.IoctlSetTermios(fd, unix.TCSETS, &newState) + if err != nil { + return nil, err + } + + defer unix.IoctlSetTermios(fd, unix.TCSETS, &oldState) + + var buf [16]byte + var ret []byte + for { + n, err := syscall.Read(fd, buf[:]) + if err != nil { + return nil, err + } + if n == 0 { + if len(ret) == 0 { + return nil, io.EOF + } + break + } + if buf[n-1] == '\n' { + n-- + } + ret = append(ret, buf[:n]...) + if n < len(buf) { + break + } + } + + return ret, nil +} + +// MakeRaw puts the terminal connected to the given file descriptor into raw +// mode and returns the previous state of the terminal so that it can be +// restored. +// see http://cr.illumos.org/~webrev/andy_js/1060/ +func MakeRaw(fd int) (*State, error) { + oldTermiosPtr, err := unix.IoctlGetTermios(fd, unix.TCGETS) + if err != nil { + return nil, err + } + oldTermios := *oldTermiosPtr + + newTermios := oldTermios + newTermios.Iflag &^= syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON + newTermios.Oflag &^= syscall.OPOST + newTermios.Lflag &^= syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN + newTermios.Cflag &^= syscall.CSIZE | syscall.PARENB + newTermios.Cflag |= syscall.CS8 + newTermios.Cc[unix.VMIN] = 1 + newTermios.Cc[unix.VTIME] = 0 + + if err := unix.IoctlSetTermios(fd, unix.TCSETS, &newTermios); err != nil { + return nil, err + } + + return &State{ + state: oldTermiosPtr, + }, nil +} + +// Restore restores the terminal connected to the given file descriptor to a +// previous state. +func Restore(fd int, oldState *State) error { + return unix.IoctlSetTermios(fd, unix.TCSETS, oldState.state) +} + +// GetState returns the current state of a terminal which may be useful to +// restore the terminal after a signal. +func GetState(fd int) (*State, error) { + oldTermiosPtr, err := unix.IoctlGetTermios(fd, unix.TCGETS) + if err != nil { + return nil, err + } + + return &State{ + state: oldTermiosPtr, + }, nil +} + +// GetSize returns the dimensions of the given terminal. +func GetSize(fd int) (width, height int, err error) { + ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ) + if err != nil { + return 0, 0, err + } + return int(ws.Col), int(ws.Row), nil +} diff --git a/vendor/golang.org/x/crypto/ssh/terminal/util_windows.go b/vendor/golang.org/x/crypto/ssh/terminal/util_windows.go new file mode 100644 index 000000000..92944f3b4 --- /dev/null +++ b/vendor/golang.org/x/crypto/ssh/terminal/util_windows.go @@ -0,0 +1,97 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +// Package terminal provides support functions for dealing with terminals, as +// commonly found on UNIX systems. +// +// Putting a terminal into raw mode is the most common requirement: +// +// oldState, err := terminal.MakeRaw(0) +// if err != nil { +// panic(err) +// } +// defer terminal.Restore(0, oldState) +package terminal + +import ( + "os" + + "golang.org/x/sys/windows" +) + +type State struct { + mode uint32 +} + +// IsTerminal returns true if the given file descriptor is a terminal. +func IsTerminal(fd int) bool { + var st uint32 + err := windows.GetConsoleMode(windows.Handle(fd), &st) + return err == nil +} + +// MakeRaw put the terminal connected to the given file descriptor into raw +// mode and returns the previous state of the terminal so that it can be +// restored. +func MakeRaw(fd int) (*State, error) { + var st uint32 + if err := windows.GetConsoleMode(windows.Handle(fd), &st); err != nil { + return nil, err + } + raw := st &^ (windows.ENABLE_ECHO_INPUT | windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_LINE_INPUT | windows.ENABLE_PROCESSED_OUTPUT) + if err := windows.SetConsoleMode(windows.Handle(fd), raw); err != nil { + return nil, err + } + return &State{st}, nil +} + +// GetState returns the current state of a terminal which may be useful to +// restore the terminal after a signal. +func GetState(fd int) (*State, error) { + var st uint32 + if err := windows.GetConsoleMode(windows.Handle(fd), &st); err != nil { + return nil, err + } + return &State{st}, nil +} + +// Restore restores the terminal connected to the given file descriptor to a +// previous state. +func Restore(fd int, state *State) error { + return windows.SetConsoleMode(windows.Handle(fd), state.mode) +} + +// GetSize returns the dimensions of the given terminal. +func GetSize(fd int) (width, height int, err error) { + var info windows.ConsoleScreenBufferInfo + if err := windows.GetConsoleScreenBufferInfo(windows.Handle(fd), &info); err != nil { + return 0, 0, err + } + return int(info.Size.X), int(info.Size.Y), nil +} + +// ReadPassword reads a line of input from a terminal without local echo. This +// is commonly used for inputting passwords and other sensitive data. The slice +// returned does not include the \n. +func ReadPassword(fd int) ([]byte, error) { + var st uint32 + if err := windows.GetConsoleMode(windows.Handle(fd), &st); err != nil { + return nil, err + } + old := st + + st &^= (windows.ENABLE_ECHO_INPUT) + st |= (windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_LINE_INPUT | windows.ENABLE_PROCESSED_OUTPUT) + if err := windows.SetConsoleMode(windows.Handle(fd), st); err != nil { + return nil, err + } + + defer func() { + windows.SetConsoleMode(windows.Handle(fd), old) + }() + + return readPasswordLine(os.NewFile(uintptr(fd), "stdin")) +} diff --git a/vendor/gopkg.in/urfave/cli.v1/LICENSE b/vendor/gopkg.in/urfave/cli.v1/LICENSE new file mode 100644 index 000000000..42a597e29 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Jeremy Saenz & Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/gopkg.in/urfave/cli.v1/altsrc/altsrc.go b/vendor/gopkg.in/urfave/cli.v1/altsrc/altsrc.go new file mode 100644 index 000000000..ac34bf633 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/altsrc/altsrc.go @@ -0,0 +1,3 @@ +package altsrc + +//go:generate python ../generate-flag-types altsrc -i ../flag-types.json -o flag_generated.go diff --git a/vendor/gopkg.in/urfave/cli.v1/altsrc/flag.go b/vendor/gopkg.in/urfave/cli.v1/altsrc/flag.go new file mode 100644 index 000000000..84ef009a5 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/altsrc/flag.go @@ -0,0 +1,261 @@ +package altsrc + +import ( + "fmt" + "strconv" + "strings" + "syscall" + + "gopkg.in/urfave/cli.v1" +) + +// FlagInputSourceExtension is an extension interface of cli.Flag that +// allows a value to be set on the existing parsed flags. +type FlagInputSourceExtension interface { + cli.Flag + ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error +} + +// ApplyInputSourceValues iterates over all provided flags and +// executes ApplyInputSourceValue on flags implementing the +// FlagInputSourceExtension interface to initialize these flags +// to an alternate input source. +func ApplyInputSourceValues(context *cli.Context, inputSourceContext InputSourceContext, flags []cli.Flag) error { + for _, f := range flags { + inputSourceExtendedFlag, isType := f.(FlagInputSourceExtension) + if isType { + err := inputSourceExtendedFlag.ApplyInputSourceValue(context, inputSourceContext) + if err != nil { + return err + } + } + } + + return nil +} + +// InitInputSource is used to to setup an InputSourceContext on a cli.Command Before method. It will create a new +// input source based on the func provided. If there is no error it will then apply the new input source to any flags +// that are supported by the input source +func InitInputSource(flags []cli.Flag, createInputSource func() (InputSourceContext, error)) cli.BeforeFunc { + return func(context *cli.Context) error { + inputSource, err := createInputSource() + if err != nil { + return fmt.Errorf("Unable to create input source: inner error: \n'%v'", err.Error()) + } + + return ApplyInputSourceValues(context, inputSource, flags) + } +} + +// InitInputSourceWithContext is used to to setup an InputSourceContext on a cli.Command Before method. It will create a new +// input source based on the func provided with potentially using existing cli.Context values to initialize itself. If there is +// no error it will then apply the new input source to any flags that are supported by the input source +func InitInputSourceWithContext(flags []cli.Flag, createInputSource func(context *cli.Context) (InputSourceContext, error)) cli.BeforeFunc { + return func(context *cli.Context) error { + inputSource, err := createInputSource(context) + if err != nil { + return fmt.Errorf("Unable to create input source with context: inner error: \n'%v'", err.Error()) + } + + return ApplyInputSourceValues(context, inputSource, flags) + } +} + +// ApplyInputSourceValue applies a generic value to the flagSet if required +func (f *GenericFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.Generic(f.GenericFlag.Name) + if err != nil { + return err + } + if value != nil { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, value.String()) + }) + } + } + } + + return nil +} + +// ApplyInputSourceValue applies a StringSlice value to the flagSet if required +func (f *StringSliceFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.StringSlice(f.StringSliceFlag.Name) + if err != nil { + return err + } + if value != nil { + var sliceValue cli.StringSlice = value + eachName(f.Name, func(name string) { + underlyingFlag := f.set.Lookup(f.Name) + if underlyingFlag != nil { + underlyingFlag.Value = &sliceValue + } + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a IntSlice value if required +func (f *IntSliceFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.IntSlice(f.IntSliceFlag.Name) + if err != nil { + return err + } + if value != nil { + var sliceValue cli.IntSlice = value + eachName(f.Name, func(name string) { + underlyingFlag := f.set.Lookup(f.Name) + if underlyingFlag != nil { + underlyingFlag.Value = &sliceValue + } + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a Bool value to the flagSet if required +func (f *BoolFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.Bool(f.BoolFlag.Name) + if err != nil { + return err + } + if value { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, strconv.FormatBool(value)) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a BoolT value to the flagSet if required +func (f *BoolTFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !context.IsSet(f.Name) && !isEnvVarSet(f.EnvVar) { + value, err := isc.BoolT(f.BoolTFlag.Name) + if err != nil { + return err + } + if !value { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, strconv.FormatBool(value)) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a String value to the flagSet if required +func (f *StringFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !(context.IsSet(f.Name) || isEnvVarSet(f.EnvVar)) { + value, err := isc.String(f.StringFlag.Name) + if err != nil { + return err + } + if value != "" { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, value) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a int value to the flagSet if required +func (f *IntFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !(context.IsSet(f.Name) || isEnvVarSet(f.EnvVar)) { + value, err := isc.Int(f.IntFlag.Name) + if err != nil { + return err + } + if value > 0 { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, strconv.FormatInt(int64(value), 10)) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a Duration value to the flagSet if required +func (f *DurationFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !(context.IsSet(f.Name) || isEnvVarSet(f.EnvVar)) { + value, err := isc.Duration(f.DurationFlag.Name) + if err != nil { + return err + } + if value > 0 { + eachName(f.Name, func(name string) { + f.set.Set(f.Name, value.String()) + }) + } + } + } + return nil +} + +// ApplyInputSourceValue applies a Float64 value to the flagSet if required +func (f *Float64Flag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error { + if f.set != nil { + if !(context.IsSet(f.Name) || isEnvVarSet(f.EnvVar)) { + value, err := isc.Float64(f.Float64Flag.Name) + if err != nil { + return err + } + if value > 0 { + floatStr := float64ToString(value) + eachName(f.Name, func(name string) { + f.set.Set(f.Name, floatStr) + }) + } + } + } + return nil +} + +func isEnvVarSet(envVars string) bool { + for _, envVar := range strings.Split(envVars, ",") { + envVar = strings.TrimSpace(envVar) + if _, ok := syscall.Getenv(envVar); ok { + // TODO: Can't use this for bools as + // set means that it was true or false based on + // Bool flag type, should work for other types + return true + } + } + + return false +} + +func float64ToString(f float64) string { + return fmt.Sprintf("%v", f) +} + +func eachName(longName string, fn func(string)) { + parts := strings.Split(longName, ",") + for _, name := range parts { + name = strings.Trim(name, " ") + fn(name) + } +} diff --git a/vendor/gopkg.in/urfave/cli.v1/altsrc/flag_generated.go b/vendor/gopkg.in/urfave/cli.v1/altsrc/flag_generated.go new file mode 100644 index 000000000..0aeb0b041 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/altsrc/flag_generated.go @@ -0,0 +1,347 @@ +package altsrc + +import ( + "flag" + + "gopkg.in/urfave/cli.v1" +) + +// WARNING: This file is generated! + +// BoolFlag is the flag type that wraps cli.BoolFlag to allow +// for other values to be specified +type BoolFlag struct { + cli.BoolFlag + set *flag.FlagSet +} + +// NewBoolFlag creates a new BoolFlag +func NewBoolFlag(fl cli.BoolFlag) *BoolFlag { + return &BoolFlag{BoolFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped BoolFlag.Apply +func (f *BoolFlag) Apply(set *flag.FlagSet) { + f.set = set + f.BoolFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped BoolFlag.ApplyWithError +func (f *BoolFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.BoolFlag.ApplyWithError(set) +} + +// BoolTFlag is the flag type that wraps cli.BoolTFlag to allow +// for other values to be specified +type BoolTFlag struct { + cli.BoolTFlag + set *flag.FlagSet +} + +// NewBoolTFlag creates a new BoolTFlag +func NewBoolTFlag(fl cli.BoolTFlag) *BoolTFlag { + return &BoolTFlag{BoolTFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped BoolTFlag.Apply +func (f *BoolTFlag) Apply(set *flag.FlagSet) { + f.set = set + f.BoolTFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped BoolTFlag.ApplyWithError +func (f *BoolTFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.BoolTFlag.ApplyWithError(set) +} + +// DurationFlag is the flag type that wraps cli.DurationFlag to allow +// for other values to be specified +type DurationFlag struct { + cli.DurationFlag + set *flag.FlagSet +} + +// NewDurationFlag creates a new DurationFlag +func NewDurationFlag(fl cli.DurationFlag) *DurationFlag { + return &DurationFlag{DurationFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped DurationFlag.Apply +func (f *DurationFlag) Apply(set *flag.FlagSet) { + f.set = set + f.DurationFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped DurationFlag.ApplyWithError +func (f *DurationFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.DurationFlag.ApplyWithError(set) +} + +// Float64Flag is the flag type that wraps cli.Float64Flag to allow +// for other values to be specified +type Float64Flag struct { + cli.Float64Flag + set *flag.FlagSet +} + +// NewFloat64Flag creates a new Float64Flag +func NewFloat64Flag(fl cli.Float64Flag) *Float64Flag { + return &Float64Flag{Float64Flag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped Float64Flag.Apply +func (f *Float64Flag) Apply(set *flag.FlagSet) { + f.set = set + f.Float64Flag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped Float64Flag.ApplyWithError +func (f *Float64Flag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Float64Flag.ApplyWithError(set) +} + +// GenericFlag is the flag type that wraps cli.GenericFlag to allow +// for other values to be specified +type GenericFlag struct { + cli.GenericFlag + set *flag.FlagSet +} + +// NewGenericFlag creates a new GenericFlag +func NewGenericFlag(fl cli.GenericFlag) *GenericFlag { + return &GenericFlag{GenericFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped GenericFlag.Apply +func (f *GenericFlag) Apply(set *flag.FlagSet) { + f.set = set + f.GenericFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped GenericFlag.ApplyWithError +func (f *GenericFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.GenericFlag.ApplyWithError(set) +} + +// Int64Flag is the flag type that wraps cli.Int64Flag to allow +// for other values to be specified +type Int64Flag struct { + cli.Int64Flag + set *flag.FlagSet +} + +// NewInt64Flag creates a new Int64Flag +func NewInt64Flag(fl cli.Int64Flag) *Int64Flag { + return &Int64Flag{Int64Flag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped Int64Flag.Apply +func (f *Int64Flag) Apply(set *flag.FlagSet) { + f.set = set + f.Int64Flag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped Int64Flag.ApplyWithError +func (f *Int64Flag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Int64Flag.ApplyWithError(set) +} + +// IntFlag is the flag type that wraps cli.IntFlag to allow +// for other values to be specified +type IntFlag struct { + cli.IntFlag + set *flag.FlagSet +} + +// NewIntFlag creates a new IntFlag +func NewIntFlag(fl cli.IntFlag) *IntFlag { + return &IntFlag{IntFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped IntFlag.Apply +func (f *IntFlag) Apply(set *flag.FlagSet) { + f.set = set + f.IntFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped IntFlag.ApplyWithError +func (f *IntFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.IntFlag.ApplyWithError(set) +} + +// IntSliceFlag is the flag type that wraps cli.IntSliceFlag to allow +// for other values to be specified +type IntSliceFlag struct { + cli.IntSliceFlag + set *flag.FlagSet +} + +// NewIntSliceFlag creates a new IntSliceFlag +func NewIntSliceFlag(fl cli.IntSliceFlag) *IntSliceFlag { + return &IntSliceFlag{IntSliceFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped IntSliceFlag.Apply +func (f *IntSliceFlag) Apply(set *flag.FlagSet) { + f.set = set + f.IntSliceFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped IntSliceFlag.ApplyWithError +func (f *IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.IntSliceFlag.ApplyWithError(set) +} + +// Int64SliceFlag is the flag type that wraps cli.Int64SliceFlag to allow +// for other values to be specified +type Int64SliceFlag struct { + cli.Int64SliceFlag + set *flag.FlagSet +} + +// NewInt64SliceFlag creates a new Int64SliceFlag +func NewInt64SliceFlag(fl cli.Int64SliceFlag) *Int64SliceFlag { + return &Int64SliceFlag{Int64SliceFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped Int64SliceFlag.Apply +func (f *Int64SliceFlag) Apply(set *flag.FlagSet) { + f.set = set + f.Int64SliceFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped Int64SliceFlag.ApplyWithError +func (f *Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Int64SliceFlag.ApplyWithError(set) +} + +// StringFlag is the flag type that wraps cli.StringFlag to allow +// for other values to be specified +type StringFlag struct { + cli.StringFlag + set *flag.FlagSet +} + +// NewStringFlag creates a new StringFlag +func NewStringFlag(fl cli.StringFlag) *StringFlag { + return &StringFlag{StringFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped StringFlag.Apply +func (f *StringFlag) Apply(set *flag.FlagSet) { + f.set = set + f.StringFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped StringFlag.ApplyWithError +func (f *StringFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.StringFlag.ApplyWithError(set) +} + +// StringSliceFlag is the flag type that wraps cli.StringSliceFlag to allow +// for other values to be specified +type StringSliceFlag struct { + cli.StringSliceFlag + set *flag.FlagSet +} + +// NewStringSliceFlag creates a new StringSliceFlag +func NewStringSliceFlag(fl cli.StringSliceFlag) *StringSliceFlag { + return &StringSliceFlag{StringSliceFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped StringSliceFlag.Apply +func (f *StringSliceFlag) Apply(set *flag.FlagSet) { + f.set = set + f.StringSliceFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped StringSliceFlag.ApplyWithError +func (f *StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.StringSliceFlag.ApplyWithError(set) +} + +// Uint64Flag is the flag type that wraps cli.Uint64Flag to allow +// for other values to be specified +type Uint64Flag struct { + cli.Uint64Flag + set *flag.FlagSet +} + +// NewUint64Flag creates a new Uint64Flag +func NewUint64Flag(fl cli.Uint64Flag) *Uint64Flag { + return &Uint64Flag{Uint64Flag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped Uint64Flag.Apply +func (f *Uint64Flag) Apply(set *flag.FlagSet) { + f.set = set + f.Uint64Flag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped Uint64Flag.ApplyWithError +func (f *Uint64Flag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Uint64Flag.ApplyWithError(set) +} + +// UintFlag is the flag type that wraps cli.UintFlag to allow +// for other values to be specified +type UintFlag struct { + cli.UintFlag + set *flag.FlagSet +} + +// NewUintFlag creates a new UintFlag +func NewUintFlag(fl cli.UintFlag) *UintFlag { + return &UintFlag{UintFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls the +// wrapped UintFlag.Apply +func (f *UintFlag) Apply(set *flag.FlagSet) { + f.set = set + f.UintFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls the +// wrapped UintFlag.ApplyWithError +func (f *UintFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.UintFlag.ApplyWithError(set) +} diff --git a/vendor/gopkg.in/urfave/cli.v1/altsrc/input_source_context.go b/vendor/gopkg.in/urfave/cli.v1/altsrc/input_source_context.go new file mode 100644 index 000000000..276dcda08 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/altsrc/input_source_context.go @@ -0,0 +1,21 @@ +package altsrc + +import ( + "time" + + "gopkg.in/urfave/cli.v1" +) + +// InputSourceContext is an interface used to allow +// other input sources to be implemented as needed. +type InputSourceContext interface { + Int(name string) (int, error) + Duration(name string) (time.Duration, error) + Float64(name string) (float64, error) + String(name string) (string, error) + StringSlice(name string) ([]string, error) + IntSlice(name string) ([]int, error) + Generic(name string) (cli.Generic, error) + Bool(name string) (bool, error) + BoolT(name string) (bool, error) +} diff --git a/vendor/gopkg.in/urfave/cli.v1/altsrc/map_input_source.go b/vendor/gopkg.in/urfave/cli.v1/altsrc/map_input_source.go new file mode 100644 index 000000000..b3169e0ec --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/altsrc/map_input_source.go @@ -0,0 +1,262 @@ +package altsrc + +import ( + "fmt" + "reflect" + "strings" + "time" + + "gopkg.in/urfave/cli.v1" +) + +// MapInputSource implements InputSourceContext to return +// data from the map that is loaded. +type MapInputSource struct { + valueMap map[interface{}]interface{} +} + +// nestedVal checks if the name has '.' delimiters. +// If so, it tries to traverse the tree by the '.' delimited sections to find +// a nested value for the key. +func nestedVal(name string, tree map[interface{}]interface{}) (interface{}, bool) { + if sections := strings.Split(name, "."); len(sections) > 1 { + node := tree + for _, section := range sections[:len(sections)-1] { + if child, ok := node[section]; !ok { + return nil, false + } else { + if ctype, ok := child.(map[interface{}]interface{}); !ok { + return nil, false + } else { + node = ctype + } + } + } + if val, ok := node[sections[len(sections)-1]]; ok { + return val, true + } + } + return nil, false +} + +// Int returns an int from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Int(name string) (int, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(int) + if !isType { + return 0, incorrectTypeForFlagError(name, "int", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(int) + if !isType { + return 0, incorrectTypeForFlagError(name, "int", nestedGenericValue) + } + return otherValue, nil + } + + return 0, nil +} + +// Duration returns a duration from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Duration(name string) (time.Duration, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(time.Duration) + if !isType { + return 0, incorrectTypeForFlagError(name, "duration", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(time.Duration) + if !isType { + return 0, incorrectTypeForFlagError(name, "duration", nestedGenericValue) + } + return otherValue, nil + } + + return 0, nil +} + +// Float64 returns an float64 from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Float64(name string) (float64, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(float64) + if !isType { + return 0, incorrectTypeForFlagError(name, "float64", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(float64) + if !isType { + return 0, incorrectTypeForFlagError(name, "float64", nestedGenericValue) + } + return otherValue, nil + } + + return 0, nil +} + +// String returns a string from the map if it exists otherwise returns an empty string +func (fsm *MapInputSource) String(name string) (string, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(string) + if !isType { + return "", incorrectTypeForFlagError(name, "string", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(string) + if !isType { + return "", incorrectTypeForFlagError(name, "string", nestedGenericValue) + } + return otherValue, nil + } + + return "", nil +} + +// StringSlice returns an []string from the map if it exists otherwise returns nil +func (fsm *MapInputSource) StringSlice(name string) ([]string, error) { + otherGenericValue, exists := fsm.valueMap[name] + if !exists { + otherGenericValue, exists = nestedVal(name, fsm.valueMap) + if !exists { + return nil, nil + } + } + + otherValue, isType := otherGenericValue.([]interface{}) + if !isType { + return nil, incorrectTypeForFlagError(name, "[]interface{}", otherGenericValue) + } + + var stringSlice = make([]string, 0, len(otherValue)) + for i, v := range otherValue { + stringValue, isType := v.(string) + + if !isType { + return nil, incorrectTypeForFlagError(fmt.Sprintf("%s[%d]", name, i), "string", v) + } + + stringSlice = append(stringSlice, stringValue) + } + + return stringSlice, nil +} + +// IntSlice returns an []int from the map if it exists otherwise returns nil +func (fsm *MapInputSource) IntSlice(name string) ([]int, error) { + otherGenericValue, exists := fsm.valueMap[name] + if !exists { + otherGenericValue, exists = nestedVal(name, fsm.valueMap) + if !exists { + return nil, nil + } + } + + otherValue, isType := otherGenericValue.([]interface{}) + if !isType { + return nil, incorrectTypeForFlagError(name, "[]interface{}", otherGenericValue) + } + + var intSlice = make([]int, 0, len(otherValue)) + for i, v := range otherValue { + intValue, isType := v.(int) + + if !isType { + return nil, incorrectTypeForFlagError(fmt.Sprintf("%s[%d]", name, i), "int", v) + } + + intSlice = append(intSlice, intValue) + } + + return intSlice, nil +} + +// Generic returns an cli.Generic from the map if it exists otherwise returns nil +func (fsm *MapInputSource) Generic(name string) (cli.Generic, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(cli.Generic) + if !isType { + return nil, incorrectTypeForFlagError(name, "cli.Generic", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(cli.Generic) + if !isType { + return nil, incorrectTypeForFlagError(name, "cli.Generic", nestedGenericValue) + } + return otherValue, nil + } + + return nil, nil +} + +// Bool returns an bool from the map otherwise returns false +func (fsm *MapInputSource) Bool(name string) (bool, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(bool) + if !isType { + return false, incorrectTypeForFlagError(name, "bool", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(bool) + if !isType { + return false, incorrectTypeForFlagError(name, "bool", nestedGenericValue) + } + return otherValue, nil + } + + return false, nil +} + +// BoolT returns an bool from the map otherwise returns true +func (fsm *MapInputSource) BoolT(name string) (bool, error) { + otherGenericValue, exists := fsm.valueMap[name] + if exists { + otherValue, isType := otherGenericValue.(bool) + if !isType { + return true, incorrectTypeForFlagError(name, "bool", otherGenericValue) + } + return otherValue, nil + } + nestedGenericValue, exists := nestedVal(name, fsm.valueMap) + if exists { + otherValue, isType := nestedGenericValue.(bool) + if !isType { + return true, incorrectTypeForFlagError(name, "bool", nestedGenericValue) + } + return otherValue, nil + } + + return true, nil +} + +func incorrectTypeForFlagError(name, expectedTypeName string, value interface{}) error { + valueType := reflect.TypeOf(value) + valueTypeName := "" + if valueType != nil { + valueTypeName = valueType.Name() + } + + return fmt.Errorf("Mismatched type for flag '%s'. Expected '%s' but actual is '%s'", name, expectedTypeName, valueTypeName) +} diff --git a/vendor/gopkg.in/urfave/cli.v1/altsrc/toml_file_loader.go b/vendor/gopkg.in/urfave/cli.v1/altsrc/toml_file_loader.go new file mode 100644 index 000000000..37870fcbe --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/altsrc/toml_file_loader.go @@ -0,0 +1,113 @@ +// Disabling building of toml support in cases where golang is 1.0 or 1.1 +// as the encoding library is not implemented or supported. + +// +build go1.2 + +package altsrc + +import ( + "fmt" + "reflect" + + "github.com/BurntSushi/toml" + "gopkg.in/urfave/cli.v1" +) + +type tomlMap struct { + Map map[interface{}]interface{} +} + +func unmarshalMap(i interface{}) (ret map[interface{}]interface{}, err error) { + ret = make(map[interface{}]interface{}) + m := i.(map[string]interface{}) + for key, val := range m { + v := reflect.ValueOf(val) + switch v.Kind() { + case reflect.Bool: + ret[key] = val.(bool) + case reflect.String: + ret[key] = val.(string) + case reflect.Int: + ret[key] = int(val.(int)) + case reflect.Int8: + ret[key] = int(val.(int8)) + case reflect.Int16: + ret[key] = int(val.(int16)) + case reflect.Int32: + ret[key] = int(val.(int32)) + case reflect.Int64: + ret[key] = int(val.(int64)) + case reflect.Uint: + ret[key] = int(val.(uint)) + case reflect.Uint8: + ret[key] = int(val.(uint8)) + case reflect.Uint16: + ret[key] = int(val.(uint16)) + case reflect.Uint32: + ret[key] = int(val.(uint32)) + case reflect.Uint64: + ret[key] = int(val.(uint64)) + case reflect.Float32: + ret[key] = float64(val.(float32)) + case reflect.Float64: + ret[key] = float64(val.(float64)) + case reflect.Map: + if tmp, err := unmarshalMap(val); err == nil { + ret[key] = tmp + } else { + return nil, err + } + case reflect.Array, reflect.Slice: + ret[key] = val.([]interface{}) + default: + return nil, fmt.Errorf("Unsupported: type = %#v", v.Kind()) + } + } + return ret, nil +} + +func (self *tomlMap) UnmarshalTOML(i interface{}) error { + if tmp, err := unmarshalMap(i); err == nil { + self.Map = tmp + } else { + return err + } + return nil +} + +type tomlSourceContext struct { + FilePath string +} + +// NewTomlSourceFromFile creates a new TOML InputSourceContext from a filepath. +func NewTomlSourceFromFile(file string) (InputSourceContext, error) { + tsc := &tomlSourceContext{FilePath: file} + var results tomlMap = tomlMap{} + if err := readCommandToml(tsc.FilePath, &results); err != nil { + return nil, fmt.Errorf("Unable to load TOML file '%s': inner error: \n'%v'", tsc.FilePath, err.Error()) + } + return &MapInputSource{valueMap: results.Map}, nil +} + +// NewTomlSourceFromFlagFunc creates a new TOML InputSourceContext from a provided flag name and source context. +func NewTomlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) { + return func(context *cli.Context) (InputSourceContext, error) { + filePath := context.String(flagFileName) + return NewTomlSourceFromFile(filePath) + } +} + +func readCommandToml(filePath string, container interface{}) (err error) { + b, err := loadDataFrom(filePath) + if err != nil { + return err + } + + err = toml.Unmarshal(b, container) + if err != nil { + return err + } + + err = nil + return +} diff --git a/vendor/gopkg.in/urfave/cli.v1/altsrc/yaml_file_loader.go b/vendor/gopkg.in/urfave/cli.v1/altsrc/yaml_file_loader.go new file mode 100644 index 000000000..dd808d523 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/altsrc/yaml_file_loader.go @@ -0,0 +1,92 @@ +// Disabling building of yaml support in cases where golang is 1.0 or 1.1 +// as the encoding library is not implemented or supported. + +// +build go1.2 + +package altsrc + +import ( + "fmt" + "io/ioutil" + "net/http" + "net/url" + "os" + "runtime" + "strings" + + "gopkg.in/urfave/cli.v1" + + "gopkg.in/yaml.v2" +) + +type yamlSourceContext struct { + FilePath string +} + +// NewYamlSourceFromFile creates a new Yaml InputSourceContext from a filepath. +func NewYamlSourceFromFile(file string) (InputSourceContext, error) { + ysc := &yamlSourceContext{FilePath: file} + var results map[interface{}]interface{} + err := readCommandYaml(ysc.FilePath, &results) + if err != nil { + return nil, fmt.Errorf("Unable to load Yaml file '%s': inner error: \n'%v'", ysc.FilePath, err.Error()) + } + + return &MapInputSource{valueMap: results}, nil +} + +// NewYamlSourceFromFlagFunc creates a new Yaml InputSourceContext from a provided flag name and source context. +func NewYamlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) { + return func(context *cli.Context) (InputSourceContext, error) { + filePath := context.String(flagFileName) + return NewYamlSourceFromFile(filePath) + } +} + +func readCommandYaml(filePath string, container interface{}) (err error) { + b, err := loadDataFrom(filePath) + if err != nil { + return err + } + + err = yaml.Unmarshal(b, container) + if err != nil { + return err + } + + err = nil + return +} + +func loadDataFrom(filePath string) ([]byte, error) { + u, err := url.Parse(filePath) + if err != nil { + return nil, err + } + + if u.Host != "" { // i have a host, now do i support the scheme? + switch u.Scheme { + case "http", "https": + res, err := http.Get(filePath) + if err != nil { + return nil, err + } + return ioutil.ReadAll(res.Body) + default: + return nil, fmt.Errorf("scheme of %s is unsupported", filePath) + } + } else if u.Path != "" { // i dont have a host, but I have a path. I am a local file. + if _, notFoundFileErr := os.Stat(filePath); notFoundFileErr != nil { + return nil, fmt.Errorf("Cannot read from file: '%s' because it does not exist.", filePath) + } + return ioutil.ReadFile(filePath) + } else if runtime.GOOS == "windows" && strings.Contains(u.String(), "\\") { + // on Windows systems u.Path is always empty, so we need to check the string directly. + if _, notFoundFileErr := os.Stat(filePath); notFoundFileErr != nil { + return nil, fmt.Errorf("Cannot read from file: '%s' because it does not exist.", filePath) + } + return ioutil.ReadFile(filePath) + } else { + return nil, fmt.Errorf("unable to determine how to load from path %s", filePath) + } +} diff --git a/vendor/gopkg.in/urfave/cli.v1/app.go b/vendor/gopkg.in/urfave/cli.v1/app.go new file mode 100644 index 000000000..51fc45d87 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/app.go @@ -0,0 +1,497 @@ +package cli + +import ( + "fmt" + "io" + "io/ioutil" + "os" + "path/filepath" + "sort" + "time" +) + +var ( + changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" + appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) + runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL) + + contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you." + + errInvalidActionType = NewExitError("ERROR invalid Action type. "+ + fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+ + fmt.Sprintf("See %s", appActionDeprecationURL), 2) +) + +// App is the main structure of a cli application. It is recommended that +// an app be created with the cli.NewApp() function +type App struct { + // The name of the program. Defaults to path.Base(os.Args[0]) + Name string + // Full name of command for help, defaults to Name + HelpName string + // Description of the program. + Usage string + // Text to override the USAGE section of help + UsageText string + // Description of the program argument format. + ArgsUsage string + // Version of the program + Version string + // Description of the program + Description string + // List of commands to execute + Commands []Command + // List of flags to parse + Flags []Flag + // Boolean to enable bash completion commands + EnableBashCompletion bool + // Boolean to hide built-in help command + HideHelp bool + // Boolean to hide built-in version flag and the VERSION section of help + HideVersion bool + // Populate on app startup, only gettable through method Categories() + categories CommandCategories + // An action to execute when the bash-completion flag is set + BashComplete BashCompleteFunc + // An action to execute before any subcommands are run, but after the context is ready + // If a non-nil error is returned, no subcommands are run + Before BeforeFunc + // An action to execute after any subcommands are run, but after the subcommand has finished + // It is run even if Action() panics + After AfterFunc + + // The action to execute when no subcommands are specified + // Expects a `cli.ActionFunc` but will accept the *deprecated* signature of `func(*cli.Context) {}` + // *Note*: support for the deprecated `Action` signature will be removed in a future version + Action interface{} + + // Execute this function if the proper command cannot be found + CommandNotFound CommandNotFoundFunc + // Execute this function if an usage error occurs + OnUsageError OnUsageErrorFunc + // Compilation date + Compiled time.Time + // List of all authors who contributed + Authors []Author + // Copyright of the binary if any + Copyright string + // Name of Author (Note: Use App.Authors, this is deprecated) + Author string + // Email of Author (Note: Use App.Authors, this is deprecated) + Email string + // Writer writer to write output to + Writer io.Writer + // ErrWriter writes error output + ErrWriter io.Writer + // Other custom info + Metadata map[string]interface{} + // Carries a function which returns app specific info. + ExtraInfo func() map[string]string + // CustomAppHelpTemplate the text template for app help topic. + // cli.go uses text/template to render templates. You can + // render custom help text by setting this variable. + CustomAppHelpTemplate string + + didSetup bool +} + +// Tries to find out when this binary was compiled. +// Returns the current time if it fails to find it. +func compileTime() time.Time { + info, err := os.Stat(os.Args[0]) + if err != nil { + return time.Now() + } + return info.ModTime() +} + +// NewApp creates a new cli Application with some reasonable defaults for Name, +// Usage, Version and Action. +func NewApp() *App { + return &App{ + Name: filepath.Base(os.Args[0]), + HelpName: filepath.Base(os.Args[0]), + Usage: "A new cli application", + UsageText: "", + Version: "0.0.0", + BashComplete: DefaultAppComplete, + Action: helpCommand.Action, + Compiled: compileTime(), + Writer: os.Stdout, + } +} + +// Setup runs initialization code to ensure all data structures are ready for +// `Run` or inspection prior to `Run`. It is internally called by `Run`, but +// will return early if setup has already happened. +func (a *App) Setup() { + if a.didSetup { + return + } + + a.didSetup = true + + if a.Author != "" || a.Email != "" { + a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email}) + } + + newCmds := []Command{} + for _, c := range a.Commands { + if c.HelpName == "" { + c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) + } + newCmds = append(newCmds, c) + } + a.Commands = newCmds + + if a.Command(helpCommand.Name) == nil && !a.HideHelp { + a.Commands = append(a.Commands, helpCommand) + if (HelpFlag != BoolFlag{}) { + a.appendFlag(HelpFlag) + } + } + + if !a.HideVersion { + a.appendFlag(VersionFlag) + } + + a.categories = CommandCategories{} + for _, command := range a.Commands { + a.categories = a.categories.AddCommand(command.Category, command) + } + sort.Sort(a.categories) + + if a.Metadata == nil { + a.Metadata = make(map[string]interface{}) + } + + if a.Writer == nil { + a.Writer = os.Stdout + } +} + +// Run is the entry point to the cli app. Parses the arguments slice and routes +// to the proper flag/args combination +func (a *App) Run(arguments []string) (err error) { + a.Setup() + + // handle the completion flag separately from the flagset since + // completion could be attempted after a flag, but before its value was put + // on the command line. this causes the flagset to interpret the completion + // flag name as the value of the flag before it which is undesirable + // note that we can only do this because the shell autocomplete function + // always appends the completion flag at the end of the command + shellComplete, arguments := checkShellCompleteFlag(a, arguments) + + // parse flags + set, err := flagSet(a.Name, a.Flags) + if err != nil { + return err + } + + set.SetOutput(ioutil.Discard) + err = set.Parse(arguments[1:]) + nerr := normalizeFlags(a.Flags, set) + context := NewContext(a, set, nil) + if nerr != nil { + fmt.Fprintln(a.Writer, nerr) + ShowAppHelp(context) + return nerr + } + context.shellComplete = shellComplete + + if checkCompletions(context) { + return nil + } + + if err != nil { + if a.OnUsageError != nil { + err := a.OnUsageError(context, err, false) + HandleExitCoder(err) + return err + } + fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) + ShowAppHelp(context) + return err + } + + if !a.HideHelp && checkHelp(context) { + ShowAppHelp(context) + return nil + } + + if !a.HideVersion && checkVersion(context) { + ShowVersion(context) + return nil + } + + if a.After != nil { + defer func() { + if afterErr := a.After(context); afterErr != nil { + if err != nil { + err = NewMultiError(err, afterErr) + } else { + err = afterErr + } + } + }() + } + + if a.Before != nil { + beforeErr := a.Before(context) + if beforeErr != nil { + ShowAppHelp(context) + HandleExitCoder(beforeErr) + err = beforeErr + return err + } + } + + args := context.Args() + if args.Present() { + name := args.First() + c := a.Command(name) + if c != nil { + return c.Run(context) + } + } + + if a.Action == nil { + a.Action = helpCommand.Action + } + + // Run default Action + err = HandleAction(a.Action, context) + + HandleExitCoder(err) + return err +} + +// RunAndExitOnError calls .Run() and exits non-zero if an error was returned +// +// Deprecated: instead you should return an error that fulfills cli.ExitCoder +// to cli.App.Run. This will cause the application to exit with the given eror +// code in the cli.ExitCoder +func (a *App) RunAndExitOnError() { + if err := a.Run(os.Args); err != nil { + fmt.Fprintln(a.errWriter(), err) + OsExiter(1) + } +} + +// RunAsSubcommand invokes the subcommand given the context, parses ctx.Args() to +// generate command-specific flags +func (a *App) RunAsSubcommand(ctx *Context) (err error) { + // append help to commands + if len(a.Commands) > 0 { + if a.Command(helpCommand.Name) == nil && !a.HideHelp { + a.Commands = append(a.Commands, helpCommand) + if (HelpFlag != BoolFlag{}) { + a.appendFlag(HelpFlag) + } + } + } + + newCmds := []Command{} + for _, c := range a.Commands { + if c.HelpName == "" { + c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) + } + newCmds = append(newCmds, c) + } + a.Commands = newCmds + + // parse flags + set, err := flagSet(a.Name, a.Flags) + if err != nil { + return err + } + + set.SetOutput(ioutil.Discard) + err = set.Parse(ctx.Args().Tail()) + nerr := normalizeFlags(a.Flags, set) + context := NewContext(a, set, ctx) + + if nerr != nil { + fmt.Fprintln(a.Writer, nerr) + fmt.Fprintln(a.Writer) + if len(a.Commands) > 0 { + ShowSubcommandHelp(context) + } else { + ShowCommandHelp(ctx, context.Args().First()) + } + return nerr + } + + if checkCompletions(context) { + return nil + } + + if err != nil { + if a.OnUsageError != nil { + err = a.OnUsageError(context, err, true) + HandleExitCoder(err) + return err + } + fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) + ShowSubcommandHelp(context) + return err + } + + if len(a.Commands) > 0 { + if checkSubcommandHelp(context) { + return nil + } + } else { + if checkCommandHelp(ctx, context.Args().First()) { + return nil + } + } + + if a.After != nil { + defer func() { + afterErr := a.After(context) + if afterErr != nil { + HandleExitCoder(err) + if err != nil { + err = NewMultiError(err, afterErr) + } else { + err = afterErr + } + } + }() + } + + if a.Before != nil { + beforeErr := a.Before(context) + if beforeErr != nil { + HandleExitCoder(beforeErr) + err = beforeErr + return err + } + } + + args := context.Args() + if args.Present() { + name := args.First() + c := a.Command(name) + if c != nil { + return c.Run(context) + } + } + + // Run default Action + err = HandleAction(a.Action, context) + + HandleExitCoder(err) + return err +} + +// Command returns the named command on App. Returns nil if the command does not exist +func (a *App) Command(name string) *Command { + for _, c := range a.Commands { + if c.HasName(name) { + return &c + } + } + + return nil +} + +// Categories returns a slice containing all the categories with the commands they contain +func (a *App) Categories() CommandCategories { + return a.categories +} + +// VisibleCategories returns a slice of categories and commands that are +// Hidden=false +func (a *App) VisibleCategories() []*CommandCategory { + ret := []*CommandCategory{} + for _, category := range a.categories { + if visible := func() *CommandCategory { + for _, command := range category.Commands { + if !command.Hidden { + return category + } + } + return nil + }(); visible != nil { + ret = append(ret, visible) + } + } + return ret +} + +// VisibleCommands returns a slice of the Commands with Hidden=false +func (a *App) VisibleCommands() []Command { + ret := []Command{} + for _, command := range a.Commands { + if !command.Hidden { + ret = append(ret, command) + } + } + return ret +} + +// VisibleFlags returns a slice of the Flags with Hidden=false +func (a *App) VisibleFlags() []Flag { + return visibleFlags(a.Flags) +} + +func (a *App) hasFlag(flag Flag) bool { + for _, f := range a.Flags { + if flag == f { + return true + } + } + + return false +} + +func (a *App) errWriter() io.Writer { + + // When the app ErrWriter is nil use the package level one. + if a.ErrWriter == nil { + return ErrWriter + } + + return a.ErrWriter +} + +func (a *App) appendFlag(flag Flag) { + if !a.hasFlag(flag) { + a.Flags = append(a.Flags, flag) + } +} + +// Author represents someone who has contributed to a cli project. +type Author struct { + Name string // The Authors name + Email string // The Authors email +} + +// String makes Author comply to the Stringer interface, to allow an easy print in the templating process +func (a Author) String() string { + e := "" + if a.Email != "" { + e = " <" + a.Email + ">" + } + + return fmt.Sprintf("%v%v", a.Name, e) +} + +// HandleAction attempts to figure out which Action signature was used. If +// it's an ActionFunc or a func with the legacy signature for Action, the func +// is run! +func HandleAction(action interface{}, context *Context) (err error) { + if a, ok := action.(ActionFunc); ok { + return a(context) + } else if a, ok := action.(func(*Context) error); ok { + return a(context) + } else if a, ok := action.(func(*Context)); ok { // deprecated function signature + a(context) + return nil + } else { + return errInvalidActionType + } +} diff --git a/vendor/gopkg.in/urfave/cli.v1/category.go b/vendor/gopkg.in/urfave/cli.v1/category.go new file mode 100644 index 000000000..1a6055023 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/category.go @@ -0,0 +1,44 @@ +package cli + +// CommandCategories is a slice of *CommandCategory. +type CommandCategories []*CommandCategory + +// CommandCategory is a category containing commands. +type CommandCategory struct { + Name string + Commands Commands +} + +func (c CommandCategories) Less(i, j int) bool { + return c[i].Name < c[j].Name +} + +func (c CommandCategories) Len() int { + return len(c) +} + +func (c CommandCategories) Swap(i, j int) { + c[i], c[j] = c[j], c[i] +} + +// AddCommand adds a command to a category. +func (c CommandCategories) AddCommand(category string, command Command) CommandCategories { + for _, commandCategory := range c { + if commandCategory.Name == category { + commandCategory.Commands = append(commandCategory.Commands, command) + return c + } + } + return append(c, &CommandCategory{Name: category, Commands: []Command{command}}) +} + +// VisibleCommands returns a slice of the Commands with Hidden=false +func (c *CommandCategory) VisibleCommands() []Command { + ret := []Command{} + for _, command := range c.Commands { + if !command.Hidden { + ret = append(ret, command) + } + } + return ret +} diff --git a/vendor/gopkg.in/urfave/cli.v1/cli.go b/vendor/gopkg.in/urfave/cli.v1/cli.go new file mode 100644 index 000000000..90c07eb8e --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/cli.go @@ -0,0 +1,22 @@ +// Package cli provides a minimal framework for creating and organizing command line +// Go applications. cli is designed to be easy to understand and write, the most simple +// cli application can be written as follows: +// func main() { +// cli.NewApp().Run(os.Args) +// } +// +// Of course this application does not do much, so let's make this an actual application: +// func main() { +// app := cli.NewApp() +// app.Name = "greet" +// app.Usage = "say a greeting" +// app.Action = func(c *cli.Context) error { +// println("Greetings") +// return nil +// } +// +// app.Run(os.Args) +// } +package cli + +//go:generate python ./generate-flag-types cli -i flag-types.json -o flag_generated.go diff --git a/vendor/gopkg.in/urfave/cli.v1/command.go b/vendor/gopkg.in/urfave/cli.v1/command.go new file mode 100644 index 000000000..23de2944b --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/command.go @@ -0,0 +1,304 @@ +package cli + +import ( + "fmt" + "io/ioutil" + "sort" + "strings" +) + +// Command is a subcommand for a cli.App. +type Command struct { + // The name of the command + Name string + // short name of the command. Typically one character (deprecated, use `Aliases`) + ShortName string + // A list of aliases for the command + Aliases []string + // A short description of the usage of this command + Usage string + // Custom text to show on USAGE section of help + UsageText string + // A longer explanation of how the command works + Description string + // A short description of the arguments of this command + ArgsUsage string + // The category the command is part of + Category string + // The function to call when checking for bash command completions + BashComplete BashCompleteFunc + // An action to execute before any sub-subcommands are run, but after the context is ready + // If a non-nil error is returned, no sub-subcommands are run + Before BeforeFunc + // An action to execute after any subcommands are run, but after the subcommand has finished + // It is run even if Action() panics + After AfterFunc + // The function to call when this command is invoked + Action interface{} + // TODO: replace `Action: interface{}` with `Action: ActionFunc` once some kind + // of deprecation period has passed, maybe? + + // Execute this function if a usage error occurs. + OnUsageError OnUsageErrorFunc + // List of child commands + Subcommands Commands + // List of flags to parse + Flags []Flag + // Treat all flags as normal arguments if true + SkipFlagParsing bool + // Skip argument reordering which attempts to move flags before arguments, + // but only works if all flags appear after all arguments. This behavior was + // removed n version 2 since it only works under specific conditions so we + // backport here by exposing it as an option for compatibility. + SkipArgReorder bool + // Boolean to hide built-in help command + HideHelp bool + // Boolean to hide this command from help or completion + Hidden bool + + // Full name of command for help, defaults to full command name, including parent commands. + HelpName string + commandNamePath []string + + // CustomHelpTemplate the text template for the command help topic. + // cli.go uses text/template to render templates. You can + // render custom help text by setting this variable. + CustomHelpTemplate string +} + +type CommandsByName []Command + +func (c CommandsByName) Len() int { + return len(c) +} + +func (c CommandsByName) Less(i, j int) bool { + return c[i].Name < c[j].Name +} + +func (c CommandsByName) Swap(i, j int) { + c[i], c[j] = c[j], c[i] +} + +// FullName returns the full name of the command. +// For subcommands this ensures that parent commands are part of the command path +func (c Command) FullName() string { + if c.commandNamePath == nil { + return c.Name + } + return strings.Join(c.commandNamePath, " ") +} + +// Commands is a slice of Command +type Commands []Command + +// Run invokes the command given the context, parses ctx.Args() to generate command-specific flags +func (c Command) Run(ctx *Context) (err error) { + if len(c.Subcommands) > 0 { + return c.startApp(ctx) + } + + if !c.HideHelp && (HelpFlag != BoolFlag{}) { + // append help to flags + c.Flags = append( + c.Flags, + HelpFlag, + ) + } + + set, err := flagSet(c.Name, c.Flags) + if err != nil { + return err + } + set.SetOutput(ioutil.Discard) + + if c.SkipFlagParsing { + err = set.Parse(append([]string{"--"}, ctx.Args().Tail()...)) + } else if !c.SkipArgReorder { + firstFlagIndex := -1 + terminatorIndex := -1 + for index, arg := range ctx.Args() { + if arg == "--" { + terminatorIndex = index + break + } else if arg == "-" { + // Do nothing. A dash alone is not really a flag. + continue + } else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 { + firstFlagIndex = index + } + } + + if firstFlagIndex > -1 { + args := ctx.Args() + regularArgs := make([]string, len(args[1:firstFlagIndex])) + copy(regularArgs, args[1:firstFlagIndex]) + + var flagArgs []string + if terminatorIndex > -1 { + flagArgs = args[firstFlagIndex:terminatorIndex] + regularArgs = append(regularArgs, args[terminatorIndex:]...) + } else { + flagArgs = args[firstFlagIndex:] + } + + err = set.Parse(append(flagArgs, regularArgs...)) + } else { + err = set.Parse(ctx.Args().Tail()) + } + } else { + err = set.Parse(ctx.Args().Tail()) + } + + nerr := normalizeFlags(c.Flags, set) + if nerr != nil { + fmt.Fprintln(ctx.App.Writer, nerr) + fmt.Fprintln(ctx.App.Writer) + ShowCommandHelp(ctx, c.Name) + return nerr + } + + context := NewContext(ctx.App, set, ctx) + context.Command = c + if checkCommandCompletions(context, c.Name) { + return nil + } + + if err != nil { + if c.OnUsageError != nil { + err := c.OnUsageError(context, err, false) + HandleExitCoder(err) + return err + } + fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error()) + fmt.Fprintln(context.App.Writer) + ShowCommandHelp(context, c.Name) + return err + } + + if checkCommandHelp(context, c.Name) { + return nil + } + + if c.After != nil { + defer func() { + afterErr := c.After(context) + if afterErr != nil { + HandleExitCoder(err) + if err != nil { + err = NewMultiError(err, afterErr) + } else { + err = afterErr + } + } + }() + } + + if c.Before != nil { + err = c.Before(context) + if err != nil { + ShowCommandHelp(context, c.Name) + HandleExitCoder(err) + return err + } + } + + if c.Action == nil { + c.Action = helpSubcommand.Action + } + + err = HandleAction(c.Action, context) + + if err != nil { + HandleExitCoder(err) + } + return err +} + +// Names returns the names including short names and aliases. +func (c Command) Names() []string { + names := []string{c.Name} + + if c.ShortName != "" { + names = append(names, c.ShortName) + } + + return append(names, c.Aliases...) +} + +// HasName returns true if Command.Name or Command.ShortName matches given name +func (c Command) HasName(name string) bool { + for _, n := range c.Names() { + if n == name { + return true + } + } + return false +} + +func (c Command) startApp(ctx *Context) error { + app := NewApp() + app.Metadata = ctx.App.Metadata + // set the name and usage + app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name) + if c.HelpName == "" { + app.HelpName = c.HelpName + } else { + app.HelpName = app.Name + } + + app.Usage = c.Usage + app.Description = c.Description + app.ArgsUsage = c.ArgsUsage + + // set CommandNotFound + app.CommandNotFound = ctx.App.CommandNotFound + app.CustomAppHelpTemplate = c.CustomHelpTemplate + + // set the flags and commands + app.Commands = c.Subcommands + app.Flags = c.Flags + app.HideHelp = c.HideHelp + + app.Version = ctx.App.Version + app.HideVersion = ctx.App.HideVersion + app.Compiled = ctx.App.Compiled + app.Author = ctx.App.Author + app.Email = ctx.App.Email + app.Writer = ctx.App.Writer + app.ErrWriter = ctx.App.ErrWriter + + app.categories = CommandCategories{} + for _, command := range c.Subcommands { + app.categories = app.categories.AddCommand(command.Category, command) + } + + sort.Sort(app.categories) + + // bash completion + app.EnableBashCompletion = ctx.App.EnableBashCompletion + if c.BashComplete != nil { + app.BashComplete = c.BashComplete + } + + // set the actions + app.Before = c.Before + app.After = c.After + if c.Action != nil { + app.Action = c.Action + } else { + app.Action = helpSubcommand.Action + } + app.OnUsageError = c.OnUsageError + + for index, cc := range app.Commands { + app.Commands[index].commandNamePath = []string{c.Name, cc.Name} + } + + return app.RunAsSubcommand(ctx) +} + +// VisibleFlags returns a slice of the Flags with Hidden=false +func (c Command) VisibleFlags() []Flag { + return visibleFlags(c.Flags) +} diff --git a/vendor/gopkg.in/urfave/cli.v1/context.go b/vendor/gopkg.in/urfave/cli.v1/context.go new file mode 100644 index 000000000..db94191e2 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/context.go @@ -0,0 +1,278 @@ +package cli + +import ( + "errors" + "flag" + "reflect" + "strings" + "syscall" +) + +// Context is a type that is passed through to +// each Handler action in a cli application. Context +// can be used to retrieve context-specific Args and +// parsed command-line options. +type Context struct { + App *App + Command Command + shellComplete bool + flagSet *flag.FlagSet + setFlags map[string]bool + parentContext *Context +} + +// NewContext creates a new context. For use in when invoking an App or Command action. +func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context { + c := &Context{App: app, flagSet: set, parentContext: parentCtx} + + if parentCtx != nil { + c.shellComplete = parentCtx.shellComplete + } + + return c +} + +// NumFlags returns the number of flags set +func (c *Context) NumFlags() int { + return c.flagSet.NFlag() +} + +// Set sets a context flag to a value. +func (c *Context) Set(name, value string) error { + c.setFlags = nil + return c.flagSet.Set(name, value) +} + +// GlobalSet sets a context flag to a value on the global flagset +func (c *Context) GlobalSet(name, value string) error { + globalContext(c).setFlags = nil + return globalContext(c).flagSet.Set(name, value) +} + +// IsSet determines if the flag was actually set +func (c *Context) IsSet(name string) bool { + if c.setFlags == nil { + c.setFlags = make(map[string]bool) + + c.flagSet.Visit(func(f *flag.Flag) { + c.setFlags[f.Name] = true + }) + + c.flagSet.VisitAll(func(f *flag.Flag) { + if _, ok := c.setFlags[f.Name]; ok { + return + } + c.setFlags[f.Name] = false + }) + + // XXX hack to support IsSet for flags with EnvVar + // + // There isn't an easy way to do this with the current implementation since + // whether a flag was set via an environment variable is very difficult to + // determine here. Instead, we intend to introduce a backwards incompatible + // change in version 2 to add `IsSet` to the Flag interface to push the + // responsibility closer to where the information required to determine + // whether a flag is set by non-standard means such as environment + // variables is avaliable. + // + // See https://github.com/urfave/cli/issues/294 for additional discussion + flags := c.Command.Flags + if c.Command.Name == "" { // cannot == Command{} since it contains slice types + if c.App != nil { + flags = c.App.Flags + } + } + for _, f := range flags { + eachName(f.GetName(), func(name string) { + if isSet, ok := c.setFlags[name]; isSet || !ok { + return + } + + val := reflect.ValueOf(f) + if val.Kind() == reflect.Ptr { + val = val.Elem() + } + + envVarValue := val.FieldByName("EnvVar") + if !envVarValue.IsValid() { + return + } + + eachName(envVarValue.String(), func(envVar string) { + envVar = strings.TrimSpace(envVar) + if _, ok := syscall.Getenv(envVar); ok { + c.setFlags[name] = true + return + } + }) + }) + } + } + + return c.setFlags[name] +} + +// GlobalIsSet determines if the global flag was actually set +func (c *Context) GlobalIsSet(name string) bool { + ctx := c + if ctx.parentContext != nil { + ctx = ctx.parentContext + } + + for ; ctx != nil; ctx = ctx.parentContext { + if ctx.IsSet(name) { + return true + } + } + return false +} + +// FlagNames returns a slice of flag names used in this context. +func (c *Context) FlagNames() (names []string) { + for _, flag := range c.Command.Flags { + name := strings.Split(flag.GetName(), ",")[0] + if name == "help" { + continue + } + names = append(names, name) + } + return +} + +// GlobalFlagNames returns a slice of global flag names used by the app. +func (c *Context) GlobalFlagNames() (names []string) { + for _, flag := range c.App.Flags { + name := strings.Split(flag.GetName(), ",")[0] + if name == "help" || name == "version" { + continue + } + names = append(names, name) + } + return +} + +// Parent returns the parent context, if any +func (c *Context) Parent() *Context { + return c.parentContext +} + +// value returns the value of the flag coressponding to `name` +func (c *Context) value(name string) interface{} { + return c.flagSet.Lookup(name).Value.(flag.Getter).Get() +} + +// Args contains apps console arguments +type Args []string + +// Args returns the command line arguments associated with the context. +func (c *Context) Args() Args { + args := Args(c.flagSet.Args()) + return args +} + +// NArg returns the number of the command line arguments. +func (c *Context) NArg() int { + return len(c.Args()) +} + +// Get returns the nth argument, or else a blank string +func (a Args) Get(n int) string { + if len(a) > n { + return a[n] + } + return "" +} + +// First returns the first argument, or else a blank string +func (a Args) First() string { + return a.Get(0) +} + +// Tail returns the rest of the arguments (not the first one) +// or else an empty string slice +func (a Args) Tail() []string { + if len(a) >= 2 { + return []string(a)[1:] + } + return []string{} +} + +// Present checks if there are any arguments present +func (a Args) Present() bool { + return len(a) != 0 +} + +// Swap swaps arguments at the given indexes +func (a Args) Swap(from, to int) error { + if from >= len(a) || to >= len(a) { + return errors.New("index out of range") + } + a[from], a[to] = a[to], a[from] + return nil +} + +func globalContext(ctx *Context) *Context { + if ctx == nil { + return nil + } + + for { + if ctx.parentContext == nil { + return ctx + } + ctx = ctx.parentContext + } +} + +func lookupGlobalFlagSet(name string, ctx *Context) *flag.FlagSet { + if ctx.parentContext != nil { + ctx = ctx.parentContext + } + for ; ctx != nil; ctx = ctx.parentContext { + if f := ctx.flagSet.Lookup(name); f != nil { + return ctx.flagSet + } + } + return nil +} + +func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) { + switch ff.Value.(type) { + case *StringSlice: + default: + set.Set(name, ff.Value.String()) + } +} + +func normalizeFlags(flags []Flag, set *flag.FlagSet) error { + visited := make(map[string]bool) + set.Visit(func(f *flag.Flag) { + visited[f.Name] = true + }) + for _, f := range flags { + parts := strings.Split(f.GetName(), ",") + if len(parts) == 1 { + continue + } + var ff *flag.Flag + for _, name := range parts { + name = strings.Trim(name, " ") + if visited[name] { + if ff != nil { + return errors.New("Cannot use two forms of the same flag: " + name + " " + ff.Name) + } + ff = set.Lookup(name) + } + } + if ff == nil { + continue + } + for _, name := range parts { + name = strings.Trim(name, " ") + if !visited[name] { + copyFlag(name, ff, set) + } + } + } + return nil +} diff --git a/vendor/gopkg.in/urfave/cli.v1/errors.go b/vendor/gopkg.in/urfave/cli.v1/errors.go new file mode 100644 index 000000000..562b2953c --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/errors.go @@ -0,0 +1,115 @@ +package cli + +import ( + "fmt" + "io" + "os" + "strings" +) + +// OsExiter is the function used when the app exits. If not set defaults to os.Exit. +var OsExiter = os.Exit + +// ErrWriter is used to write errors to the user. This can be anything +// implementing the io.Writer interface and defaults to os.Stderr. +var ErrWriter io.Writer = os.Stderr + +// MultiError is an error that wraps multiple errors. +type MultiError struct { + Errors []error +} + +// NewMultiError creates a new MultiError. Pass in one or more errors. +func NewMultiError(err ...error) MultiError { + return MultiError{Errors: err} +} + +// Error implements the error interface. +func (m MultiError) Error() string { + errs := make([]string, len(m.Errors)) + for i, err := range m.Errors { + errs[i] = err.Error() + } + + return strings.Join(errs, "\n") +} + +type ErrorFormatter interface { + Format(s fmt.State, verb rune) +} + +// ExitCoder is the interface checked by `App` and `Command` for a custom exit +// code +type ExitCoder interface { + error + ExitCode() int +} + +// ExitError fulfills both the builtin `error` interface and `ExitCoder` +type ExitError struct { + exitCode int + message interface{} +} + +// NewExitError makes a new *ExitError +func NewExitError(message interface{}, exitCode int) *ExitError { + return &ExitError{ + exitCode: exitCode, + message: message, + } +} + +// Error returns the string message, fulfilling the interface required by +// `error` +func (ee *ExitError) Error() string { + return fmt.Sprintf("%v", ee.message) +} + +// ExitCode returns the exit code, fulfilling the interface required by +// `ExitCoder` +func (ee *ExitError) ExitCode() int { + return ee.exitCode +} + +// HandleExitCoder checks if the error fulfills the ExitCoder interface, and if +// so prints the error to stderr (if it is non-empty) and calls OsExiter with the +// given exit code. If the given error is a MultiError, then this func is +// called on all members of the Errors slice and calls OsExiter with the last exit code. +func HandleExitCoder(err error) { + if err == nil { + return + } + + if exitErr, ok := err.(ExitCoder); ok { + if err.Error() != "" { + if _, ok := exitErr.(ErrorFormatter); ok { + fmt.Fprintf(ErrWriter, "%+v\n", err) + } else { + fmt.Fprintln(ErrWriter, err) + } + } + OsExiter(exitErr.ExitCode()) + return + } + + if multiErr, ok := err.(MultiError); ok { + code := handleMultiError(multiErr) + OsExiter(code) + return + } +} + +func handleMultiError(multiErr MultiError) int { + code := 1 + for _, merr := range multiErr.Errors { + if multiErr2, ok := merr.(MultiError); ok { + code = handleMultiError(multiErr2) + } else { + fmt.Fprintln(ErrWriter, merr) + if exitErr, ok := merr.(ExitCoder); ok { + code = exitErr.ExitCode() + } + } + } + return code +} diff --git a/vendor/gopkg.in/urfave/cli.v1/flag.go b/vendor/gopkg.in/urfave/cli.v1/flag.go new file mode 100644 index 000000000..877ff3523 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/flag.go @@ -0,0 +1,799 @@ +package cli + +import ( + "flag" + "fmt" + "reflect" + "runtime" + "strconv" + "strings" + "syscall" + "time" +) + +const defaultPlaceholder = "value" + +// BashCompletionFlag enables bash-completion for all commands and subcommands +var BashCompletionFlag Flag = BoolFlag{ + Name: "generate-bash-completion", + Hidden: true, +} + +// VersionFlag prints the version for the application +var VersionFlag Flag = BoolFlag{ + Name: "version, v", + Usage: "print the version", +} + +// HelpFlag prints the help for all commands and subcommands +// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand +// unless HideHelp is set to true) +var HelpFlag Flag = BoolFlag{ + Name: "help, h", + Usage: "show help", +} + +// FlagStringer converts a flag definition to a string. This is used by help +// to display a flag. +var FlagStringer FlagStringFunc = stringifyFlag + +// FlagsByName is a slice of Flag. +type FlagsByName []Flag + +func (f FlagsByName) Len() int { + return len(f) +} + +func (f FlagsByName) Less(i, j int) bool { + return f[i].GetName() < f[j].GetName() +} + +func (f FlagsByName) Swap(i, j int) { + f[i], f[j] = f[j], f[i] +} + +// Flag is a common interface related to parsing flags in cli. +// For more advanced flag parsing techniques, it is recommended that +// this interface be implemented. +type Flag interface { + fmt.Stringer + // Apply Flag settings to the given flag set + Apply(*flag.FlagSet) + GetName() string +} + +// errorableFlag is an interface that allows us to return errors during apply +// it allows flags defined in this library to return errors in a fashion backwards compatible +// TODO remove in v2 and modify the existing Flag interface to return errors +type errorableFlag interface { + Flag + + ApplyWithError(*flag.FlagSet) error +} + +func flagSet(name string, flags []Flag) (*flag.FlagSet, error) { + set := flag.NewFlagSet(name, flag.ContinueOnError) + + for _, f := range flags { + //TODO remove in v2 when errorableFlag is removed + if ef, ok := f.(errorableFlag); ok { + if err := ef.ApplyWithError(set); err != nil { + return nil, err + } + } else { + f.Apply(set) + } + } + return set, nil +} + +func eachName(longName string, fn func(string)) { + parts := strings.Split(longName, ",") + for _, name := range parts { + name = strings.Trim(name, " ") + fn(name) + } +} + +// Generic is a generic parseable type identified by a specific flag +type Generic interface { + Set(value string) error + String() string +} + +// Apply takes the flagset and calls Set on the generic flag with the value +// provided by the user for parsing by the flag +// Ignores parsing errors +func (f GenericFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError takes the flagset and calls Set on the generic flag with the value +// provided by the user for parsing by the flag +func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error { + val := f.Value + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + if err := val.Set(envVal); err != nil { + return fmt.Errorf("could not parse %s as value for flag %s: %s", envVal, f.Name, err) + } + break + } + } + } + + eachName(f.Name, func(name string) { + set.Var(f.Value, name, f.Usage) + }) + + return nil +} + +// StringSlice is an opaque type for []string to satisfy flag.Value and flag.Getter +type StringSlice []string + +// Set appends the string value to the list of values +func (f *StringSlice) Set(value string) error { + *f = append(*f, value) + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (f *StringSlice) String() string { + return fmt.Sprintf("%s", *f) +} + +// Value returns the slice of strings set by this flag +func (f *StringSlice) Value() []string { + return *f +} + +// Get returns the slice of strings set by this flag +func (f *StringSlice) Get() interface{} { + return *f +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f StringSliceFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + newVal := &StringSlice{} + for _, s := range strings.Split(envVal, ",") { + s = strings.TrimSpace(s) + if err := newVal.Set(s); err != nil { + return fmt.Errorf("could not parse %s as string value for flag %s: %s", envVal, f.Name, err) + } + } + f.Value = newVal + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Value == nil { + f.Value = &StringSlice{} + } + set.Var(f.Value, name, f.Usage) + }) + + return nil +} + +// IntSlice is an opaque type for []int to satisfy flag.Value and flag.Getter +type IntSlice []int + +// Set parses the value into an integer and appends it to the list of values +func (f *IntSlice) Set(value string) error { + tmp, err := strconv.Atoi(value) + if err != nil { + return err + } + *f = append(*f, tmp) + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (f *IntSlice) String() string { + return fmt.Sprintf("%#v", *f) +} + +// Value returns the slice of ints set by this flag +func (f *IntSlice) Value() []int { + return *f +} + +// Get returns the slice of ints set by this flag +func (f *IntSlice) Get() interface{} { + return *f +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f IntSliceFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + newVal := &IntSlice{} + for _, s := range strings.Split(envVal, ",") { + s = strings.TrimSpace(s) + if err := newVal.Set(s); err != nil { + return fmt.Errorf("could not parse %s as int slice value for flag %s: %s", envVal, f.Name, err) + } + } + f.Value = newVal + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Value == nil { + f.Value = &IntSlice{} + } + set.Var(f.Value, name, f.Usage) + }) + + return nil +} + +// Int64Slice is an opaque type for []int to satisfy flag.Value and flag.Getter +type Int64Slice []int64 + +// Set parses the value into an integer and appends it to the list of values +func (f *Int64Slice) Set(value string) error { + tmp, err := strconv.ParseInt(value, 10, 64) + if err != nil { + return err + } + *f = append(*f, tmp) + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (f *Int64Slice) String() string { + return fmt.Sprintf("%#v", *f) +} + +// Value returns the slice of ints set by this flag +func (f *Int64Slice) Value() []int64 { + return *f +} + +// Get returns the slice of ints set by this flag +func (f *Int64Slice) Get() interface{} { + return *f +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f Int64SliceFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + newVal := &Int64Slice{} + for _, s := range strings.Split(envVal, ",") { + s = strings.TrimSpace(s) + if err := newVal.Set(s); err != nil { + return fmt.Errorf("could not parse %s as int64 slice value for flag %s: %s", envVal, f.Name, err) + } + } + f.Value = newVal + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Value == nil { + f.Value = &Int64Slice{} + } + set.Var(f.Value, name, f.Usage) + }) + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f BoolFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error { + val := false + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + if envVal == "" { + val = false + break + } + + envValBool, err := strconv.ParseBool(envVal) + if err != nil { + return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) + } + + val = envValBool + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.BoolVar(f.Destination, name, val, f.Usage) + return + } + set.Bool(name, val, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f BoolTFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error { + val := true + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + if envVal == "" { + val = false + break + } + + envValBool, err := strconv.ParseBool(envVal) + if err != nil { + return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) + } + + val = envValBool + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.BoolVar(f.Destination, name, val, f.Usage) + return + } + set.Bool(name, val, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f StringFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f StringFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + f.Value = envVal + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.StringVar(f.Destination, name, f.Value, f.Usage) + return + } + set.String(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f IntFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f IntFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValInt, err := strconv.ParseInt(envVal, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) + } + f.Value = int(envValInt) + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.IntVar(f.Destination, name, f.Value, f.Usage) + return + } + set.Int(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f Int64Flag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValInt, err := strconv.ParseInt(envVal, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) + } + + f.Value = envValInt + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.Int64Var(f.Destination, name, f.Value, f.Usage) + return + } + set.Int64(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f UintFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f UintFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValInt, err := strconv.ParseUint(envVal, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %s as uint value for flag %s: %s", envVal, f.Name, err) + } + + f.Value = uint(envValInt) + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.UintVar(f.Destination, name, f.Value, f.Usage) + return + } + set.Uint(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f Uint64Flag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValInt, err := strconv.ParseUint(envVal, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %s as uint64 value for flag %s: %s", envVal, f.Name, err) + } + + f.Value = uint64(envValInt) + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.Uint64Var(f.Destination, name, f.Value, f.Usage) + return + } + set.Uint64(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f DurationFlag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValDuration, err := time.ParseDuration(envVal) + if err != nil { + return fmt.Errorf("could not parse %s as duration for flag %s: %s", envVal, f.Name, err) + } + + f.Value = envValDuration + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.DurationVar(f.Destination, name, f.Value, f.Usage) + return + } + set.Duration(name, f.Value, f.Usage) + }) + + return nil +} + +// Apply populates the flag given the flag set and environment +// Ignores errors +func (f Float64Flag) Apply(set *flag.FlagSet) { + f.ApplyWithError(set) +} + +// ApplyWithError populates the flag given the flag set and environment +func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error { + if f.EnvVar != "" { + for _, envVar := range strings.Split(f.EnvVar, ",") { + envVar = strings.TrimSpace(envVar) + if envVal, ok := syscall.Getenv(envVar); ok { + envValFloat, err := strconv.ParseFloat(envVal, 10) + if err != nil { + return fmt.Errorf("could not parse %s as float64 value for flag %s: %s", envVal, f.Name, err) + } + + f.Value = float64(envValFloat) + break + } + } + } + + eachName(f.Name, func(name string) { + if f.Destination != nil { + set.Float64Var(f.Destination, name, f.Value, f.Usage) + return + } + set.Float64(name, f.Value, f.Usage) + }) + + return nil +} + +func visibleFlags(fl []Flag) []Flag { + visible := []Flag{} + for _, flag := range fl { + field := flagValue(flag).FieldByName("Hidden") + if !field.IsValid() || !field.Bool() { + visible = append(visible, flag) + } + } + return visible +} + +func prefixFor(name string) (prefix string) { + if len(name) == 1 { + prefix = "-" + } else { + prefix = "--" + } + + return +} + +// Returns the placeholder, if any, and the unquoted usage string. +func unquoteUsage(usage string) (string, string) { + for i := 0; i < len(usage); i++ { + if usage[i] == '`' { + for j := i + 1; j < len(usage); j++ { + if usage[j] == '`' { + name := usage[i+1 : j] + usage = usage[:i] + name + usage[j+1:] + return name, usage + } + } + break + } + } + return "", usage +} + +func prefixedNames(fullName, placeholder string) string { + var prefixed string + parts := strings.Split(fullName, ",") + for i, name := range parts { + name = strings.Trim(name, " ") + prefixed += prefixFor(name) + name + if placeholder != "" { + prefixed += " " + placeholder + } + if i < len(parts)-1 { + prefixed += ", " + } + } + return prefixed +} + +func withEnvHint(envVar, str string) string { + envText := "" + if envVar != "" { + prefix := "$" + suffix := "" + sep := ", $" + if runtime.GOOS == "windows" { + prefix = "%" + suffix = "%" + sep = "%, %" + } + envText = fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(strings.Split(envVar, ","), sep), suffix) + } + return str + envText +} + +func flagValue(f Flag) reflect.Value { + fv := reflect.ValueOf(f) + for fv.Kind() == reflect.Ptr { + fv = reflect.Indirect(fv) + } + return fv +} + +func stringifyFlag(f Flag) string { + fv := flagValue(f) + + switch f.(type) { + case IntSliceFlag: + return withEnvHint(fv.FieldByName("EnvVar").String(), + stringifyIntSliceFlag(f.(IntSliceFlag))) + case Int64SliceFlag: + return withEnvHint(fv.FieldByName("EnvVar").String(), + stringifyInt64SliceFlag(f.(Int64SliceFlag))) + case StringSliceFlag: + return withEnvHint(fv.FieldByName("EnvVar").String(), + stringifyStringSliceFlag(f.(StringSliceFlag))) + } + + placeholder, usage := unquoteUsage(fv.FieldByName("Usage").String()) + + needsPlaceholder := false + defaultValueString := "" + + if val := fv.FieldByName("Value"); val.IsValid() { + needsPlaceholder = true + defaultValueString = fmt.Sprintf(" (default: %v)", val.Interface()) + + if val.Kind() == reflect.String && val.String() != "" { + defaultValueString = fmt.Sprintf(" (default: %q)", val.String()) + } + } + + if defaultValueString == " (default: )" { + defaultValueString = "" + } + + if needsPlaceholder && placeholder == "" { + placeholder = defaultPlaceholder + } + + usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultValueString)) + + return withEnvHint(fv.FieldByName("EnvVar").String(), + fmt.Sprintf("%s\t%s", prefixedNames(fv.FieldByName("Name").String(), placeholder), usageWithDefault)) +} + +func stringifyIntSliceFlag(f IntSliceFlag) string { + defaultVals := []string{} + if f.Value != nil && len(f.Value.Value()) > 0 { + for _, i := range f.Value.Value() { + defaultVals = append(defaultVals, fmt.Sprintf("%d", i)) + } + } + + return stringifySliceFlag(f.Usage, f.Name, defaultVals) +} + +func stringifyInt64SliceFlag(f Int64SliceFlag) string { + defaultVals := []string{} + if f.Value != nil && len(f.Value.Value()) > 0 { + for _, i := range f.Value.Value() { + defaultVals = append(defaultVals, fmt.Sprintf("%d", i)) + } + } + + return stringifySliceFlag(f.Usage, f.Name, defaultVals) +} + +func stringifyStringSliceFlag(f StringSliceFlag) string { + defaultVals := []string{} + if f.Value != nil && len(f.Value.Value()) > 0 { + for _, s := range f.Value.Value() { + if len(s) > 0 { + defaultVals = append(defaultVals, fmt.Sprintf("%q", s)) + } + } + } + + return stringifySliceFlag(f.Usage, f.Name, defaultVals) +} + +func stringifySliceFlag(usage, name string, defaultVals []string) string { + placeholder, usage := unquoteUsage(usage) + if placeholder == "" { + placeholder = defaultPlaceholder + } + + defaultVal := "" + if len(defaultVals) > 0 { + defaultVal = fmt.Sprintf(" (default: %s)", strings.Join(defaultVals, ", ")) + } + + usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultVal)) + return fmt.Sprintf("%s\t%s", prefixedNames(name, placeholder), usageWithDefault) +} diff --git a/vendor/gopkg.in/urfave/cli.v1/flag_generated.go b/vendor/gopkg.in/urfave/cli.v1/flag_generated.go new file mode 100644 index 000000000..491b61956 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/flag_generated.go @@ -0,0 +1,627 @@ +package cli + +import ( + "flag" + "strconv" + "time" +) + +// WARNING: This file is generated! + +// BoolFlag is a flag with type bool +type BoolFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Destination *bool +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f BoolFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f BoolFlag) GetName() string { + return f.Name +} + +// Bool looks up the value of a local BoolFlag, returns +// false if not found +func (c *Context) Bool(name string) bool { + return lookupBool(name, c.flagSet) +} + +// GlobalBool looks up the value of a global BoolFlag, returns +// false if not found +func (c *Context) GlobalBool(name string) bool { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupBool(name, fs) + } + return false +} + +func lookupBool(name string, set *flag.FlagSet) bool { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseBool(f.Value.String()) + if err != nil { + return false + } + return parsed + } + return false +} + +// BoolTFlag is a flag with type bool that is true by default +type BoolTFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Destination *bool +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f BoolTFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f BoolTFlag) GetName() string { + return f.Name +} + +// BoolT looks up the value of a local BoolTFlag, returns +// false if not found +func (c *Context) BoolT(name string) bool { + return lookupBoolT(name, c.flagSet) +} + +// GlobalBoolT looks up the value of a global BoolTFlag, returns +// false if not found +func (c *Context) GlobalBoolT(name string) bool { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupBoolT(name, fs) + } + return false +} + +func lookupBoolT(name string, set *flag.FlagSet) bool { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseBool(f.Value.String()) + if err != nil { + return false + } + return parsed + } + return false +} + +// DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration) +type DurationFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value time.Duration + Destination *time.Duration +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f DurationFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f DurationFlag) GetName() string { + return f.Name +} + +// Duration looks up the value of a local DurationFlag, returns +// 0 if not found +func (c *Context) Duration(name string) time.Duration { + return lookupDuration(name, c.flagSet) +} + +// GlobalDuration looks up the value of a global DurationFlag, returns +// 0 if not found +func (c *Context) GlobalDuration(name string) time.Duration { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupDuration(name, fs) + } + return 0 +} + +func lookupDuration(name string, set *flag.FlagSet) time.Duration { + f := set.Lookup(name) + if f != nil { + parsed, err := time.ParseDuration(f.Value.String()) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// Float64Flag is a flag with type float64 +type Float64Flag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value float64 + Destination *float64 +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Float64Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Float64Flag) GetName() string { + return f.Name +} + +// Float64 looks up the value of a local Float64Flag, returns +// 0 if not found +func (c *Context) Float64(name string) float64 { + return lookupFloat64(name, c.flagSet) +} + +// GlobalFloat64 looks up the value of a global Float64Flag, returns +// 0 if not found +func (c *Context) GlobalFloat64(name string) float64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupFloat64(name, fs) + } + return 0 +} + +func lookupFloat64(name string, set *flag.FlagSet) float64 { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseFloat(f.Value.String(), 64) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// GenericFlag is a flag with type Generic +type GenericFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value Generic +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f GenericFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f GenericFlag) GetName() string { + return f.Name +} + +// Generic looks up the value of a local GenericFlag, returns +// nil if not found +func (c *Context) Generic(name string) interface{} { + return lookupGeneric(name, c.flagSet) +} + +// GlobalGeneric looks up the value of a global GenericFlag, returns +// nil if not found +func (c *Context) GlobalGeneric(name string) interface{} { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupGeneric(name, fs) + } + return nil +} + +func lookupGeneric(name string, set *flag.FlagSet) interface{} { + f := set.Lookup(name) + if f != nil { + parsed, err := f.Value, error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// Int64Flag is a flag with type int64 +type Int64Flag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value int64 + Destination *int64 +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Int64Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Int64Flag) GetName() string { + return f.Name +} + +// Int64 looks up the value of a local Int64Flag, returns +// 0 if not found +func (c *Context) Int64(name string) int64 { + return lookupInt64(name, c.flagSet) +} + +// GlobalInt64 looks up the value of a global Int64Flag, returns +// 0 if not found +func (c *Context) GlobalInt64(name string) int64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupInt64(name, fs) + } + return 0 +} + +func lookupInt64(name string, set *flag.FlagSet) int64 { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// IntFlag is a flag with type int +type IntFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value int + Destination *int +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f IntFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f IntFlag) GetName() string { + return f.Name +} + +// Int looks up the value of a local IntFlag, returns +// 0 if not found +func (c *Context) Int(name string) int { + return lookupInt(name, c.flagSet) +} + +// GlobalInt looks up the value of a global IntFlag, returns +// 0 if not found +func (c *Context) GlobalInt(name string) int { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupInt(name, fs) + } + return 0 +} + +func lookupInt(name string, set *flag.FlagSet) int { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return int(parsed) + } + return 0 +} + +// IntSliceFlag is a flag with type *IntSlice +type IntSliceFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value *IntSlice +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f IntSliceFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f IntSliceFlag) GetName() string { + return f.Name +} + +// IntSlice looks up the value of a local IntSliceFlag, returns +// nil if not found +func (c *Context) IntSlice(name string) []int { + return lookupIntSlice(name, c.flagSet) +} + +// GlobalIntSlice looks up the value of a global IntSliceFlag, returns +// nil if not found +func (c *Context) GlobalIntSlice(name string) []int { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupIntSlice(name, fs) + } + return nil +} + +func lookupIntSlice(name string, set *flag.FlagSet) []int { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*IntSlice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// Int64SliceFlag is a flag with type *Int64Slice +type Int64SliceFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value *Int64Slice +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Int64SliceFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Int64SliceFlag) GetName() string { + return f.Name +} + +// Int64Slice looks up the value of a local Int64SliceFlag, returns +// nil if not found +func (c *Context) Int64Slice(name string) []int64 { + return lookupInt64Slice(name, c.flagSet) +} + +// GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns +// nil if not found +func (c *Context) GlobalInt64Slice(name string) []int64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupInt64Slice(name, fs) + } + return nil +} + +func lookupInt64Slice(name string, set *flag.FlagSet) []int64 { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// StringFlag is a flag with type string +type StringFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value string + Destination *string +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f StringFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f StringFlag) GetName() string { + return f.Name +} + +// String looks up the value of a local StringFlag, returns +// "" if not found +func (c *Context) String(name string) string { + return lookupString(name, c.flagSet) +} + +// GlobalString looks up the value of a global StringFlag, returns +// "" if not found +func (c *Context) GlobalString(name string) string { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupString(name, fs) + } + return "" +} + +func lookupString(name string, set *flag.FlagSet) string { + f := set.Lookup(name) + if f != nil { + parsed, err := f.Value.String(), error(nil) + if err != nil { + return "" + } + return parsed + } + return "" +} + +// StringSliceFlag is a flag with type *StringSlice +type StringSliceFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value *StringSlice +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f StringSliceFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f StringSliceFlag) GetName() string { + return f.Name +} + +// StringSlice looks up the value of a local StringSliceFlag, returns +// nil if not found +func (c *Context) StringSlice(name string) []string { + return lookupStringSlice(name, c.flagSet) +} + +// GlobalStringSlice looks up the value of a global StringSliceFlag, returns +// nil if not found +func (c *Context) GlobalStringSlice(name string) []string { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupStringSlice(name, fs) + } + return nil +} + +func lookupStringSlice(name string, set *flag.FlagSet) []string { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*StringSlice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// Uint64Flag is a flag with type uint64 +type Uint64Flag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value uint64 + Destination *uint64 +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Uint64Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Uint64Flag) GetName() string { + return f.Name +} + +// Uint64 looks up the value of a local Uint64Flag, returns +// 0 if not found +func (c *Context) Uint64(name string) uint64 { + return lookupUint64(name, c.flagSet) +} + +// GlobalUint64 looks up the value of a global Uint64Flag, returns +// 0 if not found +func (c *Context) GlobalUint64(name string) uint64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupUint64(name, fs) + } + return 0 +} + +func lookupUint64(name string, set *flag.FlagSet) uint64 { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// UintFlag is a flag with type uint +type UintFlag struct { + Name string + Usage string + EnvVar string + Hidden bool + Value uint + Destination *uint +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f UintFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f UintFlag) GetName() string { + return f.Name +} + +// Uint looks up the value of a local UintFlag, returns +// 0 if not found +func (c *Context) Uint(name string) uint { + return lookupUint(name, c.flagSet) +} + +// GlobalUint looks up the value of a global UintFlag, returns +// 0 if not found +func (c *Context) GlobalUint(name string) uint { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupUint(name, fs) + } + return 0 +} + +func lookupUint(name string, set *flag.FlagSet) uint { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return uint(parsed) + } + return 0 +} diff --git a/vendor/gopkg.in/urfave/cli.v1/funcs.go b/vendor/gopkg.in/urfave/cli.v1/funcs.go new file mode 100644 index 000000000..cba5e6cb0 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/funcs.go @@ -0,0 +1,28 @@ +package cli + +// BashCompleteFunc is an action to execute when the bash-completion flag is set +type BashCompleteFunc func(*Context) + +// BeforeFunc is an action to execute before any subcommands are run, but after +// the context is ready if a non-nil error is returned, no subcommands are run +type BeforeFunc func(*Context) error + +// AfterFunc is an action to execute after any subcommands are run, but after the +// subcommand has finished it is run even if Action() panics +type AfterFunc func(*Context) error + +// ActionFunc is the action to execute when no subcommands are specified +type ActionFunc func(*Context) error + +// CommandNotFoundFunc is executed if the proper command cannot be found +type CommandNotFoundFunc func(*Context, string) + +// OnUsageErrorFunc is executed if an usage error occurs. This is useful for displaying +// customized usage error messages. This function is able to replace the +// original error messages. If this function is not set, the "Incorrect usage" +// is displayed and the execution is interrupted. +type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error + +// FlagStringFunc is used by the help generation to display a flag, which is +// expected to be a single line. +type FlagStringFunc func(Flag) string diff --git a/vendor/gopkg.in/urfave/cli.v1/help.go b/vendor/gopkg.in/urfave/cli.v1/help.go new file mode 100644 index 000000000..57ec98d58 --- /dev/null +++ b/vendor/gopkg.in/urfave/cli.v1/help.go @@ -0,0 +1,338 @@ +package cli + +import ( + "fmt" + "io" + "os" + "strings" + "text/tabwriter" + "text/template" +) + +// AppHelpTemplate is the text template for the Default help topic. +// cli.go uses text/template to render templates. You can +// render custom help text by setting this variable. +var AppHelpTemplate = `NAME: + {{.Name}}{{if .Usage}} - {{.Usage}}{{end}} + +USAGE: + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} + +VERSION: + {{.Version}}{{end}}{{end}}{{if .Description}} + +DESCRIPTION: + {{.Description}}{{end}}{{if len .Authors}} + +AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: + {{range $index, $author := .Authors}}{{if $index}} + {{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}} + +COMMANDS:{{range .VisibleCategories}}{{if .Name}} + {{.Name}}:{{end}}{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} + +GLOBAL OPTIONS: + {{range $index, $option := .VisibleFlags}}{{if $index}} + {{end}}{{$option}}{{end}}{{end}}{{if .Copyright}} + +COPYRIGHT: + {{.Copyright}}{{end}} +` + +// CommandHelpTemplate is the text template for the command help topic. +// cli.go uses text/template to render templates. You can +// render custom help text by setting this variable. +var CommandHelpTemplate = `NAME: + {{.HelpName}} - {{.Usage}} + +USAGE: + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}} + +CATEGORY: + {{.Category}}{{end}}{{if .Description}} + +DESCRIPTION: + {{.Description}}{{end}}{{if .VisibleFlags}} + +OPTIONS: + {{range .VisibleFlags}}{{.}} + {{end}}{{end}} +` + +// SubcommandHelpTemplate is the text template for the subcommand help topic. +// cli.go uses text/template to render templates. You can +// render custom help text by setting this variable. +var SubcommandHelpTemplate = `NAME: + {{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}} + +USAGE: + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} + +COMMANDS:{{range .VisibleCategories}}{{if .Name}} + {{.Name}}:{{end}}{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}} +{{end}}{{if .VisibleFlags}} +OPTIONS: + {{range .VisibleFlags}}{{.}} + {{end}}{{end}} +` + +var helpCommand = Command{ + Name: "help", + Aliases: []string{"h"}, + Usage: "Shows a list of commands or help for one command", + ArgsUsage: "[command]", + Action: func(c *Context) error { + args := c.Args() + if args.Present() { + return ShowCommandHelp(c, args.First()) + } + + ShowAppHelp(c) + return nil + }, +} + +var helpSubcommand = Command{ + Name: "help", + Aliases: []string{"h"}, + Usage: "Shows a list of commands or help for one command", + ArgsUsage: "[command]", + Action: func(c *Context) error { + args := c.Args() + if args.Present() { + return ShowCommandHelp(c, args.First()) + } + + return ShowSubcommandHelp(c) + }, +} + +// Prints help for the App or Command +type helpPrinter func(w io.Writer, templ string, data interface{}) + +// Prints help for the App or Command with custom template function. +type helpPrinterCustom func(w io.Writer, templ string, data interface{}, customFunc map[string]interface{}) + +// HelpPrinter is a function that writes the help output. If not set a default +// is used. The function signature is: +// func(w io.Writer, templ string, data interface{}) +var HelpPrinter helpPrinter = printHelp + +// HelpPrinterCustom is same as HelpPrinter but +// takes a custom function for template function map. +var HelpPrinterCustom helpPrinterCustom = printHelpCustom + +// VersionPrinter prints the version for the App +var VersionPrinter = printVersion + +// ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code. +func ShowAppHelpAndExit(c *Context, exitCode int) { + ShowAppHelp(c) + os.Exit(exitCode) +} + +// ShowAppHelp is an action that displays the help. +func ShowAppHelp(c *Context) (err error) { + if c.App.CustomAppHelpTemplate == "" { + HelpPrinter(c.App.Writer, AppHelpTemplate, c.App) + return + } + customAppData := func() map[string]interface{} { + if c.App.ExtraInfo == nil { + return nil + } + return map[string]interface{}{ + "ExtraInfo": c.App.ExtraInfo, + } + } + HelpPrinterCustom(c.App.Writer, c.App.CustomAppHelpTemplate, c.App, customAppData()) + return nil +} + +// DefaultAppComplete prints the list of subcommands as the default app completion method +func DefaultAppComplete(c *Context) { + for _, command := range c.App.Commands { + if command.Hidden { + continue + } + for _, name := range command.Names() { + fmt.Fprintln(c.App.Writer, name) + } + } +} + +// ShowCommandHelpAndExit - exits with code after showing help +func ShowCommandHelpAndExit(c *Context, command string, code int) { + ShowCommandHelp(c, command) + os.Exit(code) +} + +// ShowCommandHelp prints help for the given command +func ShowCommandHelp(ctx *Context, command string) error { + // show the subcommand help for a command with subcommands + if command == "" { + HelpPrinter(ctx.App.Writer, SubcommandHelpTemplate, ctx.App) + return nil + } + + for _, c := range ctx.App.Commands { + if c.HasName(command) { + if c.CustomHelpTemplate != "" { + HelpPrinterCustom(ctx.App.Writer, c.CustomHelpTemplate, c, nil) + } else { + HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c) + } + return nil + } + } + + if ctx.App.CommandNotFound == nil { + return NewExitError(fmt.Sprintf("No help topic for '%v'", command), 3) + } + + ctx.App.CommandNotFound(ctx, command) + return nil +} + +// ShowSubcommandHelp prints help for the given subcommand +func ShowSubcommandHelp(c *Context) error { + return ShowCommandHelp(c, c.Command.Name) +} + +// ShowVersion prints the version number of the App +func ShowVersion(c *Context) { + VersionPrinter(c) +} + +func printVersion(c *Context) { + fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version) +} + +// ShowCompletions prints the lists of commands within a given context +func ShowCompletions(c *Context) { + a := c.App + if a != nil && a.BashComplete != nil { + a.BashComplete(c) + } +} + +// ShowCommandCompletions prints the custom completions for a given command +func ShowCommandCompletions(ctx *Context, command string) { + c := ctx.App.Command(command) + if c != nil && c.BashComplete != nil { + c.BashComplete(ctx) + } +} + +func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc map[string]interface{}) { + funcMap := template.FuncMap{ + "join": strings.Join, + } + if customFunc != nil { + for key, value := range customFunc { + funcMap[key] = value + } + } + + w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0) + t := template.Must(template.New("help").Funcs(funcMap).Parse(templ)) + err := t.Execute(w, data) + if err != nil { + // If the writer is closed, t.Execute will fail, and there's nothing + // we can do to recover. + if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" { + fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err) + } + return + } + w.Flush() +} + +func printHelp(out io.Writer, templ string, data interface{}) { + printHelpCustom(out, templ, data, nil) +} + +func checkVersion(c *Context) bool { + found := false + if VersionFlag.GetName() != "" { + eachName(VersionFlag.GetName(), func(name string) { + if c.GlobalBool(name) || c.Bool(name) { + found = true + } + }) + } + return found +} + +func checkHelp(c *Context) bool { + found := false + if HelpFlag.GetName() != "" { + eachName(HelpFlag.GetName(), func(name string) { + if c.GlobalBool(name) || c.Bool(name) { + found = true + } + }) + } + return found +} + +func checkCommandHelp(c *Context, name string) bool { + if c.Bool("h") || c.Bool("help") { + ShowCommandHelp(c, name) + return true + } + + return false +} + +func checkSubcommandHelp(c *Context) bool { + if c.Bool("h") || c.Bool("help") { + ShowSubcommandHelp(c) + return true + } + + return false +} + +func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) { + if !a.EnableBashCompletion { + return false, arguments + } + + pos := len(arguments) - 1 + lastArg := arguments[pos] + + if lastArg != "--"+BashCompletionFlag.GetName() { + return false, arguments + } + + return true, arguments[:pos] +} + +func checkCompletions(c *Context) bool { + if !c.shellComplete { + return false + } + + if args := c.Args(); args.Present() { + name := args.First() + if cmd := c.App.Command(name); cmd != nil { + // let the command handle the completion + return false + } + } + + ShowCompletions(c) + return true +} + +func checkCommandCompletions(c *Context, name string) bool { + if !c.shellComplete { + return false + } + + ShowCommandCompletions(c, name) + return true +} diff --git a/vendor/manifest b/vendor/manifest index 1a8532626..e78f3b86b 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -33,6 +33,31 @@ "branch": "master", "notests": true }, + { + "importpath": "github.com/BurntSushi/toml", + "repository": "https://github.com/BurntSushi/toml", + "vcs": "git", + "revision": "a368813c5e648fee92e5f6c30e3944ff9d5e8895", + "branch": "master", + "notests": true + }, + { + "importpath": "github.com/a8m/mark", + "repository": "https://github.com/a8m/mark", + "vcs": "git", + "revision": "44f2db6188458162890ca13980819247418d8e45", + "branch": "master", + "notests": true + }, + { + "importpath": "github.com/beorn7/perks/quantile", + "repository": "https://github.com/beorn7/perks", + "vcs": "git", + "revision": "4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9", + "branch": "master", + "path": "/quantile", + "notests": true + }, { "importpath": "github.com/bkaradzic/go-lz4", "repository": "https://github.com/bkaradzic/go-lz4", @@ -65,6 +90,14 @@ "branch": "master", "notests": true }, + { + "importpath": "github.com/cheggaaa/pb", + "repository": "https://github.com/cheggaaa/pb", + "vcs": "git", + "revision": "18d384da9bdc1e5a08fc2a62a494c321d9ae74ea", + "branch": "master", + "notests": true + }, { "importpath": "github.com/chmduquesne/rollinghash", "repository": "https://github.com/chmduquesne/rollinghash", @@ -73,106 +106,6 @@ "branch": "master", "notests": true }, - { - "importpath": "github.com/cznic/b", - "repository": "https://github.com/cznic/b", - "vcs": "git", - "revision": "c0c71e655879a2848b5a0e0208b63f97325cbacd", - "branch": "master", - "notests": true - }, - { - "importpath": "github.com/cznic/fileutil", - "repository": "https://github.com/cznic/fileutil", - "vcs": "git", - "revision": "2d566d841097e1297dfb576f809cf9eeecbdbc37", - "branch": "master", - "notests": true - }, - { - "importpath": "github.com/cznic/golex/lex", - "repository": "https://github.com/cznic/golex", - "vcs": "git", - "revision": "4ab7c5e190e49208c823ce8ec803aa39e6a4b31a", - "branch": "master", - "path": "/lex", - "notests": true - }, - { - "importpath": "github.com/cznic/internal/buffer", - "repository": "https://github.com/cznic/internal", - "vcs": "git", - "revision": "4747030f7cf2f4c0a01512b00cd68734b167ac3b", - "branch": "master", - "path": "/buffer", - "notests": true - }, - { - "importpath": "github.com/cznic/internal/file", - "repository": "https://github.com/cznic/internal", - "vcs": "git", - "revision": "4747030f7cf2f4c0a01512b00cd68734b167ac3b", - "branch": "master", - "path": "file", - "notests": true - }, - { - "importpath": "github.com/cznic/internal/slice", - "repository": "https://github.com/cznic/internal", - "vcs": "git", - "revision": "4747030f7cf2f4c0a01512b00cd68734b167ac3b", - "branch": "master", - "path": "slice", - "notests": true - }, - { - "importpath": "github.com/cznic/lldb", - "repository": "https://github.com/cznic/lldb", - "vcs": "git", - "revision": "bea8611dd5c407f3c5eab9f9c68e887a27dc6f0e", - "branch": "master", - "notests": true - }, - { - "importpath": "github.com/cznic/mathutil", - "repository": "https://github.com/cznic/mathutil", - "vcs": "git", - "revision": "09cde8d5df5fd3e1944897ce6d00d83dd5ed3a91", - "branch": "master", - "notests": true - }, - { - "importpath": "github.com/cznic/ql", - "repository": "https://github.com/cznic/ql", - "vcs": "git", - "revision": "3f53e147d722f949b627631bc771623ab9bdb396", - "branch": "master", - "notests": true - }, - { - "importpath": "github.com/cznic/sortutil", - "repository": "https://github.com/cznic/sortutil", - "vcs": "git", - "revision": "4c7342852e65c2088c981288f2c5610d10b9f7f4", - "branch": "master", - "notests": true - }, - { - "importpath": "github.com/cznic/strutil", - "repository": "https://github.com/cznic/strutil", - "vcs": "git", - "revision": "529a34b1c186b483642a7a230c67521d9aa4b0fb", - "branch": "master", - "notests": true - }, - { - "importpath": "github.com/cznic/zappy", - "repository": "https://github.com/cznic/zappy", - "vcs": "git", - "revision": "2533cb5b45cc6c07421468ce262899ddc9d53fb7", - "branch": "master", - "notests": true - }, { "importpath": "github.com/d4l3k/messagediff", "repository": "https://github.com/d4l3k/messagediff", @@ -181,6 +114,14 @@ "branch": "master", "notests": true }, + { + "importpath": "github.com/dustin/go-humanize", + "repository": "https://github.com/dustin/go-humanize", + "vcs": "git", + "revision": "bb3d318650d48840a39aa21a027c6630e198e626", + "branch": "master", + "notests": true + }, { "importpath": "github.com/edsrzf/mmap-go", "repository": "https://github.com/edsrzf/mmap-go", @@ -189,6 +130,22 @@ "branch": "master", "notests": true }, + { + "importpath": "github.com/gernest/wow", + "repository": "https://github.com/gernest/wow", + "vcs": "git", + "revision": "7e0b2a2398989a5d220eebac5742d45422ba7de8", + "branch": "master", + "notests": true + }, + { + "importpath": "github.com/go-ini/ini", + "repository": "https://github.com/go-ini/ini", + "vcs": "git", + "revision": "32e4c1e6bc4e7d0d8451aa6b75200d19e37a536a", + "branch": "master", + "notests": true + }, { "importpath": "github.com/gobwas/glob", "repository": "https://github.com/gobwas/glob", @@ -201,9 +158,10 @@ "importpath": "github.com/gogo/protobuf", "repository": "https://github.com/gogo/protobuf", "vcs": "git", - "revision": "35b81a066e522fb86ece043a8ef1dbfa10b4fed1", + "revision": "160de10b2537169b5ae3e7e221d28269ef40d311", "branch": "master", - "notests": true + "notests": true, + "allfiles": true }, { "importpath": "github.com/golang/groupcache/lru", @@ -281,10 +239,62 @@ "notests": true }, { - "importpath": "github.com/lib/pq", - "repository": "https://github.com/lib/pq", + "importpath": "github.com/magefile/mage/mg", + "repository": "https://github.com/magefile/mage", "vcs": "git", - "revision": "83612a56d3dd153a94a629cd64925371c9adad78", + "revision": "63768081a3236a7c6c53ef72e402ae1fe1664b61", + "branch": "master", + "path": "/mg", + "notests": true + }, + { + "importpath": "github.com/magefile/mage/sh", + "repository": "https://github.com/magefile/mage", + "vcs": "git", + "revision": "63768081a3236a7c6c53ef72e402ae1fe1664b61", + "branch": "master", + "path": "sh", + "notests": true + }, + { + "importpath": "github.com/magefile/mage/types", + "repository": "https://github.com/magefile/mage", + "vcs": "git", + "revision": "63768081a3236a7c6c53ef72e402ae1fe1664b61", + "branch": "master", + "path": "types", + "notests": true + }, + { + "importpath": "github.com/mattn/go-runewidth", + "repository": "https://github.com/mattn/go-runewidth", + "vcs": "git", + "revision": "97311d9f7767e3d6f422ea06661bc2c7a19e8a5d", + "branch": "master", + "notests": true + }, + { + "importpath": "github.com/matttproud/golang_protobuf_extensions/pbutil", + "repository": "https://github.com/matttproud/golang_protobuf_extensions", + "vcs": "git", + "revision": "c12348ce28de40eed0136aa2b644d0ee0650e56c", + "branch": "master", + "path": "/pbutil", + "notests": true + }, + { + "importpath": "github.com/minio/cli", + "repository": "https://github.com/minio/cli", + "vcs": "git", + "revision": "45db1f8a055198ad8c12754026cb2c51c584c756", + "branch": "master", + "notests": true + }, + { + "importpath": "github.com/minio/minio-go", + "repository": "https://github.com/minio/minio-go", + "vcs": "git", + "revision": "17b9efe2ee358a550ff2d414160b75fc85c86f2e", "branch": "master", "notests": true }, @@ -296,6 +306,14 @@ "branch": "master", "notests": true }, + { + "importpath": "github.com/mitchellh/go-homedir", + "repository": "https://github.com/mitchellh/go-homedir", + "vcs": "git", + "revision": "b8bc1bf767474819792c23f32d8286a45736f1c6", + "branch": "master", + "notests": true + }, { "importpath": "github.com/onsi/ginkgo", "repository": "https://github.com/onsi/ginkgo", @@ -344,6 +362,59 @@ "branch": "master", "notests": true }, + { + "importpath": "github.com/prometheus/client_golang/prometheus", + "repository": "https://github.com/prometheus/client_golang", + "vcs": "git", + "revision": "180b8fdc22b4ea7750bcb43c925277654a1ea2f3", + "branch": "master", + "path": "/prometheus", + "notests": true + }, + { + "importpath": "github.com/prometheus/client_model/go", + "repository": "https://github.com/prometheus/client_model", + "vcs": "git", + "revision": "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c", + "branch": "master", + "path": "/go", + "notests": true + }, + { + "importpath": "github.com/prometheus/common/expfmt", + "repository": "https://github.com/prometheus/common", + "vcs": "git", + "revision": "2e54d0b93cba2fd133edc32211dcc32c06ef72ca", + "branch": "master", + "path": "expfmt", + "notests": true + }, + { + "importpath": "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg", + "repository": "https://github.com/prometheus/common", + "vcs": "git", + "revision": "2e54d0b93cba2fd133edc32211dcc32c06ef72ca", + "branch": "master", + "path": "internal/bitbucket.org/ww/goautoneg", + "notests": true + }, + { + "importpath": "github.com/prometheus/common/model", + "repository": "https://github.com/prometheus/common", + "vcs": "git", + "revision": "2e54d0b93cba2fd133edc32211dcc32c06ef72ca", + "branch": "master", + "path": "/model", + "notests": true + }, + { + "importpath": "github.com/prometheus/procfs", + "repository": "https://github.com/prometheus/procfs", + "vcs": "git", + "revision": "b15cd069a83443be3154b719d0cc9fe8117f09fb", + "branch": "master", + "notests": true + }, { "importpath": "github.com/rcrowley/go-metrics", "repository": "https://github.com/rcrowley/go-metrics", @@ -368,6 +439,14 @@ "branch": "master", "notests": true }, + { + "importpath": "github.com/sirupsen/logrus", + "repository": "https://github.com/sirupsen/logrus", + "vcs": "git", + "revision": "d682213848ed68c0a260ca37d6dd5ace8423f5ba", + "branch": "master", + "notests": true + }, { "importpath": "github.com/stathat/go", "repository": "https://github.com/stathat/go", @@ -514,6 +593,15 @@ "path": "salsa20", "notests": true }, + { + "importpath": "golang.org/x/crypto/ssh/terminal", + "repository": "https://go.googlesource.com/crypto", + "vcs": "git", + "revision": "0fcca4842a8d74bfddc2c96a073bd2a4d2a7a2e8", + "branch": "master", + "path": "/ssh/terminal", + "notests": true + }, { "importpath": "golang.org/x/crypto/tea", "repository": "https://go.googlesource.com/crypto", @@ -748,6 +836,14 @@ "path": "/rate", "notests": true }, + { + "importpath": "gopkg.in/urfave/cli.v1", + "repository": "https://gopkg.in/urfave/cli.v1", + "vcs": "git", + "revision": "cfb38830724cc34fedffe9a2a29fb54fa9169cd1", + "branch": "master", + "notests": true + }, { "importpath": "gopkg.in/yaml.v2", "repository": "https://gopkg.in/yaml.v2",